Skip to content

Commit 4e3ee2c

Browse files
calebzulawskiindirect
authored andcommitted
Don't implement Fn* for unsafe #[target_feature] functions
1 parent 93688c7 commit 4e3ee2c

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
293293
self.tcx.lang_items().fn_once_trait(),
294294
]
295295
.contains(&Some(trait_ref.def_id()));
296-
let is_safe_target_feature_fn =
296+
let is_target_feature_fn =
297297
if let ty::FnDef(def_id, _) = trait_ref.skip_binder().self_ty().kind {
298-
trait_ref.skip_binder().self_ty().fn_sig(self.tcx).unsafety()
299-
== hir::Unsafety::Normal
300-
&& !self.tcx.codegen_fn_attrs(def_id).target_features.is_empty()
298+
!self.tcx.codegen_fn_attrs(def_id).target_features.is_empty()
301299
} else {
302300
false
303301
};
@@ -443,7 +441,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
443441
);
444442
}
445443

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

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

Lines changed: 3 additions & 0 deletions
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)