-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Stabilize Frontmatter #148051
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
base: master
Are you sure you want to change the base?
Stabilize Frontmatter #148051
Conversation
|
Some changes occurred in src/doc/style-guide cc @rust-lang/style |
|
r? @davidtwco rustbot has assigned @davidtwco. Use |
| gate_all!(unsafe_fields, "`unsafe` fields are experimental"); | ||
| gate_all!(unsafe_binders, "unsafe binder types are experimental"); | ||
| gate_all!(contracts, "contracts are incomplete"); | ||
| gate_all!(contracts_internals, "contract internal machinery is for internal use only"); |
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.
(Commenting on an arbitrary line to make this discussion threaded)
From the PR description (emphasis and ellipses mine):
Post-RFC changes
[…]
- acceptable places for frontmatter
- […]
- rustc: support removed from […]
include![…]- […]
include!can be used to inject code into the middle of a file which becomes ambiguous between a frontmatter start and a very negated number (----x)
In #146340 I actually struck a (temporary) compromise: We do still strip/lex/recognize frontmatter (and shebang) in item-context include!s. However, we no longer strip frontmatter in expression/statement-context include!s like in let _ = include!(…); (to prevent the manifold negation backcompat issue you've rightly mentioned).
Now, I don't know what's best here. I'm eager to know your and T-lang's stance on the matter. Note that we do strip shebang in expression/statement-context include!s which I consider to be quite odd (but still understandable on a lexical level). I have an open PR #146377 which would stop stripping shebang in that position, too. I still need to rebase+polish, lang-nominate and possibly crater it. The outcome of that T-lang discussion likely affects the decision mentioned in the first paragraph (†).
(†): If that PR was accepted it would mean that we would strip shebang+frontmatter in item-ctxt includes and wouldn't strip either(!) shebang or frontmatter in expr/stmt-ctxt includes which would make the behavior of shebang+frontmatter consistent thereby fulfilling the original goal of "This applies anywhere shebang stripping is performed." in this specific case (obviously the goal wasn't achieved in other cases, like in the proc_macro API case).
When working on the stabilization report (rust-lang#148051), I found it annoying to determine what cases were covered because areas of the frontmatter feature were either not in the file name or in inconsistent locations. This moves the area of frontmatter to the start of the file name and the moves to more specific the later in the file name so coverage is easier to see.
test(frontmatter): Rename tests to make coverage more obvious When working on the stabilization report (#148051), I found it annoying to determine what cases were covered because areas of the frontmatter feature were either not in the file name or in inconsistent locations. This moves the area of frontmatter to the start of the file name and the moves to more specific the later in the file name so coverage is easier to see. Tracking issue: #136889
test(frontmatter): Rename tests to make coverage more obvious When working on the stabilization report (rust-lang#148051), I found it annoying to determine what cases were covered because areas of the frontmatter feature were either not in the file name or in inconsistent locations. This moves the area of frontmatter to the start of the file name and the moves to more specific the later in the file name so coverage is easier to see. Tracking issue: rust-lang#136889
test(frontmatter): Rename tests to make coverage more obvious When working on the stabilization report (rust-lang#148051), I found it annoying to determine what cases were covered because areas of the frontmatter feature were either not in the file name or in inconsistent locations. This moves the area of frontmatter to the start of the file name and the moves to more specific the later in the file name so coverage is easier to see. Tracking issue: rust-lang#136889
Rollup merge of #148073 - epage:org-frontmatter, r=jieyouxu test(frontmatter): Rename tests to make coverage more obvious When working on the stabilization report (#148051), I found it annoying to determine what cases were covered because areas of the frontmatter feature were either not in the file name or in inconsistent locations. This moves the area of frontmatter to the start of the file name and the moves to more specific the later in the file name so coverage is easier to see. Tracking issue: #136889
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.
Implementation of this LGTM, r=me once t-lang has approved stabilisation
|
☔ The latest upstream changes (presumably #148090) made this pull request unmergeable. Please resolve the merge conflicts. |
Stabilization report
Summary
This report proposes the stabilization of
#[feature(frontmatter)]in preparation for Cargo Script to be stabilized.A frontmatter is a special kind of attribute intended to be read and modified by external tools, like Cargo. This puts a particular constraint on this attribute in that full awareness of the Rust grammar would be prohibitive.
For example:
The goal of Cargo script is to improve:
Closes #136889
Tracking:
frontmatter#136889Reference PRs:
cc @rust-lang/lang @rust-lang/lang-advisors, @rust-lang/compiler
What is stabilized
This is stabilizing frontmatter, an optional section in a source file that can only exist before any Rust code or comments, for use by external tools.
After the opening frontmatter fence, an infostring is allowed that can identify the contents.
Calling tools are responsible for interpreting the infostring.
What isn't stabilized
Only a subset of the allowed infostring syntax is being stabilized.
(XID_Start |_) ( XID_Continue |-|.)*-in the start of an infostring which is ambiguous with frontmatter open which accepts 3 or more-Future possibilities include:
Design
Reference
RFC history
Answers to unresolved questions
The RFC has no unresolved questions
Post-RFC changes
--cfg(Disallow frontmatter in--cfgand--check-cfgarguments #146137),include!, and proc-macros (Strip frontmatter in fewer places #146340)--cfginclude!can be used to inject code into the middle of a file which becomes ambiguous between a frontmatter start and a very negated number (----x)Key points
---needs to be escaped---at the start of a line needs escaping---needing escaping-ZunprettyNightly extensions
No nightly extensions exist
Doors closed
There are no known efforts that this affects.
Feedback
Call for testing
Call for testing with feedback at:
Previous call for testing: rust-lang/rfcs#3424 (comment) with some feedback at rust-lang/cargo#12207 (comment)
Overall, feedback is enthusiastic. Any quibbles are with the Cargo side.
Nightly use
Samples from grepping for
-ZscriptImplementation
Major parts
Parts:
PRs:
TokenStream::new#145568--cfgand--check-cfgarguments #146137Coverage
Tests (directory):
,in the infostring.or-.or-elsewhereuse---doesn't need escaping-escape lines starting with fewer-include!doesn't treat---as frontmatter---as frontmatterOutstanding bugs
No known bugs
Outstanding FIXMEs
An idea for future editions
rust/compiler/rustc_parse/src/lib.rs
Lines 176 to 180 in 779e19d
Diagnostic improvements can be iterated on over time, particularly with use feedback
rust/tests/ui/frontmatter/frontmatter-after-tokens.rs
Lines 3 to 6 in 779e19d
rust/tests/ui/frontmatter/multifrontmatter.rs
Lines 1 to 7 in 779e19d
Both can be handled as need is shown.
Tool changes
Breaking changes
No known breaking change
Type system, opsem
Compile-time checks
N/A, this is only relevant to tools inspecting the source
Type system rules
N/A, this is only relevant to tools inspecting the source
Sound by default?
No, this is only relevant to tools inspecting the source
Breaks the AM?
No, this is only relevant to tools inspecting the source
Common interactions
Temporaries
No, this is only relevant to tools inspecting the source
Drop order
No, this is only relevant to tools inspecting the source
Pre-expansion / post-expansion
No, this is only relevant to tools inspecting the source
Edition hygiene
N/A, this is independent of editions
SemVer implications
N/A, downstream users cannot access this feature
Exposing other features
Not aware of any
History
PRs
TokenStream::new#145568--cfgand--check-cfgarguments #146137Acknowledgments
Open items