-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use cfg_attr
in AST with a placeholder attribute for accurate suggestion
#133823
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
Open
estebank
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
estebank:issue-56328
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
warning: unused extern crate | ||
warning: unused `extern crate` | ||
--> $DIR/edition-extern-crate-allowed.rs:7:1 | ||
| | ||
LL | extern crate edition_extern_crate_allowed; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/edition-extern-crate-allowed.rs:5:9 | ||
| | ||
LL | #![warn(rust_2018_idioms)] | ||
| ^^^^^^^^^^^^^^^^ | ||
= note: `#[warn(unused_extern_crates)]` implied by `#[warn(rust_2018_idioms)]` | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate edition_extern_crate_allowed; | ||
| | ||
|
||
warning: 1 warning emitted | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
error: unused extern crate | ||
error: unused `extern crate` | ||
--> $DIR/extern-crate-used.rs:18:1 | ||
| | ||
LL | extern crate core; | ||
| ^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/extern-crate-used.rs:6:9 | ||
| | ||
LL | #![deny(unused_extern_crates)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate core; | ||
LL + | ||
| | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,73 @@ | ||
error: unused extern crate | ||
error: unused `extern crate` | ||
--> $DIR/unnecessary-extern-crate.rs:6:1 | ||
| | ||
LL | extern crate core; | ||
| ^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/unnecessary-extern-crate.rs:3:9 | ||
| | ||
LL | #![deny(unused_extern_crates)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate core; | ||
| | ||
|
||
error: unused extern crate | ||
error: unused `extern crate` | ||
--> $DIR/unnecessary-extern-crate.rs:9:1 | ||
| | ||
LL | extern crate core as x; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate core as x; | ||
| | ||
|
||
error: unused extern crate | ||
error: unused `extern crate` | ||
--> $DIR/unnecessary-extern-crate.rs:31:5 | ||
| | ||
LL | extern crate core; | ||
| ^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate core; | ||
| | ||
|
||
error: unused extern crate | ||
error: unused `extern crate` | ||
--> $DIR/unnecessary-extern-crate.rs:35:5 | ||
| | ||
LL | extern crate core as x; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate core as x; | ||
| | ||
|
||
error: unused extern crate | ||
error: unused `extern crate` | ||
--> $DIR/unnecessary-extern-crate.rs:44:9 | ||
| | ||
LL | extern crate core; | ||
| ^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate core; | ||
| | ||
|
||
error: unused extern crate | ||
error: unused `extern crate` | ||
--> $DIR/unnecessary-extern-crate.rs:48:9 | ||
| | ||
LL | extern crate core as x; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate core as x; | ||
| | ||
|
||
error: aborting due to 6 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,31 @@ | ||
error: unused extern crate | ||
error: unused `extern crate` | ||
--> $DIR/lint-unused-extern-crate.rs:11:1 | ||
| | ||
LL | extern crate lint_unused_extern_crate5; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/lint-unused-extern-crate.rs:7:9 | ||
| | ||
LL | #![deny(unused_extern_crates)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate lint_unused_extern_crate5; | ||
LL + | ||
| | ||
|
||
error: unused extern crate | ||
error: unused `extern crate` | ||
--> $DIR/lint-unused-extern-crate.rs:29:5 | ||
| | ||
LL | extern crate lint_unused_extern_crate2; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate lint_unused_extern_crate2; | ||
LL + | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_attribute] | ||
pub fn my_proc_macro(_: TokenStream, input: TokenStream) -> TokenStream { | ||
if format!("{input:#?}").contains("my_attr1") { | ||
panic!("found gated attribute my_attr1"); | ||
} | ||
if format!("{input:#?}").contains("placeholder") { | ||
panic!("found placeholder attribute"); | ||
} | ||
if !format!("{input:#?}").contains("my_attr2") { | ||
panic!("didn't if gated my_attr2"); | ||
} | ||
input | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn my_attr1(_: TokenStream, input: TokenStream) -> TokenStream { | ||
panic!("my_attr1 was called"); | ||
input | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn my_attr2(_: TokenStream, input: TokenStream) -> TokenStream { | ||
if format!("{input:#?}").contains("my_attr1") { | ||
panic!("found gated attribute my_attr1"); | ||
} | ||
input | ||
} | ||
13 changes: 13 additions & 0 deletions
13
tests/ui/proc-macro/cfg-attr-placeholder-invisible-to-proc-macro.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Ensure that `rustc-cfg-placeholder` isn't visible to proc-macros. | ||
//@proc-macro: cfg-placeholder.rs | ||
//@check-pass | ||
#![feature(cfg_eval)] | ||
#[macro_use] extern crate cfg_placeholder; | ||
|
||
#[cfg_eval] | ||
#[my_proc_macro] | ||
#[cfg_attr(FALSE, my_attr1)] | ||
#[cfg_attr(all(), my_attr2)] | ||
struct S {} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
warning: unused extern crate | ||
warning: unused `extern crate` | ||
--> $DIR/no-macro-use-attr.rs:6:1 | ||
| | ||
LL | extern crate test_macros; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ unused | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/no-macro-use-attr.rs:4:9 | ||
| | ||
LL | #![warn(unused_extern_crates)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
help: remove the unused `extern crate` | ||
| | ||
LL - extern crate test_macros; | ||
| | ||
|
||
warning: 1 warning emitted | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A similar test was already added in #138515, so this one shouldn't be necessary.