Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8d78bf6

Browse files
committedOct 28, 2019
Auto merge of #65421 - estebank:variants, r=petrochenkov
Point at local similarly named element and tweak references to variants Partially address #65386.
2 parents 03a50ae + b26ddb8 commit 8d78bf6

File tree

132 files changed

+600
-331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+600
-331
lines changed
 

‎src/librustc_resolve/build_reduced_graph.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -849,12 +849,14 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
849849
Res::Def(kind @ DefKind::Mod, def_id)
850850
| Res::Def(kind @ DefKind::Enum, def_id)
851851
| Res::Def(kind @ DefKind::Trait, def_id) => {
852-
let module = self.r.new_module(parent,
853-
ModuleKind::Def(kind, def_id, ident.name),
854-
def_id,
855-
expansion,
856-
span);
857-
self.r.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion));
852+
let module = self.r.new_module(
853+
parent,
854+
ModuleKind::Def(kind, def_id, ident.name),
855+
def_id,
856+
expansion,
857+
span,
858+
);
859+
self.r.define(parent, ident, TypeNS, (module, vis, span, expansion));
858860
}
859861
Res::Def(DefKind::Struct, _)
860862
| Res::Def(DefKind::Union, _)
@@ -867,17 +869,17 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
867869
| Res::Def(DefKind::AssocOpaqueTy, _)
868870
| Res::PrimTy(..)
869871
| Res::ToolMod =>
870-
self.r.define(parent, ident, TypeNS, (res, vis, DUMMY_SP, expansion)),
872+
self.r.define(parent, ident, TypeNS, (res, vis, span, expansion)),
871873
Res::Def(DefKind::Fn, _)
872874
| Res::Def(DefKind::Method, _)
873875
| Res::Def(DefKind::Static, _)
874876
| Res::Def(DefKind::Const, _)
875877
| Res::Def(DefKind::AssocConst, _)
876878
| Res::Def(DefKind::Ctor(..), _) =>
877-
self.r.define(parent, ident, ValueNS, (res, vis, DUMMY_SP, expansion)),
879+
self.r.define(parent, ident, ValueNS, (res, vis, span, expansion)),
878880
Res::Def(DefKind::Macro(..), _)
879881
| Res::NonMacroAttr(..) =>
880-
self.r.define(parent, ident, MacroNS, (res, vis, DUMMY_SP, expansion)),
882+
self.r.define(parent, ident, MacroNS, (res, vis, span, expansion)),
881883
Res::Def(DefKind::TyParam, _) | Res::Def(DefKind::ConstParam, _)
882884
| Res::Local(..) | Res::SelfTy(..) | Res::SelfCtor(..) | Res::Err =>
883885
bug!("unexpected resolution: {:?}", res)

‎src/librustc_resolve/diagnostics.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,6 @@ fn reduce_impl_span_to_impl_keyword(cm: &SourceMap, impl_span: Span) -> Span {
5858
impl_span
5959
}
6060

61-
crate fn add_typo_suggestion(
62-
err: &mut DiagnosticBuilder<'_>, suggestion: Option<TypoSuggestion>, span: Span
63-
) -> bool {
64-
if let Some(suggestion) = suggestion {
65-
let msg = format!(
66-
"{} {} with a similar name exists", suggestion.res.article(), suggestion.res.descr()
67-
);
68-
err.span_suggestion(
69-
span, &msg, suggestion.candidate.to_string(), Applicability::MaybeIncorrect
70-
);
71-
return true;
72-
}
73-
false
74-
}
75-
7661
impl<'a> Resolver<'a> {
7762
crate fn add_module_candidates(
7863
&mut self,
@@ -641,7 +626,7 @@ impl<'a> Resolver<'a> {
641626
let suggestion = self.early_lookup_typo_candidate(
642627
ScopeSet::Macro(macro_kind), parent_scope, ident, is_expected
643628
);
644-
add_typo_suggestion(err, suggestion, ident.span);
629+
self.add_typo_suggestion(err, suggestion, ident.span);
645630

646631
if macro_kind == MacroKind::Derive &&
647632
(ident.as_str() == "Send" || ident.as_str() == "Sync") {
@@ -652,6 +637,33 @@ impl<'a> Resolver<'a> {
652637
err.help("have you added the `#[macro_use]` on the module/import?");
653638
}
654639
}
640+
641+
crate fn add_typo_suggestion(
642+
&self,
643+
err: &mut DiagnosticBuilder<'_>,
644+
suggestion: Option<TypoSuggestion>,
645+
span: Span,
646+
) -> bool {
647+
if let Some(suggestion) = suggestion {
648+
let msg = format!(
649+
"{} {} with a similar name exists", suggestion.res.article(), suggestion.res.descr()
650+
);
651+
err.span_suggestion(
652+
span, &msg, suggestion.candidate.to_string(), Applicability::MaybeIncorrect
653+
);
654+
let def_span = suggestion.res.opt_def_id()
655+
.and_then(|def_id| self.definitions.opt_span(def_id));
656+
if let Some(span) = def_span {
657+
err.span_label(span, &format!(
658+
"similarly named {} `{}` defined here",
659+
suggestion.res.descr(),
660+
suggestion.candidate.as_str(),
661+
));
662+
}
663+
return true;
664+
}
665+
false
666+
}
655667
}
656668

657669
impl<'a, 'b> ImportResolver<'a, 'b> {

0 commit comments

Comments
 (0)
Please sign in to comment.