Skip to content

Commit 4f7dddd

Browse files
committed
recover primary span label
1 parent 8bd8f3b commit 4f7dddd

File tree

51 files changed

+131
-107
lines changed

Some content is hidden

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

51 files changed

+131
-107
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -2418,9 +2418,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24182418
field_ident: Ident,
24192419
base: &'tcx hir::Expr<'tcx>,
24202420
ty: Ty<'tcx>,
2421-
) {
2421+
) -> bool {
24222422
let Some(output_ty) = self.get_impl_future_output_ty(ty) else {
2423-
return;
2423+
return false;
24242424
};
24252425
let mut add_label = true;
24262426
if let ty::Adt(def, _) = output_ty.kind() {
@@ -2449,6 +2449,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24492449
if add_label {
24502450
err.span_label(field_ident.span, format!("field not found in `{ty}`"));
24512451
}
2452+
true
24522453
}
24532454

24542455
fn ban_nonexisting_field(
@@ -2464,20 +2465,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24642465
);
24652466
let mut err = self.no_such_field_err(ident, base_ty, base.hir_id);
24662467

2467-
match *base_ty.peel_refs().kind() {
2468+
let has_label = match *base_ty.peel_refs().kind() {
24682469
ty::Array(_, len) => {
24692470
self.maybe_suggest_array_indexing(&mut err, expr, base, ident, len);
2471+
false
24702472
}
24712473
ty::RawPtr(..) => {
24722474
self.suggest_first_deref_field(&mut err, expr, base, ident);
2475+
false
24732476
}
24742477
ty::Param(param_ty) => {
24752478
self.point_at_param_definition(&mut err, param_ty);
2479+
false
24762480
}
24772481
ty::Alias(ty::Opaque, _) => {
2478-
self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs());
2482+
self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs())
24792483
}
2480-
_ => {}
2484+
_ => false,
2485+
};
2486+
2487+
if !has_label {
2488+
err.span_label(ident.span, "unknown field");
24812489
}
24822490

