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

hir: Disallow target_feature on constants #64809

Merged
merged 2 commits into from
Sep 28, 2019

Conversation

davidtwco
Copy link
Member

Fixes #64768.

This PR fixes an ICE when #[target_feature] is applied to constants by disallowing this with the same error as when #[target_feature] is applied to other places it shouldn't be.

I couldn't see anything in the RFC that suggested that #[target_feature] should be applicable to constants or any tests that suggested it should, though I might have missed something - if this is desirable in future, it remains possible to remove this error (but for the time being, I think this error is better than an ICE).

I also added some extra cases to the test for other places where #[target_feature] should not be permitted.

cc @gnzlbg

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 26, 2019
@gnzlbg
Copy link
Contributor

gnzlbg commented Sep 26, 2019 via email

@davidtwco davidtwco force-pushed the issue-64768-target-feature-const branch from feb6cd8 to b310f61 Compare September 26, 2019 13:34
Copy link
Member

@varkor varkor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! r=me after a test case for multiple invalid attributes.

src/librustc/hir/check_attr.rs Outdated Show resolved Hide resolved
@varkor varkor assigned varkor and unassigned estebank Sep 26, 2019
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-09-26T13:35:15.3525571Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-09-26T13:35:15.3715437Z ##[command]git config gc.auto 0
2019-09-26T13:35:15.3795716Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-09-26T13:35:15.3862150Z ##[command]git config --get-all http.proxy
2019-09-26T13:35:15.4054899Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/64809/merge:refs/remotes/pull/64809/merge
---
2019-09-26T13:42:19.6401777Z    Compiling serde_json v1.0.40
2019-09-26T13:42:21.1726983Z    Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
2019-09-26T13:42:31.4290540Z     Finished release [optimized] target(s) in 1m 19s
2019-09-26T13:42:31.4360707Z tidy check
2019-09-26T13:42:31.9043977Z tidy error: /checkout/src/librustc/hir/check_attr.rs:138: line longer than 100 chars
2019-09-26T13:42:31.9044140Z tidy error: /checkout/src/librustc/hir/check_attr.rs:168: line longer than 100 chars
2019-09-26T13:42:33.0717758Z some tidy checks failed
2019-09-26T13:42:33.0719556Z 
2019-09-26T13:42:33.0719556Z 
2019-09-26T13:42:33.0720701Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2019-09-26T13:42:33.0720869Z 
2019-09-26T13:42:33.0720915Z 
2019-09-26T13:42:33.0732887Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-09-26T13:42:33.0732944Z Build completed unsuccessfully in 0:01:22
2019-09-26T13:42:33.0732944Z Build completed unsuccessfully in 0:01:22
2019-09-26T13:42:33.0777125Z == clock drift check ==
2019-09-26T13:42:33.0800453Z   local time: Thu Sep 26 13:42:33 UTC 2019
2019-09-26T13:42:33.3412426Z   network time: Thu, 26 Sep 2019 13:42:33 GMT
2019-09-26T13:42:33.3416864Z == end clock drift check ==
2019-09-26T13:42:34.7539413Z ##[error]Bash exited with code '1'.
2019-09-26T13:42:34.7570935Z ##[section]Starting: Checkout
2019-09-26T13:42:34.7573055Z ==============================================================================
2019-09-26T13:42:34.7573295Z Task         : Get sources
2019-09-26T13:42:34.7573349Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@davidtwco davidtwco force-pushed the issue-64768-target-feature-const branch from b310f61 to a31c8bc Compare September 26, 2019 14:22
@davidtwco davidtwco force-pushed the issue-64768-target-feature-const branch from a31c8bc to 351f551 Compare September 26, 2019 15:33
@varkor
Copy link
Member

varkor commented Sep 26, 2019

r=me when tests pass (with or without the final suggestions, which are entirely preferential).

This commit fixes an ICE when `target_feature` is applied to constants.

Signed-off-by: David Wood <david@davidtw.co>
See linked comment[1] for context.

1: rust-lang#64809 (comment)

Signed-off-by: David Wood <david@davidtw.co>
@davidtwco davidtwco force-pushed the issue-64768-target-feature-const branch from 351f551 to c3368bd Compare September 26, 2019 16:05
@gnzlbg
Copy link
Contributor

gnzlbg commented Sep 26, 2019 via email

@moonheart08
Copy link
Contributor

