Test and note unsafe ctor to fn ptr coercion

Also remove a note that I don't consider to be very useful in context.
This commit is contained in:
Michael Goulet 2023-08-28 02:37:38 +00:00
parent 0100a94231
commit bf66723c0e
18 changed files with 29 additions and 22 deletions

View file

@ -266,12 +266,10 @@ impl<T> Trait<T> for X {
}
}
}
(ty::FnPtr(_), ty::FnDef(def, _))
if let hir::def::DefKind::Fn = tcx.def_kind(def) => {
diag.note(
"when the arguments and return types match, functions can be coerced \
to function pointers",
);
(ty::FnPtr(sig), ty::FnDef(def_id, _)) | (ty::FnDef(def_id, _), ty::FnPtr(sig)) => {
if tcx.fn_sig(*def_id).skip_binder().unsafety() < sig.unsafety() {
diag.note("unsafe functions cannot be coerced into safe function pointers");
}
}
_ => {}
}