@@ -86,8 +86,7 @@ impl<'tcx> ItemLikeVisitor<'_> for InherentCollect<'tcx> {
86
86
| ty:: Ref ( ..)
87
87
| ty:: Never
88
88
| ty:: Tuple ( ..) => self . check_primitive_impl ( item. def_id , self_ty, items, ty. span ) ,
89
- ty:: Error ( _) => { }
90
- _ => {
89
+ ty:: FnPtr ( _) | ty:: Projection ( ..) | ty:: Opaque ( ..) | ty:: Param ( _) => {
91
90
let mut err = struct_span_err ! (
92
91
self . tcx. sess,
93
92
ty. span,
@@ -98,16 +97,18 @@ impl<'tcx> ItemLikeVisitor<'_> for InherentCollect<'tcx> {
98
97
err. span_label ( ty. span , "impl requires a nominal type" )
99
98
. note ( "either implement a trait on it or create a newtype to wrap it instead" ) ;
100
99
101
- if let ty:: Ref ( _, subty, _) = self_ty. kind ( ) {
102
- err. note ( & format ! (
103
- "you could also try moving the reference to \
104
- uses of `{}` (such as `self`) within the implementation",
105
- subty
106
- ) ) ;
107
- }
108
-
109
100
err. emit ( ) ;
110
101
}
102
+ ty:: FnDef ( ..)
103
+ | ty:: Closure ( ..)
104
+ | ty:: Generator ( ..)
105
+ | ty:: GeneratorWitness ( ..)
106
+ | ty:: Bound ( ..)
107
+ | ty:: Placeholder ( _)
108
+ | ty:: Infer ( _) => {
109
+ bug ! ( "unexpected impl self type of impl: {:?} {:?}" , item. def_id, self_ty) ;
110
+ }
111
+ ty:: Error ( _) => { }
111
112
}
112
113
}
113
114
@@ -170,21 +171,29 @@ impl<'tcx> InherentCollect<'tcx> {
170
171
}
171
172
}
172
173
} else {
173
- struct_span_err ! (
174
+ let mut err = struct_span_err ! (
174
175
self . tcx. sess,
175
176
span,
176
177
E0390 ,
177
178
"cannot define inherent `impl` for primitive types" ,
178
- )
179
- . help ( "consider using an extension trait instead" )
180
- . emit ( ) ;
179
+ ) ;
180
+ err. help ( "consider using an extension trait instead" ) ;
181
+ if let ty:: Ref ( _, subty, _) = ty. kind ( ) {
182
+ err. note ( & format ! (
183
+ "you could also try moving the reference to \
184
+ uses of `{}` (such as `self`) within the implementation",
185
+ subty
186
+ ) ) ;
187
+ }
188
+ err. emit ( ) ;
189
+ return ;
181
190
}
182
191
}
183
192
184
- let Some ( simp) = simplify_type ( self . tcx , ty, TreatParams :: AsPlaceholders ) else {
193
+ if let Some ( simp) = simplify_type ( self . tcx , ty, TreatParams :: AsPlaceholders ) {
194
+ self . impls_map . incoherent_impls . entry ( simp) . or_default ( ) . push ( impl_def_id) ;
195
+ } else {
185
196
bug ! ( "unexpected primitive type: {:?}" , ty) ;
186
- } ;
187
- self . impls_map . incoherent_impls . entry ( simp) . or_default ( ) . push ( impl_def_id) ;
188
- return ;
197
+ }
189
198
}
190
199
}
0 commit comments