tamer: parse::trace: Generalize reason for trace output
The trace outputs a note in the footer indicating _why_ it's being output, so that the reader understands both where the potentially-unexpected behavior originates from and so they know (in the case of the feature flag) how to inhibit it. That information originally lived in `Parser`, where the `cfg` directive to enable it lives, but it was moved into the abstraction. This corrects that. DEV-7145main
parent
864f50c025
commit
b38c16fd08
|
@ -129,8 +129,10 @@ pub struct Parser<S: ParseState, I: TokenStream<S::Token>> {
|
|||
/// elide the move of [`Parser::state`] in [`Parser::feed_tok`].
|
||||
ctx: S::Context,
|
||||
|
||||
#[cfg(any(test, feature = "parser-trace-stderr"))]
|
||||
tracer: trace::HumanReadableTrace,
|
||||
#[cfg(test)]
|
||||
tracer: trace::HumanReadableTrace<"`cfg(test)`">,
|
||||
#[cfg(all(not(test), feature = "parser-trace-stderr"))]
|
||||
tracer: trace::HumanReadableTrace<"`cfg(parser-trace-stderr)`">,
|
||||
#[cfg(not(any(test, feature = "parser-trace-stderr")))]
|
||||
tracer: trace::VoidTrace,
|
||||
}
|
||||
|
|
|
@ -98,9 +98,9 @@ impl ParserTrace for VoidTrace {
|
|||
///
|
||||
/// See [module-level](super) documentation for more information.
|
||||
#[derive(Debug, PartialEq, Default)]
|
||||
pub struct HumanReadableTrace;
|
||||
pub struct HumanReadableTrace<const REASON: &'static str>;
|
||||
|
||||
impl ParserTrace for HumanReadableTrace {
|
||||
impl<const REASON: &'static str> ParserTrace for HumanReadableTrace<REASON> {
|
||||
fn trace_tok_begin<S: ParseState>(&mut self, st_orig: &S, tok: &S::Token) {
|
||||
eprint!(
|
||||
"\
|
||||
|
@ -149,16 +149,9 @@ impl ParserTrace for HumanReadableTrace {
|
|||
);
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
let cfg = ""; // so that this compiles without matching cfg
|
||||
#[cfg(feature = "parser-trace-stderr")]
|
||||
#[allow(unused_variables)]
|
||||
let cfg = "feature = \"parser-trace-stderr\"";
|
||||
#[cfg(test)] // takes precedence if both are set
|
||||
let cfg = "test";
|
||||
eprint!(
|
||||
"= note: this trace was output as a debugging aid \
|
||||
because `cfg({cfg})`.\n\n",
|
||||
because {REASON}.\n\n",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue