Rollup merge of #48752 - alexcrichton:fix-target-feature, r=michaelwoerister
rustc: Fix ICE with `#[target_feature]` on module This commit fixes an ICE in rustc when `#[target_feature]` was applied to items other than functions due to the way the feature was validated.
This commit is contained in:
commit
c8a73e438a
4 changed files with 22 additions and 2 deletions
|
@ -47,7 +47,13 @@ struct CheckAttrVisitor<'a, 'tcx: 'a> {
|
||||||
impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
|
impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
|
||||||
/// Check any attribute.
|
/// Check any attribute.
|
||||||
fn check_attributes(&self, item: &hir::Item, target: Target) {
|
fn check_attributes(&self, item: &hir::Item, target: Target) {
|
||||||
self.tcx.trans_fn_attrs(self.tcx.hir.local_def_id(item.id));
|
if target == Target::Fn {
|
||||||
|
self.tcx.trans_fn_attrs(self.tcx.hir.local_def_id(item.id));
|
||||||
|
} else if let Some(a) = item.attrs.iter().find(|a| a.check_name("target_feature")) {
|
||||||
|
self.tcx.sess.struct_span_err(a.span, "attribute should be applied to a function")
|
||||||
|
.span_label(item.span, "not a function")
|
||||||
|
.emit();
|
||||||
|
}
|
||||||
|
|
||||||
for attr in &item.attrs {
|
for attr in &item.attrs {
|
||||||
if let Some(name) = attr.name() {
|
if let Some(name) = attr.name() {
|
||||||
|
|
|
@ -1866,6 +1866,7 @@ fn trans_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> TransFnAt
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
} else if attr.check_name("target_feature") {
|
} else if attr.check_name("target_feature") {
|
||||||
|
// handle deprecated #[target_feature = "..."]
|
||||||
if let Some(val) = attr.value_str() {
|
if let Some(val) = attr.value_str() {
|
||||||
for feat in val.as_str().split(",").map(|f| f.trim()) {
|
for feat in val.as_str().split(",").map(|f| f.trim()) {
|
||||||
if !feat.is_empty() && !feat.contains('\0') {
|
if !feat.is_empty() && !feat.contains('\0') {
|
||||||
|
|
|
@ -29,6 +29,10 @@ unsafe fn foo() {}
|
||||||
//~^ ERROR: can only be applied to `unsafe` function
|
//~^ ERROR: can only be applied to `unsafe` function
|
||||||
fn bar() {}
|
fn bar() {}
|
||||||
|
|
||||||
|
#[target_feature(enable = "sse2")]
|
||||||
|
//~^ ERROR: should be applied to a function
|
||||||
|
mod another {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
foo();
|
foo();
|
||||||
|
|
|
@ -28,5 +28,14 @@ error: #[target_feature(..)] can only be applied to `unsafe` function
|
||||||
LL | #[target_feature(enable = "sse2")]
|
LL | #[target_feature(enable = "sse2")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: attribute should be applied to a function
|
||||||
|
--> $DIR/target-feature-wrong.rs:32:1
|
||||||
|
|
|
||||||
|
LL | #[target_feature(enable = "sse2")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
LL | //~^ ERROR: should be applied to a function
|
||||||
|
LL | mod another {}
|
||||||
|
| -------------- not a function
|
||||||
|
|
||||||
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue