Skip to content

Commit c4949b7

Browse files
committed
Auto merge of rust-lang#18153 - ChayimFriedman2:mbe-const, r=Veykril
fix: When checking for forbidden expr kind matches, account for rawness An expression starting with `r#const` etc. should be accepted even in edition <=2021. Fixes rust-lang#18148. This was not fixed when testing with edition 2024, I wonder whether that means our check for edition is incorrect...
2 parents 814da15 + 6ec47a3 commit c4949b7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/mbe/regression.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1144,3 +1144,27 @@ mod any {
11441144
"#]],
11451145
);
11461146
}
1147+
1148+
#[test]
1149+
fn regression_18148() {
1150+
check(
1151+
r#"
1152+
macro_rules! m {
1153+
( $e:expr ) => {};
1154+
}
1155+
1156+
fn foo() {
1157+
m!(r#const);
1158+
}
1159+
"#,
1160+
expect![[r#"
1161+
macro_rules! m {
1162+
( $e:expr ) => {};
1163+
}
1164+
1165+
fn foo() {
1166+
;
1167+
}
1168+
"#]],
1169+
);
1170+
}

src/tools/rust-analyzer/crates/mbe/src/expander/matcher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ fn match_meta_var(
780780
// [1]: https://github.com/rust-lang/rust/blob/f0c4da499/compiler/rustc_expand/src/mbe/macro_parser.rs#L576
781781
match input.peek_n(0) {
782782
Some(tt::TokenTree::Leaf(tt::Leaf::Ident(it))) => {
783-
let is_err = if matches!(expr, ExprKind::Expr2021) {
783+
let is_err = if it.is_raw.no() && matches!(expr, ExprKind::Expr2021) {
784784
it.sym == sym::underscore || it.sym == sym::let_ || it.sym == sym::const_
785785
} else {
786786
it.sym == sym::let_

0 commit comments

Comments
 (0)