-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #47560.
- Loading branch information
Showing
4 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// run-rustfix | ||
struct A; | ||
struct B; | ||
impl From<A> for B { | ||
fn from(_: A) -> Self { B } | ||
} | ||
fn foo1(x: Result<(), A>) -> Result<(), B> { | ||
Ok(x?) //~ ERROR mismatched types | ||
} | ||
fn foo2(x: Result<(), A>) -> Result<(), B> { | ||
return Ok(x?); //~ ERROR mismatched types | ||
} | ||
fn main() { | ||
let _ = foo1(Ok(())); | ||
let _ = foo2(Ok(())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// run-rustfix | ||
struct A; | ||
struct B; | ||
impl From<A> for B { | ||
fn from(_: A) -> Self { B } | ||
} | ||
fn foo1(x: Result<(), A>) -> Result<(), B> { | ||
x //~ ERROR mismatched types | ||
} | ||
fn foo2(x: Result<(), A>) -> Result<(), B> { | ||
return x; //~ ERROR mismatched types | ||
} | ||
fn main() { | ||
let _ = foo1(Ok(())); | ||
let _ = foo2(Ok(())); | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/ui/type/type-check/coerce-result-return-value.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/coerce-result-return-value.rs:8:5 | ||
| | ||
LL | fn foo1(x: Result<(), A>) -> Result<(), B> { | ||
| ------------- expected `Result<(), B>` because of return type | ||
LL | x | ||
| ^ expected struct `B`, found struct `A` | ||
| | ||
= note: expected enum `Result<_, B>` | ||
found enum `Result<_, A>` | ||
help: you can rely on the implicit conversion that `?` does to transform the error type | ||
| | ||
LL | Ok(x?) | ||
| +++ ++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/coerce-result-return-value.rs:11:12 | ||
| | ||
LL | fn foo2(x: Result<(), A>) -> Result<(), B> { | ||
| ------------- expected `Result<(), B>` because of return type | ||
LL | return x; | ||
| ^ expected struct `B`, found struct `A` | ||
| | ||
= note: expected enum `Result<_, B>` | ||
found enum `Result<_, A>` | ||
help: you can rely on the implicit conversion that `?` does to transform the error type | ||
| | ||
LL | return Ok(x?); | ||
| +++ ++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |