From 7a8854037b81e04bea5309e5b107bfe09fc841c0 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 2 Oct 2022 19:07:31 +0000 Subject: [PATCH] Add example to opaque_hidden_inferred_bound lint --- .../src/opaque_hidden_inferred_bound.rs | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index 7f18bf0018f..d8ce20db37c 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -11,13 +11,44 @@ use crate::{LateContext, LateLintPass, LintContext}; declare_lint! { /// The `opaque_hidden_inferred_bound` lint detects cases in which nested /// `impl Trait` in associated type bounds are not written generally enough - /// to satisfy the bounds of the associated type. This functionality was - /// removed in #97346, but then rolled back in #99860 because it was made - /// into a hard error too quickly. + /// to satisfy the bounds of the associated type. /// - /// We plan on reintroducing this as a hard error, but in the mean time, this - /// lint serves to warn and suggest fixes for any use-cases which rely on this - /// behavior. + /// ### Explanation + /// + /// This functionality was removed in #97346, but then rolled back in #99860 + /// because it caused regressions. + /// + /// We plan on reintroducing this as a hard error, but in the mean time, + /// this lint serves to warn and suggest fixes for any use-cases which rely + /// on this behavior. + /// + /// ### Example + /// + /// ``` + /// trait Trait { + /// type Assoc: Send; + /// } + /// + /// struct Struct; + /// + /// impl Trait for Struct { + /// type Assoc = i32; + /// } + /// + /// fn test() -> impl Trait { + /// Struct + /// } + /// ``` + /// + /// {{produces}} + /// + /// In this example, `test` declares that the associated type `Assoc` for + /// `impl Trait` is `impl Sized`, which does not satisfy the `Send` bound + /// on the associated type. + /// + /// Although the hidden type, `i32` does satisfy this bound, we do not + /// consider the return type to be well-formed with this lint. It can be + /// fixed by changing `impl Sized` into `impl Sized + Send`. pub OPAQUE_HIDDEN_INFERRED_BOUND, Warn, "detects the use of nested `impl Trait` types in associated type bounds that are not general enough"