Skip to content

Commit d4a5ec1

Browse files
authored
Rollup merge of #100978 - nnethercote:fix-100948, r=petrochenkov
Handle `Err` in `ast::LitKind::to_token_lit`. Fixes #100948. r? ``@petrochenkov``
2 parents 6849555 + b997af9 commit d4a5ec1

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

compiler/rustc_ast/src/util/literal.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ impl LitKind {
199199
let symbol = if value { kw::True } else { kw::False };
200200
(token::Bool, symbol, None)
201201
}
202-
LitKind::Err => unreachable!(),
202+
// This only shows up in places like `-Zunpretty=hir` output, so we
203+
// don't bother to produce something useful.
204+
LitKind::Err => (token::Err, Symbol::intern("<bad-literal>"), None),
203205
};
204206

205207
token::Lit::new(kind, symbol, suffix)

src/test/ui/unpretty/bad-literal.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// compile-flags: -Zunpretty=hir
2+
// check-fail
3+
4+
// In #100948 this caused an ICE with -Zunpretty=hir.
5+
fn main() {
6+
1u;
7+
//~^ ERROR invalid suffix `u` for number literal
8+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: invalid suffix `u` for number literal
2+
--> $DIR/bad-literal.rs:6:5
3+
|
4+
LL | 1u;
5+
| ^^ invalid suffix `u`
6+
|
7+
= help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
8+
9+
error: aborting due to previous error
10+
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[prelude_import]
2+
use ::std::prelude::rust_2015::*;
3+
#[macro_use]
4+
extern crate std;
5+
// compile-flags: -Zunpretty=hir
6+
// check-fail
7+
8+
// In #100948 this caused an ICE with -Zunpretty=hir.
9+
fn main() {
10+
<bad-literal>;
11+
}

0 commit comments

Comments
 (0)