diff options
| author | bors <bors@rust-lang.org> | 2025-01-26 06:42:03 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-01-26 06:42:03 +0000 |
| commit | c2270becb63d4c52a2740137db2e9b49246f9362 (patch) | |
| tree | 822f92973f9c6feeed8eb1b7099f35533d8e95de /compiler/rustc_parse/src/parser/mod.rs | |
| parent | 2f0ad2a71e4a4528bb80bcb24bf8fa4e50cb87c2 (diff) | |
| parent | 64550d1ed8023bea8668888ea8cfa91f4978875f (diff) | |
| download | rust-c2270becb63d4c52a2740137db2e9b49246f9362.tar.gz rust-c2270becb63d4c52a2740137db2e9b49246f9362.zip | |
Auto merge of #136085 - jhpratt:rollup-dxmb2h2, r=jhpratt
Rollup of 7 pull requests Successful merges: - #133951 (Make the wasm_c_abi future compat warning a hard error) - #134283 (fix(libtest): Deprecate '--logfile') - #135785 (use `PassMode::Direct` for vector types on `s390x`) - #135948 (Update emscripten std tests) - #135951 (Use `fmt::from_fn` in more places in the compiler) - #136031 (Expand polonius MIR dump) - #136032 (Account for mutable borrow in argument suggestion) Failed merges: - #135635 (Move `std::io::pipe` code into its own file) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser/mod.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 25d8eb9b453..714a60cb179 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1598,45 +1598,35 @@ impl<'a> Parser<'a> { // Only used when debugging. #[allow(unused)] pub(crate) fn debug_lookahead(&self, lookahead: usize) -> impl fmt::Debug + '_ { - struct DebugParser<'dbg> { - parser: &'dbg Parser<'dbg>, - lookahead: usize, - } - - impl fmt::Debug for DebugParser<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { parser, lookahead } = self; - let mut dbg_fmt = f.debug_struct("Parser"); // or at least, one view of - - // we don't need N spans, but we want at least one, so print all of prev_token - dbg_fmt.field("prev_token", &parser.prev_token); - let mut tokens = vec![]; - for i in 0..*lookahead { - let tok = parser.look_ahead(i, |tok| tok.kind.clone()); - let is_eof = tok == TokenKind::Eof; - tokens.push(tok); - if is_eof { - // Don't look ahead past EOF. - break; - } - } - dbg_fmt.field_with("tokens", |field| field.debug_list().entries(tokens).finish()); - dbg_fmt.field("approx_token_stream_pos", &parser.num_bump_calls); - - // some fields are interesting for certain values, as they relate to macro parsing - if let Some(subparser) = parser.subparser_name { - dbg_fmt.field("subparser_name", &subparser); - } - if let Recovery::Forbidden = parser.recovery { - dbg_fmt.field("recovery", &parser.recovery); + fmt::from_fn(move |f| { + let mut dbg_fmt = f.debug_struct("Parser"); // or at least, one view of + + // we don't need N spans, but we want at least one, so print all of prev_token + dbg_fmt.field("prev_token", &self.prev_token); + let mut tokens = vec![]; + for i in 0..lookahead { + let tok = self.look_ahead(i, |tok| tok.kind.clone()); + let is_eof = tok == TokenKind::Eof; + tokens.push(tok); + if is_eof { + // Don't look ahead past EOF. + break; } + } + dbg_fmt.field_with("tokens", |field| field.debug_list().entries(tokens).finish()); + dbg_fmt.field("approx_token_stream_pos", &self.num_bump_calls); - // imply there's "more to know" than this view - dbg_fmt.finish_non_exhaustive() + // some fields are interesting for certain values, as they relate to macro parsing + if let Some(subparser) = self.subparser_name { + dbg_fmt.field("subparser_name", &subparser); + } + if let Recovery::Forbidden = self.recovery { + dbg_fmt.field("recovery", &self.recovery); } - } - DebugParser { parser: self, lookahead } + // imply there's "more to know" than this view + dbg_fmt.finish_non_exhaustive() + }) } pub fn clear_expected_token_types(&mut self) { |
