Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Oct 15, 2019
1 parent 437ca55 commit cab814b
Show file tree
Hide file tree
Showing 46 changed files with 517 additions and 63 deletions.
4 changes: 4 additions & 0 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ impl cstore::CStore {
pub fn crate_source_untracked(&self, cnum: CrateNum) -> CrateSource {
self.get_crate_data(cnum).source.clone()
}

pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
}
}

impl CrateStore for cstore::CStore {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
def_id,
expansion,
span);
self.r.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion));
self.r.define(parent, ident, TypeNS, (module, vis, span, expansion));
}
Res::Def(DefKind::Struct, _)
| Res::Def(DefKind::Union, _)
Expand All @@ -879,17 +879,17 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
| Res::Def(DefKind::AssocOpaqueTy, _)
| Res::PrimTy(..)
| Res::ToolMod =>
self.r.define(parent, ident, TypeNS, (res, vis, DUMMY_SP, expansion)),
self.r.define(parent, ident, TypeNS, (res, vis, span, expansion)),
Res::Def(DefKind::Fn, _)
| Res::Def(DefKind::Method, _)
| Res::Def(DefKind::Static, _)
| Res::Def(DefKind::Const, _)
| Res::Def(DefKind::AssocConst, _)
| Res::Def(DefKind::Ctor(..), _) =>
self.r.define(parent, ident, ValueNS, (res, vis, DUMMY_SP, expansion)),
self.r.define(parent, ident, ValueNS, (res, vis, span, expansion)),
Res::Def(DefKind::Macro(..), _)
| Res::NonMacroAttr(..) =>
self.r.define(parent, ident, MacroNS, (res, vis, DUMMY_SP, expansion)),
self.r.define(parent, ident, MacroNS, (res, vis, span, expansion)),
Res::Def(DefKind::TyParam, _) | Res::Def(DefKind::ConstParam, _)
| Res::Local(..) | Res::SelfTy(..) | Res::SelfCtor(..) | Res::Err =>
bug!("unexpected resolution: {:?}", res)
Expand Down
15 changes: 14 additions & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn reduce_impl_span_to_impl_keyword(cm: &SourceMap, impl_span: Span) -> Span {
}

