Hide the internal unsafety of safe target_feature fn items
This commit is contained in:
parent
56178ddc90
commit
e1a8b0da2d
2 changed files with 15 additions and 3 deletions
|
@ -850,8 +850,20 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
|
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
|
||||||
// ^^^^^^
|
// ^^^^^^
|
||||||
values.0.push(sig1.safety.prefix_str(), sig1.safety != sig2.safety);
|
let safety = |fn_def, sig: ty::FnSig<'_>| match fn_def {
|
||||||
values.1.push(sig2.safety.prefix_str(), sig1.safety != sig2.safety);
|
None => sig.safety.prefix_str(),
|
||||||
|
Some((did, _)) => {
|
||||||
|
if self.tcx.codegen_fn_attrs(did).safe_target_features {
|
||||||
|
"#[target_features] "
|
||||||
|
} else {
|
||||||
|
sig.safety.prefix_str()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let safety1 = safety(fn_def1, sig1);
|
||||||
|
let safety2 = safety(fn_def2, sig2);
|
||||||
|
values.0.push(safety1, safety1 != safety2);
|
||||||
|
values.1.push(safety2, safety1 != safety2);
|
||||||
|
|
||||||
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
|
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
|
||||||
// ^^^^^^^^^^
|
// ^^^^^^^^^^
|
||||||
|
|
|
@ -10,7 +10,7 @@ LL | let foo: fn() = foo;
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
= note: expected fn pointer `fn()`
|
= note: expected fn pointer `fn()`
|
||||||
found fn item `unsafe fn() {foo}`
|
found fn item `#[target_features] fn() {foo}`
|
||||||
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers
|
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers
|
||||||
= note: unsafe functions cannot be coerced into safe function pointers
|
= note: unsafe functions cannot be coerced into safe function pointers
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue