about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-06-07 16:38:38 +0000
committerbors <bors@rust-lang.org>2024-06-07 16:38:38 +0000
commit1e407642e82e038f0d2f81aa71271649af23b097 (patch)
tree4ddeef1acf5078714da94a3c4243d2e6f6069fb4
parent336046c5e268b08dca338354afe24465c1f67df3 (diff)
parent1781333ec75b9222446405aa0ab960f2fea004bb (diff)
downloadrust-1e407642e82e038f0d2f81aa71271649af23b097.tar.gz
rust-1e407642e82e038f0d2f81aa71271649af23b097.zip
Auto merge of #12901 - J-ZhengLi:test_case, r=Manishearth
[`match_same_arms`]: add a test case with lifetimes

as reminded by: #8919

---

changelog: none
-rw-r--r--tests/ui/match_same_arms2.fixed17
-rw-r--r--tests/ui/match_same_arms2.rs18
-rw-r--r--tests/ui/match_same_arms2.stderr18
3 files changed, 52 insertions, 1 deletions
diff --git a/tests/ui/match_same_arms2.fixed b/tests/ui/match_same_arms2.fixed
index fba0cf33b3c..09e960ddd6a 100644
--- a/tests/ui/match_same_arms2.fixed
+++ b/tests/ui/match_same_arms2.fixed
@@ -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
+            }
+        }
+    }
+}
diff --git a/tests/ui/match_same_arms2.rs b/tests/ui/match_same_arms2.rs
index 8a4e3b325bb..cc7425135cc 100644
--- a/tests/ui/match_same_arms2.rs
+++ b/tests/ui/match_same_arms2.rs
@@ -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
+            }
+        }
+    }
+}
diff --git a/tests/ui/match_same_arms2.stderr b/tests/ui/match_same_arms2.stderr
index 3d15176ccf9..a5d137c658b 100644
--- a/tests/ui/match_same_arms2.stderr
+++ b/tests/ui/match_same_arms2.stderr
@@ -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