pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any + Send>>
    where F: FnOnce() -> R + Send + 'static,
          R: Send + 'static,
{
    // Temporarily have stack size set to 16MB to deal with nom-using crates failing
    const STACK_SIZE: usize = 16 * 1024 * 1024; // 16MB

    #[cfg(all(unix,not(target_os = "haiku")))]
    let spawn_thread = unsafe {
        // Fetch the current resource limits
        let mut rlim = libc::rlimit {
            rlim_cur: 0,
            rlim_max: 0,
        };
        if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 {
            let err = io::Error::last_os_error();
            error!("in_rustc_thread: error calling getrlimit: {}", err);
            true
        } else if rlim.rlim_max < STACK_SIZE as libc::rlim_t {
            true
        } else if rlim.rlim_cur < STACK_SIZE as libc::rlim_t {
            std::rt::deinit_stack_guard();
            rlim.rlim_cur = STACK_SIZE as libc::rlim_t;
            if libc::setrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 {
                let err = io::Error::last_os_error();
                error!("in_rustc_thread: error calling setrlimit: {}", err);
                std::rt::update_stack_guard();
                true
            } else {
                std::rt::update_stack_guard();
                false
            }
        } else {
            false
        }
    };

    // We set the stack size at link time. See src/rustc/rustc.rs.
    #[cfg(windows)]
    let spawn_thread = false;

    #[cfg(target_os = "haiku")]
    let spawn_thread = unsafe {
        // Haiku does not have setrlimit implemented for the stack size.
        // By default it does have the 16 MB stack limit, but we check this in
        // case the minimum STACK_SIZE changes or Haiku's defaults change.
        let mut rlim = libc::rlimit {
            rlim_cur: 0,
            rlim_max: 0,
        };
        if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 {
            let err = io::Error::last_os_error();
            error!("in_rustc_thread: error calling getrlimit: {}", err);
            true
        } else if rlim.rlim_cur >= STACK_SIZE {
            false
        } else {
            true
        }
    };

    #[cfg(not(any(windows,unix)))]
    let spawn_thread = true;

    // The or condition is added from backward compatibility.
    if spawn_thread || env::var_os("RUST_MIN_STACK").is_some() {
        let mut cfg = thread::Builder::new().name(name);

        // FIXME: Hacks on hacks. If the env is trying to override the stack size
        // then *don't* set it explicitly.
        if env::var_os("RUST_MIN_STACK").is_none() {
            cfg = cfg.stack_size(STACK_SIZE);
        }

        let thread = cfg.spawn(f);
        thread.unwrap().join()
    } else {
        let f = panic::AssertUnwindSafe(f);
        panic::catch_unwind(f)
    }
}
/// Runs `f` in a suitable thread for running `rustc`; returns a `Result` with either the return
/// value of `f` or -- if a panic occurs -- the panic value.
///
/// This version applies the given name to the thread. This is used by rustdoc to ensure consistent
/// doctest output across platforms and executions.


