about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2022-07-26 13:12:20 +0900
committerGitHub <noreply@github.com>2022-07-26 13:12:20 +0900
commitd89e99a805838bb03e6f81a461efcdab8e616aee (patch)
tree8ee6295ea78064272dc4d9579534fff4c04e8f11 /src
parent29444545405471a106c67adf48593c5943b6f483 (diff)
parentf85f37583d91152b967cd0d1bd7253b339a26d42 (diff)
downloadrust-d89e99a805838bb03e6f81a461efcdab8e616aee.tar.gz
rust-d89e99a805838bb03e6f81a461efcdab8e616aee.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.fixed17
-rw-r--r--src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.rs17
-rw-r--r--src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.stderr41
3 files changed, 75 insertions, 0 deletions
diff --git a/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.fixed b/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.fixed
new file mode 100644
index 00000000000..63b65ab20fe
--- /dev/null
+++ b/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.fixed
@@ -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);
+}
diff --git a/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.rs b/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.rs
new file mode 100644
index 00000000000..2ab4e3955f3
--- /dev/null
+++ b/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.rs
@@ -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);
+}
diff --git a/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.stderr b/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.stderr
new file mode 100644
index 00000000000..82a7f276372
--- /dev/null
+++ b/src/test/ui/mismatched_types/suggest-removing-tulpe-struct-field.stderr
@@ -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`.