Skip to content

Commit 77bdb35

Browse files
committed
Add test demonstrating existing behaviour.
This commit adds a test that demonstrates the compiler's current behaviour when a function attempts to return a value that was unwrapped by a `?` operator when the omission of `?` would have made the code compile.
1 parent 4fb888b commit 77bdb35

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/test/ui/issue-59756.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![allow(warnings)]
2+
3+
struct A;
4+
struct B;
5+
6+
fn foo() -> Result<A, B> {
7+
Ok(A)
8+
}
9+
10+
fn bar() -> Result<A, B> {
11+
foo()?
12+
//~^ ERROR try expression alternatives have incompatible types [E0308]
13+
}
14+
15+
fn main() {}

src/test/ui/issue-59756.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: try expression alternatives have incompatible types
2+
--> $DIR/issue-59756.rs:11:5
3+
|
4+
LL | foo()?
5+
| ^^^^^^ expected enum `std::result::Result`, found struct `A`
6+
|
7+
= note: expected type `std::result::Result<A, B>`
8+
found type `A`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)