@@ -88,16 +88,59 @@ pub(super) fn check_fn<'a, 'tcx>(
8888 let declared_ret_ty = fn_sig. output ( ) ;
8989
9090 let feature = match tcx. hir ( ) . get ( fn_id) {
91+ // TAIT usage in function return position.
92+ // Example:
93+ //
94+ // ```rust
95+ // type Foo = impl Debug;
96+ // fn bar() -> Foo { 42 }
97+ // ```
9198 Node :: Item ( hir:: Item { kind : ItemKind :: Fn ( ..) , .. } ) |
99+ // TAIT usage in associated function return position.
100+ //
101+ // Example with a free type alias:
102+ //
103+ // ```rust
104+ // type Foo = impl Debug;
105+ // impl SomeTrait for SomeType {
106+ // fn bar() -> Foo { 42 }
107+ // }
108+ // ```
109+ //
110+ // Example with an associated TAIT:
111+ //
112+ // ```rust
113+ // impl SomeTrait for SomeType {
114+ // type Foo = impl Debug;
115+ // fn bar() -> Self::Foo { 42 }
116+ // }
117+ // ```
92118 Node :: ImplItem ( hir:: ImplItem {
93119 kind : hir:: ImplItemKind :: Fn ( ..) , ..
94120 } ) => None ,
95- // I don't know if TAIT uses in trait declarations make sense at all
121+ // Forbid TAIT in trait declarations for now.
122+ // Examples:
123+ //
124+ // ```rust
125+ // type Foo = impl Debug;
126+ // trait Bar {
127+ // fn bar() -> Foo;
128+ // }
129+ // trait Bop {
130+ // type Bop: PartialEq<Foo>;
131+ // }
132+ // ```
96133 Node :: TraitItem ( hir:: TraitItem {
97134 kind : hir:: TraitItemKind :: Fn ( ..) ,
98135 ..
99136 } ) |
100137 // Forbid TAIT in closure return position for now.
138+ // Example:
139+ //
140+ // ```rust
141+ // type Foo = impl Debug;
142+ // let x = |y| -> Foo { 42 + y };
143+ // ```
101144 Node :: Expr ( hir:: Expr { kind : hir:: ExprKind :: Closure ( ..) , .. } ) => Some ( sym:: type_alias_impl_trait) ,
102145 node => bug ! ( "Item being checked wasn't a function/closure: {:?}" , node) ,
103146 } ;
0 commit comments