Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 688999b

Browse files
committed
Fix unnecessary restrictions in struct-target-features.
Allow using struct-tf with functions with non-Rust ABI. Also allow converting struct-tf functions to function pointers / let them implement function traits.
1 parent 93f3333 commit 688999b

File tree

4 files changed

+12
-19
lines changed

4 files changed

+12
-19
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
625625
&mut additional_tf,
626626
)
627627
}
628-
// FIXME(struct_target_features): is this really necessary?
629-
if !additional_tf.is_empty() && sig.skip_binder().abi() != abi::Abi::Rust {
630-
tcx.dcx().span_err(
631-
tcx.hir().span(tcx.local_def_id_to_hir_id(did)),
632-
"cannot use a struct with target features in a function with non-Rust ABI",
633-
);
634-
}
635628
if !additional_tf.is_empty() && codegen_fn_attrs.inline == InlineAttr::Always {
636629
tcx.dcx().span_err(
637630
tcx.hir().span(tcx.local_def_id_to_hir_id(did)),

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,15 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
850850
return Err(TypeError::IntrinsicCast);
851851
}
852852

853-
// Safe `#[target_feature]` functions are not assignable to safe fn pointers (RFC 2396).
854-
// FIXME(struct_target_features): should this be true also for functions that inherit
855-
// target features from structs?
856-
853+
// Safe functions with explicit `#[target_feature]` attributes are not
854+
// assignable to safe fn pointers (RFC 2396).
857855
if b_hdr.safety == hir::Safety::Safe
858-
&& !self.tcx.codegen_fn_attrs(def_id).target_features.is_empty()
856+
&& self
857+
.tcx
858+
.codegen_fn_attrs(def_id)
859+
.target_features
860+
.iter()
861+
.any(|x| !x.implied)
859862
{
860863
return Err(TypeError::TargetFeatureCast(def_id));
861864
}

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
439439
let is_target_feature_fn = if let ty::FnDef(def_id, _) =
440440
*leaf_trait_ref.skip_binder().self_ty().kind()
441441
{
442-
// FIXME(struct_target_features): should a function that inherits
443-
// target_features through arguments implement Fn traits?
444-
!self.tcx.codegen_fn_attrs(def_id).target_features.is_empty()
442+
self.tcx.codegen_fn_attrs(def_id).target_features.iter().any(|x| !x.implied)
445443
} else {
446444
false
447445
};

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
549549
.push(FnPointerCandidate { fn_host_effect: self.tcx().consts.true_ });
550550
}
551551
}
552-
// Provide an impl for suitable functions, rejecting `#[target_feature]` functions (RFC 2396).
552+
// Provide an impl for suitable functions, rejecting functions with explicit
553+
// `#[target_feature]` attributes (RFC 2396).
553554
ty::FnDef(def_id, args) => {
554555
let tcx = self.tcx();
555-
// FIXME(struct_target_features): should a function that inherits target_features
556-
// through an argument implement Fn traits?
557556
if tcx.fn_sig(def_id).skip_binder().is_fn_trait_compatible()
558-
&& tcx.codegen_fn_attrs(def_id).target_features.is_empty()
557+
&& !tcx.codegen_fn_attrs(def_id).target_features.iter().any(|x| !x.implied)
559558
{
560559
candidates.vec.push(FnPointerCandidate {
561560
fn_host_effect: tcx

0 commit comments

Comments
 (0)