Skip to content

Commit 888a968

Browse files
committed
Add field used: Cell<bool> to variant NameBindingKind::Import.
1 parent 07f8cb2 commit 888a968

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

src/librustc_resolve/lib.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ enum NameBindingKind<'a> {
871871
Import {
872872
binding: &'a NameBinding<'a>,
873873
directive: &'a ImportDirective<'a>,
874+
used: Cell<bool>,
874875
},
875876
Ambiguity {
876877
b1: &'a NameBinding<'a>,
@@ -938,14 +939,6 @@ impl<'a> NameBinding<'a> {
938939
_ => true,
939940
}
940941
}
941-
942-
fn ambiguity(&self) -> Option<(&'a NameBinding<'a>, &'a NameBinding<'a>)> {
943-
match self.kind {
944-
NameBindingKind::Ambiguity { b1, b2 } => Some((b1, b2)),
945-
NameBindingKind::Import { binding, .. } => binding.ambiguity(),
946-
_ => None,
947-
}
948-
}
949942
}
950943

951944
/// Interns the names of the primitive types.
@@ -1064,7 +1057,7 @@ pub struct Resolver<'a> {
10641057
pub maybe_unused_trait_imports: NodeSet,
10651058

10661059
privacy_errors: Vec<PrivacyError<'a>>,
1067-
ambiguity_errors: Vec<(Span, Name, &'a NameBinding<'a>)>,
1060+
ambiguity_errors: Vec<(Span, Name, &'a NameBinding<'a>, &'a NameBinding<'a>)>,
10681061

10691062
arenas: &'a ResolverArenas<'a>,
10701063
dummy_binding: &'a NameBinding<'a>,
@@ -1276,18 +1269,20 @@ impl<'a> Resolver<'a> {
12761269
self.used_crates.insert(krate);
12771270
}
12781271

1279-
if binding.ambiguity().is_some() {
1280-
self.ambiguity_errors.push((span, name, binding));
1281-
return true;
1282-
}
1283-
1284-
if let NameBindingKind::Import { directive, binding } = binding.kind {
1285-
self.used_imports.insert((directive.id, ns));
1286-
self.add_to_glob_map(directive.id, name);
1287-
self.record_use(name, ns, binding, span);
1272+
match binding.kind {
1273+
NameBindingKind::Import { directive, binding, ref used } if !used.get() => {
1274+
used.set(true);
1275+
self.used_imports.insert((directive.id, ns));
1276+
self.add_to_glob_map(directive.id, name);
1277+
self.record_use(name, ns, binding, span)
1278+
}
1279+
NameBindingKind::Import { .. } => false,
1280+
NameBindingKind::Ambiguity { b1, b2 } => {
1281+
self.ambiguity_errors.push((span, name, b1, b2));
1282+
true
1283+
}
1284+
_ => false
12881285
}
1289-
1290-
false
12911286
}
12921287

12931288
fn add_to_glob_map(&mut self, id: NodeId, name: Name) {
@@ -3307,9 +3302,8 @@ impl<'a> Resolver<'a> {
33073302
fn report_errors(&self) {
33083303
let mut reported_spans = FnvHashSet();
33093304

3310-
for &(span, name, binding) in &self.ambiguity_errors {
3305+
for &(span, name, b1, b2) in &self.ambiguity_errors {
33113306
if !reported_spans.insert(span) { continue }
3312-
let (b1, b2) = binding.ambiguity().unwrap();
33133307
let msg1 = format!("`{}` could resolve to the name imported here", name);
33143308
let msg2 = format!("`{}` could also resolve to the name imported here", name);
33153309
self.session.struct_span_err(span, &format!("`{}` is ambiguous", name))

src/librustc_resolve/resolve_imports.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ impl<'a> Resolver<'a> {
308308
kind: NameBindingKind::Import {
309309
binding: binding,
310310
directive: directive,
311+
used: Cell::new(false),
311312
},
312313
span: directive.span,
313314
vis: vis,

0 commit comments

Comments
 (0)