From bf66723c0ecbadc3b4b24da44fa02b7ea3cd73bb Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 28 Aug 2023 02:37:38 +0000 Subject: Test and note unsafe ctor to fn ptr coercion Also remove a note that I don't consider to be very useful in context. --- .../rustc_infer/src/infer/error_reporting/note_and_explain.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs index 372539d73b1..445f68160d2 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs @@ -266,12 +266,10 @@ impl Trait 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"); + } } _ => {} } -- cgit 1.4.1-3-g733a5