From bec8dbdb602688d6da4f49b7fdd74226f0f9f04c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 4 Apr 2022 17:37:59 -0700 Subject: diagnostics: give a special note for unsafe fn / Fn/FnOnce/FnMut Fixes #90073 --- .../src/traits/error_reporting/on_unimplemented.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'compiler/rustc_trait_selection/src') 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)))); -- cgit 1.4.1-3-g733a5