1
Fork 0

Don't implement AsyncFn for FnDef/FnPtr that wouldnt implement Fn

This commit is contained in:
Michael Goulet 2024-08-07 12:36:41 -04:00
parent 9bad7ba324
commit ec1c424293
6 changed files with 139 additions and 23 deletions

View file

@ -467,8 +467,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
candidates.vec.push(AsyncClosureCandidate);
}
ty::FnDef(..) | ty::FnPtr(..) => {
candidates.vec.push(AsyncClosureCandidate);
// Provide an impl, but only for suitable `fn` pointers.
ty::FnPtr(sig) => {
if sig.is_fn_trait_compatible() {
candidates.vec.push(AsyncClosureCandidate);
}
}
// Provide an impl for suitable functions, rejecting `#[target_feature]` functions (RFC 2396).
ty::FnDef(def_id, _) => {
let tcx = self.tcx();
if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
&& tcx.codegen_fn_attrs(def_id).target_features.is_empty()
{
candidates.vec.push(AsyncClosureCandidate);
}
}
_ => {}
}