Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: Fix ICE with #[target_feature] on module #48752

Merged
merged 1 commit into from
Mar 9, 2018
Merged
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
8 changes: 7 additions & 1 deletion src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ struct CheckAttrVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
/// Check any attribute.
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 {
if let Some(name) = attr.name() {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,7 @@ fn trans_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> TransFnAt
.emit();
}
} else if attr.check_name("target_feature") {
// handle deprecated #[target_feature = "..."]
if let Some(val) = attr.value_str() {
for feat in val.as_str().split(",").map(|f| f.trim()) {
if !feat.is_empty() && !feat.contains('\0') {
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/target-feature-wrong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ unsafe fn foo() {}
//~^ ERROR: can only be applied to `unsafe` function
fn bar() {}

#[target_feature(enable = "sse2")]
//~^ ERROR: should be applied to a function
mod another {}

fn main() {
unsafe {
foo();
Expand Down
11 changes: 10 additions & 1 deletion src/test/ui/target-feature-wrong.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ error: #[target_feature(..)] can only be applied to `unsafe` function
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