Skip to content

Commit 1b0ab0b

Browse files
committed
Tweak spans for E0599
1 parent 0f118f6 commit 1b0ab0b

28 files changed

+72
-133
lines changed

src/librustc_typeck/check/method/suggest.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
6969
error: MethodError<'tcx>,
7070
args: Option<&'gcx [hir::Expr]>,
7171
) {
72+
let mut span = span;
7273
// Avoid suggestions when we don't know what's going on.
7374
if rcvr_ty.references_error() {
7475
return;
7576
}
7677

77-
let report_candidates = |err: &mut DiagnosticBuilder<'_>,
78-
mut sources: Vec<CandidateSource>| {
78+
let report_candidates = |
79+
span: Span,
80+
err: &mut DiagnosticBuilder<'_>,
81+
mut sources: Vec<CandidateSource>,
82+
| {
7983
sources.sort();
8084
sources.dedup();
8185
// Dynamic limit to avoid hiding just one candidate, which is silly.
@@ -293,9 +297,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
293297
err.emit();
294298
return;
295299
} else {
300+
span = item_name.span;
296301
let mut err = struct_span_err!(
297302
tcx.sess,
298-
item_name.span,
303+
span,
299304
E0599,
300305
"no {} named `{}` found for type `{}` in the current scope",
301306
item_kind,
@@ -305,7 +310,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
305310
if let Some(suggestion) = suggestion {
306311
// enum variant
307312
err.span_suggestion(
308-
item_name.span,
313+
span,
309314
"did you mean",
310315
suggestion.to_string(),
311316
Applicability::MaybeIncorrect,
@@ -434,9 +439,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
434439
self.ty_to_string(actual), item_name));
435440
}
436441

437-
report_candidates(&mut err, static_sources);
442+
report_candidates(span, &mut err, static_sources);
438443
} else if static_sources.len() > 1 {
439-
report_candidates(&mut err, static_sources);
444+
report_candidates(span, &mut err, static_sources);
440445
}
441446

442447
if !unsatisfied_predicates.is_empty() {
@@ -481,7 +486,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
481486
"multiple applicable items in scope");
482487
err.span_label(span, format!("multiple `{}` found", item_name));
483488

484-
report_candidates(&mut err, sources);
489+
report_candidates(span, &mut err, sources);
485490
err.emit();
486491
}
487492

src/test/ui/associated-const/associated-const-no-item.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0599]: no associated item named `ID` found for type `i32` in the current
22
--> $DIR/associated-const-no-item.rs:5:23
33
|
44
LL | const X: i32 = <i32>::ID;
5-
| -------^^
6-
| |
7-
| associated item not found in `i32`
5+
| ^^ associated item not found in `i32`
86
|
97
= help: items from traits can only be used if the trait is implemented and in scope
108
= note: the following trait defines an item `ID`, perhaps you need to implement it:

src/test/ui/bogus-tag.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | enum Color { Rgb(isize, isize, isize), Rgba(isize, isize, isize, isize), }
55
| ---------- variant `Hsl` not found here
66
...
77
LL | Color::Hsl(h, s, l) => { println!("hsl"); }
8-
| -------^^^--------- variant not found in `Color`
8+
| ^^^ variant not found in `Color`
99

1010
error: aborting due to previous error
1111

src/test/ui/did_you_mean/bad-assoc-pat.stderr

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,25 @@ error[E0599]: no associated item named `AssocItem` found for type `[u8]` in the
4141
--> $DIR/bad-assoc-pat.rs:3:15
4242
|
4343
LL | [u8]::AssocItem => {}
44-
| ------^^^^^^^^^
45-
| |
46-
| associated item not found in `[u8]`
44+
| ^^^^^^^^^ associated item not found in `[u8]`
4745

4846
error[E0599]: no associated item named `AssocItem` found for type `(u8, u8)` in the current scope
4947
--> $DIR/bad-assoc-pat.rs:6:19
5048
|
5149
LL | (u8, u8)::AssocItem => {}
52-
| ----------^^^^^^^^^
53-
| |
54-
| associated item not found in `(u8, u8)`
50+
| ^^^^^^^^^ associated item not found in `(u8, u8)`
5551

