Skip to content

Commit 7e17ecf

Browse files
committed
Add test suggest-compatible-variants-macro-issue-142359.rs
Signed-off-by: xizheyin <[email protected]>
1 parent 55d4364 commit 7e17ecf

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Make sure we don't suggest compatible variants inside macro. (issue #142359)
2+
use std::ops::ControlFlow;
3+
4+
fn main(){
5+
let x: Result<i32, i32> = Err(1);
6+
7+
let v= match x {
8+
Err(r) => ControlFlow::Break(r),
9+
Ok(r) => { println!("A")} //~ ERROR `match` arms have incompatible types [E0308]
10+
};
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0308]: `match` arms have incompatible types
2+
--> $DIR/suggest-compatible-variants-macro-issue-142359.rs:9:20
3+
|
4+
LL | let v= match x {
5+
| ____________-
6+
LL | | Err(r) => ControlFlow::Break(r),
7+
| | --------------------- this is found to be of type `ControlFlow<i32, _>`
8+
LL | | Ok(r) => { println!("A")}
9+
| | ^^^^^^^^^^^^^ expected `ControlFlow<i32, _>`, found `()`
10+
LL | | };
11+
| |_____- `match` arms have incompatible types
12+
|
13+
= note: expected enum `ControlFlow<i32, _>`
14+
found unit type `()`
15+
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)