Uh oh!
There was an error while loading. Please reload this page.
Implement basic input validation for built-in attributes - #57321
Conversation
petrochenkov
commented
Jan 4, 2019
@bors try |
bors
commented
Jan 4, 2019
Implement basic input validation for built-in attributes + Stabilize `unrestricted_attribute_tokens` Based on #57272 --- In accordance with the plan in https://internals.rust-lang.org/t/unrestricted-attribute-tokens-feature-status/8561: - The correct top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is enforced for built-in attributes. - For non-built-in non-macro attributes: - The key-value form is restricted to bare minimum required to support what we support on stable - unsuffixed literals (#34981). - Arbitrary token streams in remaining forms (`#[attr(token_stream)]`, `#[attr{token_stream}]`, `#[attr[token_stream]]` ) are now allowed without a feature gate, like in macro attributes. This will close#55208 once completed. Need to go through crater first.
petrochenkov
commented
Jan 4, 2019
cc @CAD97 |
bors
commented
Jan 4, 2019
☀️ Test successful - status-travis |
| struct Foo; | ||
| // compile-pass | ||
| #[derive()] //~ WARNING empty trait list in `derive` |
There was a problem hiding this comment.
Btw... I tried to look for the reason why this happens instead of unused_attributes but got lost... (cc #54651).
There was a problem hiding this comment.
This is a hardcoded warning in libsyntax/ext/derive.rs.derive is removed during expansion currently (
rust/src/libsyntax/ext/expand.rs
Lines 373 to 374 in d6d32ac
Expansion should degrade #[derive(Macro1, Macro2, ...)] into #[derive()] instead with derive attribute itself marked as used when it applies a macro.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Centril
commented
Jan 4, 2019
I really enjoyed this and the improved error messages as well as the improvements to
My understanding is that the stable grammar of attributes then are: OuterAttr = "#" attr:Attr;InnerAttr = "#""!" attr:Attr;Attr = "[" path:Path input:AttrInput"]";AttrInput =
| {}
| "("TOKEN_STREAM")"
| "["TOKEN_STREAM"]"
| "{"TOKEN_STREAM"}"
| "="LITERAL;Is that correct?
I have some thoughts on this:
Regardless of what I've written here let's do that. |
Centril
commented
Jan 4, 2019
Assigning to r? @nikomatsakis for technical review |
petrochenkov
commented
Jan 4, 2019
@craterbot run start=master#c0bbc3927e28c22edefe6a1353b5ecc95ea9a104 end=try#b9139d2caca1db46014a9c302d5c47cfae0d8ae0 mode=check-only |
craterbot
commented
Jan 4, 2019
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
craterbot
commented
Jan 4, 2019
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
Correct.
In this case the prose is already kind of written actually, in https://internals.rust-lang.org/t/unrestricted-attribute-tokens-feature-status/8561/3.
Hm, I feel exactly oppositely, this is the most trivial part of the proposal.
This also needs some attention and FCP, since this is some change of direction.
I wouldn't want to delay simple and already semi-stable delimited attributes on this.
I think this does requires an RFC and some thoughts about the future, but I wouldn't want to want to work on it myself, since it's not high priority. |
Centril
commented
Jan 4, 2019
Fair.
Hah; that was implied, sorry... :) (I propose that we do what the PR description suggests; tho I would split off the
It definitely is an improvement; the improved diagnostics are particularly great.
Also fair... I might have some time to work on this, or @CAD97 can do it if they prefer (we can collaborate ofc...). |
craterbot
commented
Jan 5, 2019
🎉 Experiment
|
petrochenkov
commented
Jan 5, 2019
O_O |
Centril
commented
Jan 5, 2019
We might want to analyze these to categorize the regressions and see what the roots are before going for plan B... After doing that we might want to allow some new forms (and give them correct semantics rather than just ignoring...) and interpret them correctly or not based on the analysis. From a quick look I saw a lot of |
petrochenkov
commented
Jan 5, 2019
That's exactly the purpose of the plan B. |
Centril
commented
Jan 5, 2019
Oh, OK =P |
First of all - no regressions from restricting key-value attributes to literals. Beside that, here's the list of offending attributes with some statistics (statistics include non-root regressions): Here's the list of root regressions: |
petrochenkov
commented
Jan 5, 2019
Conclusions:
It seems quite reasonable to support
|
Centril
commented
Jan 5, 2019
👍
Agreed; I suggested the same in #56896 (comment).
re. As for deprecation lints, do you mean C-future-compatibility or that we should keep this forever?
😂 |
Yes, didn't notice that. If
What's the difference? Even if the warning ends up being kept forever, it's going to be framed as a deprecation lint anyway. |
nikomatsakis
commented
Jan 15, 2019
@bors r+ |
bors
commented
Jan 15, 2019
📌 Commit d3411d3 has been approved by |
Centril
commented
Jan 15, 2019
@bors p=7 Rollup fairness. |
bors
commented
Jan 16, 2019
Implement basic input validation for built-in attributes Correct top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is enforced for built-in attributes, built-in attributes must also fit into the "meta-item" syntax (aka the "classic attribute syntax"). For some subset of attributes (found by crater run), errors are lowered to deprecation warnings. NOTE: This PR previously included #57367 as well.
bors
commented
Jan 16, 2019
☀️ Test successful - checks-travis, status-appveyor |
Stabilize `unrestricted_attribute_tokens` In accordance with a plan described in https://internals.rust-lang.org/t/unrestricted-attribute-tokens-feature-status/8561/3. Delimited non-macro non-builtin attributes now support the same syntax as macro attributes: ``` PATH PATH `(` TOKEN_STREAM `)` PATH `[` TOKEN_STREAM `]` PATH `{` TOKEN_STREAM `}` ``` Such attributes mostly serve as inert proc macro helpers or tool attributes. To some extent these attributes are de-facto stable due to a hole in feature gate checking (feature gating is done too late - after macro expansion.) So if macro *removes* such helper attributes during expansion (and it must remove them, unless it's a derive macro), then the code will work on stable. Key-value non-macro non-builtin attributes are now restricted to bare minimum required to support what we support on stable - unsuffixed literals (#34981). ``` PATH `=` LITERAL ``` (Key-value macro attributes are not supported at all right now.) Crater run in #57321 found no regressions for this change. There are multiple possible ways to extend key-value attributes (#57321 (comment)), but I'd expect an RFC for that and it's not a pressing enough issue to block stabilization of delimited attributes. Built-in attributes are still restricted to the "classic" meta-item syntax, nothing changes here. #57321 goes further and adds some additional restrictions (more consistent input checking) to built-in attributes. Closes#55208
ehuss
commented
Feb 27, 2019
@petrochenkov I was curious, was the Also |
Ha, good catch. |
ehuss
commented
Feb 27, 2019
Ah, thanks!. The reason I ask is because I'm looking at improving the reference documentation for attributes, and now all the attributes have nice input validation, except |
petrochenkov
commented
Feb 27, 2019
I think so, each macro will have to do that individually though, without help from the validation infra introduced in this PR. |
Correct top-level shape (
#[attr]vs#[attr(...)]vs#[attr = ...]) is enforced for built-in attributes, built-in attributes must also fit into the "meta-item" syntax (aka the "classic attribute syntax").For some subset of attributes (found by crater run), errors are lowered to deprecation warnings.
NOTE: This PR previously included #57367 as well.