diff options
| author | Ralf Jung <post@ralfj.de> | 2025-08-21 14:48:22 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-21 14:48:22 +0000 |
| commit | 802de3ded1682319ba125fb8d58cd4bebdb8a5ba (patch) | |
| tree | dd1093afbfb803515cab44d11749a61a05af5475 /compiler/rustc_parse/src | |
| parent | 6370c8ed1c1e846003d6ab435a9673615b67ada3 (diff) | |
| parent | f702219ba61d94a50ecb581a4e0ab51dc459e99e (diff) | |
| download | rust-802de3ded1682319ba125fb8d58cd4bebdb8a5ba.tar.gz rust-802de3ded1682319ba125fb8d58cd4bebdb8a5ba.zip | |
Merge pull request #4534 from rust-lang/rustup-2025-08-21
Automatic Rustup
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 41ed1f95a01..21f42b54f21 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1388,15 +1388,26 @@ impl<'a> Parser<'a> { // matching `CloseDelim` we are *after* the delimited sequence, // i.e. at depth `d - 1`. let target_depth = self.token_cursor.stack.len() - 1; - loop { - // Advance one token at a time, so `TokenCursor::next()` - // can capture these tokens if necessary. + + if let Capturing::No = self.capture_state.capturing { + // We are not capturing tokens, so skip to the end of the + // delimited sequence. This is a perf win when dealing with + // declarative macros that pass large `tt` fragments through + // multiple rules, as seen in the uom-0.37.0 crate. + self.token_cursor.curr.bump_to_end(); self.bump(); - if self.token_cursor.stack.len() == target_depth { - debug_assert!(self.token.kind.close_delim().is_some()); - break; + debug_assert_eq!(self.token_cursor.stack.len(), target_depth); + } else { + loop { + // Advance one token at a time, so `TokenCursor::next()` + // can capture these tokens if necessary. + self.bump(); + if self.token_cursor.stack.len() == target_depth { + break; + } } } + debug_assert!(self.token.kind.close_delim().is_some()); // Consume close delimiter self.bump(); |
