Skip to content

Commit

Permalink
Make trait_map an Option.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jun 1, 2021
1 parent 0839cd5 commit 93b25bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Expand Up @@ -1959,7 +1959,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
if ns == ValueNS {
let item_name = path.last().unwrap().ident;
let traits = self.traits_in_scope(item_name, ns);
self.r.trait_map.insert(id, traits);
self.r.trait_map.as_mut().unwrap().insert(id, traits);
}

if PrimTy::from_name(path[0].ident.name).is_some() {
Expand Down Expand Up @@ -2435,12 +2435,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
// the field name so that we can do some nice error reporting
// later on in typeck.
let traits = self.traits_in_scope(ident, ValueNS);
self.r.trait_map.insert(expr.id, traits);
self.r.trait_map.as_mut().unwrap().insert(expr.id, traits);
}
ExprKind::MethodCall(ref segment, ..) => {
debug!("(recording candidate traits for expr) recording traits for {}", expr.id);
let traits = self.traits_in_scope(segment.ident, ValueNS);
self.r.trait_map.insert(expr.id, traits);
self.r.trait_map.as_mut().unwrap().insert(expr.id, traits);
}
_ => {
// Nothing to do.
Expand Down
15 changes: 3 additions & 12 deletions compiler/rustc_resolve/src/lib.rs
Expand Up @@ -909,9 +909,7 @@ pub struct Resolver<'a> {
/// `CrateNum` resolutions of `extern crate` items.
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
export_map: ExportMap<LocalDefId>,
trait_map: NodeMap<Vec<TraitCandidate>>,
#[cfg(debug_assertions)]
took_trait_map: bool,
trait_map: Option<NodeMap<Vec<TraitCandidate>>>,

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

fn take_trait_map(&mut self) -> NodeMap<Vec<TraitCandidate>> {
#[cfg(debug_assertions)]
{
debug_assert!(!self.took_trait_map);
self.took_trait_map = true;
}
std::mem::take(&mut self.trait_map)
std::mem::replace(&mut self.trait_map, None).unwrap()
}

fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
Expand Down Expand Up @@ -1293,9 +1286,7 @@ impl<'a> Resolver<'a> {
label_res_map: Default::default(),
extern_crate_map: Default::default(),
export_map: FxHashMap::default(),
trait_map: Default::default(),
#[cfg(debug_assertions)]
took_trait_map: false,
trait_map: Some(NodeMap::default()),
underscore_disambiguator: 0,
empty_module,
module_map,
Expand Down

0 comments on commit 93b25bd

Please sign in to comment.