Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ impl DefKind {
/// Whether `query struct_target_features` should be used with this definition.
pub fn has_struct_target_features(self) -> bool {
match self {
DefKind::Struct | DefKind::Union | DefKind::Enum => true,
DefKind::Struct => true,
DefKind::Fn
| DefKind::Union
| DefKind::Enum
| DefKind::AssocFn
| DefKind::Ctor(..)
| DefKind::Closure
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ provide! { tcx, def_id, other, cdata,
variances_of => { table }
fn_sig => { table }
codegen_fn_attrs => { table }
struct_target_features => { table }
struct_target_features => { table_defaulted_array }
impl_trait_header => { table }
const_param_default => { table }
object_lifetime_default => { table }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
}
if def_kind.has_struct_target_features() {
record_array!(self.tables.struct_target_features[def_id] <- self.tcx.struct_target_features(def_id));
record_defaulted_array!(self.tables.struct_target_features[def_id] <- self.tcx.struct_target_features(def_id));
}
if should_encode_visibility(def_kind) {
let vis =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ define_tables! {
// individually instead of `DefId`s.
module_children_reexports: Table<DefIndex, LazyArray<ModChild>>,
cross_crate_inlinable: Table<DefIndex, bool>,
struct_target_features: Table<DefIndex, LazyArray<TargetFeature>>,

- optional:
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
Expand All @@ -427,7 +428,6 @@ define_tables! {
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, ty::PolyFnSig<'static>>>>,
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
struct_target_features: Table<DefIndex, LazyArray<TargetFeature>>,
impl_trait_header: Table<DefIndex, LazyValue<ty::ImplTraitHeader<'static>>>,
const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, rustc_middle::ty::Const<'static>>>>,
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![feature(struct_target_features)]

#[target_feature(enable = "avx")]
pub struct Avx {}

pub struct NoFeatures {}
23 changes: 23 additions & 0 deletions tests/ui/target-feature/struct-target-features-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//@ only-x86_64
//@ aux-build: struct-target-features-crate-dep.rs
//@ check-pass
#![feature(target_feature_11)]

extern crate struct_target_features_crate_dep;

#[target_feature(enable = "avx")]
fn avx() {}

fn f(_: struct_target_features_crate_dep::Avx) {
avx();
}

fn g(_: struct_target_features_crate_dep::NoFeatures) {}

fn main() {
if is_x86_feature_detected!("avx") {
let avx = unsafe { struct_target_features_crate_dep::Avx {} };
f(avx);
}
g(struct_target_features_crate_dep::NoFeatures {});
}
Loading