Rollup merge of #99593 - TaKO8Ki:suggest-removing-tuple-struct-field, r=compiler-errors

Suggest removing the tuple struct field for the unwrapped value

fixes #99416
This commit is contained in:
Yuki Okushi 2022-07-26 13:12:20 +09:00 committed by GitHub
commit d89e99a805
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 0 deletions

View file

@ -0,0 +1,17 @@
// run-rustfix
macro_rules! my_wrapper {
($expr:expr) => { MyWrapper($expr) }
}
pub struct MyWrapper(u32);
fn main() {
let value = MyWrapper(123);
some_fn(value); //~ ERROR mismatched types
some_fn(my_wrapper!(123)); //~ ERROR mismatched types
}
fn some_fn(wrapped: MyWrapper) {
drop(wrapped);
}

View file

@ -0,0 +1,17 @@
// run-rustfix
macro_rules! my_wrapper {
($expr:expr) => { MyWrapper($expr) }
}
pub struct MyWrapper(u32);
fn main() {
let value = MyWrapper(123);
some_fn(value.0); //~ ERROR mismatched types
some_fn(my_wrapper!(123).0); //~ ERROR mismatched types
}
fn some_fn(wrapped: MyWrapper) {
drop(wrapped);
}

View file

@ -0,0 +1,41 @@
error[E0308]: mismatched types
--> $DIR/suggest-removing-tulpe-struct-field.rs:11:13
|
LL | some_fn(value.0);
| ------- ^^^^^^^ expected struct `MyWrapper`, found `u32`
| |
| arguments to this function are incorrect
|
note: function defined here
--> $DIR/suggest-removing-tulpe-struct-field.rs:15:4
|
LL | fn some_fn(wrapped: MyWrapper) {
| ^^^^^^^ ------------------
help: consider removing the tuple struct field `0`
|
LL - some_fn(value.0);
LL + some_fn(value);
|
error[E0308]: mismatched types
--> $DIR/suggest-removing-tulpe-struct-field.rs:12:13
|
LL | some_fn(my_wrapper!(123).0);
| ------- ^^^^^^^^^^^^^^^^^^ expected struct `MyWrapper`, found `u32`
| |
| arguments to this function are incorrect
|
note: function defined here
--> $DIR/suggest-removing-tulpe-struct-field.rs:15:4
|
LL | fn some_fn(wrapped: MyWrapper) {
| ^^^^^^^ ------------------
help: consider removing the tuple struct field `0`
|
LL - some_fn(my_wrapper!(123).0);
LL + some_fn(my_wrapper!(123));
|
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.