Skip to content

Commit 1e40764

Browse files
committed
Auto merge of rust-lang#12901 - J-ZhengLi:test_case, r=Manishearth
[`match_same_arms`]: add a test case with lifetimes as reminded by: rust-lang#8919 --- changelog: none
2 parents 336046c + 1781333 commit 1e40764

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

tests/ui/match_same_arms2.fixed

+17
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,20 @@ fn main() {
239239
_ => false,
240240
};
241241
}
242+
243+
// issue #8919, fixed on https://github.com/rust-lang/rust/pull/97312
244+
mod with_lifetime {
245+
enum MaybeStaticStr<'a> {
246+
Static(&'static str),
247+
Borrowed(&'a str),
248+
}
249+
250+
impl<'a> MaybeStaticStr<'a> {
251+
fn get(&self) -> &'a str {
252+
match *self {
253+
MaybeStaticStr::Borrowed(s) | MaybeStaticStr::Static(s) => s,
254+
//~^ ERROR: this match arm has an identical body to another arm
255+
}
256+
}
257+
}
258+
}

tests/ui/match_same_arms2.rs

+18
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,21 @@ fn main() {
262262
_ => false,
263263
};
264264
}
265+
266+
// issue #8919, fixed on https://github.com/rust-lang/rust/pull/97312
267+
mod with_lifetime {
268+
enum MaybeStaticStr<'a> {
269+
Static(&'static str),
270+
Borrowed(&'a str),
271+
}
272+
273+
impl<'a> MaybeStaticStr<'a> {
274+
fn get(&self) -> &'a str {
275+
match *self {
276+
MaybeStaticStr::Static(s) => s,
277+
MaybeStaticStr::Borrowed(s) => s,
278+
//~^ ERROR: this match arm has an identical body to another arm
279+
}
280+
}
281+
}
282+
}

tests/ui/match_same_arms2.stderr

+17-1
Original file line numberDiff line numberDiff line change
@@ -221,5 +221,21 @@ help: and remove this obsolete arm
221221
LL - 0 => cfg!(not_enable),
222222
|
223223

224-
error: aborting due to 13 previous errors
224+
error: this match arm has an identical body to another arm
225+
--> tests/ui/match_same_arms2.rs:277:17
226+
|
227+
LL | MaybeStaticStr::Borrowed(s) => s,
228+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
229+
|
230+
= help: try changing either arm body
231+
help: or try merging the arm patterns
232+
|
233+
LL | MaybeStaticStr::Borrowed(s) | MaybeStaticStr::Static(s) => s,
234+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235+
help: and remove this obsolete arm
236+
|
237+
LL - MaybeStaticStr::Static(s) => s,
238+
|
239+
240+
error: aborting due to 14 previous errors
225241

0 commit comments

Comments
 (0)