Skip to content

Commit cab814b

Browse files
committed
temp
1 parent 437ca55 commit cab814b

Some content is hidden

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

46 files changed

+517
-63
lines changed

src/librustc_metadata/cstore_impl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,10 @@ impl cstore::CStore {
482482
pub fn crate_source_untracked(&self, cnum: CrateNum) -> CrateSource {
483483
self.get_crate_data(cnum).source.clone()
484484
}
485+
486+
pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
487+
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
488+
}
485489
}
486490

487491
impl CrateStore for cstore::CStore {

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
866866
def_id,
867867
expansion,
868868
span);
869-
self.r.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion));
869+
self.r.define(parent, ident, TypeNS, (module, vis, span, expansion));
870870
}
871871
Res::Def(DefKind::Struct, _)
872872
| Res::Def(DefKind::Union, _)
@@ -879,17 +879,17 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
879879
| Res::Def(DefKind::AssocOpaqueTy, _)
880880
| Res::PrimTy(..)
881881
| Res::ToolMod =>
882-
self.r.define(parent, ident, TypeNS, (res, vis, DUMMY_SP, expansion)),
882+
self.r.define(parent, ident, TypeNS, (res, vis, span, expansion)),
883883
Res::Def(DefKind::Fn, _)
884884
| Res::Def(DefKind::Method, _)
885885
| Res::Def(DefKind::Static, _)
886886
| Res::Def(DefKind::Const, _)
887887
| Res::Def(DefKind::AssocConst, _)
888888
| Res::Def(DefKind::Ctor(..), _) =>
889-
self.r.define(parent, ident, ValueNS, (res, vis, DUMMY_SP, expansion)),
889+
self.r.define(parent, ident, ValueNS, (res, vis, span, expansion)),
890890
Res::Def(DefKind::Macro(..), _)
891891
| Res::NonMacroAttr(..) =>
892-
self.r.define(parent, ident, MacroNS, (res, vis, DUMMY_SP, expansion)),
892+
self.r.define(parent, ident, MacroNS, (res, vis, span, expansion)),
893893
Res::Def(DefKind::TyParam, _) | Res::Def(DefKind::ConstParam, _)
894894
| Res::Local(..) | Res::SelfTy(..) | Res::SelfCtor(..) | Res::Err =>
895895
bug!("unexpected resolution: {:?}", res)

src/librustc_resolve/diagnostics.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ fn reduce_impl_span_to_impl_keyword(cm: &SourceMap, impl_span: Span) -> Span {
5959
}
6060

