Skip to content

Commit 8e899b1

Browse files
committed
Don't implement Fn* for unsafe #[target_feature] functions
1 parent c98b4c8 commit 8e899b1

File tree

2 files changed

+6
-5
lines changed
  • src

2 files changed

+6
-5
lines changed

src/librustc_trait_selection/traits/error_reporting/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
292292
self.tcx.lang_items().fn_once_trait(),
293293
]
294294
.contains(&Some(trait_ref.def_id()));
295-
let is_safe_target_feature_fn =
295+
let is_target_feature_fn =
296296
if let ty::FnDef(def_id, _) = trait_ref.skip_binder().self_ty().kind {
297-
trait_ref.skip_binder().self_ty().fn_sig(self.tcx).unsafety()
298-
== hir::Unsafety::Normal
299-
&& !self.tcx.codegen_fn_attrs(def_id).target_features.is_empty()
297+
!self.tcx.codegen_fn_attrs(def_id).target_features.is_empty()
300298
} else {
301299
false
302300
};
@@ -441,7 +439,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
441439
);
442440
}
443441

444-
if is_fn_trait && is_safe_target_feature_fn {
442+
if is_fn_trait && is_target_feature_fn {
445443
err.note(&format!(
446444
"`{}` has `#[target_feature]` and is unsafe to call",
447445
trait_ref.skip_binder().self_ty(),

src/test/ui/rfcs/rfc-2396-target_feature-11/fn-traits.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ LL | call(foo_unsafe);
4848
|
4949
= help: the trait `std::ops::Fn<()>` is not implemented for `unsafe fn() {foo_unsafe}`
5050
= note: wrap the `unsafe fn() {foo_unsafe}` in a closure with no arguments: `|| { /* code */ }
51+
= note: `unsafe fn() {foo_unsafe}` has `#[target_feature]` and is unsafe to call
5152

5253
error[E0277]: expected a `std::ops::FnMut<()>` closure, found `unsafe fn() {foo_unsafe}`
5354
--> $DIR/fn-traits.rs:30:14
@@ -60,6 +61,7 @@ LL | call_mut(foo_unsafe);
6061
|
6162
= help: the trait `std::ops::FnMut<()>` is not implemented for `unsafe fn() {foo_unsafe}`
6263
= note: wrap the `unsafe fn() {foo_unsafe}` in a closure with no arguments: `|| { /* code */ }
64+
= note: `unsafe fn() {foo_unsafe}` has `#[target_feature]` and is unsafe to call
6365

6466
error[E0277]: expected a `std::ops::FnOnce<()>` closure, found `unsafe fn() {foo_unsafe}`
6567
--> $DIR/fn-traits.rs:32:15
@@ -72,6 +74,7 @@ LL | call_once(foo_unsafe);
7274
|
7375
= help: the trait `std::ops::FnOnce<()>` is not implemented for `unsafe fn() {foo_unsafe}`
7476
= note: wrap the `unsafe fn() {foo_unsafe}` in a closure with no arguments: `|| { /* code */ }
77+
= note: `unsafe fn() {foo_unsafe}` has `#[target_feature]` and is unsafe to call
7578

7679
error: aborting due to 6 previous errors
7780

0 commit comments

Comments
 (0)