-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add unstable frontmatter support #137193
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
Closed
Closed
Add unstable frontmatter support #137193
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e55878b
test: Show frontmatter behavior before impl
epage b5d2a6c
feat: Add 'frontmatter' unstable feature
epage 05973f4
feat(lexer): Add frontmatter stripping
epage 359eb20
feat(parse): Strip frontmatter
epage 1ccba03
fix(parse): Feature gate frontmatter
epage a7cd78f
test(fmt): Verify frontmatter is not stripped
epage 8cd8298
feat(pretty): Preserve the frontmatter
epage 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
42 changes: 42 additions & 0 deletions
42
src/doc/unstable-book/src/language-features/frontmatter.md
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,42 @@ | ||
# `frontmatter` | ||
|
||
The tracking issue for this feature is: [#136889] | ||
|
||
[#136889]: https://github.com/rust-lang/rust/issues/136889 | ||
|
||
------------------------ | ||
|
||
The `frontmatter` feature adds support for a specialized and simplified attribute syntax | ||
intended for external tools to consume. | ||
|
||
For example, when used with Cargo: | ||
```rust,ignore (frontmatter/shebang are not intended for doctests) | ||
#!/usr/bin/env -S cargo -Zscript | ||
|
||
--- | ||
[dependencies] | ||
clap = "4" | ||
--- | ||
|
||
#![feature(frontmatter)] | ||
|
||
use clap::Parser; | ||
|
||
#[derive(Parser)] | ||
struct Cli { | ||
} | ||
|
||
fn main () { | ||
Cli::parse(); | ||
} | ||
``` | ||
|
||
A frontmatter may come after a shebang and must come before any other syntax except whitespace. | ||
The open delimiter is three or more dashes (`-`) at the start of a new line. | ||
The open delimiter may be followed by whitespace and / or an identifier to mark the interpretation of the frontmatter within an external tool. | ||
It is then concluded at a newline. | ||
The close delimiter is a series of dashes that matches the open delimiter, at the start of a line. | ||
The close delimiter may be followed by whitespace. | ||
Any other trailing content, including more dashes than the open delimiter, is an error. | ||
It is then concluded at a newline. | ||
All content between the open and close delimiter lines is ignored. |
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,11 @@ | ||
|
||
|
||
--- identifier | ||
[dependencies] | ||
regex = "1" | ||
|
||
--- | ||
|
||
#![feature(frontmatter)] | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- identifier | ||
[dependencies] | ||
regex = "1" | ||
|
||
--- | ||
|
||
#![feature(frontmatter)] | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
//~^ frontmatter syntax is unstable [E0658] | ||
--- | ||
|
||
|
||
pub 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error[E0658]: frontmatter syntax is unstable | ||
--> $DIR/feature-gate-frontmatter.rs:1:1 | ||
| | ||
LL | / --- | ||
LL | | | ||
LL | | --- | ||
LL | | | ||
| |_^ | ||
| | ||
= note: see issue #136889 <https://github.com/rust-lang/rust/issues/136889> for more information | ||
= help: add `#![feature(frontmatter)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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 @@ | ||
----- | ||
|
||
--- | ||
--- | ||
|
||
----- | ||
|
||
//@ check-pass | ||
|
||
#![feature(frontmatter)] | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
|
||
--- | ||
|
||
--- | ||
|
||
//@ check-pass | ||
#![feature(frontmatter)] | ||
// ignore-tidy-end-whitespace | ||
// ignore-tidy-leading-newlines | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![feature(frontmatter)] | ||
|
||
--- | ||
//~^ ERROR expected item, found `-` | ||
--- | ||
|
||
fn main() { | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/ui/frontmatter/frontmatter-invalid-after-attribute.stderr
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,10 @@ | ||
error: expected item, found `-` | ||
--> $DIR/frontmatter-invalid-after-attribute.rs:3:1 | ||
| | ||
LL | --- | ||
| ^ expected item | ||
| | ||
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html> | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Comment | ||
|
||
--- | ||
//~^ ERROR expected item, found `-` | ||
--- | ||
|
||
#![feature(frontmatter)] | ||
|
||
fn main() { | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.