Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir_def/src/macro_expansion_tests/mbe/tt_conversion.rs')
-rw-r--r--crates/hir_def/src/macro_expansion_tests/mbe/tt_conversion.rs50
1 files changed, 49 insertions, 1 deletions
diff --git a/crates/hir_def/src/macro_expansion_tests/mbe/tt_conversion.rs b/crates/hir_def/src/macro_expansion_tests/mbe/tt_conversion.rs
index 291f99330f..97c27c453b 100644
--- a/crates/hir_def/src/macro_expansion_tests/mbe/tt_conversion.rs
+++ b/crates/hir_def/src/macro_expansion_tests/mbe/tt_conversion.rs
@@ -2,7 +2,9 @@
//! Rather, token trees are an explicit bridge between the parser and
//! (procedural or declarative) macros.
//!
-//! This module tests tt <-> syntax tree conversion specifically
+//! This module tests tt <-> syntax tree conversion specifically. In particular,
+//! it, among other things, check that we convert `tt` to the right kind of
+//! syntax node depending on the macro call-site.
use expect_test::expect;
use crate::macro_expansion_tests::check;
@@ -100,3 +102,49 @@ macro_rules! m2 { ($x:ident) => {} }
"#]],
)
}
+
+#[test]
+fn expansion_does_not_parse_as_expression() {
+ cov_mark::check!(expansion_does_not_parse_as_expression);
+ check(
+ r#"
+macro_rules! stmts {
+ () => { let _ = 0; }
+}
+
+fn f() { let _ = stmts!(); }
+"#,
+ expect![[r#"
+macro_rules! stmts {
+ () => { let _ = 0; }
+}
+
+fn f() { let _ = /* error: could not convert tokens */; }
+"#]],
+ )
+}
+
+#[test]
+fn broken_pat() {
+ check(
+ r#"
+macro_rules! m1 { () => (Some(x) left overs) }
+macro_rules! m2 { () => ($) }
+
+fn main() {
+ let m1!() = ();
+ let m2!/*+errors*/() = ();
+}
+"#,
+ expect![[r#"
+macro_rules! m1 { () => (Some(x) left overs) }
+macro_rules! m2 { () => ($) }
+
+fn main() {
+ let Some(x) = ();
+ let /* parse error: expected pattern */
+$ = ();
+}
+"#]],
+ )
+}