about summary refs log tree commit diff
path: root/tests/ui/drop
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-06-05 19:49:30 +0000
committerbors <bors@rust-lang.org>2025-06-05 19:49:30 +0000
commitccf3198de316b488ee17441935182e9d5292b4d3 (patch)
tree0d6d7fde04921baf3b9edc84b906541c6590a8b3 /tests/ui/drop
parent076ec59ff1dcf538b9d3a0b8e0d7f4edd0559959 (diff)
parentd35ad948492146f0811d43606db66c65c55980a9 (diff)
downloadrust-ccf3198de316b488ee17441935182e9d5292b4d3.tar.gz
rust-ccf3198de316b488ee17441935182e9d5292b4d3.zip
Auto merge of #138677 - shepmaster:consistent-elided-lifetime-syntax, r=traviscross,jieyouxu
Add a new `mismatched-lifetime-syntaxes` lint

The lang-team [discussed this](https://hackmd.io/nf4ZUYd7Rp6rq-1svJZSaQ) and I attempted to [summarize](https://github.com/rust-lang/rust/pull/120808#issuecomment-2701863833) their decision. The summary-of-the-summary is:

- Using two different kinds of syntax for elided lifetimes is confusing. In rare cases, it may even [lead to unsound code](https://github.com/rust-lang/rust/issues/48686)! Some examples:

    ```rust
    // Lint will warn about these
    fn(v: ContainsLifetime) -> ContainsLifetime<'_>;
    fn(&'static u8) -> &u8;
    ```

- Matching up references with no lifetime syntax, references with anonymous lifetime syntax, and paths with anonymous lifetime syntax is an exception to the simplest possible rule:

    ```rust
    // Lint will not warn about these
    fn(&u8) -> &'_ u8;
    fn(&'_ u8) -> &u8;
    fn(&u8) -> ContainsLifetime<'_>;
    ```

- Having a lint for consistent syntax of elided lifetimes will make the [future goal](https://github.com/rust-lang/rust/issues/91639) of warning-by-default for paths participating in elision much simpler.

---

This new lint attempts to accomplish the goal of enforcing consistent syntax. In the process, it supersedes and replaces the existing `elided-named-lifetimes` lint, which means it starts out life as warn-by-default.
Diffstat (limited to 'tests/ui/drop')
-rw-r--r--tests/ui/drop/drop-order-comparisons.e2021.fixed2
-rw-r--r--tests/ui/drop/drop-order-comparisons.rs2
-rw-r--r--tests/ui/drop/drop_order.rs4
-rw-r--r--tests/ui/drop/drop_order_if_let_rescope.rs2
-rw-r--r--tests/ui/drop/issue-2735-2.rs2
-rw-r--r--tests/ui/drop/issue-2735-3.rs2
-rw-r--r--tests/ui/drop/issue-979.rs2
-rw-r--r--tests/ui/drop/tail-expr-drop-order.rs4
8 files changed, 10 insertions, 10 deletions
diff --git a/tests/ui/drop/drop-order-comparisons.e2021.fixed b/tests/ui/drop/drop-order-comparisons.e2021.fixed
index 6c8d2d3fa9c..42f805923ec 100644
--- a/tests/ui/drop/drop-order-comparisons.e2021.fixed
+++ b/tests/ui/drop/drop-order-comparisons.e2021.fixed
@@ -589,7 +589,7 @@ impl Events {
         Ok(LogDrop(self, m))
     }
     /// Return an `Err` value that logs its drop.
-    fn err(&self, m: u64) -> Result<LogDrop, LogDrop> {
+    fn err(&self, m: u64) -> Result<LogDrop<'_>, LogDrop<'_>> {
         Err(LogDrop(self, m))
     }
     /// Log an event.
diff --git a/tests/ui/drop/drop-order-comparisons.rs b/tests/ui/drop/drop-order-comparisons.rs
index 9a10a08a3ff..e7425159aa2 100644
--- a/tests/ui/drop/drop-order-comparisons.rs
+++ b/tests/ui/drop/drop-order-comparisons.rs
@@ -589,7 +589,7 @@ impl Events {
         Ok(LogDrop(self, m))
     }
     /// Return an `Err` value that logs its drop.
-    fn err(&self, m: u64) -> Result<LogDrop, LogDrop> {
+    fn err(&self, m: u64) -> Result<LogDrop<'_>, LogDrop<'_>> {
         Err(LogDrop(self, m))
     }
     /// Log an event.
diff --git a/tests/ui/drop/drop_order.rs b/tests/ui/drop/drop_order.rs
index b96e55a2535..34b1a0e8f75 100644
--- a/tests/ui/drop/drop_order.rs
+++ b/tests/ui/drop/drop_order.rs
@@ -23,11 +23,11 @@ impl Drop for LoudDrop<'_> {
 }
 
 impl DropOrderCollector {
-    fn option_loud_drop(&self, n: u32) -> Option<LoudDrop> {
+    fn option_loud_drop(&self, n: u32) -> Option<LoudDrop<'_>> {
         Some(LoudDrop(self, n))
     }
 
-    fn loud_drop(&self, n: u32) -> LoudDrop {
+    fn loud_drop(&self, n: u32) -> LoudDrop<'_> {
         LoudDrop(self, n)
     }
 
diff --git a/tests/ui/drop/drop_order_if_let_rescope.rs b/tests/ui/drop/drop_order_if_let_rescope.rs
index 27bced5fa62..e96ceedd5cb 100644
--- a/tests/ui/drop/drop_order_if_let_rescope.rs
+++ b/tests/ui/drop/drop_order_if_let_rescope.rs
@@ -18,7 +18,7 @@ impl Drop for LoudDrop<'_> {
 }
 
 impl DropOrderCollector {
-    fn option_loud_drop(&self, n: u32) -> Option<LoudDrop> {
+    fn option_loud_drop(&self, n: u32) -> Option<LoudDrop<'_>> {
         Some(LoudDrop(self, n))
     }
 
diff --git a/tests/ui/drop/issue-2735-2.rs b/tests/ui/drop/issue-2735-2.rs
index 7a6ed6ea2f8..66025956e08 100644
--- a/tests/ui/drop/issue-2735-2.rs
+++ b/tests/ui/drop/issue-2735-2.rs
@@ -14,7 +14,7 @@ impl<'a> Drop for defer<'a> {
     }
 }
 
-fn defer(b: &Cell<bool>) -> defer {
+fn defer(b: &Cell<bool>) -> defer<'_> {
     defer {
         b: b
     }
diff --git a/tests/ui/drop/issue-2735-3.rs b/tests/ui/drop/issue-2735-3.rs
index 3bb4536537c..c9535168653 100644
--- a/tests/ui/drop/issue-2735-3.rs
+++ b/tests/ui/drop/issue-2735-3.rs
@@ -14,7 +14,7 @@ impl<'a> Drop for defer<'a> {
     }
 }
 
-fn defer(b: &Cell<bool>) -> defer {
+fn defer(b: &Cell<bool>) -> defer<'_> {
     defer {
         b: b
     }
diff --git a/tests/ui/drop/issue-979.rs b/tests/ui/drop/issue-979.rs
index 8d98ac4df23..70052708be6 100644
--- a/tests/ui/drop/issue-979.rs
+++ b/tests/ui/drop/issue-979.rs
@@ -13,7 +13,7 @@ impl<'a> Drop for r<'a> {
     }
 }
 
-fn r(b: &Cell<isize>) -> r {
+fn r(b: &Cell<isize>) -> r<'_> {
     r {
         b: b
     }
diff --git a/tests/ui/drop/tail-expr-drop-order.rs b/tests/ui/drop/tail-expr-drop-order.rs
index f74530fce1e..a6807b16b50 100644
--- a/tests/ui/drop/tail-expr-drop-order.rs
+++ b/tests/ui/drop/tail-expr-drop-order.rs
@@ -28,11 +28,11 @@ impl Drop for LoudDrop<'_> {
 }
 
 impl DropOrderCollector {
-    fn option_loud_drop(&self, n: u32) -> Option<LoudDrop> {
+    fn option_loud_drop(&self, n: u32) -> Option<LoudDrop<'_>> {
         Some(LoudDrop(self, n))
     }
 
-    fn loud_drop(&self, n: u32) -> LoudDrop {
+    fn loud_drop(&self, n: u32) -> LoudDrop<'_> {
         LoudDrop(self, n)
     }