Skip to content

[match_same_arms]: add a test case with lifetimes #12901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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