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

0 commit comments

Comments
 (0)