-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add the -Zcrate-attr=foo unstable rustc option #52355
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
Would it be possible to generalize to a |
Hmm, what other attributes did you have in mind? I can't think of many of them that apply to the whole crate and can be useful to dynamically add. |
@pietroalbini I was discussing a while back "custom test frameworks" with @Manishearth, and this came up: the usecases I had in mind were injecting Also there are some things like crate name, type, recursion limits, etc. where it'd be nice if there was a common interface (e.g. EDIT: @michaelwoerister might have some opinions regarding incremental, but I think such a flag would simplify things, by modifying the input source code itself, rather than being a side-channel. |
src/librustc/session/config.rs
Outdated
@@ -1351,6 +1351,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, | |||
"generate build artifacts that are compatible with linker-based LTO."), | |||
no_parallel_llvm: bool = (false, parse_bool, [UNTRACKED], | |||
"don't run LLVM in parallel (while keeping codegen-units and ThinLTO)"), | |||
feature: Vec<String> = (Vec::new(), parse_string_push, [UNTRACKED], |
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.
cc @michaelwoerister on the UNTRACKED
here - I think you can only do this if you actually modify the AST to include explicit attributes (which I think we should do).
Also, it'd be easier to handle e.g. the "unused feature" lint, if we have the attributes in the AST.
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.
Modifying the AST would probably work for incremental, yes, but it also seems .. like overkill? In particular, the reason for this change is to unblock our ability to run a crater run and test the Edition migration, so I'd hate to just stall out on possible future improvements. We could just make the attribute [TRACKED]
.
Where would you propose doing the AST modification exactly?
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.
I was working on converting this PR to -Zcrate-attr=feature(foo)
(wip branch), but I don't have time to finish it now (maybe in a few days). If you want to merge this as soon as possible I can do a quick commit changing the flag to [TRACKED]
, and then I can open a new PR implementing -Zcrate-attr
and reverting this one.
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.
Oh @nikomatsakis, now that I think about it, if we want to do a crater run as soon as possible we could also @bors try
this and use this PR as the second crater toolchain.
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.
Good point.
Let's get a toolchain built for the edition crater run. @bors try |
Add the -Zfeature=foo unstable rustc option This PR adds a new unstable option to `rustc`: `-Zfeature=foo`. The option can be used to enable nightly features from the CLI, and it's meant to be used by tools like Crater to try enabling features without changing the crate's source code. The exact reason I need this is to implement "edition runs" in Crater: we need to add the preview feature flag to every crate, and editing the crates' source code on the fly might produce unexpected results, while a compiler flag is more reliable. Obviously this won't be stabilized in the future. cc rust-lang/crater#282 @Mark-Simulacrum
☀️ Test successful - status-travis |
92fb368
to
277fbf3
Compare
Ok, implemented
But when another part of rustc raises an error about that attribute the spans are messed up (showing the crate code instead of the attribute):
|
Diagnostics fixed. This should be ready for a review now. |
@bors try |
Add the -Zcrate-attr=foo unstable rustc option This PR adds a new unstable option to `rustc`: `-Zcrate-attr=foo`. The option can be used to inject crate-level attributes from the CLI, and it's meant to be used by tools like Crater that needs to add their own attributes to a crate without changing the source code. The exact reason I need this is to implement "edition runs" in Crater: we need to add the preview feature flag to every crate, and editing the crates' source code on the fly might produce unexpected results, while a compiler flag is more reliable. cc rust-lang/crater#282 @Mark-Simulacrum
☀️ Test successful - status-travis |
@bors r+ |
📌 Commit 71276c6 has been approved by |
cc @djrenren this may be useful for custom test frameworks |
Add the -Zcrate-attr=foo unstable rustc option This PR adds a new unstable option to `rustc`: `-Zcrate-attr=foo`. The option can be used to inject crate-level attributes from the CLI, and it's meant to be used by tools like Crater that needs to add their own attributes to a crate without changing the source code. The exact reason I need this is to implement "edition runs" in Crater: we need to add the preview feature flag to every crate, and editing the crates' source code on the fly might produce unexpected results, while a compiler flag is more reliable. cc rust-lang/crater#282 @Mark-Simulacrum
☀️ Test successful - status-appveyor, status-travis |
This PR adds a new unstable option to
rustc
:-Zcrate-attr=foo
. The option can be used to inject crate-level attributes from the CLI, and it's meant to be used by tools like Crater that needs to add their own attributes to a crate without changing the source code.The exact reason I need this is to implement "edition runs" in Crater: we need to add the preview feature flag to every crate, and editing the crates' source code on the fly might produce unexpected results, while a compiler flag is more reliable.
cc rust-lang/crater#282 @Mark-Simulacrum