Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assertion failed for break_last_token and trailing token #103333

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions compiler/rustc_parse/src/parser/attr_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,23 @@ impl<'a> Parser<'a> {
let cursor_snapshot_next_calls = cursor_snapshot.num_next_calls;
let mut end_pos = self.token_cursor.num_next_calls;

let mut captured_trailing = false;

// Capture a trailing token if requested by the callback 'f'
match trailing {
TrailingToken::None => {}
TrailingToken::Gt => {
assert_eq!(self.token.kind, token::Gt);
}
TrailingToken::Semi => {
assert_eq!(self.token.kind, token::Semi);
end_pos += 1;
captured_trailing = true;
}
TrailingToken::MaybeComma => {
if self.token.kind == token::Comma {
end_pos += 1;
captured_trailing = true;
}
}
}
Expand All @@ -292,11 +299,7 @@ impl<'a> Parser<'a> {
// was not actually bumped past it. When the `LazyAttrTokenStream` gets converted
// into an `AttrTokenStream`, we will create the proper token.
if self.token_cursor.break_last_token {
assert_eq!(
trailing,
TrailingToken::None,
"Cannot set `break_last_token` and have trailing token"
);
assert!(!captured_trailing, "Cannot set break_last_token and have trailing token");
end_pos += 1;
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3080,6 +3080,8 @@ impl<'a> Parser<'a> {
&& this.token.kind == token::Semi
{
TrailingToken::Semi
} else if this.token.kind == token::Gt {
TrailingToken::Gt
} else {
// FIXME - pass this through from the place where we know
// we need a comma, rather than assuming that `#[attr] expr,`
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub enum ForceCollect {
pub enum TrailingToken {
None,
Semi,
Gt,
/// If the trailing token is a comma, then capture it
/// Otherwise, ignore the trailing token
MaybeComma,
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/parser/issue-103143.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
x::<#[a]y::<z>>
//~^ ERROR invalid const generic expression
//~| ERROR cannot find value `x` in this scope
}
20 changes: 20 additions & 0 deletions src/test/ui/parser/issue-103143.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: invalid const generic expression
--> $DIR/issue-103143.rs:2:13
|
LL | x::<#[a]y::<z>>
| ^^^^^^
|
help: expressions must be enclosed in braces to be used as const generic arguments
|
LL | x::<#[a]{ y::<z> }>
| + +

error[E0425]: cannot find value `x` in this scope
--> $DIR/issue-103143.rs:2:5
|
LL | x::<#[a]y::<z>>
| ^ not found in this scope

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.