summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-05-11 17:43:08 -0700
committerGitHub <noreply@github.com>2023-05-11 17:43:08 -0700
commit7c31df9d6c7f0baf38c331607dbc51be50d9eb84 (patch)
treee1c9192842ce5f405da86fad177ee55a519ac127
parentd4d15e8a7450312debdb953689095f30fe33900d (diff)
parenta2fe9935ea6b2cef2cc9b3aca6d1fee3ae15524b (diff)
downloadrust-7c31df9d6c7f0baf38c331607dbc51be50d9eb84.tar.gz
rust-7c31df9d6c7f0baf38c331607dbc51be50d9eb84.zip
Rollup merge of #111444 - cjgillot:issue-111400, r=oli-obk
Only warn single-use lifetime when the binders match.

Fixes https://github.com/rust-lang/rust/issues/111400
-rw-r--r--compiler/rustc_resolve/src/late.rs16
-rw-r--r--tests/ui/associated-inherent-types/issue-109790.rs1
2 files changed, 12 insertions, 5 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs
index 2a8287d5554..d7509cbf10e 100644
--- a/compiler/rustc_resolve/src/late.rs
+++ b/compiler/rustc_resolve/src/late.rs
@@ -1482,7 +1482,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
             if let Some(&(_, res)) = rib.bindings.get(&normalized_ident) {
                 self.record_lifetime_res(lifetime.id, res, LifetimeElisionCandidate::Named);
 
-                if let LifetimeRes::Param { param, .. } = res {
+                if let LifetimeRes::Param { param, binder } = res {
                     match self.lifetime_uses.entry(param) {
                         Entry::Vacant(v) => {
                             debug!("First use of {:?} at {:?}", res, ident.span);
@@ -1496,10 +1496,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
                                     LifetimeRibKind::Item
                                     | LifetimeRibKind::AnonymousReportError
                                     | LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
-                                    // An anonymous lifetime is legal here, go ahead.
-                                    LifetimeRibKind::AnonymousCreateParameter { .. } => {
-                                        Some(LifetimeUseSet::One { use_span: ident.span, use_ctxt })
-                                    }
+                                    // An anonymous lifetime is legal here, and bound to the right
+                                    // place, go ahead.
+                                    LifetimeRibKind::AnonymousCreateParameter {
+                                        binder: anon_binder,
+                                        ..
+                                    } => Some(if binder == anon_binder {
+                                        LifetimeUseSet::One { use_span: ident.span, use_ctxt }
+                                    } else {
+                                        LifetimeUseSet::Many
+                                    }),
                                     // Only report if eliding the lifetime would have the same
                                     // semantics.
                                     LifetimeRibKind::Elided(r) => Some(if res == r {
diff --git a/tests/ui/associated-inherent-types/issue-109790.rs b/tests/ui/associated-inherent-types/issue-109790.rs
index b2be19a28f4..88327f86423 100644
--- a/tests/ui/associated-inherent-types/issue-109790.rs
+++ b/tests/ui/associated-inherent-types/issue-109790.rs
@@ -2,6 +2,7 @@
 
 #![feature(inherent_associated_types)]
 #![allow(incomplete_features)]
+#![deny(single_use_lifetimes)]
 
 struct Foo<T>(T);