@@ -89,10 +89,10 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
8989 self . report_op ( ty, args, fn_span, expr) ;
9090 }
9191
92- // Closures in thir look something akin to
93- // `for<'a> extern "rust-call" fn(&'a [closure@...], ()) -> <[closure@...] as FnOnce<()>>::Output {<[closure@...] as Fn<()>>::call}`
94- // So we have to check for them in this weird way...
9592 if let & ty:: FnDef ( did, args) = ty. kind ( ) {
93+ // Closures in thir look something akin to
94+ // `for<'a> extern "rust-call" fn(&'a [closure@...], ()) -> <[closure@...] as FnOnce<()>>::Output {<[closure@...] as Fn<()>>::call}`
95+ // So we have to check for them in this weird way...
9696 let parent = self . tcx . parent ( did) ;
9797 if self . tcx . fn_trait_kind_from_def_id ( parent) . is_some ( )
9898 && args. first ( ) . and_then ( |arg| arg. as_type ( ) ) . is_some_and ( Ty :: is_closure)
@@ -103,6 +103,13 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
103103 // skip them, producing an error about calling a closure is enough.
104104 return ;
105105 } ;
106+
107+ if let Ok ( Some ( instance) ) =
108+ ty:: Instance :: try_resolve ( self . tcx , self . typing_env , did, args)
109+ && let ty:: InstanceKind :: Intrinsic ( _) = instance. def
110+ {
111+ self . report_calling_intrinsic ( expr) ;
112+ }
106113 }
107114
108115 // Erase regions since tail calls don't care about lifetimes
@@ -280,6 +287,16 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
280287 self . found_errors = Err ( err) ;
281288 }
282289
290+ fn report_calling_intrinsic ( & mut self , expr : & Expr < ' _ > ) {
291+ let err = self
292+ . tcx
293+ . dcx ( )
294+ . struct_span_err ( expr. span , "tail calling intrinsics is not allowed" )
295+ . emit ( ) ;
296+
297+ self . found_errors = Err ( err) ;
298+ }
299+
283300 fn report_abi_mismatch ( & mut self , sp : Span , caller_abi : ExternAbi , callee_abi : ExternAbi ) {
284301 let err = self
285302 . tcx
0 commit comments