Auto merge of #89031 - the8472:outline-once-cell-init-closure, r=Mark-Simulacrum
Don't inline OnceCell initialization closures The more general variant of #89026, originally suggested in https://github.com/rust-lang/rust/pull/86898#issuecomment-920138051
This commit is contained in:
commit
7a3d1a5f3d
@ -214,7 +214,16 @@ pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E>
|
||||
if let Some(val) = self.get() {
|
||||
return Ok(val);
|
||||
}
|
||||
let val = f()?;
|
||||
/// Avoid inlining the initialization closure into the common path that fetches
|
||||
/// the already initialized value
|
||||
#[cold]
|
||||
fn outlined_call<F, T, E>(f: F) -> Result<T, E>
|
||||
where
|
||||
F: FnOnce() -> Result<T, E>,
|
||||
{
|
||||
f()
|
||||
}
|
||||
let val = outlined_call(f)?;
|
||||
// Note that *some* forms of reentrant initialization might lead to
|
||||
// UB (see `reentrant_init` test). I believe that just removing this
|
||||
// `assert`, while keeping `set/get` would be sound, but it seems
|
||||
|
Loading…
Reference in New Issue
Block a user