Skip to content

Commit 6338176

Browse files
interior mutability for (single,multi)_segment_macro_resolutions
1 parent 5711bff commit 6338176

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

compiler/rustc_resolve/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,11 @@ pub struct Resolver<'ra, 'tcx> {
11601160
unused_macro_rules: FxIndexMap<NodeId, DenseBitSet<usize>>,
11611161
proc_macro_stubs: FxHashSet<LocalDefId>,
11621162
/// Traces collected during macro resolution and validated when it's complete.
1163+
// FIXME: Remove interior mutability when speculative resolution produces these as outputs.
11631164
single_segment_macro_resolutions:
1164-
Vec<(Ident, MacroKind, ParentScope<'ra>, Option<NameBinding<'ra>>, Option<Span>)>,
1165+
RefCell<Vec<(Ident, MacroKind, ParentScope<'ra>, Option<NameBinding<'ra>>, Option<Span>)>>,
11651166
multi_segment_macro_resolutions:
1166-
Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'ra>, Option<Res>, Namespace)>,
1167+
RefCell<Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'ra>, Option<Res>, Namespace)>>,
11671168
builtin_attrs: Vec<(Ident, ParentScope<'ra>)>,
11681169
/// `derive(Copy)` marks items they are applied to so they are treated specially later.
11691170
/// Derive macros cannot modify the item themselves and have to store the markers in the global

compiler/rustc_resolve/src/macros.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
782782

783783
if trace {
784784
let kind = kind.expect("macro kind must be specified if tracing is enabled");
785-
self.res_mut().multi_segment_macro_resolutions.push((
785+
// FIXME: Should be an output of Speculative Resolution.
786+
self.multi_segment_macro_resolutions.borrow_mut().push((
786787
path,
787788
path_span,
788789
kind,
@@ -811,7 +812,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
811812

812813
if trace {
813814
let kind = kind.expect("macro kind must be specified if tracing is enabled");
814-
self.res_mut().single_segment_macro_resolutions.push((
815+
// FIXME: Should be an output of Speculative Resolution.
816+
self.single_segment_macro_resolutions.borrow_mut().push((
815817
path[0].ident,
816818
kind,
817819
*parent_scope,
@@ -877,7 +879,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
877879
}
878880
};
879881

880-
let macro_resolutions = mem::take(&mut self.multi_segment_macro_resolutions);
882+
// FIXME: Should be an output of Speculative Resolution.
883+
let macro_resolutions = self.multi_segment_macro_resolutions.take();
881884
for (mut path, path_span, kind, parent_scope, initial_res, ns) in macro_resolutions {
882885
// FIXME: Path resolution will ICE if segment IDs present.
883886
for seg in &mut path {
@@ -954,7 +957,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
954957
}
955958
}
956959

957-
let macro_resolutions = mem::take(&mut self.single_segment_macro_resolutions);
960+
// FIXME: Should be an output of Speculative Resolution.
961+
let macro_resolutions = self.single_segment_macro_resolutions.take();
958962
for (ident, kind, parent_scope, initial_binding, sugg_span) in macro_resolutions {
959963
match self.smart().early_resolve_ident_in_lexical_scope(
960964
ident,

0 commit comments

Comments
 (0)