Skip to content

Commit 0b8f9e5

Browse files
compiler: derive Debug in parser
It's annoying to debug the parser if you have to stop every five seconds to add a Debug impl.
1 parent 0d57b22 commit 0b8f9e5

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ impl<'t> Iterator for RefTokenTreeCursor<'t> {
706706
/// involve associated types) for getting individual elements, or
707707
/// `RefTokenTreeCursor` if you really want an `Iterator`, e.g. in a `for`
708708
/// loop.
709-
#[derive(Clone)]
709+
#[derive(Clone, Debug)]
710710
pub struct TokenTreeCursor {
711711
pub stream: TokenStream,
712712
index: usize,

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub(crate) use item::FnParseMode;
1919
pub use pat::{CommaRecoveryMode, RecoverColon, RecoverComma};
2020
pub use path::PathStyle;
2121

22+
use core::fmt;
2223
use rustc_ast::ptr::P;
2324
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
2425
use rustc_ast::tokenstream::{AttributesData, DelimSpacing, DelimSpan, Spacing};
@@ -46,7 +47,7 @@ use crate::errors::{
4647
};
4748

4849
bitflags::bitflags! {
49-
#[derive(Clone, Copy)]
50+
#[derive(Clone, Copy, Debug)]
5051
struct Restrictions: u8 {
5152
const STMT_EXPR = 1 << 0;
5253
const NO_STRUCT_LITERAL = 1 << 1;
@@ -72,7 +73,7 @@ enum BlockMode {
7273

7374
/// Whether or not we should force collection of tokens for an AST node,
7475
/// regardless of whether or not it has attributes
75-
#[derive(Clone, Copy, PartialEq)]
76+
#[derive(Clone, Copy, Debug, PartialEq)]
7677
pub enum ForceCollect {
7778
Yes,
7879
No,
@@ -120,7 +121,7 @@ macro_rules! maybe_recover_from_interpolated_ty_qpath {
120121
};
121122
}
122123

123-
#[derive(Clone, Copy)]
124+
#[derive(Clone, Copy, Debug)]
124125
pub enum Recovery {
125126
Allowed,
126127
Forbidden,
@@ -182,7 +183,7 @@ pub struct Parser<'a> {
182183
rustc_data_structures::static_assert_size!(Parser<'_>, 264);
183184

184185
/// Stores span information about a closure.
185-
#[derive(Clone)]
186+
#[derive(Clone, Debug)]
186187
pub struct ClosureSpans {
187188
pub whole_closure: Span,
188189
pub closing_pipe: Span,
@@ -211,7 +212,7 @@ pub type ReplaceRange = (Range<u32>, Vec<(FlatToken, Spacing)>);
211212
/// Controls how we capture tokens. Capturing can be expensive,
212213
/// so we try to avoid performing capturing in cases where
213214
/// we will never need an `AttrTokenStream`.
214-
#[derive(Copy, Clone, Default)]
215+
#[derive(Copy, Clone, Debug, Default)]
215216
pub enum Capturing {
216217
/// We aren't performing any capturing
217218
#[default]
@@ -220,7 +221,7 @@ pub enum Capturing {
220221
Yes,
221222
}
222223

223-
#[derive(Clone)]
224+
#[derive(Clone, Debug)]
224225
struct CaptureState {
225226
capturing: Capturing,
226227
replace_ranges: Vec<ReplaceRange>,
@@ -231,7 +232,7 @@ struct CaptureState {
231232
/// we (a) lex tokens into a nice tree structure (`TokenStream`), and then (b)
232233
/// use this type to emit them as a linear sequence. But a linear sequence is
233234
/// what the parser expects, for the most part.
234-
#[derive(Clone)]
235+
#[derive(Clone, Debug)]
235236
struct TokenCursor {
236237
// Cursor for the current (innermost) token stream. The delimiters for this
237238
// token stream are found in `self.stack.last()`; when that is `None` then
@@ -336,6 +337,7 @@ enum TokenExpectType {
336337
}
337338

338339
/// A sequence separator.
340+
#[derive(Debug)]
339341
struct SeqSep {
340342
/// The separator token.
341343
sep: Option<TokenKind>,
@@ -353,6 +355,7 @@ impl SeqSep {
353355
}
354356
}
355357

358+
#[derive(Debug)]
356359
pub enum FollowedByType {
357360
Yes,
358361
No,
@@ -377,7 +380,7 @@ pub enum Trailing {
377380
Yes,
378381
}
379382

380-
#[derive(Clone, Copy, PartialEq, Eq)]
383+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
381384
pub enum TokenDescription {
382385
ReservedIdentifier,
383386
Keyword,

0 commit comments

Comments
 (0)