Skip to content

Commit 443d9f6

Browse files
Add example to opaque_hidden_inferred_bound lint
1 parent 9d3d9cd commit 443d9f6

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,37 @@ declare_lint! {
1313
/// `impl Trait` in associated type bounds are not written generally enough
1414
/// to satisfy the bounds of the associated type. This functionality was
1515
/// removed in #97346, but then rolled back in #99860 because it was made
16-
/// into a hard error too quickly.
16+
/// into a hard error too quickly and caused regressions.
1717
///
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.
18+
/// We plan on reintroducing this as a hard error, but in the mean time,
19+
/// this lint serves to warn and suggest fixes for any use-cases which rely
20+
/// on this behavior.
21+
///
22+
/// ### Example
23+
///
24+
/// ```
25+
/// trait Trait {
26+
/// type Assoc: Send;
27+
/// }
28+
///
29+
/// struct Struct;
30+
///
31+
/// impl Trait for Struct {
32+
/// type Assoc = i32;
33+
/// }
34+
///
35+
/// fn test() -> impl Trait<Assoc = impl Sized> {
36+
/// Struct
37+
/// }
38+
/// ```
39+
///
40+
/// In this example, `test` declares that the associated type `Assoc` for
41+
/// `impl Trait` is `impl Sized`, which does not satisfy the `Send` bound
42+
/// on the associated type.
43+
///
44+
/// Although the hidden type, `i32` does satisfy this bound, we do not
45+
/// consider the return type to be well-formed with this lint. It can be
46+
/// fixed by changing `impl Sized` into `impl Sized + Send`.
2147
pub OPAQUE_HIDDEN_INFERRED_BOUND,
2248
Warn,
2349
"detects the use of nested `impl Trait` types in associated type bounds that are not general enough"

0 commit comments

Comments
 (0)