Skip to content

Commit 7629451

Browse files
committed
fix(parse): Feature gate frontmatter
1 parent 8fae219 commit 7629451

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

Diff for: compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
515515
gate_all!(unsafe_binders, "unsafe binder types are experimental");
516516
gate_all!(contracts, "contracts are incomplete");
517517
gate_all!(contracts_internals, "contract internal machinery is for internal use only");
518+
gate_all!(frontmatter, "frontmatter syntax is unstable");
518519

519520
if !visitor.features.never_patterns() {
520521
if let Some(spans) = spans.get(&sym::never_patterns) {

Diff for: compiler/rustc_parse/src/lexer/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_session::lint::builtin::{
1414
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
1515
};
1616
use rustc_session::parse::ParseSess;
17-
use rustc_span::{BytePos, Pos, Span, Symbol};
17+
use rustc_span::{BytePos, Pos, Span, Symbol, sym};
1818
use tracing::debug;
1919

2020
use crate::lexer::diagnostics::TokenTreeDiagInfo;
@@ -58,7 +58,11 @@ pub(crate) fn lex_token_trees<'psess, 'src>(
5858
// Skip frontmatter, if present.
5959
if let Some(frontmatter_len) = rustc_lexer::strip_frontmatter(src) {
6060
src = &src[frontmatter_len..];
61+
let lo = start_pos;
6162
start_pos = start_pos + BytePos::from_usize(frontmatter_len);
63+
let hi = start_pos;
64+
let span = Span::with_root_ctxt(lo, hi);
65+
psess.gated_spans.gate(sym::frontmatter, span);
6266
}
6367

6468
let cursor = Cursor::new(src);

Diff for: src/doc/unstable-book/src/language-features/frontmatter.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ For example, when used with Cargo:
1818
clap = "4"
1919
---
2020
21+
#![feature(frontmatter)]
22+
2123
use clap::Parser;
2224
2325
#[derive(Parser)]

Diff for: tests/ui/feature-gates/feature-gate-frontmatter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2+
//~^ frontmatter syntax is unstable [E0658]
23
---
34

4-
//@ check-pass
55

66
pub fn main() {
77
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0658]: frontmatter syntax is unstable
2+
--> $DIR/feature-gate-frontmatter.rs:1:1
3+
|
4+
LL | / ---
5+
LL | |
6+
LL | | ---
7+
LL | |
8+
| |_^
9+
|
10+
= note: see issue #136889 <https://github.com/rust-lang/rust/issues/136889> for more information
11+
= help: add `#![feature(frontmatter)]` to the crate attributes to enable
12+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
13+
14+
error: aborting due to 1 previous error
15+
16+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)