Skip to content

Commit

Permalink
Merge pull request #433 from dtolnay/mismatch
Browse files Browse the repository at this point in the history
Include line number in compiler/fallback mismatch panic
  • Loading branch information
dtolnay authored Jan 3, 2024
2 parents 9c5b613 + 8da8b88 commit 3eb1857
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl LexError {
}

#[cold]
fn mismatch() -> ! {
panic!("compiler/fallback mismatch")
fn mismatch(line: u32) -> ! {
panic!("compiler/fallback mismatch #{}", line)
}

impl DeferredTokenStream {
Expand Down Expand Up @@ -89,13 +89,13 @@ impl TokenStream {
fn unwrap_nightly(self) -> proc_macro::TokenStream {
match self {
TokenStream::Compiler(s) => s.into_token_stream(),
TokenStream::Fallback(_) => mismatch(),
TokenStream::Fallback(_) => mismatch(line!()),
}
}

fn unwrap_stable(self) -> fallback::TokenStream {
match self {
TokenStream::Compiler(_) => mismatch(),
TokenStream::Compiler(_) => mismatch(line!()),
TokenStream::Fallback(s) => s,
}
}
Expand Down Expand Up @@ -199,14 +199,14 @@ impl FromIterator<TokenStream> for TokenStream {
first.evaluate_now();
first.stream.extend(streams.map(|s| match s {
TokenStream::Compiler(s) => s.into_token_stream(),
TokenStream::Fallback(_) => mismatch(),
TokenStream::Fallback(_) => mismatch(line!()),
}));
TokenStream::Compiler(first)
}
Some(TokenStream::Fallback(mut first)) => {
first.extend(streams.map(|s| match s {
TokenStream::Fallback(s) => s,
TokenStream::Compiler(_) => mismatch(),
TokenStream::Compiler(_) => mismatch(line!()),
}));
TokenStream::Fallback(first)
}
Expand Down Expand Up @@ -419,15 +419,15 @@ impl Span {
match (self, other) {
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.resolved_at(b)),
(Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.resolved_at(b)),
_ => mismatch(),
_ => mismatch(line!()),
}
}

pub fn located_at(&self, other: Span) -> Span {
match (self, other) {
(Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.located_at(b)),
(Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.located_at(b)),
_ => mismatch(),
_ => mismatch(line!()),
}
}

Expand Down Expand Up @@ -494,7 +494,7 @@ impl Span {
fn unwrap_nightly(self) -> proc_macro::Span {
match self {
Span::Compiler(s) => s,
Span::Fallback(_) => mismatch(),
Span::Fallback(_) => mismatch(line!()),
}
}
}
Expand Down Expand Up @@ -597,14 +597,14 @@ impl Group {
match (self, span) {
(Group::Compiler(g), Span::Compiler(s)) => g.set_span(s),
(Group::Fallback(g), Span::Fallback(s)) => g.set_span(s),
_ => mismatch(),
_ => mismatch(line!()),
}
}

fn unwrap_nightly(self) -> proc_macro::Group {
match self {
Group::Compiler(g) => g,
Group::Fallback(_) => mismatch(),
Group::Fallback(_) => mismatch(line!()),
}
}
}
Expand Down Expand Up @@ -675,14 +675,14 @@ impl Ident {
match (self, span) {
(Ident::Compiler(t), Span::Compiler(s)) => t.set_span(s),
(Ident::Fallback(t), Span::Fallback(s)) => t.set_span(s),
_ => mismatch(),
_ => mismatch(line!()),
}
}

fn unwrap_nightly(self) -> proc_macro::Ident {
match self {
Ident::Compiler(s) => s,
Ident::Fallback(_) => mismatch(),
Ident::Fallback(_) => mismatch(line!()),
}
}
}
Expand All @@ -692,7 +692,7 @@ impl PartialEq for Ident {
match (self, other) {
(Ident::Compiler(t), Ident::Compiler(o)) => t.to_string() == o.to_string(),
(Ident::Fallback(t), Ident::Fallback(o)) => t == o,
_ => mismatch(),
_ => mismatch(line!()),
}
}
}
Expand Down Expand Up @@ -851,7 +851,7 @@ impl Literal {
match (self, span) {
(Literal::Compiler(lit), Span::Compiler(s)) => lit.set_span(s),
(Literal::Fallback(lit), Span::Fallback(s)) => lit.set_span(s),
_ => mismatch(),
_ => mismatch(line!()),
}
}

Expand All @@ -868,7 +868,7 @@ impl Literal {
fn unwrap_nightly(self) -> proc_macro::Literal {
match self {
Literal::Compiler(s) => s,
Literal::Fallback(_) => mismatch(),
Literal::Fallback(_) => mismatch(line!()),
}
}
}
Expand Down

0 comments on commit 3eb1857

Please sign in to comment.