This version applies the given name to the thread. This is used by rustdoc to ensure consistent
doctest output across platforms and executions.
This version applies the given name to the thread . This is used by rustdoc to ensure consistent doctest output across platforms and executions .
pub fn in_named_rustc_thread<F, R>(name: String, f: F) -> Result<R, Box<dyn Any + Send>>
    where F: FnOnce() -> R + Send + 'static,
          R: Send + 'static,
{
    // Temporarily have stack size set to 16MB to deal with nom-using crates failing
    const STACK_SIZE: usize = 16 * 1024 * 1024; // 16MB
    #[cfg(all(unix,not(target_os = "haiku")))]
    let spawn_thread = unsafe {
        // Fetch the current resource limits
        let mut rlim = libc::rlimit {
            rlim_cur: 0,
            rlim_max: 0,
        };
        if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 {
            let err = io::Error::last_os_error();
            error!("in_rustc_thread: error calling getrlimit: {}", err);
            true
        } else if rlim.rlim_max < STACK_SIZE as libc::rlim_t {
            true
        } else if rlim.rlim_cur < STACK_SIZE as libc::rlim_t {
            std::rt::deinit_stack_guard();
            rlim.rlim_cur = STACK_SIZE as libc::rlim_t;
            if libc::setrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 {
                let err = io::Error::last_os_error();
                error!("in_rustc_thread: error calling setrlimit: {}", err);
                std::rt::update_stack_guard();
                true
            } else {
                std::rt::update_stack_guard();
                false
            }
        } else {
            false
        }
    };
    // We set the stack size at link time. See src/rustc/rustc.rs.
    #[cfg(windows)]
    let spawn_thread = false;
    #[cfg(target_os = "haiku")]
    let spawn_thread = unsafe {
        // Haiku does not have setrlimit implemented for the stack size.
        // By default it does have the 16 MB stack limit, but we check this in
        // case the minimum STACK_SIZE changes or Haiku's defaults change.
        let mut rlim = libc::rlimit {
            rlim_cur: 0,
            rlim_max: 0,
        };
        if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 {
            let err = io::Error::last_os_error();
            error!("in_rustc_thread: error calling getrlimit: {}", err);
            true
        } else if rlim.rlim_cur >= STACK_SIZE {
            false
        } else {
            true
        }
    };
    #[cfg(not(any(windows,unix)))]
    let spawn_thread = true;
    // The or condition is added from backward compatibility.
    if spawn_thread || env::var_os("RUST_MIN_STACK").is_some() {
        let mut cfg = thread::Builder::new().name(name);
        // FIXME: Hacks on hacks. If the env is trying to override the stack size
        // then *don't* set it explicitly.
        if env::var_os("RUST_MIN_STACK").is_none() {
            cfg = cfg.stack_size(STACK_SIZE);
        }
        let thread = cfg.spawn(f);
        thread.unwrap().join()
    } else {
        let f = panic::AssertUnwindSafe(f);
        panic::catch_unwind(f)
    }
}
pub fn in_named_rustc_thread < F , R > ( name : String , f : F ) -> Result < R , Box < dyn Any + Send > > where F : FnOnce ( ) -> R + Send + ' static , R : Send + ' static , { // Temporarily have stack size set to 16MB to deal with nom-using crates failing const STACK_SIZE : usize = 16 * 1024 * 1024 ; // 16MB # [ cfg ( all ( unix not ( target_os " " ) ) ) ] let spawn_thread = unsafe { // Fetch the current resource limits let mut rlim = libc :: rlimit { rlim_cur : 0 , rlim_max : 0 , } ; if libc :: getrlimit ( libc :: RLIMIT_STACK , & mut rlim ) != 0 { let err = io :: Error :: last_os_error ( ) ; error ! ( " " err ) ; true } else if rlim . rlim_max < STACK_SIZE as libc :: rlim_t { true } else if rlim . rlim_cur < STACK_SIZE as libc :: rlim_t { std :: rt :: deinit_stack_guard ( ) ; rlim . rlim_cur = STACK_SIZE as libc :: rlim_t ; if libc :: setrlimit ( libc :: RLIMIT_STACK , & mut rlim ) != 0 { let err = io :: Error :: last_os_error ( ) ; error ! ( " " err ) ; std :: rt :: update_stack_guard ( ) ; true } else { std :: rt :: update_stack_guard ( ) ; false } } else { false } } ; // We set the stack size at link time. See src/rustc/rustc.rs. # [ cfg ( windows ) ] let spawn_thread = false ; # [ cfg ( target_os " " ) ] let spawn_thread = unsafe { // Haiku does not have setrlimit implemented for the stack size. // By default it does have the 16 MB stack limit, but we check this in // case the minimum STACK_SIZE changes or Haiku's defaults change. let mut rlim = libc :: rlimit { rlim_cur : 0 , rlim_max : 0 , } ; if libc :: getrlimit ( libc :: RLIMIT_STACK , & mut rlim ) != 0 { let err = io :: Error :: last_os_error ( ) ; error ! ( " " err ) ; true } else if rlim . rlim_cur >= STACK_SIZE { false } else { true } } ; # [ cfg ( not ( any ( windows unix ) ) ) ] let spawn_thread = true ; // The or condition is added from backward compatibility. if spawn_thread || env :: var_os ( " " ) . is_some ( ) { let mut cfg = thread :: Builder :: new ( ) . name ( name ) ; // FIXME: Hacks on hacks. If the env is trying to override the stack size // then *don't* set it explicitly. if env :: var_os ( " " ) . is_none ( ) { cfg = cfg . stack_size ( STACK_SIZE ) ; } let thread = cfg . spawn ( f ) ; thread . unwrap ( ) . join ( ) } else { let f = panic :: AssertUnwindSafe ( f ) ; panic :: catch_unwind ( f ) } }
Runs `f` in a suitable thread for running `rustc`; returns a `Result` with either the return
value of `f` or -- if a panic occurs -- the panic value.
Runs ` f ` in a suitable thread for running ` rustc ` ; returns a ` Result ` with either the return value of ` f ` or -- if a panic occurs -- the panic value .
name
String
f
F
name
String
f
F