summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-04-25 23:03:50 +0000
committerbors <bors@rust-lang.org>2022-04-25 23:03:50 +0000
commitec8619dca239f57201a3ceb59e93149659c07b58 (patch)
tree41baa6b20ee48a404cca9257b124f13e7feaabc2 /compiler/rustc_mir_transform/src
parent055bf4ccd521c2c2185166c86951be7be145727c (diff)
parentf71597cb59f6dc6f3ab30d70ff5b722c6b4adcc1 (diff)
downloadrust-ec8619dca239f57201a3ceb59e93149659c07b58.tar.gz
rust-ec8619dca239f57201a3ceb59e93149659c07b58.zip
Auto merge of #96294 - Emilgardis:def_id-in-unsafetyviolationdetails, r=oli-obk
Display function path in unsafety violations - E0133

adds `DefId` to `UnsafetyViolationDetails`

this enables consumers to access the function definition that was reported to be unsafe and also changes the output for some E0133 diagnostics
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/check_unsafety.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs
index 1b4510b6220..34093eb29eb 100644
--- a/compiler/rustc_mir_transform/src/check_unsafety.rs
+++ b/compiler/rustc_mir_transform/src/check_unsafety.rs
@@ -70,15 +70,17 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
 
             TerminatorKind::Call { ref func, .. } => {
                 let func_ty = func.ty(self.body, self.tcx);
+                let func_id =
+                    if let ty::FnDef(func_id, _) = func_ty.kind() { Some(func_id) } else { None };
                 let sig = func_ty.fn_sig(self.tcx);
                 if let hir::Unsafety::Unsafe = sig.unsafety() {
                     self.require_unsafe(
                         UnsafetyViolationKind::General,
-                        UnsafetyViolationDetails::CallToUnsafeFunction,
+                        UnsafetyViolationDetails::CallToUnsafeFunction(func_id.copied()),
                     )
                 }
 
-                if let ty::FnDef(func_id, _) = func_ty.kind() {
+                if let Some(func_id) = func_id {
                     self.check_target_features(*func_id);
                 }
             }
@@ -379,7 +381,7 @@ impl<'tcx> UnsafetyChecker<'_, 'tcx> {
         if !callee_features.iter().all(|feature| self_features.contains(feature)) {
             self.require_unsafe(
                 UnsafetyViolationKind::General,
-                UnsafetyViolationDetails::CallToFunctionWith,
+                UnsafetyViolationDetails::CallToFunctionWith(func_did),
             )
         }
     }
@@ -578,7 +580,8 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
     let UnsafetyCheckResult { violations, unused_unsafes, .. } = tcx.unsafety_check_result(def_id);
 
     for &UnsafetyViolation { source_info, lint_root, kind, details } in violations.iter() {
-        let (description, note) = details.description_and_note();
+        let (description, note) =
+            ty::print::with_no_trimmed_paths!(details.description_and_note(tcx));
 
         // Report an error.
         let unsafe_fn_msg =
@@ -595,7 +598,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
                     description,
                     unsafe_fn_msg,
                 )
-                .span_label(source_info.span, description)
+                .span_label(source_info.span, details.simple_description())
                 .note(note)
                 .emit();
             }