Skip to content

Commit 11d11e3

Browse files
author
Yuki Okushi
authoredOct 24, 2022
Rollup merge of #103333 - chenyukang:yukang/fix-103143, r=wesleywiser
Fix assertion failed for break_last_token and trailing token Fixes #103143
2 parents 758f196 + 2414357 commit 11d11e3

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed
 

‎compiler/rustc_parse/src/parser/attr_wrapper.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,23 @@ impl<'a> Parser<'a> {
273273
let cursor_snapshot_next_calls = cursor_snapshot.num_next_calls;
274274
let mut end_pos = self.token_cursor.num_next_calls;
275275

276+
let mut captured_trailing = false;
277+
276278
// Capture a trailing token if requested by the callback 'f'
277279
match trailing {
278280
TrailingToken::None => {}
281+
TrailingToken::Gt => {
282+
assert_eq!(self.token.kind, token::Gt);
283+
}
279284
TrailingToken::Semi => {
280285
assert_eq!(self.token.kind, token::Semi);
281286
end_pos += 1;
287+
captured_trailing = true;
282288
}
283289
TrailingToken::MaybeComma => {
284290
if self.token.kind == token::Comma {
285291
end_pos += 1;
292+
captured_trailing = true;
286293
}
287294
}
288295
}
@@ -292,11 +299,7 @@ impl<'a> Parser<'a> {
292299
// was not actually bumped past it. When the `LazyAttrTokenStream` gets converted
293300
// into an `AttrTokenStream`, we will create the proper token.
294301
if self.token_cursor.break_last_token {
295-
assert_eq!(
296-
trailing,
297-
TrailingToken::None,
298-
"Cannot set `break_last_token` and have trailing token"
299-
);
302+
assert!(!captured_trailing, "Cannot set break_last_token and have trailing token");
300303
end_pos += 1;
301304
}
302305

‎compiler/rustc_parse/src/parser/expr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3142,6 +3142,8 @@ impl<'a> Parser<'a> {
31423142
&& this.token.kind == token::Semi
31433143
{
31443144
TrailingToken::Semi
3145+
} else if this.token.kind == token::Gt {
3146+
TrailingToken::Gt
31453147
} else {
31463148
// FIXME - pass this through from the place where we know
31473149
// we need a comma, rather than assuming that `#[attr] expr,`

‎compiler/rustc_parse/src/parser/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub enum ForceCollect {
7979
pub enum TrailingToken {
8080
None,
8181
Semi,
82+
Gt,
8283
/// If the trailing token is a comma, then capture it
8384
/// Otherwise, ignore the trailing token
8485
MaybeComma,

‎src/test/ui/parser/issue-103143.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
x::<#[a]y::<z>>
3+
//~^ ERROR invalid const generic expression
4+
//~| ERROR cannot find value `x` in this scope
5+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: invalid const generic expression
2+
--> $DIR/issue-103143.rs:2:13
3+
|
4+
LL | x::<#[a]y::<z>>
5+
| ^^^^^^
6+
|
7+
help: expressions must be enclosed in braces to be used as const generic arguments
8+
|
9+
LL | x::<#[a]{ y::<z> }>
10+
| + +
11+
12+
error[E0425]: cannot find value `x` in this scope
13+
--> $DIR/issue-103143.rs:2:5
14+
|
15+
LL | x::<#[a]y::<z>>
16+
| ^ not found in this scope
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)
Please sign in to comment.