Skip to content

Commit 8745fdc

Browse files
committed
Replace a lazy RefCell<Option<T>> with OnceCell<T>
1 parent 6cacb52 commit 8745fdc

File tree

1 file changed

+3
-4
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+3
-4
lines changed

Diff for: compiler/rustc_mir_transform/src/coverage/spans.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt;
1111
use rustc_span::source_map::original_sp;
1212
use rustc_span::{BytePos, ExpnKind, MacroKind, Span, Symbol};
1313

14-
use std::cell::RefCell;
14+
use std::cell::OnceCell;
1515
use std::cmp::Ordering;
1616

1717
#[derive(Debug, Copy, Clone)]
@@ -67,7 +67,7 @@ impl CoverageStatement {
6767
pub(super) struct CoverageSpan {
6868
pub span: Span,
6969
pub expn_span: Span,
70-
pub current_macro_or_none: RefCell<Option<Option<Symbol>>>,
70+
pub current_macro_or_none: OnceCell<Option<Symbol>>,
7171
pub bcb: BasicCoverageBlock,
7272
pub coverage_statements: Vec<CoverageStatement>,
7373
pub is_closure: bool,
@@ -175,8 +175,7 @@ impl CoverageSpan {
175175
/// If the span is part of a macro, returns the macro name symbol.
176176
pub fn current_macro(&self) -> Option<Symbol> {
177177
self.current_macro_or_none
178-
.borrow_mut()
179-
.get_or_insert_with(|| {
178+
.get_or_init(|| {
180179
if let ExpnKind::Macro(MacroKind::Bang, current_macro) =
181180
self.expn_span.ctxt().outer_expn_data().kind
182181
{

0 commit comments

Comments
 (0)