Skip to content

Commit 93b25bd

Browse files
committed
Make trait_map an Option.
1 parent 0839cd5 commit 93b25bd

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

Diff for: compiler/rustc_resolve/src/late.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19591959
if ns == ValueNS {
19601960
let item_name = path.last().unwrap().ident;
19611961
let traits = self.traits_in_scope(item_name, ns);
1962-
self.r.trait_map.insert(id, traits);
1962+
self.r.trait_map.as_mut().unwrap().insert(id, traits);
19631963
}
19641964

19651965
if PrimTy::from_name(path[0].ident.name).is_some() {
@@ -2435,12 +2435,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
24352435
// the field name so that we can do some nice error reporting
24362436
// later on in typeck.
24372437
let traits = self.traits_in_scope(ident, ValueNS);
2438-
self.r.trait_map.insert(expr.id, traits);
2438+
self.r.trait_map.as_mut().unwrap().insert(expr.id, traits);
24392439
}
24402440
ExprKind::MethodCall(ref segment, ..) => {
24412441
debug!("(recording candidate traits for expr) recording traits for {}", expr.id);
24422442
let traits = self.traits_in_scope(segment.ident, ValueNS);
2443-
self.r.trait_map.insert(expr.id, traits);
2443+
self.r.trait_map.as_mut().unwrap().insert(expr.id, traits);
24442444
}
24452445
_ => {
24462446
// Nothing to do.

Diff for: compiler/rustc_resolve/src/lib.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,7 @@ pub struct Resolver<'a> {
909909
/// `CrateNum` resolutions of `extern crate` items.
910910
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
911911
export_map: ExportMap<LocalDefId>,
912-
trait_map: NodeMap<Vec<TraitCandidate>>,
913-
#[cfg(debug_assertions)]
914-
took_trait_map: bool,
912+
trait_map: Option<NodeMap<Vec<TraitCandidate>>>,
915913

916914
/// A map from nodes to anonymous modules.
917915
/// Anonymous modules are pseudo-modules that are implicitly created around items
@@ -1141,12 +1139,7 @@ impl ResolverAstLowering for Resolver<'_> {
11411139
}
11421140

11431141
fn take_trait_map(&mut self) -> NodeMap<Vec<TraitCandidate>> {
1144-
#[cfg(debug_assertions)]
1145-
{
1146-
debug_assert!(!self.took_trait_map);
1147-
self.took_trait_map = true;
1148-
}
1149-
std::mem::take(&mut self.trait_map)
1142+
std::mem::replace(&mut self.trait_map, None).unwrap()
11501143
}
11511144

11521145
fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
@@ -1293,9 +1286,7 @@ impl<'a> Resolver<'a> {
12931286
label_res_map: Default::default(),
12941287
extern_crate_map: Default::default(),
12951288
export_map: FxHashMap::default(),
1296-
trait_map: Default::default(),
1297-
#[cfg(debug_assertions)]
1298-
took_trait_map: false,
1289+
trait_map: Some(NodeMap::default()),
12991290
underscore_disambiguator: 0,
13001291
empty_module,
13011292
module_map,

0 commit comments

Comments
 (0)