Skip to content

Commit

Permalink
Rollup merge of rust-lang#100978 - nnethercote:fix-100948, r=petroche…
Browse files Browse the repository at this point in the history
…nkov

Handle `Err` in `ast::LitKind::to_token_lit`.

Fixes rust-lang#100948.

r? ``@petrochenkov``
  • Loading branch information
JohnTitor committed Aug 26, 2022
2 parents 6849555 + b997af9 commit d4a5ec1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_ast/src/util/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ impl LitKind {
let symbol = if value { kw::True } else { kw::False };
(token::Bool, symbol, None)
}
LitKind::Err => unreachable!(),
// This only shows up in places like `-Zunpretty=hir` output, so we
// don't bother to produce something useful.
LitKind::Err => (token::Err, Symbol::intern("<bad-literal>"), None),
};

token::Lit::new(kind, symbol, suffix)
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/unpretty/bad-literal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// compile-flags: -Zunpretty=hir
// check-fail

// In #100948 this caused an ICE with -Zunpretty=hir.
fn main() {
1u;
//~^ ERROR invalid suffix `u` for number literal
}
10 changes: 10 additions & 0 deletions src/test/ui/unpretty/bad-literal.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: invalid suffix `u` for number literal
--> $DIR/bad-literal.rs:6:5
|
LL | 1u;
| ^^ invalid suffix `u`
|
= help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)

error: aborting due to previous error

11 changes: 11 additions & 0 deletions src/test/ui/unpretty/bad-literal.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
// compile-flags: -Zunpretty=hir
// check-fail

// In #100948 this caused an ICE with -Zunpretty=hir.
fn main() {
<bad-literal>;
}

0 comments on commit d4a5ec1

Please sign in to comment.