Skip to content

Commit 0712869

Browse files
committed
Hide the internal unsafety of safe target_feature fn items
1 parent 241c453 commit 0712869

File tree

2 files changed

+15
-3
lines changed
  • compiler/rustc_trait_selection/src/error_reporting/infer
  • tests/ui/rfcs/rfc-2396-target_feature-11

2 files changed

+15
-3
lines changed

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,20 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
850850

851851
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
852852
// ^^^^^^
853-
values.0.push(sig1.safety.prefix_str(), sig1.safety != sig2.safety);
854-
values.1.push(sig2.safety.prefix_str(), sig1.safety != sig2.safety);
853+
let safety = |fn_def, sig: ty::FnSig<'_>| match fn_def {
854+
None => sig.safety.prefix_str(),
855+
Some((did, _)) => {
856+
if self.tcx.codegen_fn_attrs(did).safe_target_features {
857+
"#[target_features] "
858+
} else {
859+
sig.safety.prefix_str()
860+
}
861+
}
862+
};
863+
let safety1 = safety(fn_def1, sig1);
864+
let safety2 = safety(fn_def2, sig2);
865+
values.0.push(safety1, safety1 != safety2);
866+
values.1.push(safety2, safety1 != safety2);
855867

856868
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
857869
// ^^^^^^^^^^

tests/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | let foo: fn() = foo;
1010
| expected due to this
1111
|
1212
= note: expected fn pointer `fn()`
13-
found fn item `unsafe fn() {foo}`
13+
found fn item `#[target_features] fn() {foo}`
1414
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers
1515
= note: unsafe functions cannot be coerced into safe function pointers
1616

0 commit comments

Comments
 (0)