提交 888a9681 编写于 作者: J Jeffrey Seyfried

Add field `used: Cell<bool>` to variant `NameBindingKind::Import`.

上级 07f8cb28
......@@ -871,6 +871,7 @@ enum NameBindingKind<'a> {
Import {
binding: &'a NameBinding<'a>,
directive: &'a ImportDirective<'a>,
used: Cell<bool>,
},
Ambiguity {
b1: &'a NameBinding<'a>,
......@@ -938,14 +939,6 @@ fn is_importable(&self) -> bool {
_ => true,
}
}
fn ambiguity(&self) -> Option<(&'a NameBinding<'a>, &'a NameBinding<'a>)> {
match self.kind {
NameBindingKind::Ambiguity { b1, b2 } => Some((b1, b2)),
NameBindingKind::Import { binding, .. } => binding.ambiguity(),
_ => None,
}
}
}
/// Interns the names of the primitive types.
......@@ -1064,7 +1057,7 @@ pub struct Resolver<'a> {
pub maybe_unused_trait_imports: NodeSet,
privacy_errors: Vec<PrivacyError<'a>>,
ambiguity_errors: Vec<(Span, Name, &'a NameBinding<'a>)>,
ambiguity_errors: Vec<(Span, Name, &'a NameBinding<'a>, &'a NameBinding<'a>)>,
arenas: &'a ResolverArenas<'a>,
dummy_binding: &'a NameBinding<'a>,
......@@ -1276,18 +1269,20 @@ fn record_use(&mut self, name: Name, ns: Namespace, binding: &'a NameBinding<'a>
self.used_crates.insert(krate);
}
if binding.ambiguity().is_some() {
self.ambiguity_errors.push((span, name, binding));
return true;
}
if let NameBindingKind::Import { directive, binding } = binding.kind {
self.used_imports.insert((directive.id, ns));
self.add_to_glob_map(directive.id, name);
self.record_use(name, ns, binding, span);
match binding.kind {
NameBindingKind::Import { directive, binding, ref used } if !used.get() => {
used.set(true);
self.used_imports.insert((directive.id, ns));
self.add_to_glob_map(directive.id, name);
self.record_use(name, ns, binding, span)
}
NameBindingKind::Import { .. } => false,
NameBindingKind::Ambiguity { b1, b2 } => {
self.ambiguity_errors.push((span, name, b1, b2));
true
}
_ => false
}
false
}
fn add_to_glob_map(&mut self, id: NodeId, name: Name) {
......@@ -3307,9 +3302,8 @@ fn is_accessible_from(&self, vis: ty::Visibility, module: Module<'a>) -> bool {
fn report_errors(&self) {
let mut reported_spans = FnvHashSet();
for &(span, name, binding) in &self.ambiguity_errors {
for &(span, name, b1, b2) in &self.ambiguity_errors {
if !reported_spans.insert(span) { continue }
let (b1, b2) = binding.ambiguity().unwrap();
let msg1 = format!("`{}` could resolve to the name imported here", name);
let msg2 = format!("`{}` could also resolve to the name imported here", name);
self.session.struct_span_err(span, &format!("`{}` is ambiguous", name))
......
......@@ -308,6 +308,7 @@ fn import(&mut self, binding: &'a NameBinding<'a>, directive: &'a ImportDirectiv
kind: NameBindingKind::Import {
binding: binding,
directive: directive,
used: Cell::new(false),
},
span: directive.span,
vis: vis,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册