about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorEmil Gardström <emil.gardstrom@gmail.com>2022-04-24 14:08:23 +0200
committerEmil Gardström <emil.gardstrom@gmail.com>2022-04-24 18:33:06 +0200
commit8b8f6653cfd54525714f02efe7af0a0f830e185c (patch)
tree08350f3a61cde865ec0fa0ca084b874e88a389f3 /compiler/rustc_mir_transform/src
parentd8e59edbfa47ff38e23e6dedab6bedd3b41895e0 (diff)
downloadrust-8b8f6653cfd54525714f02efe7af0a0f830e185c.tar.gz
rust-8b8f6653cfd54525714f02efe7af0a0f830e185c.zip
add `DefId` to unsafety violations and display function path in E0133
this enables consumers to access the function definition that was reported to be unsafe
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/check_unsafety.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs
index 1b4510b6220..33b83d90e0f 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 =