6161
crate fn add_typo_suggestion(
62+
resolver: &Resolver<'_>,
6263
err: &mut DiagnosticBuilder<'_>, suggestion: Option<TypoSuggestion>, span: Span
6364
) -> bool {
6465
if let Some(suggestion) = suggestion {
@@ -68,6 +69,18 @@ crate fn add_typo_suggestion(
6869
err.span_suggestion(
6970
span, &msg, suggestion.candidate.to_string(), Applicability::MaybeIncorrect
7071
);
72+
let def_span = suggestion.res.opt_def_id()
73+
.map(|def_id| {
74+
resolver.definitions.opt_span(def_id)
75+
.unwrap_or_else(|| resolver.cstore.get_span_untracked(def_id, resolver.session))
76+
});
77+
if let Some(def_span) = def_span {
78+
err.span_label(def_span, &format!(
79+
"similarly named {} `{}` defined here",
80+
suggestion.res.descr(),
81+
suggestion.candidate.as_str(),
82+
));
83+
}
7184
return true;
7285
}
7386
false
@@ -651,7 +664,7 @@ impl<'a> Resolver<'a> {
651664
let suggestion = self.early_lookup_typo_candidate(
652665
ScopeSet::Macro(macro_kind), parent_scope, ident, is_expected
653666
);
654-
add_typo_suggestion(err, suggestion, ident.span);
667+
add_typo_suggestion(self, err, suggestion, ident.span);
655668

656669
if macro_kind == MacroKind::Derive &&
657670
(ident.as_str() == "Send" || ident.as_str() == "Sync") {

src/librustc_resolve/late/diagnostics.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,8 @@ impl<'a> LateResolutionVisitor<'a, '_> {
236236
}
237237

238238
// Try Levenshtein algorithm.
239-
let levenshtein_worked = add_typo_suggestion(
240-
&mut err, self.lookup_typo_candidate(path, ns, is_expected, span), ident_span
241-
);
239+
let suggestion = self.lookup_typo_candidate(path, ns, is_expected, span);
240+
let levenshtein_worked = add_typo_suggestion(self.r, &mut err, suggestion, ident_span);
242241

243242
// Try context-dependent help if relaxed lookup didn't work.
244243
if let Some(res) = res {

src/test/ui/associated-types/associated-types-eq-1.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error[E0412]: cannot find type `A` in this scope
22
--> $DIR/associated-types-eq-1.rs:10:12
33
|
4+
LL | fn foo2<I: Foo>(x: I) {
5+
| - similarly named type parameter `I` defined here
46
LL | let _: A = x.boo();
57
| ^ help: a type parameter with a similar name exists: `I`
68

src/test/ui/const-generics/struct-with-invalid-const-param.stderr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ error[E0573]: expected type, found const parameter `C`
22
--> $DIR/struct-with-invalid-const-param.rs:4:23
33
|
44
LL | struct S<const C: u8>(C);
5-
| ^ help: a struct with a similar name exists: `S`
5+
| ----------------------^--
6+
| | |
7+
| | help: a struct with a similar name exists: `S`
8+
| similarly named struct `S` defined here
69

710
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
811
--> $DIR/struct-with-invalid-const-param.rs:1:12

src/test/ui/derives/deriving-meta-unknown-trait.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error: cannot find derive macro `Eqr` in this scope
33
|
44
LL | #[derive(Eqr)]
55
| ^^^ help: a derive macro with a similar name exists: `Eq`
6+
|
7+
::: $SRC_DIR/libcore/cmp.rs:LL:COL
8+
|
9+
LL | pub macro Eq($item:item) { /* compiler built-in */ }
10+
| ---------------------------------------------------- similarly named derive macro `Eq` defined here
611

712
error: aborting due to previous error
813

src/test/ui/empty/empty-struct-braces-expr.stderr

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ LL | let e1 = Empty1;
99
| |
1010
| did you mean `Empty1 { /* fields */ }`?
1111
| help: a unit struct with a similar name exists: `XEmpty2`
12+
|
13+
::: $DIR/auxiliary/empty-struct.rs:2:1
14+
|
15+
LL | pub struct XEmpty2;
16+
| ------------------- similarly named unit struct `XEmpty2` defined here
1217

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

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

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

6181
error[E0599]: no variant or associated item named `Empty3` found for type `empty_struct::XE` in the current scope
6282
--> $DIR/empty-struct-braces-expr.rs:22:19

src/test/ui/empty/empty-struct-braces-pat-1.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ LL | XE::XEmpty3 => ()
1515
| | |
1616
| | help: a unit variant with a similar name exists: `XEmpty4`
1717
| did you mean `XE::XEmpty3 { /* fields */ }`?
18+
|
19+
::: $DIR/auxiliary/empty-struct.rs:7:5
20+
|
21+
LL | XEmpty4,
22+
| ------- similarly named unit variant `XEmpty4` defined here
1823

1924
error: aborting due to 2 previous errors
2025

src/test/ui/empty/empty-struct-braces-pat-2.stderr

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ LL | Empty1() => ()
99
| |
1010
| did you mean `Empty1 { /* fields */ }`?
1111
| help: a tuple struct with a similar name exists: `XEmpty6`
12+
|
13+
::: $DIR/auxiliary/empty-struct.rs:3:1
14+
|
15+
LL | pub struct XEmpty6();
16+
| --------------------- similarly named tuple struct `XEmpty6` defined here
1217

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

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

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

4363
error: aborting due to 4 previous errors
4464

src/test/ui/empty/empty-struct-braces-pat-3.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ LL | XE::XEmpty3() => ()
1515
| | |
1616
| | help: a tuple variant with a similar name exists: `XEmpty5`
1717
| did you mean `XE::XEmpty3 { /* fields */ }`?
18+
|
19+
::: $DIR/auxiliary/empty-struct.rs:8:5
20+
|
21+
LL | XEmpty5(),
22+
| --------- similarly named tuple variant `XEmpty5` defined here
1823

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

3747
error: aborting due to 4 previous errors
3848

src/test/ui/empty/empty-struct-tuple-pat.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ LL | XE::XEmpty5 => (),
3333
| | |
3434
| | help: a unit variant with a similar name exists: `XEmpty4`
3535
| did you mean `XE::XEmpty5( /* fields */ )`?
36+
|
37+
::: $DIR/auxiliary/empty-struct.rs:7:5
38+
|
39+
LL | XEmpty4,
40+
| ------- similarly named unit variant `XEmpty4` defined here
3641

3742
error: aborting due to 4 previous errors
3843

src/test/ui/empty/empty-struct-unit-pat.stderr

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,44 @@ error[E0532]: expected tuple struct/variant, found unit struct `Empty2`
33
|
44
LL | Empty2() => ()
55
| ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
6+
|
7+
::: $DIR/auxiliary/empty-struct.rs:3:1
8+
|
9+
LL | pub struct XEmpty6();
10+
| --------------------- similarly named tuple struct `XEmpty6` defined here
611

712
error[E0532]: expected tuple struct/variant, found unit struct `XEmpty2`
813
--> $DIR/empty-struct-unit-pat.rs:24:9
914
|
1015
LL | XEmpty2() => ()
1116
| ^^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
17+
|
18+
::: $DIR/auxiliary/empty-struct.rs:3:1
19+
|
20+
LL | pub struct XEmpty6();
21+
| --------------------- similarly named tuple struct `XEmpty6` defined here
1222

1323
error[E0532]: expected tuple struct/variant, found unit struct `Empty2`
1424
--> $DIR/empty-struct-unit-pat.rs:27:9
1525
|
1626
LL | Empty2(..) => ()
1727
| ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
28+
|
29+
::: $DIR/auxiliary/empty-struct.rs:3:1
30+
|
31+
LL | pub struct XEmpty6();
32+
| --------------------- similarly named tuple struct `XEmpty6` defined here
1833

1934
error[E0532]: expected tuple struct/variant, found unit struct `XEmpty2`
2035
--> $DIR/empty-struct-unit-pat.rs:30:9
2136
|
2237
LL | XEmpty2(..) => ()
2338
| ^^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
39+
|
40+
::: $DIR/auxiliary/empty-struct.rs:3:1
41+
|
42+
LL | pub struct XEmpty6();
43+
| --------------------- similarly named tuple struct `XEmpty6` defined here
2444

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

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

5383
error: aborting due to 8 previous errors
5484

src/test/ui/error-codes/E0423.stderr

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ LL | for _ in (std::ops::Range { start: 0, end: 10 }) {}
2727
error[E0423]: expected function, found struct `Foo`
2828
--> $DIR/E0423.rs:4:13
2929
|
30-
LL | struct Foo { a: bool };
31-
| ---------------------- `Foo` defined here
30+
LL | struct Foo { a: bool };
31+
| ---------------------- `Foo` defined here
3232
LL |
33-
LL | let f = Foo();
34-
| ^^^
35-
| |
36-
| did you mean `Foo { /* fields */ }`?
37-
| help: a function with a similar name exists (notice the capitalization): `foo`
33+
LL | let f = Foo();
34+
| ^^^
35+
| |
36+
| did you mean `Foo { /* fields */ }`?
37+
| help: a function with a similar name exists (notice the capitalization): `foo`
38+
...
39+
LL | / fn foo() {
40+
LL | | for _ in std::ops::Range { start: 0, end: 10 } {}
41+
LL | |
42+
LL | | }
43+
| |_- similarly named function `foo` defined here
3844

3945
error[E0423]: expected value, found struct `T`
4046
--> $DIR/E0423.rs:14:8

src/test/ui/glob-resolve1.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ LL | import();
4343
error[E0412]: cannot find type `A` in this scope
4444
--> $DIR/glob-resolve1.rs:28:11
4545
|
46+
LL | pub enum B { B1 }
47+
| ----------------- similarly named enum `B` defined here
48+
...
4649
LL | foo::<A>();
4750
| ^
4851
help: an enum with a similar name exists
@@ -57,6 +60,9 @@ LL | use bar::A;
5760
error[E0412]: cannot find type `C` in this scope
5861
--> $DIR/glob-resolve1.rs:29:11
5962
|
63+
LL | pub enum B { B1 }
64+
| ----------------- similarly named enum `B` defined here
65+
...
6066
LL | foo::<C>();
6167
| ^
6268
help: an enum with a similar name exists
@@ -71,6 +77,9 @@ LL | use bar::C;
7177
error[E0412]: cannot find type `D` in this scope
7278
--> $DIR/glob-resolve1.rs:30:11
7379
|
80+
LL | pub enum B { B1 }
81+
| ----------------- similarly named enum `B` defined here
82+
...
7483
LL | foo::<D>();
7584
| ^
7685
help: an enum with a similar name exists

0 commit comments

Comments
 (0)