Skip to content

Commit 0ce564a

Browse files
committed
Add test related to the ICE
This test doesn't reproduce the ICE since it only happens, when the macro is defined in another file. Currently we can't add tests with multiple files AFAIK Also using the auxiliary folder didn't help
1 parent 87ae6c8 commit 0ce564a

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

tests/ui/matches.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,29 @@ fn match_as_ref() {
150150
};
151151
}
152152

153-
fn main() {}
153+
macro_rules! foo_variant(
154+
($idx:expr) => (Foo::get($idx).unwrap())
155+
);
156+
157+
enum Foo {
158+
A,
159+
B,
160+
}
161+
162+
impl Foo {
163+
fn get(idx: u8) -> Option<&'static Self> {
164+
match idx {
165+
0 => Some(&Foo::A),
166+
1 => Some(&Foo::B),
167+
_ => None,
168+
}
169+
}
170+
}
171+
172+
fn main() {
173+
// ICE #3719
174+
match foo_variant!(0) {
175+
&Foo::A => println!("A"),
176+
_ => println!("Wild"),
177+
}
178+
}

tests/ui/matches.stderr

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,19 @@ LL | | Some(ref mut v) => Some(v),
278278
LL | | };
279279
| |_____^ help: try this: `mut_owned.as_mut()`
280280

281-
error: aborting due to 19 previous errors
281+
error: you don't need to add `&` to all patterns
282+
--> $DIR/matches.rs:174:5
283+
|
284+
LL | / match foo_variant!(0) {
285+
LL | | &Foo::A => println!("A"),
286+
LL | | _ => println!("Wild"),
287+
LL | | }
288+
| |_____^
289+
help: instead of prefixing all patterns with `&`, you can dereference the expression
290+
|
291+
LL | match *foo_variant!(0) {
292+
LL | Foo::A => println!("A"),
293+
|
294+
295+
error: aborting due to 20 previous errors
282296

0 commit comments

Comments
 (0)