Edit error messages for rustc_resolve::AmbiguityKind variants

Emit description of the ambiguity as a note.

Co-authored-by: Noah Lev <camelidcamel@gmail.com>
Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
This commit is contained in:
pierwill 2021-10-20 08:56:10 -05:00
parent 84c2a8505d
commit 7de1ff1ba8
38 changed files with 160 additions and 93 deletions

View file

@ -1165,14 +1165,9 @@ impl<'a> Resolver<'a> {
(b1, b2, misc1, misc2, false)
};
let mut err = struct_span_err!(
self.session,
ident.span,
E0659,
"`{ident}` is ambiguous ({why})",
why = kind.descr()
);
let mut err = struct_span_err!(self.session, ident.span, E0659, "`{ident}` is ambiguous");
err.span_label(ident.span, "ambiguous name");
err.note(&format!("ambiguous because of {}", kind.descr()));
let mut could_refer_to = |b: &NameBinding<'_>, misc: AmbiguityErrorMisc, also: &str| {
let what = self.binding_description(b, ident, misc == AmbiguityErrorMisc::FromPrelude);

View file

@ -728,23 +728,21 @@ enum AmbiguityKind {
impl AmbiguityKind {
fn descr(self) -> &'static str {
match self {
AmbiguityKind::Import => "name vs any other name during import resolution",
AmbiguityKind::BuiltinAttr => "built-in attribute vs any other name",
AmbiguityKind::DeriveHelper => "derive helper attribute vs any other name",
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 => {
"`macro_rules` vs non-`macro_rules` from other module"
"a conflict between a `macro_rules` name and a non-`macro_rules` name from another module"
}
AmbiguityKind::GlobVsOuter => {
"glob import vs any other name from outer scope during import/macro resolution"
"a conflict between a name from a glob import and an outer scope during import or macro resolution"
}
AmbiguityKind::GlobVsGlob => "glob import vs glob import in the same module",
AmbiguityKind::GlobVsGlob => "multiple glob imports of a name in the same module",
AmbiguityKind::GlobVsExpanded => {
"glob import vs macro-expanded name in the same \
module during import/macro resolution"
"a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution"
}
AmbiguityKind::MoreExpandedVsOuter => {
"macro-expanded name vs less macro-expanded name \
from outer scope during import/macro resolution"
"a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution"
}
}
}