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.
This commit is contained in:
parent
4fb888bf04
commit
77bdb354bf
2 changed files with 27 additions and 0 deletions
15
src/test/ui/issue-59756.rs
Normal file
15
src/test/ui/issue-59756.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
#![allow(warnings)]
|
||||
|
||||
struct A;
|
||||
struct B;
|
||||
|
||||
fn foo() -> Result<A, B> {
|
||||
Ok(A)
|
||||
}
|
||||
|
||||
fn bar() -> Result<A, B> {
|
||||
foo()?
|
||||
//~^ ERROR try expression alternatives have incompatible types [E0308]
|
||||
}
|
||||
|
||||
fn main() {}
|
12
src/test/ui/issue-59756.stderr
Normal file
12
src/test/ui/issue-59756.stderr
Normal file
|
@ -0,0 +1,12 @@
|
|||
error[E0308]: try expression alternatives have incompatible types
|
||||
--> $DIR/issue-59756.rs:11:5
|
||||
|
|
||||
LL | foo()?
|
||||
| ^^^^^^ expected enum `std::result::Result`, found struct `A`
|
||||
|
|
||||
= note: expected type `std::result::Result<A, B>`
|
||||
found type `A`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in a new issue