about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-08-28 02:37:38 +0000
committerMichael Goulet <michael@errs.io>2023-08-30 15:09:40 -0700
commitbf66723c0ecbadc3b4b24da44fa02b7ea3cd73bb (patch)
tree3239ecc9f73116928e02f714a72410b16f89854c /compiler
parent0100a94231344987bc93998d5975e656bfd7767d (diff)
downloadrust-bf66723c0ecbadc3b4b24da44fa02b7ea3cd73bb.tar.gz
rust-bf66723c0ecbadc3b4b24da44fa02b7ea3cd73bb.zip
Test and note unsafe ctor to fn ptr coercion
Also remove a note that I don't consider to be very useful in context.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs10
1 files changed, 4 insertions, 6 deletions
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<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");
+                        }
                     }
                     _ => {}
                 }