-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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: main
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).
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.
Thanks! I've updated the stabilization report as well as linked to your comment as a place for discussing it.
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've now made that PR ready & lang-nominated it, sorry for the delay. See the nomination text here: #146377 (comment) (it's maybe a bit rambly since I threw it together rather quickly, I hope it's comprehensible enough).
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.
Thanks!
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. |
test(frontmatter): Rename tests to make coverage more obvious When working on the stabilization report (rust-lang/rust#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/rust#136889
This comment has been minimized.
This comment has been minimized.
|
@rustbot label +I-lang-nominated This has been quiet for a while. There is an open issue on the rustdoc side but I figure that can be worked out in parallel to T-lang discussions in case T-lang uncovers anything. Even if this goes straight to FCP, someone can raise a blocking concern on behalf of rustdoc. |
|
Having now read through the stabilization report and the linked PRs, issues, and threads, this seems to me to be ready for stabilization modulo the open rustdoc item mentioned by @epage, getting the Reference PR into a final state, and documenting the behavior of @rfcbot fcp merge lang Thanks to @epage for the thorough stabilization report and for his many efforts in pushing along this feature. |
|
Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
We talked about this in the lang call today. We generally agreed that, in the interest of consistency and conservatism, it'd make sense to not allow CRs that survive CRLF normalization within frontmatter, just as we reject these within raw string literals. If someone has a use-case for these, we could always allow it later (with a lint), and if we did, perhaps it'd make sense to similarly allow it (with a lint) for raw string literals. |
I think likening frontmatter to raw string literals can be taken too far. While on a practical level I am not blocked on stray carriage returns, on a conceptual level, this feels off. This is a section we are intentionally saying "this is owned by an external tool" and so to apply Rust specific rules to the contained content feels off to me. |
|
I share your conceptual model @epage. The argument that convinced me was: It can catch confusing situations for users where they have a stray CR that looks like a line break but isn't, and since we would want a lint even if we do allow it, the simplest thing is just not to allow it. This simplifies the reference now and doesn't prevent us from adding the capability later. |
|
While I disagree, I've gone ahead and posted #149823. |
|
From #149823 (comment)
From #149823 (comment)
Something else to keep in mind with all of this is that at least for use cases like cargo or buck2, they'll process it before rustc sees it, so if they feel it is an issue it will be handled already. |
fix(parse): Limit frontmatter fences to 255 dashes Like raw string literals. As discussed on rust-lang/rust#148051. Part of rust-lang/rust#136889
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
@rfcbot reviewed |
|
re: jack-should-we-strip-frontmatter-in-item-context We landed #146377, do we have an answer for this concern now? I see that PR landed as about expr-context stripping? Do we not have an answer for item-context yet? |
|
The concern is still open because, yes, #146377 is only expr-ctxt. Note that this sort of overlaps with the |
|
This is still blocked, for a variety of reasons. With my champion hat on: I think we should revisit it in a lang meeting soon. @traviscross, could you bump it up, please, so we can unblock it? Summary of what needs lang attention: Major: Revisit and definitively determine the desired behavior for bare CRsWhen we originally looked at this, we said it should disallow bare CRs (as opposed to CR-LF pairs) in frontmatter, due to the way they'd cause the code to look. @epage raised the concern, which as the champion I agree with, that disallowing CRs will create potential conflicts with whatever tool parses the frontmatter: if the tool emits warnings or errors for bare CRs, there would be duplicate warnings from the tool and from rustc. @epage proposes that the tool should be responsible for this. I want to reiterate the general lang policy that rustc is not intended to be robust against malicious Rust code. While we did adopt lints for cases like text direction codepoints (1 2), I don't think in general we should attempt to handle arbitrary malice in misleadingly presented code. With that in mind, I would propose that we not attempt to detect bare CRs at this time. We can, at a later time, consider whether there are specific cases we feel need lints (not hard errors) in rustc; however, at this time I don't think there are likely to be any such cases. So, my proposal is that we close #149823 and resolve the concern Minor: Frontmatter stripping in item contextThere's a concern regarding frontmatter (and shebang) stripping for Solving this would address the concerns |
|
Bumped. It was awaiting a comment describing the ask (such as yours there) to make it more actionable. |
If that is what you were waiting on, I think that needs clearer signposting so folks know what would unblock something. |
I don't really follow. If
The (approximate) grammar for raw string literals is: If we develop a consensus that this should change to Without that, though, my worry remains that 1) whatever reasons we went with For my part, I think of what we're doing here as defining the Absent a consensus that we're going to move to |
I do not believe we had a team consensus on this. Both @tmandry and I had raised questions about why we'd want to do this given that it could only cause fewer programs to compile. Other languages commonly handle shebangs gracefully on their similar constructs, probably (i'd imagine) for this reason. (I.e., I don't think we finished the discussion. I don't know where we'd all fall on this after finishing it.) |
That's for the case of hard-error; consider the case where it's a warning or lint, instead. Tool warns, tool invokes rustc, rustc warns/denies. Re raw strings:
I would, broadly, argue that this should be a deny-by-default lint rather than a hard error; I think it's inconsistent for CR to be a hard error and RTL override characters to be a deny-by-default lint. That said, to be explicit: I would at this time check a box for any of the three paths that allows us to make a definitive statement and forward progress towards stabilization: 1) defer for now, 2) hard error for now, or 3) deny-by-default lint. My preference would be 3 over 1 and 1 over 2. But what I don't want to have happen is that we fail to reach a consensus and thus fail to stabilize and ship this in a timely fashion.
I had thought we had, but apparently not; we should finish that discussion, then. I agree that it will exclusively cause fewer programs to compile. I would hypothesize that there are essentially zero such programs currently, given that shebangs on Rust are rare (in part because we haven't shipped cargo-script yet) and frontmatter is not yet stable. It also simplifies the language and the complexity of That said, as with the above: I would check a box for any of "don't strip" (preferred), "strip both in item context for now and decide later", "always strip both in item context", or even "only strip shebangs and not frontmatter" (least preferred), as long as we go ahead and make a definitive decision. What I'd like to avoid is blocking frontmatter further on a decision about changing shebang stripping, which AFAICT we've done here out of regard for a combination of consistency and seemingly not wanting to add and subsequently remove frontmatter stripping. |
It wasn't clear this was blocked on us having a discussion. We had earlier discussed it and developed a consensus for how to resolve the Regarding @jackh726's concern, I didn't see any movement here on that or a particular ask for us on it either (again until your comment). Our nomination queue is rather deep, and that strains not just lang but also ops. It's my view that it's as much the role of champions as anyone to notice when an item that should be discussed with lang does not have any clear ask of that on the relevant PR or issue. |
I don't think the concerns apply equally well to frontmatter. CR is an invisible character and including one in a string meaningfully changes the behavior of a program. Whereas for frontmatter, it's usually "just code" which is not inherently sensitive to more whitespace. Philosophically I agree that the concern is within the domain of the tool parsing the frontmatter. As I wrote above, I'm ok with starting out with a more restrictive version since that buys us something (a simpler reference) and we can always relax it later. But I still don't consider it "correct". |
This is perhaps a philosophical point, but I still think these are roughly the same. A CR in a string doesn't necessarily change the behavior of the program -- that's up to the program -- But in making my main point -- consistency of the grammar in our file format -- it's not actually even Footnotes
|
|
To be more precise, the CR changes the value of a raw string literal. While rustc doesn't know if this affects program behavior, it's very likely that it does, and it's within rustc's scope to check the correctness of programs. Finding issues in frontmatter is not within rustc's scope. Your point about simplifying tools is taken, but for many tools this might be one of the places where it's better to accept a superset of Rust. With all that said, I agree with Josh that we should accept CR with a deny-by-default lint instead of building it into the grammar. If we can all agree on that being the eventual goal, perhaps we should shift the discussion to talking about the best way of getting there. |
It has occurred to me that maybe we should go the other way. Maybe there's not any good reason to allow CRs that survive CRLF normalization in a Rust file, period. E.g., after CRLF normalization, the byte string CR CR LF becomes CR LF (!). Arguably, at that point, what we have produced is file corruption. It's difficult to produce examples of Rust programs that can observe this weirdness today because we exclude CRs in so many places in our grammar. If we were to go in the direction of allowing these CRs, this weirdness -- that's a peculiar artifact of how we do CRLF normalization -- would be readily observable. |
Stabilization report
FCP
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) and proc-macros (Strip frontmatter in fewer places #146340)include!in expression/statement-content (still supported in item context)include!(…)#146377 for having shebangs match--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)-s to 255 like#in raw string literalsKey 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