@@ -1482,69 +1482,13 @@ pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any
14821482 where F : FnOnce ( ) -> R + Send + ' static ,
14831483 R : Send + ' static ,
14841484{
1485- #[ cfg( all( unix, not( target_os = "haiku" ) ) ) ]
1486- let spawn_thread = unsafe {
1487- // Fetch the current resource limits
1488- let mut rlim = libc:: rlimit {
1489- rlim_cur : 0 ,
1490- rlim_max : 0 ,
1491- } ;
1492- if libc:: getrlimit ( libc:: RLIMIT_STACK , & mut rlim) != 0 {
1493- let err = io:: Error :: last_os_error ( ) ;
1494- error ! ( "in_rustc_thread: error calling getrlimit: {}" , err) ;
1495- true
1496- } else if rlim. rlim_max < STACK_SIZE as libc:: rlim_t {
1497- true
1498- } else if rlim. rlim_cur < STACK_SIZE as libc:: rlim_t {
1499- std:: rt:: deinit_stack_guard ( ) ;
1500- rlim. rlim_cur = STACK_SIZE as libc:: rlim_t ;
1501- if libc:: setrlimit ( libc:: RLIMIT_STACK , & mut rlim) != 0 {
1502- let err = io:: Error :: last_os_error ( ) ;
1503- error ! ( "in_rustc_thread: error calling setrlimit: {}" , err) ;
1504- std:: rt:: update_stack_guard ( ) ;
1505- true
1506- } else {
1507- std:: rt:: update_stack_guard ( ) ;
1508- false
1509- }
1510- } else {
1511- false
1512- }
1513- } ;
1514-
1515- // We set the stack size at link time. See src/rustc/rustc.rs.
1516- #[ cfg( windows) ]
1517- let spawn_thread = false ;
1518-
1519- #[ cfg( target_os = "haiku" ) ]
1520- let spawn_thread = unsafe {
1521- // Haiku does not have setrlimit implemented for the stack size.
1522- // By default it does have the 16 MB stack limit, but we check this in
1523- // case the minimum STACK_SIZE changes or Haiku's defaults change.
1524- let mut rlim = libc:: rlimit {
1525- rlim_cur : 0 ,
1526- rlim_max : 0 ,
1527- } ;
1528- if libc:: getrlimit ( libc:: RLIMIT_STACK , & mut rlim) != 0 {
1529- let err = io:: Error :: last_os_error ( ) ;
1530- error ! ( "in_rustc_thread: error calling getrlimit: {}" , err) ;
1531- true
1532- } else if rlim. rlim_cur >= STACK_SIZE {
1533- false
1534- } else {
1535- true
1536- }
1537- } ;
1538-
1539- #[ cfg( not( any( windows, unix) ) ) ]
1540- let spawn_thread = true ;
1541-
1542- // The or condition is added from backward compatibility.
1543- if spawn_thread || env:: var_os ( "RUST_MIN_STACK" ) . is_some ( ) {
1485+ // We need a thread for soundness of thread local storage in rustc. For debugging purposes
1486+ // we allow an escape hatch where everything runs on the main thread.
1487+ if env:: var_os ( "RUSTC_UNSTABLE_NO_MAIN_THREAD" ) . is_none ( ) {
15441488 let mut cfg = thread:: Builder :: new ( ) . name ( name) ;
15451489
1546- // FIXME: Hacks on hacks. If the env is trying to override the stack size
1547- // then *don't* set it explicitly .
1490+ // If the env is trying to override the stack size then *don't* set it explicitly.
1491+ // The libstd thread impl will fetch the `RUST_MIN_STACK` env var itself .
15481492 if env:: var_os ( "RUST_MIN_STACK" ) . is_none ( ) {
15491493 cfg = cfg. stack_size ( STACK_SIZE ) ;
15501494 }
0 commit comments