diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index ea60e083c4ced..85a5a4393a6b0 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -511,6 +511,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { gate_all!(contracts, "contracts are incomplete"); gate_all!(contracts_internals, "contract internal machinery is for internal use only"); gate_all!(where_clause_attrs, "attributes in `where` clause are unstable"); + gate_all!(frontmatter, "frontmatter syntax is unstable"); if !visitor.features.never_patterns() { if let Some(spans) = spans.get(&sym::never_patterns) { diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 3dbfc191f8f50..a76acd006339a 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -120,6 +120,15 @@ fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec pos += shebang_len; } + if let Some(frontmatter_len) = rustc_lexer::strip_frontmatter(&text[pos..]) { + comments.push(Comment { + style: CommentStyle::Isolated, + lines: vec![text[pos..pos + frontmatter_len].to_string()], + pos: start_bpos + BytePos(pos as u32), + }); + pos += frontmatter_len; + } + for token in rustc_lexer::tokenize(&text[pos..]) { let token_text = &text[pos..pos + token.len as usize]; match token.kind { diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 7c931e32f63fd..9c023fdef9edb 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -501,6 +501,8 @@ declare_features! ( (incomplete, fn_delegation, "1.76.0", Some(118212)), /// Allows impls for the Freeze trait. (internal, freeze_impls, "1.78.0", Some(121675)), + /// Frontmatter blocks for build tool metadata. + (unstable, frontmatter, "CURRENT_RUSTC_VERSION", Some(136889)), /// Allows defining gen blocks and `gen fn`. (unstable, gen_blocks, "1.75.0", Some(117078)), /// Infer generic args for both consts and types. diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs index 61638e45253fd..afa1ecc6475b7 100644 --- a/compiler/rustc_lexer/src/lib.rs +++ b/compiler/rustc_lexer/src/lib.rs @@ -276,6 +276,58 @@ pub fn strip_shebang(input: &str) -> Option { None } +/// Frontmatter is a special attribute type reserved for use by external tools +/// +/// This must be called after [`strip_shebang`] +pub fn strip_frontmatter(input: &str) -> Option { + // Whitespace may precede a frontmatter but must end with a newline + let rest = input.trim_start_matches(is_whitespace); + if rest.len() != input.len() { + let trimmed_len = input.len() - rest.len(); + let last_trimmed_index = trimmed_len - 1; + if input.as_bytes()[last_trimmed_index] != b'\n' { + // either not a frontmatter or invalid opening + return None; + } + } + + // Opens with a line that starts with 3 or more `-` followed by an optional identifier + const FENCE_CHAR: char = '-'; + let fence_length = + rest.char_indices().find_map(|(i, c)| (c != FENCE_CHAR).then_some(i)).unwrap_or(rest.len()); + if fence_length < 3 { + // either not a frontmatter or invalid frontmatter opening + return None; + } + let (fence_pattern, rest) = rest.split_at(fence_length); + let Some(info_end_index) = rest.find('\n') else { + // frontmatter close is required + return None; + }; + let (info, rest) = rest.split_at(info_end_index); + let info = info.trim_matches(is_whitespace); + if !info.is_empty() && !is_ident(info) { + // optional infostring is not an identifier + return None; + } + + // Ends with a line that starts with a matching number of `-` only followed by whitespace + let nl_fence_pattern = format!("\n{fence_pattern}"); + let Some(frontmatter_nl) = rest.find(&nl_fence_pattern) else { + // frontmatter close is required + return None; + }; + let rest = &rest[frontmatter_nl + nl_fence_pattern.len()..]; + + let (after_closing_fence, rest) = rest.split_once("\n").unwrap_or((rest, "")); + let after_closing_fence = after_closing_fence.trim_matches(is_whitespace); + if !after_closing_fence.is_empty() { + // extra characters beyond the original fence pattern, even if they are extra `-` + return None; + } + Some(input.len() - rest.len()) +} + /// Validates a raw string literal. Used for getting more information about a /// problem with a `RawStr`/`RawByteStr` with a `None` field. #[inline] diff --git a/compiler/rustc_lexer/src/tests.rs b/compiler/rustc_lexer/src/tests.rs index 8203ae70b0700..1c3fcc3b5e92a 100644 --- a/compiler/rustc_lexer/src/tests.rs +++ b/compiler/rustc_lexer/src/tests.rs @@ -124,6 +124,119 @@ fn test_valid_shebang() { assert_eq!(strip_shebang(input), None); } +#[test] +fn test_frontmatter() { + let input = "--- +--- +"; + assert_eq!(strip_frontmatter(input), Some(input.len())); + + let input = "--- +package.edition = '2024' + +[dependencies] +regex = '1' +--- +"; + assert_eq!(strip_frontmatter(input), Some(input.len())); + + // allow ident infostring + let input = "---cargo + +--- +"; + assert_eq!(strip_frontmatter(input), Some(input.len())); + + // disallow non-ident infostring + let input = "---cargo hello + +--- +"; + assert_eq!(strip_frontmatter(input), None); + + // ignore extra whitespace + let input = " + + +---\u{0020} + +---\u{0020} +"; + assert_eq!(strip_frontmatter(input), Some(input.len())); + + // disallow indented opening/close + let input = " --- + --- +"; + assert_eq!(strip_frontmatter(input), None); + + // ignore inner dashes not at line start + let input = "--- + + --- + --- + +--- +"; + assert_eq!(strip_frontmatter(input), Some(input.len())); + + // ignore fewer dashes inside + let input = "----- + +--- +--- + +----- +"; + assert_eq!(strip_frontmatter(input), Some(input.len())); + + // disallow more dashes inside + let input = "--- + +----- +----- + +--- +"; + assert_eq!(strip_frontmatter(input), None); + + // disallow mismatch close + let input = "---- + +--- +"; + assert_eq!(strip_frontmatter(input), None); + + // disallow unclosed + let input = "--- + +"; + assert_eq!(strip_frontmatter(input), None); + + // disallow short open/close + let input = "-- + +-- +"; + assert_eq!(strip_frontmatter(input), None); + + // disallow content before + let input = "#![feature(frontmatter)] + +--- +--- +"; + assert_eq!(strip_frontmatter(input), None); + + // disallow trailing text + let input = "#![feature(frontmatter)] + +--- +---cargo +"; + assert_eq!(strip_frontmatter(input), None); +} + fn check_lexing(src: &str, expect: Expect) { let actual: String = tokenize(src).map(|token| format!("{:?}\n", token)).collect(); expect.assert_eq(&actual) diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index 1d17290e1c706..89938889cc358 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -14,7 +14,7 @@ use rustc_session::lint::builtin::{ TEXT_DIRECTION_CODEPOINT_IN_COMMENT, }; use rustc_session::parse::ParseSess; -use rustc_span::{BytePos, Pos, Span, Symbol}; +use rustc_span::{BytePos, Pos, Span, Symbol, sym}; use tracing::debug; use crate::lexer::diagnostics::TokenTreeDiagInfo; @@ -55,6 +55,16 @@ pub(crate) fn lex_token_trees<'psess, 'src>( start_pos = start_pos + BytePos::from_usize(shebang_len); } + // Skip frontmatter, if present. + if let Some(frontmatter_len) = rustc_lexer::strip_frontmatter(src) { + src = &src[frontmatter_len..]; + let lo = start_pos; + start_pos = start_pos + BytePos::from_usize(frontmatter_len); + let hi = start_pos; + let span = Span::with_root_ctxt(lo, hi); + psess.gated_spans.gate(sym::frontmatter, span); + } + let cursor = Cursor::new(src); let mut lexer = Lexer { psess, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index c6e570e524f59..28a9234bcfb51 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1044,6 +1044,7 @@ symbols! { from_u16, from_usize, from_yeet, + frontmatter, fs_create_dir, fsub_algebraic, fsub_fast, diff --git a/src/doc/unstable-book/src/language-features/frontmatter.md b/src/doc/unstable-book/src/language-features/frontmatter.md new file mode 100644 index 0000000000000..795ce5bfcde3a --- /dev/null +++ b/src/doc/unstable-book/src/language-features/frontmatter.md @@ -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. diff --git a/src/tools/rustfmt/tests/source/frontmatter.rs b/src/tools/rustfmt/tests/source/frontmatter.rs new file mode 100644 index 0000000000000..45bee64dbd885 --- /dev/null +++ b/src/tools/rustfmt/tests/source/frontmatter.rs @@ -0,0 +1,11 @@ + + +--- identifier +[dependencies] +regex = "1" + +--- + +#![feature(frontmatter)] + +fn main() {} diff --git a/src/tools/rustfmt/tests/target/frontmatter.rs b/src/tools/rustfmt/tests/target/frontmatter.rs new file mode 100644 index 0000000000000..8e4257b7d3d49 --- /dev/null +++ b/src/tools/rustfmt/tests/target/frontmatter.rs @@ -0,0 +1,9 @@ +--- identifier +[dependencies] +regex = "1" + +--- + +#![feature(frontmatter)] + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-frontmatter.rs b/tests/ui/feature-gates/feature-gate-frontmatter.rs new file mode 100644 index 0000000000000..647ca10f36c1d --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-frontmatter.rs @@ -0,0 +1,7 @@ +--- +//~^ frontmatter syntax is unstable [E0658] +--- + + +pub fn main() { +} diff --git a/tests/ui/feature-gates/feature-gate-frontmatter.stderr b/tests/ui/feature-gates/feature-gate-frontmatter.stderr new file mode 100644 index 0000000000000..2e40090c5a3f6 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-frontmatter.stderr @@ -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 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`. diff --git a/tests/ui/frontmatter/frontmatter-escaped.rs b/tests/ui/frontmatter/frontmatter-escaped.rs new file mode 100644 index 0000000000000..b882bcab0d6d1 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-escaped.rs @@ -0,0 +1,13 @@ +----- + +--- +--- + +----- + +//@ check-pass + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-ignored-space.rs b/tests/ui/frontmatter/frontmatter-ignored-space.rs new file mode 100644 index 0000000000000..0063cca5aba24 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-ignored-space.rs @@ -0,0 +1,13 @@ + + +--- + +--- + +//@ check-pass +#![feature(frontmatter)] +// ignore-tidy-end-whitespace +// ignore-tidy-leading-newlines + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-after-attribute.rs b/tests/ui/frontmatter/frontmatter-invalid-after-attribute.rs new file mode 100644 index 0000000000000..c3b77a9d05d09 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-after-attribute.rs @@ -0,0 +1,8 @@ +#![feature(frontmatter)] + +--- +//~^ ERROR expected item, found `-` +--- + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-after-attribute.stderr b/tests/ui/frontmatter/frontmatter-invalid-after-attribute.stderr new file mode 100644 index 0000000000000..b8398a46e9edd --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-after-attribute.stderr @@ -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 + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-invalid-after-comment.rs b/tests/ui/frontmatter/frontmatter-invalid-after-comment.rs new file mode 100644 index 0000000000000..27960bd6149b2 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-after-comment.rs @@ -0,0 +1,10 @@ +// Comment + +--- +//~^ ERROR expected item, found `-` +--- + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-after-comment.stderr b/tests/ui/frontmatter/frontmatter-invalid-after-comment.stderr new file mode 100644 index 0000000000000..09d1813e7efb8 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-after-comment.stderr @@ -0,0 +1,10 @@ +error: expected item, found `-` + --> $DIR/frontmatter-invalid-after-comment.rs:3:1 + | +LL | --- + | ^ expected item + | + = note: for a full list of items that can appear in modules, see + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-invalid-escaped.rs b/tests/ui/frontmatter/frontmatter-invalid-escaped.rs new file mode 100644 index 0000000000000..1d705d58cca59 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-escaped.rs @@ -0,0 +1,12 @@ +--- +//~^ ERROR expected item, found `-` + +----- +----- + +--- + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-escaped.stderr b/tests/ui/frontmatter/frontmatter-invalid-escaped.stderr new file mode 100644 index 0000000000000..1ff363015478e --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-escaped.stderr @@ -0,0 +1,10 @@ +error: expected item, found `-` + --> $DIR/frontmatter-invalid-escaped.rs:1:1 + | +LL | --- + | ^ expected item + | + = note: for a full list of items that can appear in modules, see + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-invalid-in-fn.rs b/tests/ui/frontmatter/frontmatter-invalid-in-fn.rs new file mode 100644 index 0000000000000..c5809e074607b --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-in-fn.rs @@ -0,0 +1,7 @@ +#![feature(frontmatter)] + +fn main() { +--- +--- +} +//~^ ERROR expected expression, found `}` diff --git a/tests/ui/frontmatter/frontmatter-invalid-in-fn.stderr b/tests/ui/frontmatter/frontmatter-invalid-in-fn.stderr new file mode 100644 index 0000000000000..55cc130b211b2 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-in-fn.stderr @@ -0,0 +1,8 @@ +error: expected expression, found `}` + --> $DIR/frontmatter-invalid-in-fn.rs:6:1 + | +LL | } + | ^ expected expression + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-invalid-indentation.rs b/tests/ui/frontmatter/frontmatter-invalid-indentation.rs new file mode 100644 index 0000000000000..b7aa9a87e764e --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-indentation.rs @@ -0,0 +1,8 @@ + --- +//~^ ERROR expected item, found `-` + --- + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-indentation.stderr b/tests/ui/frontmatter/frontmatter-invalid-indentation.stderr new file mode 100644 index 0000000000000..99b04ea14ef45 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-indentation.stderr @@ -0,0 +1,10 @@ +error: expected item, found `-` + --> $DIR/frontmatter-invalid-indentation.rs:1:3 + | +LL | --- + | ^ expected item + | + = note: for a full list of items that can appear in modules, see + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-invalid-mismatched-close.rs b/tests/ui/frontmatter/frontmatter-invalid-mismatched-close.rs new file mode 100644 index 0000000000000..d6afe90fad31b --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-mismatched-close.rs @@ -0,0 +1,8 @@ +--- +//~^ ERROR expected item, found `-` +---- + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-mismatched-close.stderr b/tests/ui/frontmatter/frontmatter-invalid-mismatched-close.stderr new file mode 100644 index 0000000000000..58468ef498b0f --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-mismatched-close.stderr @@ -0,0 +1,10 @@ +error: expected item, found `-` + --> $DIR/frontmatter-invalid-mismatched-close.rs:1:1 + | +LL | --- + | ^ expected item + | + = note: for a full list of items that can appear in modules, see + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-invalid-multiple.rs b/tests/ui/frontmatter/frontmatter-invalid-multiple.rs new file mode 100644 index 0000000000000..adb08ecb6bb26 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-multiple.rs @@ -0,0 +1,11 @@ +---cargo +--- + +---buck +//~^ ERROR expected item, found `-` +--- + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-multiple.stderr b/tests/ui/frontmatter/frontmatter-invalid-multiple.stderr new file mode 100644 index 0000000000000..65f733823f2ea --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-multiple.stderr @@ -0,0 +1,10 @@ +error: expected item, found `-` + --> $DIR/frontmatter-invalid-multiple.rs:4:1 + | +LL | ---buck + | ^ expected item + | + = note: for a full list of items that can appear in modules, see + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-invalid-non-ident-infostring.rs b/tests/ui/frontmatter/frontmatter-invalid-non-ident-infostring.rs new file mode 100644 index 0000000000000..57db85f72ae0b --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-non-ident-infostring.rs @@ -0,0 +1,8 @@ +---cargo,hello-world +//~^ ERROR expected item, found `-` +--- + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-non-ident-infostring.stderr b/tests/ui/frontmatter/frontmatter-invalid-non-ident-infostring.stderr new file mode 100644 index 0000000000000..3f9fb7bebc7a2 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-non-ident-infostring.stderr @@ -0,0 +1,10 @@ +error: expected item, found `-` + --> $DIR/frontmatter-invalid-non-ident-infostring.rs:1:1 + | +LL | ---cargo,hello-world + | ^ expected item + | + = note: for a full list of items that can appear in modules, see + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-invalid-short-open.rs b/tests/ui/frontmatter/frontmatter-invalid-short-open.rs new file mode 100644 index 0000000000000..cf7363d668859 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-short-open.rs @@ -0,0 +1,8 @@ +-- +//~^ ERROR expected item, found `-` +-- + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-short-open.stderr b/tests/ui/frontmatter/frontmatter-invalid-short-open.stderr new file mode 100644 index 0000000000000..e1ea652c73243 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-short-open.stderr @@ -0,0 +1,10 @@ +error: expected item, found `-` + --> $DIR/frontmatter-invalid-short-open.rs:1:1 + | +LL | -- + | ^ expected item + | + = note: for a full list of items that can appear in modules, see + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-invalid-trailing-text.rs b/tests/ui/frontmatter/frontmatter-invalid-trailing-text.rs new file mode 100644 index 0000000000000..ee11c56f9ebc1 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-trailing-text.rs @@ -0,0 +1,8 @@ +--- +//~^ ERROR expected item, found `-` +--- text + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-trailing-text.stderr b/tests/ui/frontmatter/frontmatter-invalid-trailing-text.stderr new file mode 100644 index 0000000000000..bdf3438e86374 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-trailing-text.stderr @@ -0,0 +1,10 @@ +error: expected item, found `-` + --> $DIR/frontmatter-invalid-trailing-text.rs:1:1 + | +LL | --- + | ^ expected item + | + = note: for a full list of items that can appear in modules, see + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-invalid-unclosed.rs b/tests/ui/frontmatter/frontmatter-invalid-unclosed.rs new file mode 100644 index 0000000000000..3166e73a40e8e --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-unclosed.rs @@ -0,0 +1,7 @@ +--- +//~^ ERROR expected item, found `-` + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-invalid-unclosed.stderr b/tests/ui/frontmatter/frontmatter-invalid-unclosed.stderr new file mode 100644 index 0000000000000..e3fb7a685d0cf --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-invalid-unclosed.stderr @@ -0,0 +1,10 @@ +error: expected item, found `-` + --> $DIR/frontmatter-invalid-unclosed.rs:1:1 + | +LL | --- + | ^ expected item + | + = note: for a full list of items that can appear in modules, see + +error: aborting due to 1 previous error + diff --git a/tests/ui/frontmatter/frontmatter-with-body.rs b/tests/ui/frontmatter/frontmatter-with-body.rs new file mode 100644 index 0000000000000..c5350cebcda39 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-with-body.rs @@ -0,0 +1,10 @@ +--- +[dependencies] +--- + +//@ check-pass + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-with-infostring-spaces.rs b/tests/ui/frontmatter/frontmatter-with-infostring-spaces.rs new file mode 100644 index 0000000000000..5038382e1da5d --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-with-infostring-spaces.rs @@ -0,0 +1,9 @@ +--- cargo +--- + +//@ check-pass + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter-with-infostring.rs b/tests/ui/frontmatter/frontmatter-with-infostring.rs new file mode 100644 index 0000000000000..88be7a278e7ff --- /dev/null +++ b/tests/ui/frontmatter/frontmatter-with-infostring.rs @@ -0,0 +1,9 @@ +---cargo +--- + +//@ check-pass + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/frontmatter/frontmatter.rs b/tests/ui/frontmatter/frontmatter.rs new file mode 100644 index 0000000000000..ac77a3de0bd36 --- /dev/null +++ b/tests/ui/frontmatter/frontmatter.rs @@ -0,0 +1,9 @@ +--- +--- + +//@ check-pass + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/unpretty/frontmatter.rs b/tests/ui/unpretty/frontmatter.rs new file mode 100644 index 0000000000000..1971808e2a866 --- /dev/null +++ b/tests/ui/unpretty/frontmatter.rs @@ -0,0 +1,10 @@ +--- +--- + +//@ compile-flags: -Zunpretty=normal +//@ check-pass + +#![feature(frontmatter)] + +fn main() { +} diff --git a/tests/ui/unpretty/frontmatter.stdout b/tests/ui/unpretty/frontmatter.stdout new file mode 100644 index 0000000000000..2ccbb1b258255 --- /dev/null +++ b/tests/ui/unpretty/frontmatter.stdout @@ -0,0 +1,9 @@ +--- +--- + +//@ compile-flags: -Zunpretty=normal +//@ check-pass + +#![feature(frontmatter)] + +fn main() {}