about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui-fulldeps/auxiliary/parser.rs3
-rw-r--r--tests/ui-fulldeps/mod_dir_path_canonicalized.rs9
-rw-r--r--tests/ui/frontmatter/auxiliary/expr.rs4
-rw-r--r--tests/ui/frontmatter/auxiliary/makro.rs14
-rw-r--r--tests/ui/frontmatter/include-in-expr-ctxt.rs9
-rw-r--r--tests/ui/frontmatter/include-in-item-ctxt.rs10
-rw-r--r--tests/ui/frontmatter/included-frontmatter.rs12
-rw-r--r--tests/ui/frontmatter/proc-macro-observer.rs7
8 files changed, 48 insertions, 20 deletions
diff --git a/tests/ui-fulldeps/auxiliary/parser.rs b/tests/ui-fulldeps/auxiliary/parser.rs
index 6726969350d..6ee39e5130f 100644
--- a/tests/ui-fulldeps/auxiliary/parser.rs
+++ b/tests/ui-fulldeps/auxiliary/parser.rs
@@ -10,7 +10,7 @@ extern crate rustc_span;
 use rustc_ast::ast::{AttrKind, Attribute, DUMMY_NODE_ID, Expr};
 use rustc_ast::mut_visit::{self, MutVisitor};
 use rustc_ast::node_id::NodeId;
-use rustc_ast::token::{self, Token};
+use rustc_ast::token;
 use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, LazyAttrTokenStream};
 use rustc_errors::Diag;
 use rustc_parse::parser::Recovery;
@@ -23,6 +23,7 @@ pub fn parse_expr(psess: &ParseSess, source_code: &str) -> Option<Box<Expr>> {
         psess,
         FileName::anon_source_code(source_code),
         source_code.to_owned(),
+        rustc_parse::lexer::StripTokens::Nothing,
     ));
 
     let mut parser = parser.recovery(Recovery::Forbidden);
diff --git a/tests/ui-fulldeps/mod_dir_path_canonicalized.rs b/tests/ui-fulldeps/mod_dir_path_canonicalized.rs
index 99cb5fc5aa1..df5f29e35fe 100644
--- a/tests/ui-fulldeps/mod_dir_path_canonicalized.rs
+++ b/tests/ui-fulldeps/mod_dir_path_canonicalized.rs
@@ -16,7 +16,7 @@ extern crate rustc_span;
 #[allow(unused_extern_crates)]
 extern crate rustc_driver;
 
-use rustc_parse::{new_parser_from_file, unwrap_or_emit_fatal};
+use rustc_parse::{lexer::StripTokens, new_parser_from_file, unwrap_or_emit_fatal};
 use rustc_session::parse::ParseSess;
 use std::path::Path;
 
@@ -34,6 +34,11 @@ fn parse() {
 
     let path = Path::new(file!());
     let path = path.canonicalize().unwrap();
-    let mut parser = unwrap_or_emit_fatal(new_parser_from_file(&psess, &path, None));
+    let mut parser = unwrap_or_emit_fatal(new_parser_from_file(
+        &psess,
+        &path,
+        StripTokens::ShebangAndFrontmatter,
+        None,
+    ));
     let _ = parser.parse_crate_mod();
 }
diff --git a/tests/ui/frontmatter/auxiliary/expr.rs b/tests/ui/frontmatter/auxiliary/expr.rs
new file mode 100644
index 00000000000..5f694110666
--- /dev/null
+++ b/tests/ui/frontmatter/auxiliary/expr.rs
@@ -0,0 +1,4 @@
+---
+-
+---
+1
diff --git a/tests/ui/frontmatter/auxiliary/makro.rs b/tests/ui/frontmatter/auxiliary/makro.rs
index 70707b27bff..1d64fa44bd3 100644
--- a/tests/ui/frontmatter/auxiliary/makro.rs
+++ b/tests/ui/frontmatter/auxiliary/makro.rs
@@ -1,8 +1,20 @@
 extern crate proc_macro;
-use proc_macro::TokenStream;
+use proc_macro::{Literal, TokenStream};
 
 #[proc_macro]
 pub fn check(_: TokenStream) -> TokenStream {
+    // In the following test cases, the `---` may look like the start of frontmatter but it is not!
+    // That's because it would be backward incompatible to interpret them as such in the latest
+    // stable edition. That's not only the case due to the feature gate error but also due to the
+    // fact that we "eagerly" emit errors on malformed frontmatter.
+
+    // issue: <https://github.com/rust-lang/rust/issues/145520>
+    _ = "---".parse::<TokenStream>();
+    // Just a sequence of regular Rust punctuation tokens.
     assert_eq!(6, "---\n---".parse::<TokenStream>().unwrap().into_iter().count());
+
+    // issue: <https://github.com/rust-lang/rust/issues/146132>
+    assert!("---".parse::<Literal>().is_err());
+
     Default::default()
 }
diff --git a/tests/ui/frontmatter/include-in-expr-ctxt.rs b/tests/ui/frontmatter/include-in-expr-ctxt.rs
new file mode 100644
index 00000000000..7b02c9cb8a5
--- /dev/null
+++ b/tests/ui/frontmatter/include-in-expr-ctxt.rs
@@ -0,0 +1,9 @@
+// Check that an expr-ctxt `include` doesn't try to parse frontmatter and instead
+// treats it as a regular Rust token sequence.
+//@ check-pass
+#![expect(double_negations)]
+
+fn main() {
+    // issue: <https://github.com/rust-lang/rust/issues/145945>
+    const _: () = assert!(-1 == include!("auxiliary/expr.rs"));
+}
diff --git a/tests/ui/frontmatter/include-in-item-ctxt.rs b/tests/ui/frontmatter/include-in-item-ctxt.rs
new file mode 100644
index 00000000000..c8455bc49ab
--- /dev/null
+++ b/tests/ui/frontmatter/include-in-item-ctxt.rs
@@ -0,0 +1,10 @@
+// Ensure that in item ctxts we can `include` files that contain frontmatter.
+//@ check-pass
+
+#![feature(frontmatter)]
+
+include!("auxiliary/lib.rs");
+
+fn main() {
+    foo(1);
+}
diff --git a/tests/ui/frontmatter/included-frontmatter.rs b/tests/ui/frontmatter/included-frontmatter.rs
deleted file mode 100644
index 57616cd1228..00000000000
--- a/tests/ui/frontmatter/included-frontmatter.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-#![feature(frontmatter)]
-
-//@ check-pass
-
-include!("auxiliary/lib.rs");
-
-// auxiliary/lib.rs contains a frontmatter. Ensure that we can use them in an
-// `include!` macro.
-
-fn main() {
-    foo(1);
-}
diff --git a/tests/ui/frontmatter/proc-macro-observer.rs b/tests/ui/frontmatter/proc-macro-observer.rs
index b1cc1460933..6c4c8c57289 100644
--- a/tests/ui/frontmatter/proc-macro-observer.rs
+++ b/tests/ui/frontmatter/proc-macro-observer.rs
@@ -2,10 +2,9 @@
 //@ proc-macro: makro.rs
 //@ edition: 2021
 
-makro::check!();
+// Check that a proc-macro doesn't try to parse frontmatter and instead treats
+// it as a regular Rust token sequence. See `auxiliary/makro.rs` for details.
 
-// checks that a proc-macro doesn't know or parse frontmatters at all and instead treats
-// it as normal Rust code.
-// see auxiliary/makro.rs for how it is tested.
+makro::check!();
 
 fn main() {}