summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2022-04-04 17:37:59 -0700
committerMichael Howell <michael@notriddle.com>2022-04-04 17:39:35 -0700
commitbec8dbdb602688d6da4f49b7fdd74226f0f9f04c (patch)
tree70177740bbd8b4b90213e8823648b61870e4a79e /compiler/rustc_trait_selection/src
parent60e50fc1cfe0bb693a5f4f93eb83ef70854531e3 (diff)
downloadrust-bec8dbdb602688d6da4f49b7fdd74226f0f9f04c.tar.gz
rust-bec8dbdb602688d6da4f49b7fdd74226f0f9f04c.zip
diagnostics: give a special note for unsafe fn / Fn/FnOnce/FnMut
Fixes #90073
Diffstat (limited to 'compiler/rustc_trait_selection/src')
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs
index d2b1fe2e0df..31b92d52beb 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs
@@ -208,6 +208,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                 flags.push((sym::_Self, Some("&[]".to_owned())));
             }
 
+            if self_ty.is_fn() {
+                let fn_sig = self_ty.fn_sig(self.tcx);
+                let shortname = match fn_sig.unsafety() {
+                    hir::Unsafety::Normal => "fn",
+                    hir::Unsafety::Unsafe => "unsafe fn",
+                };
+                flags.push((sym::_Self, Some(shortname.to_owned())));
+            }
+
             if let ty::Array(aty, len) = self_ty.kind() {
                 flags.push((sym::_Self, Some("[]".to_owned())));
                 flags.push((sym::_Self, Some(format!("[{}]", aty))));