@@ -89,10 +89,10 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
89
89
self . report_op ( ty, args, fn_span, expr) ;
90
90
}
91
91
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...
95
92
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...
96
96
let parent = self . tcx . parent ( did) ;
97
97
if self . tcx . fn_trait_kind_from_def_id ( parent) . is_some ( )
98
98
&& args. first ( ) . and_then ( |arg| arg. as_type ( ) ) . is_some_and ( Ty :: is_closure)
@@ -103,6 +103,13 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
103
103
// skip them, producing an error about calling a closure is enough.
104
104
return ;
105
105
} ;
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
+ }
106
113
}
107
114
108
115
// Erase regions since tail calls don't care about lifetimes
@@ -280,6 +287,16 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
280
287
self . found_errors = Err ( err) ;
281
288
}
282
289
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
+
283
300
fn report_abi_mismatch ( & mut self , sp : Span , caller_abi : ExternAbi , callee_abi : ExternAbi ) {
284
301
let err = self
285
302
. tcx
0 commit comments