-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suggest removing the tuple struct field for the unwrapped value
add a test case for macro
- Loading branch information
Showing
4 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |