Skip to content

Commit 498bead

Browse files
committed
Tweak spans for E0599
1 parent 7cf074a commit 498bead

28 files changed

+81
-140
lines changed

src/librustc_typeck/check/method/suggest.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,26 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
6060
}
6161
}
6262

63-
pub fn report_method_error<'b>(&self,
64-
span: Span,
65-
rcvr_ty: Ty<'tcx>,
66-
item_name: ast::Ident,
67-
source: SelfSource<'b>,
68-
error: MethodError<'tcx>,
69-
args: Option<&'gcx [hir::Expr]>) {
63+
pub fn report_method_error<'b>(
64+
&self,
65+
span: Span,
66+
rcvr_ty: Ty<'tcx>,
67+
item_name: ast::Ident,
68+
source: SelfSource<'b>,
69+
error: MethodError<'tcx>,
70+
args: Option<&'gcx [hir::Expr]>,
71+
) {
72+
let mut span = span;
7073
// Avoid suggestions when we don't know what's going on.
7174
if rcvr_ty.references_error() {
7275
return;
7376
}
7477

75-
let report_candidates = |err: &mut DiagnosticBuilder<'_>,
76-
mut sources: Vec<CandidateSource>| {
78+
let report_candidates = |
79+
span: Span,
80+
err: &mut DiagnosticBuilder<'_>,
81+
mut sources: Vec<CandidateSource>,
82+
| {
7783
sources.sort();
7884
sources.dedup();
7985
// Dynamic limit to avoid hiding just one candidate, which is silly.
@@ -291,9 +297,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
291297
err.emit();
292298
return;
293299
} else {
300+
span = item_name.span;
294301
let mut err = struct_span_err!(
295302
tcx.sess,
296-
item_name.span,
303+
span,
297304
E0599,
298305
"no {} named `{}` found for type `{}` in the current scope",
299306
item_kind,
@@ -303,7 +310,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
303310
if let Some(suggestion) = suggestion {
304311
// enum variant
305312
err.span_suggestion(
306-
item_name.span,
313+
span,
307314
"did you mean",
308315
suggestion.to_string(),
309316
Applicability::MaybeIncorrect,
@@ -414,9 +421,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
414421
self.ty_to_string(actual), item_name));
415422
}
416423

417-
report_candidates(&mut err, static_sources);
424+
report_candidates(span, &mut err, static_sources);
418425
} else if static_sources.len() > 1 {
419-
report_candidates(&mut err, static_sources);
426+
report_candidates(span, &mut err, static_sources);
420427
}
421428

422429
if !unsatisfied_predicates.is_empty() {
@@ -461,7 +468,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
461468
"multiple applicable items in scope");
462469
err.span_label(span, format!("multiple `{}` found", item_name));
463470

464-
report_candidates(&mut err, sources);
471+
report_candidates(span, &mut err, sources);
465472
err.emit();
466473
}
467474

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
@@ -26,33 +26,25 @@ error[E0599]: no associated item named `AssocItem` found for type `[u8]` in the
2626
--> $DIR/bad-assoc-pat.rs:3:15
2727
|
2828
LL | [u8]::AssocItem => {}
29-
| ------^^^^^^^^^
30-
| |
31-
| associated item not found in `[u8]`
29+
| ^^^^^^^^^ associated item not found in `[u8]`
3230

3331
error[E0599]: no associated item named `AssocItem` found for type `(u8, u8)` in the current scope
3432
--> $DIR/bad-assoc-pat.rs:6:19
3533
|
3634
LL | (u8, u8)::AssocItem => {}
37-
| ----------^^^^^^^^^
38-
| |
39-
| associated item not found in `(u8, u8)`
35+
| ^^^^^^^^^ associated item not found in `(u8, u8)`
4036

4137
error[E0599]: no associated item named `AssocItem` found for type `_` in the current scope
4238
--> $DIR/bad-assoc-pat.rs:9:12
4339
|
4440
LL | _::AssocItem => {}
45-
| ---^^^^^^^^^
46-
| |
47-
| associated item not found in `_`
41+
| ^^^^^^^^^ associated item not found in `_`
4842

4943
error[E0599]: no associated item named `AssocItem` found for type `(u8,)` in the current scope
5044
--> $DIR/bad-assoc-pat.rs:14:17
5145
|
5246
LL | &(u8,)::AssocItem => {}
53-
| -------^^^^^^^^^
54-
| |
55-
| associated item not found in `(u8,)`
47+
| ^^^^^^^^^ associated item not found in `(u8,)`
5648

5749
error: aborting due to 8 previous errors
5850

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)