about summary refs log tree commit diff
diff options
context:
space:
mode:
authorxizheyin <xizheyin@smail.nju.edu.cn>2025-08-13 23:17:29 +0800
committerxizheyin <xizheyin@smail.nju.edu.cn>2025-08-13 23:17:29 +0800
commit12d1665d1163d62de0dd2c2fcb2f508fea8123f1 (patch)
treed5241710d2a4deb282823f502a4eea221f7dbd09
parenta980cd4311ae4b5bf9099d418e32643d068f1344 (diff)
Add test suggest-add-wrapper-issue-145294
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
-rw-r--r--tests/ui/typeck/suggestions/suggest-add-wrapper-issue-145294.rs26
-rw-r--r--tests/ui/typeck/suggestions/suggest-add-wrapper-issue-145294.stderr29
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/ui/typeck/suggestions/suggest-add-wrapper-issue-145294.rs b/tests/ui/typeck/suggestions/suggest-add-wrapper-issue-145294.rs
new file mode 100644
index 00000000000..cfe167cf88d
--- /dev/null
+++ b/tests/ui/typeck/suggestions/suggest-add-wrapper-issue-145294.rs
@@ -0,0 +1,26 @@
+// Suppress the suggestion that adding a wrapper.
+// When expected_ty and expr_ty are the same ADT,
+// we prefer to compare their internal generic params,
+// so when the current variant corresponds to an unresolved infer,
+// the suggestion is rejected.
+// e.g. `Ok(Some("hi"))` is type of `Result<Option<&str>, _>`,
+// where `E` is still an unresolved inference variable.
+
+fn foo() -> Result<Option<String>, ()> {
+    todo!()
+}
+
+#[derive(PartialEq, Debug)]
+enum Bar<T, E> {
+    A(T),
+    B(E),
+}
+
+fn bar() -> Bar<String, ()> {
+    todo!()
+}
+
+fn main() {
+    assert_eq!(Ok(Some("hi")), foo()); //~ ERROR mismatched types [E0308]
+    assert_eq!(Bar::A("hi"), bar()); //~ ERROR mismatched types [E0308]
+}
diff --git a/tests/ui/typeck/suggestions/suggest-add-wrapper-issue-145294.stderr b/tests/ui/typeck/suggestions/suggest-add-wrapper-issue-145294.stderr
new file mode 100644
index 00000000000..ef5eeb29cf5
--- /dev/null
+++ b/tests/ui/typeck/suggestions/suggest-add-wrapper-issue-145294.stderr
@@ -0,0 +1,29 @@
+error[E0308]: mismatched types
+  --> $DIR/suggest-add-wrapper-issue-145294.rs:24:32
+   |
+LL |     assert_eq!(Ok(Some("hi")), foo());
+   |                                ^^^^^ expected `Result<Option<&str>, _>`, found `Result<Option<String>, ()>`
+   |
+   = note: expected enum `Result<Option<&str>, _>`
+              found enum `Result<Option<String>, ()>`
+help: try wrapping the expression in `Err`
+   |
+LL |     assert_eq!(Ok(Some("hi")), Err(foo()));
+   |                                ++++     +
+
+error[E0308]: mismatched types
+  --> $DIR/suggest-add-wrapper-issue-145294.rs:25:30
+   |
+LL |     assert_eq!(Bar::A("hi"), bar());
+   |                              ^^^^^ expected `Bar<&str, _>`, found `Bar<String, ()>`
+   |
+   = note: expected enum `Bar<&str, _>`
+              found enum `Bar<String, ()>`
+help: try wrapping the expression in `Bar::B`
+   |
+LL |     assert_eq!(Bar::A("hi"), Bar::B(bar()));
+   |                              +++++++     +
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.