Skip to content

Commit 4721f3a

Browse files
committed
Rollup merge of rust-lang#33841 - LeoTestard:macro-sequence-lhs, r=pnkfelix
Reject a LHS formed of a single sequence TT during `macro_rules!` checking. This was already rejected during expansion. Encountering malformed LHS or RHS during expansion is now considered a bug. Follow up to rust-lang#33689. r? @pnkfelix Note: this can break code that defines such macros but does not use them.
2 parents cbfe74c + 864b3c8 commit 4721f3a

File tree

3 files changed

+6
-30
lines changed

3 files changed

+6
-30
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
179179
for (i, lhs) in lhses.iter().enumerate() { // try each arm's matchers
180180
let lhs_tt = match *lhs {
181181
TokenTree::Delimited(_, ref delim) => &delim.tts[..],
182-
_ => cx.span_fatal(sp, "malformed macro lhs")
182+
_ => cx.span_bug(sp, "malformed macro lhs")
183183
};
184184

185185
match TokenTree::parse(cx, lhs_tt, arg) {
186186
Success(named_matches) => {
187187
let rhs = match rhses[i] {
188188
// ignore delimiters
189189
TokenTree::Delimited(_, ref delimed) => delimed.tts.clone(),
190-
_ => cx.span_fatal(sp, "malformed macro rhs"),
190+
_ => cx.span_bug(sp, "malformed macro rhs"),
191191
};
192192
// rhs has holes ( `$id` and `$(...)` that need filled)
193193
let trncbr = new_tt_reader(&cx.parse_sess().span_diagnostic,
@@ -326,19 +326,14 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
326326
NormalTT(exp, Some(def.span), def.allow_internal_unstable)
327327
}
328328

329-
// why is this here? because of https://github.com/rust-lang/rust/issues/27774
330-
fn ref_slice<A>(s: &A) -> &[A] { use std::slice::from_raw_parts; unsafe { from_raw_parts(s, 1) } }
331-
332329
fn check_lhs_nt_follows(cx: &mut ExtCtxt, lhs: &TokenTree) -> bool {
333330
// lhs is going to be like TokenTree::Delimited(...), where the
334331
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
335332
match lhs {
336333
&TokenTree::Delimited(_, ref tts) => check_matcher(cx, &tts.tts),
337-
tt @ &TokenTree::Sequence(..) => check_matcher(cx, ref_slice(tt)),
338334
_ => {
339-
cx.span_err(lhs.get_span(),
340-
"invalid macro matcher; matchers must be contained \
341-
in balanced delimiters or a repetition indicator");
335+
cx.span_err(lhs.get_span(), "invalid macro matcher; matchers must \
336+
be contained in balanced delimiters");
342337
false
343338
}
344339
}

src/test/compile-fail/malformed_macro_lhs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// except according to those terms.
1010

1111
macro_rules! my_precioooous {
12-
$($t:tt)* => (1);
12+
$($t:tt)* => (1); //~ ERROR invalid macro matcher
1313
}
1414

1515
fn main() {
16-
my_precioooous!(); //~ ERROR malformed macro lhs
16+
my_precioooous!();
1717
}

src/test/run-pass/issue-21350.rs

-19
This file was deleted.

0 commit comments

Comments
 (0)