Skip to content

Commit 7edb3ad

Browse files
authored
Rollup merge of rust-lang#81655 - matsujika:suggest-accessing-field-rewording, r=estebank
Improve wording of suggestion about accessing field Follow-up to rust-lang#81504 The compiler at this moment suggests "you might have meant to use field `b` of type `B`", sounding like it's type `B` which has the field `b`. r? ```@estebank```
2 parents 7f2eeb1 + bad0f28 commit 7edb3ad

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
18551855
diag.span_suggestion(
18561856
span,
18571857
&format!(
1858-
"you might have meant to use field `{}` of type `{}`",
1858+
"you might have meant to use field `{}` whose type is `{}`",
18591859
name, ty
18601860
),
18611861
suggestion,

src/test/ui/suggestions/field-access.fixed

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ union Foo {
1818
fn main() {
1919
let a = A { b: B::Fst };
2020
if let B::Fst = a.b {}; //~ ERROR mismatched types [E0308]
21-
//~^ HELP you might have meant to use field `b` of type `B`
21+
//~^ HELP you might have meant to use field `b` whose type is `B`
2222
match a.b {
23-
//~^ HELP you might have meant to use field `b` of type `B`
24-
//~| HELP you might have meant to use field `b` of type `B`
23+
//~^ HELP you might have meant to use field `b` whose type is `B`
24+
//~| HELP you might have meant to use field `b` whose type is `B`
2525
B::Fst => (), //~ ERROR mismatched types [E0308]
2626
B::Snd => (), //~ ERROR mismatched types [E0308]
2727
}
2828

2929
let foo = Foo { bar: 42 };
3030
match unsafe { foo.bar } {
31-
//~^ HELP you might have meant to use field `bar` of type `u32`
31+
//~^ HELP you might have meant to use field `bar` whose type is `u32`
3232
1u32 => (), //~ ERROR mismatched types [E0308]
3333
_ => (),
3434
}

src/test/ui/suggestions/field-access.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ union Foo {
1818
fn main() {
1919
let a = A { b: B::Fst };
2020
if let B::Fst = a {}; //~ ERROR mismatched types [E0308]
21-
//~^ HELP you might have meant to use field `b` of type `B`
21+
//~^ HELP you might have meant to use field `b` whose type is `B`
2222
match a {
23-
//~^ HELP you might have meant to use field `b` of type `B`
24-
//~| HELP you might have meant to use field `b` of type `B`
23+
//~^ HELP you might have meant to use field `b` whose type is `B`
24+
//~| HELP you might have meant to use field `b` whose type is `B`
2525
B::Fst => (), //~ ERROR mismatched types [E0308]
2626
B::Snd => (), //~ ERROR mismatched types [E0308]
2727
}
2828

2929
let foo = Foo { bar: 42 };
3030
match foo {
31-
//~^ HELP you might have meant to use field `bar` of type `u32`
31+
//~^ HELP you might have meant to use field `bar` whose type is `u32`
3232
1u32 => (), //~ ERROR mismatched types [E0308]
3333
_ => (),
3434
}

src/test/ui/suggestions/field-access.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | if let B::Fst = a {};
99
| |
1010
| expected struct `A`, found enum `B`
1111
|
12-
help: you might have meant to use field `b` of type `B`
12+
help: you might have meant to use field `b` whose type is `B`
1313
|
1414
LL | if let B::Fst = a.b {};
1515
| ^^^
@@ -26,7 +26,7 @@ LL | match a {
2626
LL | B::Fst => (),
2727
| ^^^^^^ expected struct `A`, found enum `B`
2828
|
29-
help: you might have meant to use field `b` of type `B`
29+
help: you might have meant to use field `b` whose type is `B`
3030
|
3131
LL | match a.b {
3232
| ^^^
@@ -43,7 +43,7 @@ LL | match a {
4343
LL | B::Snd => (),
4444
| ^^^^^^ expected struct `A`, found enum `B`
4545
|
46-
help: you might have meant to use field `b` of type `B`
46+
help: you might have meant to use field `b` whose type is `B`
4747
|
4848
LL | match a.b {
4949
| ^^^
@@ -57,7 +57,7 @@ LL |
5757
LL | 1u32 => (),
5858
| ^^^^ expected union `Foo`, found `u32`
5959
|
60-
help: you might have meant to use field `bar` of type `u32`
60+
help: you might have meant to use field `bar` whose type is `u32`
6161
|
6262
LL | match unsafe { foo.bar } {
6363
| ^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)