@@ -88,16 +88,59 @@ pub(super) fn check_fn<'a, 'tcx>(
88
88
let declared_ret_ty = fn_sig. output ( ) ;
89
89
90
90
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
+ // ```
91
98
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
+ // ```
92
118
Node :: ImplItem ( hir:: ImplItem {
93
119
kind : hir:: ImplItemKind :: Fn ( ..) , ..
94
120
} ) => 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
+ // ```
96
133
Node :: TraitItem ( hir:: TraitItem {
97
134
kind : hir:: TraitItemKind :: Fn ( ..) ,
98
135
..
99
136
} ) |
100
137
// 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
+ // ```
101
144
Node :: Expr ( hir:: Expr { kind : hir:: ExprKind :: Closure ( ..) , .. } ) => Some ( sym:: type_alias_impl_trait) ,
102
145
node => bug ! ( "Item being checked wasn't a function/closure: {:?}" , node) ,
103
146
} ;
0 commit comments