crate fn add_typo_suggestion(
resolver: &Resolver<'_>,
err: &mut DiagnosticBuilder<'_>, suggestion: Option<TypoSuggestion>, span: Span
) -> bool {
if let Some(suggestion) = suggestion {
Expand All @@ -68,6 +69,18 @@ crate fn add_typo_suggestion(
err.span_suggestion(
span, &msg, suggestion.candidate.to_string(), Applicability::MaybeIncorrect
);
let def_span = suggestion.res.opt_def_id()
.map(|def_id| {
resolver.definitions.opt_span(def_id)
.unwrap_or_else(|| resolver.cstore.get_span_untracked(def_id, resolver.session))
});
if let Some(def_span) = def_span {
err.span_label(def_span, &format!(
"similarly named {} `{}` defined here",
suggestion.res.descr(),
suggestion.candidate.as_str(),
));
}
return true;
}
false
Expand Down Expand Up @@ -651,7 +664,7 @@ impl<'a> Resolver<'a> {
let suggestion = self.early_lookup_typo_candidate(
ScopeSet::Macro(macro_kind), parent_scope, ident, is_expected
);
add_typo_suggestion(err, suggestion, ident.span);
add_typo_suggestion(self, err, suggestion, ident.span);

if macro_kind == MacroKind::Derive &&
(ident.as_str() == "Send" || ident.as_str() == "Sync") {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,8 @@ impl<'a> LateResolutionVisitor<'a, '_> {
}

// Try Levenshtein algorithm.
let levenshtein_worked = add_typo_suggestion(
&mut err, self.lookup_typo_candidate(path, ns, is_expected, span), ident_span
);
let suggestion = self.lookup_typo_candidate(path, ns, is_expected, span);
let levenshtein_worked = add_typo_suggestion(self.r, &mut err, suggestion, ident_span);

// Try context-dependent help if relaxed lookup didn't work.
if let Some(res) = res {
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/associated-types/associated-types-eq-1.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error[E0412]: cannot find type `A` in this scope
--> $DIR/associated-types-eq-1.rs:10:12
|
LL | fn foo2<I: Foo>(x: I) {
| - similarly named type parameter `I` defined here
LL | let _: A = x.boo();
| ^ help: a type parameter with a similar name exists: `I`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ error[E0573]: expected type, found const parameter `C`
--> $DIR/struct-with-invalid-const-param.rs:4:23
|
LL | struct S<const C: u8>(C);
| ^ help: a struct with a similar name exists: `S`
| ----------------------^--
| | |
| | help: a struct with a similar name exists: `S`
| similarly named struct `S` defined here

warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/struct-with-invalid-const-param.rs:1:12
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/derives/deriving-meta-unknown-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ error: cannot find derive macro `Eqr` in this scope
|
LL | #[derive(Eqr)]
| ^^^ help: a derive macro with a similar name exists: `Eq`
|
::: $SRC_DIR/libcore/cmp.rs:LL:COL
|
LL | pub macro Eq($item:item) { /* compiler built-in */ }
| ---------------------------------------------------- similarly named derive macro `Eq` defined here

error: aborting due to previous error

20 changes: 20 additions & 0 deletions src/test/ui/empty/empty-struct-braces-expr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ LL | let e1 = Empty1;
| |
| did you mean `Empty1 { /* fields */ }`?
| help: a unit struct with a similar name exists: `XEmpty2`
|
::: $DIR/auxiliary/empty-struct.rs:2:1
|
LL | pub struct XEmpty2;
| ------------------- similarly named unit struct `XEmpty2` defined here

error[E0423]: expected function, found struct `Empty1`
--> $DIR/empty-struct-braces-expr.rs:16:14
Expand All @@ -21,6 +26,11 @@ LL | let e1 = Empty1();
| |
| did you mean `Empty1 { /* fields */ }`?
| help: a unit struct with a similar name exists: `XEmpty2`
|
::: $DIR/auxiliary/empty-struct.rs:2:1
|
LL | pub struct XEmpty2;
| ------------------- similarly named unit struct `XEmpty2` defined here

error[E0423]: expected value, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-expr.rs:17:14
Expand Down Expand Up @@ -48,6 +58,11 @@ LL | let xe1 = XEmpty1;
| |
| did you mean `XEmpty1 { /* fields */ }`?
| help: a unit struct with a similar name exists: `XEmpty2`
|
::: $DIR/auxiliary/empty-struct.rs:2:1
|
LL | pub struct XEmpty2;
| ------------------- similarly named unit struct `XEmpty2` defined here

error[E0423]: expected function, found struct `XEmpty1`
--> $DIR/empty-struct-braces-expr.rs:21:15
Expand All @@ -57,6 +72,11 @@ LL | let xe1 = XEmpty1();
| |
| did you mean `XEmpty1 { /* fields */ }`?
| help: a unit struct with a similar name exists: `XEmpty2`
|
::: $DIR/auxiliary/empty-struct.rs:2:1
|
LL | pub struct XEmpty2;
| ------------------- similarly named unit struct `XEmpty2` defined here

error[E0599]: no variant or associated item named `Empty3` found for type `empty_struct::XE` in the current scope
--> $DIR/empty-struct-braces-expr.rs:22:19
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/empty/empty-struct-braces-pat-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ LL | XE::XEmpty3 => ()
| | |
| | help: a unit variant with a similar name exists: `XEmpty4`
| did you mean `XE::XEmpty3 { /* fields */ }`?
|
::: $DIR/auxiliary/empty-struct.rs:7:5
|
LL | XEmpty4,
| ------- similarly named unit variant `XEmpty4` defined here

error: aborting due to 2 previous errors

Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/empty/empty-struct-braces-pat-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ LL | Empty1() => ()
| |
| did you mean `Empty1 { /* fields */ }`?
| help: a tuple struct with a similar name exists: `XEmpty6`
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here

error[E0532]: expected tuple struct/variant, found struct `XEmpty1`
--> $DIR/empty-struct-braces-pat-2.rs:18:9
Expand All @@ -18,6 +23,11 @@ LL | XEmpty1() => ()
| |
| did you mean `XEmpty1 { /* fields */ }`?
| help: a tuple struct with a similar name exists: `XEmpty6`
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here

error[E0532]: expected tuple struct/variant, found struct `Empty1`
--> $DIR/empty-struct-braces-pat-2.rs:21:9
Expand All @@ -30,6 +40,11 @@ LL | Empty1(..) => ()
| |
| did you mean `Empty1 { /* fields */ }`?
| help: a tuple struct with a similar name exists: `XEmpty6`
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here

error[E0532]: expected tuple struct/variant, found struct `XEmpty1`
--> $DIR/empty-struct-braces-pat-2.rs:24:9
Expand All @@ -39,6 +54,11 @@ LL | XEmpty1(..) => ()
| |
| did you mean `XEmpty1 { /* fields */ }`?
| help: a tuple struct with a similar name exists: `XEmpty6`
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here

error: aborting due to 4 previous errors

Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/empty/empty-struct-braces-pat-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ LL | XE::XEmpty3() => ()
| | |
| | help: a tuple variant with a similar name exists: `XEmpty5`
| did you mean `XE::XEmpty3 { /* fields */ }`?
|
::: $DIR/auxiliary/empty-struct.rs:8:5
|
LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here

error[E0532]: expected tuple struct/variant, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-pat-3.rs:25:9
Expand All @@ -33,6 +38,11 @@ LL | XE::XEmpty3(..) => ()
| | |
| | help: a tuple variant with a similar name exists: `XEmpty5`
| did you mean `XE::XEmpty3 { /* fields */ }`?
|
::: $DIR/auxiliary/empty-struct.rs:8:5
|
LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here

error: aborting due to 4 previous errors

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/empty/empty-struct-tuple-pat.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ LL | XE::XEmpty5 => (),
| | |
| | help: a unit variant with a similar name exists: `XEmpty4`
| did you mean `XE::XEmpty5( /* fields */ )`?
|
::: $DIR/auxiliary/empty-struct.rs:7:5
|
LL | XEmpty4,
| ------- similarly named unit variant `XEmpty4` defined here

error: aborting due to 4 previous errors

Expand Down
30 changes: 30 additions & 0 deletions src/test/ui/empty/empty-struct-unit-pat.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,44 @@ error[E0532]: expected tuple struct/variant, found unit struct `Empty2`
|
LL | Empty2() => ()
| ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here

error[E0532]: expected tuple struct/variant, found unit struct `XEmpty2`
--> $DIR/empty-struct-unit-pat.rs:24:9
|
LL | XEmpty2() => ()
| ^^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here

error[E0532]: expected tuple struct/variant, found unit struct `Empty2`
--> $DIR/empty-struct-unit-pat.rs:27:9
|
LL | Empty2(..) => ()
| ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here

error[E0532]: expected tuple struct/variant, found unit struct `XEmpty2`
--> $DIR/empty-struct-unit-pat.rs:30:9
|
LL | XEmpty2(..) => ()
| ^^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here

error[E0532]: expected tuple struct/variant, found unit variant `E::Empty4`
--> $DIR/empty-struct-unit-pat.rs:34:9
Expand All @@ -35,6 +55,11 @@ LL | XE::XEmpty4() => (),
| ^^^^-------
| |
| help: a tuple variant with a similar name exists: `XEmpty5`
|
::: $DIR/auxiliary/empty-struct.rs:8:5
|
LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here

error[E0532]: expected tuple struct/variant, found unit variant `E::Empty4`
--> $DIR/empty-struct-unit-pat.rs:42:9
Expand All @@ -49,6 +74,11 @@ LL | XE::XEmpty4(..) => (),
| ^^^^-------
| |
| help: a tuple variant with a similar name exists: `XEmpty5`
|
::: $DIR/auxiliary/empty-struct.rs:8:5
|
LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here

error: aborting due to 8 previous errors

Expand Down
20 changes: 13 additions & 7 deletions src/test/ui/error-codes/E0423.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ LL | for _ in (std::ops::Range { start: 0, end: 10 }) {}
error[E0423]: expected function, found struct `Foo`
--> $DIR/E0423.rs:4:13
|
LL | struct Foo { a: bool };
| ---------------------- `Foo` defined here
LL | struct Foo { a: bool };
| ---------------------- `Foo` defined here
LL |
LL | let f = Foo();
| ^^^
| |
| did you mean `Foo { /* fields */ }`?
| help: a function with a similar name exists (notice the capitalization): `foo`
LL | let f = Foo();
| ^^^
| |
| did you mean `Foo { /* fields */ }`?
| help: a function with a similar name exists (notice the capitalization): `foo`
...
LL | / fn foo() {
LL | | for _ in std::ops::Range { start: 0, end: 10 } {}
LL | |
LL | | }
| |_- similarly named function `foo` defined here

error[E0423]: expected value, found struct `T`
--> $DIR/E0423.rs:14:8
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/glob-resolve1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ LL | import();
error[E0412]: cannot find type `A` in this scope
--> $DIR/glob-resolve1.rs:28:11
|
LL | pub enum B { B1 }
| ----------------- similarly named enum `B` defined here
...
LL | foo::<A>();
| ^
help: an enum with a similar name exists
Expand All @@ -57,6 +60,9 @@ LL | use bar::A;
error[E0412]: cannot find type `C` in this scope
--> $DIR/glob-resolve1.rs:29:11
|
LL | pub enum B { B1 }
| ----------------- similarly named enum `B` defined here
...
LL | foo::<C>();
| ^
help: an enum with a similar name exists
Expand All @@ -71,6 +77,9 @@ LL | use bar::C;
error[E0412]: cannot find type `D` in this scope
--> $DIR/glob-resolve1.rs:30:11
|
LL | pub enum B { B1 }
| ----------------- similarly named enum `B` defined here
...
LL | foo::<D>();
| ^
help: an enum with a similar name exists
Expand Down
Loading

0 comments on commit cab814b

Please sign in to comment.