From f3fb727b08587e75a6adacca1a8f06f62e31d87e Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 18 Apr 2024 22:04:14 -0400 Subject: [PATCH] Don't suggest using use<> syntax to capture APITs --- compiler/rustc_lint/src/impl_trait_overcaptures.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_lint/src/impl_trait_overcaptures.rs b/compiler/rustc_lint/src/impl_trait_overcaptures.rs index 7272618c5f20d..7659b6da1811e 100644 --- a/compiler/rustc_lint/src/impl_trait_overcaptures.rs +++ b/compiler/rustc_lint/src/impl_trait_overcaptures.rs @@ -194,10 +194,15 @@ impl<'tcx> TypeVisitor> for VisitOpaqueTypes<'tcx> { .chain(others) .map(|def_id| self.tcx.item_name(def_id).to_string()) .collect(); - Some(( - format!(" use<{}>", generics.join(", ")), - opaque_span.with_lo(opaque_span.lo() + BytePos(4)).shrink_to_lo(), - )) + // Make sure that we're not trying to name any APITs + if generics.iter().all(|name| !name.starts_with("impl ")) { + Some(( + format!(" use<{}>", generics.join(", ")), + opaque_span.with_lo(opaque_span.lo() + BytePos(4)).shrink_to_lo(), + )) + } else { + None + } } else { None };