5652
error[E0599]: no associated item named `AssocItem` found for type `_` in the current scope
5753
--> $DIR/bad-assoc-pat.rs:9:12
5854
|
5955
LL | _::AssocItem => {}
60-
| ---^^^^^^^^^
61-
| |
62-
| associated item not found in `_`
56+
| ^^^^^^^^^ associated item not found in `_`
6357

6458
error[E0599]: no associated item named `AssocItem` found for type `(u8,)` in the current scope
6559
--> $DIR/bad-assoc-pat.rs:14:17
6660
|
6761
LL | &(u8,)::AssocItem => {}
68-
| -------^^^^^^^^^
69-
| |
70-
| associated item not found in `(u8,)`
62+
| ^^^^^^^^^ associated item not found in `(u8,)`
7163

7264
error[E0599]: no associated item named `AssocItem` found for type `u8` in the current scope
7365
--> $DIR/bad-assoc-pat.rs:21:24

src/test/ui/dont-suggest-private-trait-method.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ LL | struct T;
55
| --------- function or associated item `new` not found for this
66
...
77
LL | T::new();
8-
| ---^^^
9-
| |
10-
| function or associated item not found in `T`
8+
| ^^^ function or associated item not found in `T`
119

1210
error: aborting due to previous error
1311

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ error[E0599]: no variant named `Empty3` found for type `empty_struct::XE` in the
5050
--> $DIR/empty-struct-braces-expr.rs:22:19
5151
|
5252
LL | let xe3 = XE::Empty3;
53-
| ----^^^^^^
54-
| | |
55-
| | help: did you mean: `XEmpty3`
56-
| variant not found in `empty_struct::XE`
53+
| ^^^^^^
54+
| |
55+
| variant not found in `empty_struct::XE`
56+
| help: did you mean: `XEmpty3`
5757

5858
error[E0599]: no variant named `Empty3` found for type `empty_struct::XE` in the current scope
5959
--> $DIR/empty-struct-braces-expr.rs:23:19
6060
|
6161
LL | let xe3 = XE::Empty3();
62-
| ----^^^^^^
63-
| | |
64-
| | help: did you mean: `XEmpty3`
65-
| variant not found in `empty_struct::XE`
62+
| ^^^^^^
63+
| |
64+
| variant not found in `empty_struct::XE`
65+
| help: did you mean: `XEmpty3`
6666

6767
error: aborting due to 8 previous errors
6868

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | struct Foo;
55
| ----------- associated item `NotEvenReal` not found for this
66
...
77
LL | || if let Foo::NotEvenReal() = Foo {};
8-
| -----^^^^^^^^^^^-- associated item not found in `Foo`
8+
| ^^^^^^^^^^^ associated item not found in `Foo`
99

1010
error: aborting due to previous error
1111

src/test/ui/invalid/invalid-path-in-const.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0599]: no associated item named `DOESNOTEXIST` found for type `u32` in th
22
--> $DIR/invalid-path-in-const.rs:2:23
33
|
44
LL | fn f(a: [u8; u32::DOESNOTEXIST]) {}
5-
| -----^^^^^^^^^^^^
6-
| |
7-
| associated item not found in `u32`
5+
| ^^^^^^^^^^^^ associated item not found in `u32`
86

97
error: aborting due to previous error
108

src/test/ui/issues/issue-22933-2.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ LL | enum Delicious {
55
| -------------- variant `PIE` not found here
66
...
77
LL | ApplePie = Delicious::Apple as isize | Delicious::PIE as isize,
8-
| -----------^^^
9-
| |
10-
| variant not found in `Delicious`
8+
| ^^^ variant not found in `Delicious`
119

1210
error: aborting due to previous error
1311

src/test/ui/issues/issue-22933-3.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0599]: no associated item named `MIN` found for type `u8` in the current
22
--> $DIR/issue-22933-3.rs:1:22
33
|
44
LL | const FOO: [u32; u8::MIN as usize] = [];
5-
| ----^^^
6-
| |
7-
| associated item not found in `u8`
5+
| ^^^ associated item not found in `u8`
86

