diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-07-28 19:51:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-28 19:51:16 +0200 |
| commit | 048794d62445c03e90b738f936cd0aac80e72a87 (patch) | |
| tree | 05802e31103b73498a791446d7e7f29a04d3f28b /compiler | |
| parent | 76f0a8c30c0fb2f3315d7eeddd38474a2b63f246 (diff) | |
| parent | 8745fdc4487d6200ec652abc05b7a1ac9bb16765 (diff) | |
| download | rust-048794d62445c03e90b738f936cd0aac80e72a87.tar.gz rust-048794d62445c03e90b738f936cd0aac80e72a87.zip | |
Rollup merge of #114155 - Zalathar:once-cell, r=lcnr
Replace a lazy `RefCell<Option<T>>` with `OnceCell<T>` This code was using `RefCell<Option<T>>` to manually implement lazy initialization. Now that we have `OnceCell` in the standard library, we can just use that instead. In particular, this avoids a confusing doubly-nested option, because the value being lazily computed is itself an `Option<Symbol>`.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/spans.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index 35cf9ea5f91..deebf5345ba 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt; use rustc_span::source_map::original_sp; use rustc_span::{BytePos, ExpnKind, MacroKind, Span, Symbol}; -use std::cell::RefCell; +use std::cell::OnceCell; use std::cmp::Ordering; #[derive(Debug, Copy, Clone)] @@ -67,7 +67,7 @@ impl CoverageStatement { pub(super) struct CoverageSpan { pub span: Span, pub expn_span: Span, - pub current_macro_or_none: RefCell<Option<Option<Symbol>>>, + pub current_macro_or_none: OnceCell<Option<Symbol>>, pub bcb: BasicCoverageBlock, pub coverage_statements: Vec<CoverageStatement>, pub is_closure: bool, @@ -175,8 +175,7 @@ impl CoverageSpan { /// If the span is part of a macro, returns the macro name symbol. pub fn current_macro(&self) -> Option<Symbol> { self.current_macro_or_none - .borrow_mut() - .get_or_insert_with(|| { + .get_or_init(|| { if let ExpnKind::Macro(MacroKind::Bang, current_macro) = self.expn_span.ctxt().outer_expn_data().kind { |