@moonheart08
Of note: The reason I was attempting to use target function on a const
was because the const needed a different value on different targets. For AVX2 targets, it needed a value of 7, for AVX512 targets, a value of 15, and for other targets, a value of 3. Pointers on how to do it right are appreciated. You can use #[cfg(target_feature)] for that.

I had deleted my comment and moved it to the issue that caused this PR, thank you, however!

@estebank
Copy link
Contributor

@bors r=varkor

@bors
Copy link
Contributor

bors commented Sep 27, 2019

📌 Commit c3368bd has been approved by varkor

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 27, 2019
Centril added a commit to Centril/rust that referenced this pull request Sep 28, 2019
…e-const, r=varkor

hir: Disallow `target_feature` on constants

Fixes rust-lang#64768.

This PR fixes an ICE when `#[target_feature]` is applied to constants by disallowing this with the same error as when `#[target_feature]` is applied to other places it shouldn't be.

I couldn't see anything in the [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2045-target-feature.md) that suggested that `#[target_feature]` should be applicable to constants or any tests that suggested it should, though I might have missed something - if this is desirable in future, it remains possible to remove this error (but for the time being, I think this error is better than an ICE).

I also added some extra cases to the test for other places where `#[target_feature]` should not be permitted.

cc @gnzlbg
bors added a commit that referenced this pull request Sep 28, 2019
Rollup of 14 pull requests

Successful merges:

 - #63492 (Remove redundancy from the implementation of C variadics.)
 - #64703 (Docs: slice elements are equidistant)
 - #64745 (Include message on tests that should panic but do not)
 - #64781 (Remove stray references to the old global tcx)
 - #64794 (Remove unused DepTrackingMap)
 - #64802 (Account for tail expressions when pointing at return type)
 - #64809 (hir: Disallow `target_feature` on constants)
 - #64815 (Fix div_duration() marked as stable by mistake)
 - #64818 (update rtpSpawn's parameters type(It's prototype has been updated in libc))
 - #64830 (Thou shallt not `.abort_if_errors()`)
 - #64836 (Stabilize map_get_key_value feature)
 - #64845 (pin.rs: fix links to primitives in documentation)
 - #64847 (Upgrade env_logger to 0.7)
 - #64851 (Add mailmap entry for Dustin Bensing by request)

Failed merges:

 - #64824 (No StableHasherResult everywhere)

r? @ghost
Centril added a commit to Centril/rust that referenced this pull request Sep 28, 2019
…e-const, r=varkor

hir: Disallow `target_feature` on constants

Fixes rust-lang#64768.

This PR fixes an ICE when `#[target_feature]` is applied to constants by disallowing this with the same error as when `#[target_feature]` is applied to other places it shouldn't be.

I couldn't see anything in the [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2045-target-feature.md) that suggested that `#[target_feature]` should be applicable to constants or any tests that suggested it should, though I might have missed something - if this is desirable in future, it remains possible to remove this error (but for the time being, I think this error is better than an ICE).

I also added some extra cases to the test for other places where `#[target_feature]` should not be permitted.

cc @gnzlbg
bors added a commit that referenced this pull request Sep 28, 2019
Rollup of 14 pull requests

Successful merges:

 - #64703 (Docs: slice elements are equidistant)
 - #64745 (Include message on tests that should panic but do not)
 - #64781 (Remove stray references to the old global tcx)
 - #64794 (Remove unused DepTrackingMap)
 - #64802 (Account for tail expressions when pointing at return type)
 - #64809 (hir: Disallow `target_feature` on constants)
 - #64815 (Fix div_duration() marked as stable by mistake)
 - #64818 (update rtpSpawn's parameters type(It's prototype has been updated in libc))
 - #64830 (Thou shallt not `.abort_if_errors()`)
 - #64836 (Stabilize map_get_key_value feature)
 - #64845 (pin.rs: fix links to primitives in documentation)
 - #64847 (Upgrade env_logger to 0.7)
 - #64851 (Add mailmap entry for Dustin Bensing by request)
 - #64859 (check_match: improve diagnostics for `let A = 2;` with `const A: i32 = 3`)

Failed merges:

r? @ghost
@bors bors merged commit c3368bd into rust-lang:master Sep 28, 2019
@davidtwco davidtwco deleted the issue-64768-target-feature-const branch September 28, 2019 18:13
andjo403 pushed a commit to andjo403/rust that referenced this pull request Oct 4, 2019
See linked comment[1] for context.

1: rust-lang#64809 (comment)

Signed-off-by: David Wood <david@davidtw.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE when using target_feature with a const
8 participants