resolve: Remove artificial import ambiguity errors
This commit is contained in:
parent
de22388873
commit
4dcce38cda
22 changed files with 53 additions and 230 deletions
|
@ -1403,7 +1403,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
for ns in [Namespace::MacroNS, Namespace::TypeNS, Namespace::ValueNS] {
|
||||
if let Ok(binding) = self.early_resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
ScopeSet::All(ns, false),
|
||||
ScopeSet::All(ns),
|
||||
&parent_scope,
|
||||
None,
|
||||
false,
|
||||
|
@ -1841,10 +1841,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
_ => None,
|
||||
}
|
||||
} else {
|
||||
let scopes = ScopeSet::All(ns_to_try, opt_ns.is_none());
|
||||
self.early_resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
scopes,
|
||||
ScopeSet::All(ns_to_try),
|
||||
parent_scope,
|
||||
None,
|
||||
false,
|
||||
|
|
|
@ -88,7 +88,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
let rust_2015 = ctxt.edition().is_rust_2015();
|
||||
let (ns, macro_kind, is_absolute_path) = match scope_set {
|
||||
ScopeSet::All(ns, _) => (ns, None, false),
|
||||
ScopeSet::All(ns) => (ns, None, false),
|
||||
ScopeSet::AbsolutePath(ns) => (ns, None, true),
|
||||
ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind), false),
|
||||
ScopeSet::Late(ns, ..) => (ns, None, false),
|
||||
|
@ -397,11 +397,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
return Err(Determinacy::Determined);
|
||||
}
|
||||
|
||||
let (ns, macro_kind, is_import) = match scope_set {
|
||||
ScopeSet::All(ns, is_import) => (ns, None, is_import),
|
||||
ScopeSet::AbsolutePath(ns) => (ns, None, false),
|
||||
ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind), false),
|
||||
ScopeSet::Late(ns, ..) => (ns, None, false),
|
||||
let (ns, macro_kind) = match scope_set {
|
||||
ScopeSet::All(ns) => (ns, None),
|
||||
ScopeSet::AbsolutePath(ns) => (ns, None),
|
||||
ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind)),
|
||||
ScopeSet::Late(ns, ..) => (ns, None),
|
||||
};
|
||||
|
||||
// This is *the* result, resolution from the scope closest to the resolved identifier.
|
||||
|
@ -631,9 +631,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let derive_helper_compat =
|
||||
Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat);
|
||||
|
||||
let ambiguity_error_kind = if is_import {
|
||||
Some(AmbiguityKind::Import)
|
||||
} else if is_builtin(innermost_res) || is_builtin(res) {
|
||||
let ambiguity_error_kind = if is_builtin(innermost_res)
|
||||
|| is_builtin(res)
|
||||
{
|
||||
Some(AmbiguityKind::BuiltinAttr)
|
||||
} else if innermost_res == derive_helper_compat
|
||||
|| res == derive_helper_compat && innermost_res != derive_helper
|
||||
|
@ -853,10 +853,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
let scopes = ScopeSet::All(ns, true);
|
||||
let binding = self.early_resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
scopes,
|
||||
ScopeSet::All(ns),
|
||||
parent_scope,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
|
@ -1497,7 +1496,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
} else {
|
||||
self.early_resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
ScopeSet::All(ns, opt_ns.is_none()),
|
||||
ScopeSet::All(ns),
|
||||
parent_scope,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
|
|
|
@ -10,10 +10,7 @@ use crate::errors::{
|
|||
use crate::Determinacy::{self, *};
|
||||
use crate::{fluent_generated as fluent, Namespace::*};
|
||||
use crate::{module_to_string, names_to_string, ImportSuggestion};
|
||||
use crate::{
|
||||
AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingKey, ModuleKind, ResolutionError,
|
||||
Resolver, Segment,
|
||||
};
|
||||
use crate::{AmbiguityKind, BindingKey, ModuleKind, ResolutionError, Resolver, Segment};
|
||||
use crate::{Finalize, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet};
|
||||
use crate::{NameBinding, NameBindingKind, PathResult};
|
||||
|
||||
|
@ -984,7 +981,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
match binding {
|
||||
Ok(binding) => {
|
||||
// Consistency checks, analogous to `finalize_macro_resolutions`.
|
||||
let initial_binding = source_bindings[ns].get().map(|initial_binding| {
|
||||
let initial_res = source_bindings[ns].get().map(|initial_binding| {
|
||||
all_ns_err = false;
|
||||
if let Some(target_binding) = target_bindings[ns].get() {
|
||||
if target.name == kw::Underscore
|
||||
|
@ -998,20 +995,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
);
|
||||
}
|
||||
}
|
||||
initial_binding
|
||||
initial_binding.res()
|
||||
});
|
||||
let res = binding.res();
|
||||
if let Ok(initial_binding) = initial_binding {
|
||||
let initial_res = initial_binding.res();
|
||||
if let Ok(initial_res) = initial_res {
|
||||
if res != initial_res && this.ambiguity_errors.is_empty() {
|
||||
this.ambiguity_errors.push(AmbiguityError {
|
||||
kind: AmbiguityKind::Import,
|
||||
ident,
|
||||
b1: initial_binding,
|
||||
b2: binding,
|
||||
misc1: AmbiguityErrorMisc::None,
|
||||
misc2: AmbiguityErrorMisc::None,
|
||||
});
|
||||
span_bug!(import.span, "inconsistent resolution for an import");
|
||||
}
|
||||
} else if res != Res::Err
|
||||
&& this.ambiguity_errors.is_empty()
|
||||
|
@ -1283,7 +1272,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
match this.early_resolve_ident_in_lexical_scope(
|
||||
target,
|
||||
ScopeSet::All(ns, false),
|
||||
ScopeSet::All(ns),
|
||||
&import.parent_scope,
|
||||
None,
|
||||
false,
|
||||
|
|
|
@ -131,7 +131,7 @@ enum Scope<'a> {
|
|||
#[derive(Clone, Copy)]
|
||||
enum ScopeSet<'a> {
|
||||
/// All scopes with the given namespace.
|
||||
All(Namespace, /*is_import*/ bool),
|
||||
All(Namespace),
|
||||
/// Crate root, then extern prelude (used for mixed 2015-2018 mode in macros).
|
||||
AbsolutePath(Namespace),
|
||||
/// All scopes with macro namespace and the given macro kind restriction.
|
||||
|
@ -718,7 +718,6 @@ struct UseError<'a> {
|
|||
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
enum AmbiguityKind {
|
||||
Import,
|
||||
BuiltinAttr,
|
||||
DeriveHelper,
|
||||
MacroRulesVsModularized,
|
||||
|
@ -731,7 +730,6 @@ enum AmbiguityKind {
|
|||
impl AmbiguityKind {
|
||||
fn descr(self) -> &'static str {
|
||||
match self {
|
||||
AmbiguityKind::Import => "multiple potential import sources",
|
||||
AmbiguityKind::BuiltinAttr => "a name conflict with a builtin attribute",
|
||||
AmbiguityKind::DeriveHelper => "a name conflict with a derive helper attribute",
|
||||
AmbiguityKind::MacroRulesVsModularized => {
|
||||
|
@ -1557,7 +1555,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
self.visit_scopes(ScopeSet::All(TypeNS, false), parent_scope, ctxt, |this, scope, _, _| {
|
||||
self.visit_scopes(ScopeSet::All(TypeNS), parent_scope, ctxt, |this, scope, _, _| {
|
||||
match scope {
|
||||
Scope::Module(module, _) => {
|
||||
this.traits_in_module(module, assoc_item, &mut found_traits);
|
||||
|
|
|
@ -645,7 +645,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
self.prohibit_imported_non_macro_attrs(None, res.ok(), path_span);
|
||||
res
|
||||
} else {
|
||||
let scope_set = kind.map_or(ScopeSet::All(MacroNS, false), ScopeSet::Macro);
|
||||
let scope_set = kind.map_or(ScopeSet::All(MacroNS), ScopeSet::Macro);
|
||||
let binding = self.early_resolve_ident_in_lexical_scope(
|
||||
path[0].ident,
|
||||
scope_set,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue