Skip to content

Commit 7a88540

Browse files
Add example to opaque_hidden_inferred_bound lint
1 parent 426424b commit 7a88540

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

+37-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,44 @@ use crate::{LateContext, LateLintPass, LintContext};
1111
declare_lint! {
1212
/// The `opaque_hidden_inferred_bound` lint detects cases in which nested
1313
/// `impl Trait` in associated type bounds are not written generally enough
14-
/// to satisfy the bounds of the associated type. This functionality was
15-
/// removed in #97346, but then rolled back in #99860 because it was made
16-
/// into a hard error too quickly.
14+
/// to satisfy the bounds of the associated type.
1715
///
18-
/// We plan on reintroducing this as a hard error, but in the mean time, this
19-
/// lint serves to warn and suggest fixes for any use-cases which rely on this
20-
/// behavior.
16+
/// ### Explanation
17+
///
18+
/// This functionality was removed in #97346, but then rolled back in #99860
19+
/// because it caused regressions.
20+
///
21+
/// We plan on reintroducing this as a hard error, but in the mean time,
22+
/// this lint serves to warn and suggest fixes for any use-cases which rely
23+
/// on this behavior.
24+
///
25+
/// ### Example
26+
///
27+
/// ```
28+
/// trait Trait {
29+
/// type Assoc: Send;
30+
/// }
31+
///
32+
/// struct Struct;
33+
///
34+
/// impl Trait for Struct {
35+
/// type Assoc = i32;
36+
/// }
37+
///
38+
/// fn test() -> impl Trait<Assoc = impl Sized> {
39+
/// Struct
40+
/// }
41+
/// ```
42+
///
43+
/// {{produces}}
44+
///
45+
/// In this example, `test` declares that the associated type `Assoc` for
46+
/// `impl Trait` is `impl Sized`, which does not satisfy the `Send` bound
47+
/// on the associated type.
48+
///
49+
/// Although the hidden type, `i32` does satisfy this bound, we do not
50+
/// consider the return type to be well-formed with this lint. It can be
51+
/// fixed by changing `impl Sized` into `impl Sized + Send`.
2152
pub OPAQUE_HIDDEN_INFERRED_BOUND,
2253
Warn,
2354
"detects the use of nested `impl Trait` types in associated type bounds that are not general enough"

0 commit comments

Comments
 (0)