@@ -86,8 +86,7 @@ impl<'tcx> ItemLikeVisitor<'_> for InherentCollect<'tcx> {
8686 | ty:: Ref ( ..)
8787 | ty:: Never
8888 | 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 ( _) => {
9190 let mut err = struct_span_err ! (
9291 self . tcx. sess,
9392 ty. span,
@@ -98,16 +97,18 @@ impl<'tcx> ItemLikeVisitor<'_> for InherentCollect<'tcx> {
9897 err. span_label ( ty. span , "impl requires a nominal type" )
9998 . note ( "either implement a trait on it or create a newtype to wrap it instead" ) ;
10099
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-
109100 err. emit ( ) ;
110101 }
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 ( _) => { }
111112 }
112113 }
113114
@@ -170,21 +171,29 @@ impl<'tcx> InherentCollect<'tcx> {
170171 }
171172 }
172173 } else {
173- struct_span_err ! (
174+ let mut err = struct_span_err ! (
174175 self . tcx. sess,
175176 span,
176177 E0390 ,
177178 "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 ;
181190 }
182191 }
183192
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 {
185196 bug ! ( "unexpected primitive type: {:?}" , ty) ;
186- } ;
187- self . impls_map . incoherent_impls . entry ( simp) . or_default ( ) . push ( impl_def_id) ;
188- return ;
197+ }
189198 }
190199}
0 commit comments