97
error: aborting due to previous error
108

src/test/ui/issues/issue-23173.stderr

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ LL | enum Token { LeftParen, RightParen, Plus, Minus, /* etc */ }
55
| ---------- variant `Homura` not found here
66
...
77
LL | use_token(&Token::Homura);
8-
| -------^^^^^^
9-
| |
10-
| variant not found in `Token`
8+
| ^^^^^^ variant not found in `Token`
119

1210
error[E0599]: no function or associated item named `method` found for type `Struct` in the current scope
1311
--> $DIR/issue-23173.rs:11:13
@@ -16,9 +14,7 @@ LL | struct Struct {
1614
| ------------- function or associated item `method` not found for this
1715
...
1816
LL | Struct::method();
19-
| --------^^^^^^
20-
| |
21-
| function or associated item not found in `Struct`
17+
| ^^^^^^ function or associated item not found in `Struct`
2218

2319
error[E0599]: no function or associated item named `method` found for type `Struct` in the current scope
2420
--> $DIR/issue-23173.rs:13:13
@@ -27,9 +23,7 @@ LL | struct Struct {
2723
| ------------- function or associated item `method` not found for this
2824
...
2925
LL | Struct::method;
30-
| --------^^^^^^
31-
| |
32-
| function or associated item not found in `Struct`
26+
| ^^^^^^ function or associated item not found in `Struct`
3327

3428
error[E0599]: no associated item named `Assoc` found for type `Struct` in the current scope
3529
--> $DIR/issue-23173.rs:15:13
@@ -38,9 +32,7 @@ LL | struct Struct {
3832
| ------------- associated item `Assoc` not found for this
3933
...
4034
LL | Struct::Assoc;
41-
| --------^^^^^
42-
| |
43-
| associated item not found in `Struct`
35+
| ^^^^^ associated item not found in `Struct`
4436

4537
error: aborting due to 4 previous errors
4638

src/test/ui/issues/issue-23217.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ error[E0599]: no variant named `A` found for type `SomeEnum` in the current scop
44
LL | pub enum SomeEnum {
55
| ----------------- variant `A` not found here
66
LL | B = SomeEnum::A,
7-
| ----------^
8-
| | |
9-
| | help: did you mean: `B`
10-
| variant not found in `SomeEnum`
7+
| ^
8+
| |
9+
| variant not found in `SomeEnum`
10+
| help: did you mean: `B`
1111

1212
error: aborting due to previous error
1313

src/test/ui/issues/issue-28344.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ error[E0599]: no function or associated item named `bitor` found for type `dyn s
88
--> $DIR/issue-28344.rs:4:25
99
|
1010
LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
11-
| --------^^^^^
12-
| |
13-
| function or associated item not found in `dyn std::ops::BitXor<_>`
14-
| help: did you mean: `bitxor`
11+
| ^^^^^
12+
| |
13+
| function or associated item not found in `dyn std::ops::BitXor<_>`
14+
| help: did you mean: `bitxor`
1515

1616
error[E0191]: the value of the associated type `Output` (from the trait `std::ops::BitXor`) must be specified
1717
--> $DIR/issue-28344.rs:8:13
@@ -23,10 +23,10 @@ error[E0599]: no function or associated item named `bitor` found for type `dyn s
2323
--> $DIR/issue-28344.rs:8:21
2424
|
2525
LL | let g = BitXor::bitor;
26-
| --------^^^^^
27-
| |
28-
| function or associated item not found in `dyn std::ops::BitXor<_>`
29-
| help: did you mean: `bitxor`
26+
| ^^^^^
27+
| |
28+
| function or associated item not found in `dyn std::ops::BitXor<_>`
29+
| help: did you mean: `bitxor`
3030

3131
error: aborting due to 4 previous errors
3232

src/test/ui/issues/issue-28586.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0599]: no associated item named `BYTES` found for type `usize` in the cur
22
--> $DIR/issue-28586.rs:4:26
33
|
44
LL | impl Foo for [u8; usize::BYTES] {}
5-
| -------^^^^^
6-
| |
7-
| associated item not found in `usize`
5+
| ^^^^^ associated item not found in `usize`
86

97
error: aborting due to previous error
108

src/test/ui/issues/issue-28971.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ LL | enum Foo {
55
| -------- variant `Baz` not found here
66
...
77
LL | Foo::Baz(..) => (),
8-
| -----^^^----
9-
| | |
10-
| | help: did you mean: `Bar`
11-
| variant not found in `Foo`
8+
| ^^^
9+
| |
10+
| variant not found in `Foo`
11+
| help: did you mean: `Bar`
1212

1313
error: aborting due to previous error
1414

src/test/ui/issues/issue-30123.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0599]: no function or associated item named `new_undirected` found for ty
22
--> $DIR/issue-30123.rs:7:33
33
|
44
LL | let ug = Graph::<i32, i32>::new_undirected();
5-
| -------------------^^^^^^^^^^^^^^
6-
| |
7-
| function or associated item not found in `issue_30123_aux::Graph<i32, i32>`
5+
| ^^^^^^^^^^^^^^ function or associated item not found in `issue_30123_aux::Graph<i32, i32>`
86

97
error: aborting due to previous error
108

src/test/ui/issues/issue-38919.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0599]: no associated item named `Item` found for type `T` in the current
22
--> $DIR/issue-38919.rs:2:8
33
|
44
LL | T::Item;
5-
| ---^^^^
6-
| |
7-
| associated item not found in `T`
5+
| ^^^^ associated item not found in `T`
86

97
error: aborting due to previous error
108

src/test/ui/issues/issue-39559.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0599]: no function or associated item named `dim` found for type `D` in t
22
--> $DIR/issue-39559.rs:14:21
33
|
44
LL | entries: [T; D::dim()],
5-
| ---^^^
6-
| |
7-
| function or associated item not found in `D`
5+
| ^^^ function or associated item not found in `D`
86
|
97
= help: items from traits can only be used if the trait is implemented and in scope
108
= note: the following trait defines an item `dim`, perhaps you need to implement it:

src/test/ui/issues/issue-3973.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ LL | struct Point {
1414
| ------------ function or associated item `new` not found for this
1515
...
1616
LL | let p = Point::new(0.0, 0.0);
17-
| -------^^^
18-
| |
19-
| function or associated item not found in `Point`
17+
| ^^^ function or associated item not found in `Point`
2018

2119
error: aborting due to 2 previous errors
2220

src/test/ui/issues/issue-42880.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no associated item named `String` found for type `std::string::Str
22
--> $DIR/issue-42880.rs:4:22
33
|
44
LL | let f = |&Value::String(_)| ();
5-
| -------^^^^^^--- associated item not found in `std::string::String`
5+
| ^^^^^^ associated item not found in `std::string::String`
66

77
error: aborting due to previous error
88

src/test/ui/issues/issue-57362-2.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error[E0599]: no function or associated item named `make_g` found for type `for<
22
--> $DIR/issue-57362-2.rs:22:25
33
|
44
LL | let x = <fn (&())>::make_g();
5-
| ------------^^^^^^
6-
| |
7-
| function or associated item not found in `for<'r> fn(&'r ())`
5+
| ^^^^^^ function or associated item not found in `for<'r> fn(&'r ())`
86
|
97
= help: items from traits can only be used if the trait is implemented and in scope
108
= note: the following trait defines an item `make_g`, perhaps you need to implement it:

src/test/ui/issues/issue-7950.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ LL | struct Foo;
55
| ----------- function or associated item `bar` not found for this
66
...
77
LL | Foo::bar();
8-
| -----^^^
9-
| |
10-
| function or associated item not found in `Foo`
8+
| ^^^ function or associated item not found in `Foo`
119

1210
error: aborting due to previous error
1311

0 commit comments

Comments
 (0)