Skip to content

Commit

Permalink
Auto merge of #12901 - J-ZhengLi:test_case, r=Manishearth
Browse files Browse the repository at this point in the history
[`match_same_arms`]: add a test case with lifetimes

as reminded by: #8919

---

changelog: none
  • Loading branch information
bors committed Jun 7, 2024
2 parents 336046c + 1781333 commit 1e40764
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/ui/match_same_arms2.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,20 @@ fn main() {
_ => false,
};
}

// issue #8919, fixed on https://github.com/rust-lang/rust/pull/97312
mod with_lifetime {
enum MaybeStaticStr<'a> {
Static(&'static str),
Borrowed(&'a str),
}

impl<'a> MaybeStaticStr<'a> {
fn get(&self) -> &'a str {
match *self {
MaybeStaticStr::Borrowed(s) | MaybeStaticStr::Static(s) => s,
//~^ ERROR: this match arm has an identical body to another arm
}
}
}
}
18 changes: 18 additions & 0 deletions tests/ui/match_same_arms2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,21 @@ fn main() {
_ => false,
};
}

// issue #8919, fixed on https://github.com/rust-lang/rust/pull/97312
mod with_lifetime {
enum MaybeStaticStr<'a> {
Static(&'static str),
Borrowed(&'a str),
}

impl<'a> MaybeStaticStr<'a> {
fn get(&self) -> &'a str {
match *self {
MaybeStaticStr::Static(s) => s,
MaybeStaticStr::Borrowed(s) => s,
//~^ ERROR: this match arm has an identical body to another arm
}
}
}
}
18 changes: 17 additions & 1 deletion tests/ui/match_same_arms2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,21 @@ help: and remove this obsolete arm
LL - 0 => cfg!(not_enable),
|

error: aborting due to 13 previous errors
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:277:17
|
LL | MaybeStaticStr::Borrowed(s) => s,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | MaybeStaticStr::Borrowed(s) | MaybeStaticStr::Static(s) => s,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - MaybeStaticStr::Static(s) => s,
|

error: aborting due to 14 previous errors

0 comments on commit 1e40764

Please sign in to comment.