24832491
self.suggest_fn_call(&mut err, base, base_ty, |output_ty| {

tests/ui/async-await/suggest-switching-edition-on-await-cargo.rs

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn await_on_struct_missing() {
1010
let x = S;
1111
x.await;
1212
//~^ ERROR no field `await` on type
13+
//~| NOTE unknown field
1314
//~| NOTE to `.await` a `Future`, switch to Rust 2018
1415
//~| HELP set `edition = "2021"` in `Cargo.toml`
1516
//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide
@@ -22,6 +23,7 @@ fn await_on_struct_similar() {
2223
let x = S { awai: 42 };
2324
x.await;
2425
//~^ ERROR no field `await` on type
26+
//~| NOTE unknown field
2527
//~| HELP a field with a similar name exists
2628
//~| NOTE to `.await` a `Future`, switch to Rust 2018
2729
//~| HELP set `edition = "2021"` in `Cargo.toml`
@@ -31,6 +33,7 @@ fn await_on_struct_similar() {
3133
fn await_on_63533(x: Pin<&mut dyn Future<Output = ()>>) {
3234
x.await;
3335
//~^ ERROR no field `await` on type
36+
//~| NOTE unknown field
3437
//~| NOTE to `.await` a `Future`, switch to Rust 2018
3538
//~| HELP set `edition = "2021"` in `Cargo.toml`
3639
//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide
@@ -39,6 +42,7 @@ fn await_on_63533(x: Pin<&mut dyn Future<Output = ()>>) {
3942
fn await_on_apit(x: impl Future<Output = ()>) {
4043
x.await;
4144
//~^ ERROR no field `await` on type
45+
//~| NOTE unknown field
4246
//~| NOTE to `.await` a `Future`, switch to Rust 2018
4347
//~| HELP set `edition = "2021"` in `Cargo.toml`
4448
//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide

tests/ui/async-await/suggest-switching-edition-on-await-cargo.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ error[E0609]: no field `await` on type `await_on_struct_missing::S`
22
--> $DIR/suggest-switching-edition-on-await-cargo.rs:11:7
33
|
44
LL | x.await;
5-
| ^^^^^
5+
| ^^^^^ unknown field
66
|
77
= note: to `.await` a `Future`, switch to Rust 2018 or later
88
= help: set `edition = "2021"` in `Cargo.toml`
99
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
1010

1111
error[E0609]: no field `await` on type `await_on_struct_similar::S`
12-
--> $DIR/suggest-switching-edition-on-await-cargo.rs:23:7
12+
--> $DIR/suggest-switching-edition-on-await-cargo.rs:24:7
1313
|
1414
LL | x.await;
15-
| ^^^^^
15+
| ^^^^^ unknown field
1616
|
1717
= note: to `.await` a `Future`, switch to Rust 2018 or later
1818
= help: set `edition = "2021"` in `Cargo.toml`
@@ -23,20 +23,20 @@ LL | x.awai;
2323
| ~~~~
2424

2525
error[E0609]: no field `await` on type `Pin<&mut dyn Future<Output = ()>>`
26-
--> $DIR/suggest-switching-edition-on-await-cargo.rs:32:7
26+
--> $DIR/suggest-switching-edition-on-await-cargo.rs:34:7
2727
|
2828
LL | x.await;
29-
| ^^^^^
29+
| ^^^^^ unknown field
3030
|
3131
= note: to `.await` a `Future`, switch to Rust 2018 or later
3232
= help: set `edition = "2021"` in `Cargo.toml`
3333
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
3434

3535
error[E0609]: no field `await` on type `impl Future<Output = ()>`
36-
--> $DIR/suggest-switching-edition-on-await-cargo.rs:40:7
36+
--> $DIR/suggest-switching-edition-on-await-cargo.rs:43:7
3737
|
3838
LL | x.await;
39-
| ^^^^^
39+
| ^^^^^ unknown field
4040
|
4141
= note: to `.await` a `Future`, switch to Rust 2018 or later
4242
= help: set `edition = "2021"` in `Cargo.toml`

tests/ui/async-await/suggest-switching-edition-on-await.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fn await_on_struct_missing() {
88
let x = S;
99
x.await;
1010
//~^ ERROR no field `await` on type
11+
//~| NOTE unknown field
1112
//~| NOTE to `.await` a `Future`, switch to Rust 2018
1213
//~| HELP pass `--edition 2021` to `rustc`
1314
//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide
@@ -20,6 +21,7 @@ fn await_on_struct_similar() {
2021
let x = S { awai: 42 };
2122
x.await;
2223
//~^ ERROR no field `await` on type
24+
//~| NOTE unknown field
2325
//~| HELP a field with a similar name exists
2426
//~| NOTE to `.await` a `Future`, switch to Rust 2018
2527
//~| HELP pass `--edition 2021` to `rustc`
@@ -29,6 +31,7 @@ fn await_on_struct_similar() {
2931
fn await_on_63533(x: Pin<&mut dyn Future<Output = ()>>) {
3032
x.await;
3133
//~^ ERROR no field `await` on type
34+
//~| NOTE unknown field
3235
//~| NOTE to `.await` a `Future`, switch to Rust 2018
3336
//~| HELP pass `--edition 2021` to `rustc`
3437
//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide
@@ -37,6 +40,7 @@ fn await_on_63533(x: Pin<&mut dyn Future<Output = ()>>) {
3740
fn await_on_apit(x: impl Future<Output = ()>) {
3841
x.await;
3942
//~^ ERROR no field `await` on type
43+
//~| NOTE unknown field
4044
//~| NOTE to `.await` a `Future`, switch to Rust 2018
4145
//~| HELP pass `--edition 2021` to `rustc`
4246
//~| NOTE for more on editions, read https://doc.rust-lang.org/edition-guide

tests/ui/async-await/suggest-switching-edition-on-await.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ error[E0609]: no field `await` on type `await_on_struct_missing::S`
22
--> $DIR/suggest-switching-edition-on-await.rs:9:7
33
|
44
LL | x.await;
5-
| ^^^^^
5+
| ^^^^^ unknown field
66
|
77
= note: to `.await` a `Future`, switch to Rust 2018 or later
88
= help: pass `--edition 2021` to `rustc`
99
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
1010

1111
error[E0609]: no field `await` on type `await_on_struct_similar::S`
12-
--> $DIR/suggest-switching-edition-on-await.rs:21:7
12+
--> $DIR/suggest-switching-edition-on-await.rs:22:7
1313
|
1414
LL | x.await;
15-
| ^^^^^
15+
| ^^^^^ unknown field
1616
|
1717
= note: to `.await` a `Future`, switch to Rust 2018 or later
1818
= help: pass `--edition 2021` to `rustc`
@@ -23,20 +23,20 @@ LL | x.awai;
2323
| ~~~~
2424

2525
error[E0609]: no field `await` on type `Pin<&mut dyn Future<Output = ()>>`
26-
--> $DIR/suggest-switching-edition-on-await.rs:30:7
26+
--> $DIR/suggest-switching-edition-on-await.rs:32:7
2727
|
2828
LL | x.await;
29-
| ^^^^^
29+
| ^^^^^ unknown field
3030
|
3131
= note: to `.await` a `Future`, switch to Rust 2018 or later
3232
= help: pass `--edition 2021` to `rustc`
3333
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
3434

3535
error[E0609]: no field `await` on type `impl Future<Output = ()>`
36-
--> $DIR/suggest-switching-edition-on-await.rs:38:7
36+
--> $DIR/suggest-switching-edition-on-await.rs:41:7
3737
|
3838
LL | x.await;
39-
| ^^^^^
39+
| ^^^^^ unknown field
4040
|
4141
= note: to `.await` a `Future`, switch to Rust 2018 or later
4242
= help: pass `--edition 2021` to `rustc`

tests/ui/derived-errors/issue-30580.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0609]: no field `c` on type `&Foo`
22
--> $DIR/issue-30580.rs:12:11
33
|
44
LL | b.c;
5-
| ^
5+
| ^ unknown field
66
|
77
help: a field with a similar name exists
88
|

tests/ui/did_you_mean/dont-suggest-doc-hidden-fields.rs

+3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ fn main() {
2121
// `doc(hidden)` because it's defined in this crate.
2222
A::default().hey;
2323
//~^ ERROR no field `hey` on type `A`
24+
//~| NOTE unknown field
2425
//~| NOTE available fields are: `hello`, `bye`
2526

2627
// Here we want to hide the field `hello` since it's marked
2728
// `doc(hidden)` and comes from an external crate.
2829
doc_hidden_fields::B::default().hey;
2930
//~^ ERROR no field `hey` on type `B`
31+
//~| NOTE unknown field
3032
//~| NOTE available field is: `bye`
3133

3234
C::default().hey;
3335
//~^ ERROR no field `hey` on type `C`
36+
//~| NOTE unknown field
3437
//~| NOTE available fields are: `hello`, `bye`
3538
}

tests/ui/did_you_mean/dont-suggest-doc-hidden-fields.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ error[E0609]: no field `hey` on type `A`
22
--> $DIR/dont-suggest-doc-hidden-fields.rs:22:18
33
|
44
LL | A::default().hey;
5-
| ^^^
5+
| ^^^ unknown field
66
|
77
= note: available fields are: `hello`, `bye`
88

99
error[E0609]: no field `hey` on type `B`
10-
--> $DIR/dont-suggest-doc-hidden-fields.rs:28:37
10+
--> $DIR/dont-suggest-doc-hidden-fields.rs:29:37
1111
|
1212
LL | doc_hidden_fields::B::default().hey;
13-
| ^^^
13+
| ^^^ unknown field
1414
|
1515
= note: available field is: `bye`
1616

1717
error[E0609]: no field `hey` on type `C`
18-
--> $DIR/dont-suggest-doc-hidden-fields.rs:32:18
18+
--> $DIR/dont-suggest-doc-hidden-fields.rs:34:18
1919
|
2020
LL | C::default().hey;
21-
| ^^^
21+
| ^^^ unknown field
2222
|
2323
= note: available fields are: `hello`, `bye`
2424

tests/ui/did_you_mean/dont-suggest-hygienic-fields.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ error[E0609]: no field `field` on type `Compound`
1313
--> $DIR/dont-suggest-hygienic-fields.rs:24:16
1414
|
1515
LL | let _ = ty.field;
16-
| ^^^^^
16+
| ^^^^^ unknown field
1717

1818
error[E0609]: no field `fieeld` on type `Compound`
1919
--> $DIR/dont-suggest-hygienic-fields.rs:25:16
2020
|
2121
LL | let _ = ty.fieeld;
22-
| ^^^^^^
22+
| ^^^^^^ unknown field
2323

2424
error[E0026]: struct `Compound` does not have a field named `field`
2525
--> $DIR/dont-suggest-hygienic-fields.rs:27:20
@@ -42,7 +42,7 @@ error[E0609]: no field `0` on type `Component`
4242
--> $DIR/dont-suggest-hygienic-fields.rs:34:16
4343
|
4444
LL | let _ = ty.0;
45-
| ^
45+
| ^ unknown field
4646

4747
error: aborting due to 6 previous errors
4848

tests/ui/did_you_mean/issue-36798.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0609]: no field `baz` on type `Foo`
22
--> $DIR/issue-36798.rs:7:7
33
|
44
LL | f.baz;
5-
| ^^^
5+
| ^^^ unknown field
66
|
77
help: a field with a similar name exists
88
|

tests/ui/did_you_mean/issue-36798_unknown_field.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0609]: no field `zz` on type `Foo`
22
--> $DIR/issue-36798_unknown_field.rs:7:7
33
|
44
LL | f.zz;
5-
| ^^
5+
| ^^ unknown field
66
|
77
= note: available field is: `bar`
88

tests/ui/did_you_mean/issue-42599_available_fields_note.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0609]: no field `inocently_mispellable` on type `Demo`
1616
--> $DIR/issue-42599_available_fields_note.rs:32:41
1717
|
1818
LL | let innocent_field_misaccess = demo.inocently_mispellable;
19-
| ^^^^^^^^^^^^^^^^^^^^^
19+
| ^^^^^^^^^^^^^^^^^^^^^ unknown field
2020
|
2121
help: a field with a similar name exists
2222
|
@@ -27,7 +27,7 @@ error[E0609]: no field `egregiously_nonexistent_field` on type `Demo`
2727
--> $DIR/issue-42599_available_fields_note.rs:35:42
2828
|
2929
LL | let egregious_field_misaccess = demo.egregiously_nonexistent_field;
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown field
3131
|
3232
= note: available fields are: `favorite_integer`, `innocently_misspellable`
3333

tests/ui/error-codes/E0609-private-method.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0609]: no field `method` on type `Foo`
22
--> $DIR/E0609-private-method.rs:15:7
33
|
44
LL | f.method;
5-
| ^^^^^^
5+
| ^^^^^^ unknown field
66

77
error: aborting due to previous error
88

tests/ui/error-codes/E0609.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ error[E0609]: no field `foo` on type `Foo`
22
--> $DIR/E0609.rs:8:15
33
|
44
LL | let _ = x.foo;
5-
| ^^^
5+
| ^^^ unknown field
66
|
77
= note: available field is: `x`
88

99
error[E0609]: no field `1` on type `Bar`
1010
--> $DIR/E0609.rs:11:7
1111
|
1212
LL | y.1;
13-
| ^
13+
| ^ unknown field
1414

1515
error: aborting due to 2 previous errors
1616

tests/ui/error-codes/ex-E0612.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0609]: no field `1` on type `Foo`
22
--> $DIR/ex-E0612.rs:5:6
33
|
44
LL | y.1;
5-
| ^
5+
| ^ unknown field
66
|
77
help: a field with a similar name exists
88
|

tests/ui/infinite/infinite-autoderef.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ error[E0609]: no field `foo` on type `Foo`
2929
--> $DIR/infinite-autoderef.rs:24:9
3030
|
3131
LL | Foo.foo;
32-
| ^^^
32+
| ^^^ unknown field
3333

3434
error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
3535
--> $DIR/infinite-autoderef.rs:25:9

tests/ui/issues/issue-11004.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ error[E0609]: no field `x` on type `*mut A`
33
|
44
LL | let x : i32 = n.x;
55
| --^
6-
| |
6+
| | |
7+
| | unknown field
78
| help: `n` is a raw pointer; try dereferencing it: `(*n).x`
89

910
error[E0609]: no field `y` on type `*mut A`
1011
--> $DIR/issue-11004.rs:8:21
1112
|
1213
LL | let y : f64 = n.y;
1314
| --^
14-
| |
15+
| | |
16+
| | unknown field
1517
| help: `n` is a raw pointer; try dereferencing it: `(*n).y`
1618

1719
error: aborting due to 2 previous errors

tests/ui/issues/issue-13847.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0609]: no field `is_failure` on type `!`
22
--> $DIR/issue-13847.rs:2:12
33
|
44
LL | return.is_failure
5-
| ^^^^^^^^^^
5+
| ^^^^^^^^^^ unknown field
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)