Skip to content

Commit 12d1665

Browse files
committed
Add test suggest-add-wrapper-issue-145294
Signed-off-by: xizheyin <[email protected]>
1 parent a980cd4 commit 12d1665

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Suppress the suggestion that adding a wrapper.
2+
// When expected_ty and expr_ty are the same ADT,
3+
// we prefer to compare their internal generic params,
4+
// so when the current variant corresponds to an unresolved infer,
5+
// the suggestion is rejected.
6+
// e.g. `Ok(Some("hi"))` is type of `Result<Option<&str>, _>`,
7+
// where `E` is still an unresolved inference variable.
8+
9+
fn foo() -> Result<Option<String>, ()> {
10+
todo!()
11+
}
12+
13+
#[derive(PartialEq, Debug)]
14+
enum Bar<T, E> {
15+
A(T),
16+
B(E),
17+
}
18+
19+
fn bar() -> Bar<String, ()> {
20+
todo!()
21+
}
22+
23+
fn main() {
24+
assert_eq!(Ok(Some("hi")), foo()); //~ ERROR mismatched types [E0308]
25+
assert_eq!(Bar::A("hi"), bar()); //~ ERROR mismatched types [E0308]
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/suggest-add-wrapper-issue-145294.rs:24:32
3+
|
4+
LL | assert_eq!(Ok(Some("hi")), foo());
5+
| ^^^^^ expected `Result<Option<&str>, _>`, found `Result<Option<String>, ()>`
6+
|
7+
= note: expected enum `Result<Option<&str>, _>`
8+
found enum `Result<Option<String>, ()>`
9+
help: try wrapping the expression in `Err`
10+
|
11+
LL | assert_eq!(Ok(Some("hi")), Err(foo()));
12+
| ++++ +
13+
14+
error[E0308]: mismatched types
15+
--> $DIR/suggest-add-wrapper-issue-145294.rs:25:30
16+
|
17+
LL | assert_eq!(Bar::A("hi"), bar());
18+
| ^^^^^ expected `Bar<&str, _>`, found `Bar<String, ()>`
19+
|
20+
= note: expected enum `Bar<&str, _>`
21+
found enum `Bar<String, ()>`
22+
help: try wrapping the expression in `Bar::B`
23+
|
24+
LL | assert_eq!(Bar::A("hi"), Bar::B(bar()));
25+
| +++++++ +
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)