Skip to content

Commit bf4a62c

Browse files
committed
Fix an ICE parsing a malformed literal in concat_bytes!.
Fixes #104769.
1 parent 2585bce commit bf4a62c

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

compiler/rustc_builtin_macros/src/concat_bytes.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_ast as ast;
22
use rustc_ast::{ptr::P, tokenstream::TokenStream};
33
use rustc_errors::Applicability;
44
use rustc_expand::base::{self, DummyResult};
5+
use rustc_session::errors::report_lit_error;
56
use rustc_span::Span;
67

78
/// Emits errors for literal expressions that are invalid inside and outside of an array.
@@ -68,7 +69,10 @@ fn invalid_type_err(
6869
Ok(ast::LitKind::Int(_, _)) => {
6970
cx.span_err(span, "numeric literal is not a `u8`");
7071
}
71-
_ => unreachable!(),
72+
Ok(ast::LitKind::ByteStr(_) | ast::LitKind::Byte(_)) => unreachable!(),
73+
Err(err) => {
74+
report_lit_error(&cx.sess.parse_sess, err, token_lit, span);
75+
}
7276
}
7377
}
7478

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(concat_bytes)]
2+
3+
fn main() {
4+
concat_bytes!(7Y);
5+
//~^ ERROR invalid suffix `Y` for number literal
6+
concat_bytes!(888888888888888888888888888888888888888);
7+
//~^ ERROR integer literal is too large
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: invalid suffix `Y` for number literal
2+
--> $DIR/issue-104769-concat_bytes-invalid-literal.rs:4:19
3+
|
4+
LL | concat_bytes!(7Y);
5+
| ^^ invalid suffix `Y`
6+
|
7+
= help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
8+
9+
error: integer literal is too large
10+
--> $DIR/issue-104769-concat_bytes-invalid-literal.rs:6:19
11+
|
12+
LL | concat_bytes!(888888888888888888888888888888888888888);
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to 2 previous errors
16+

0 commit comments

Comments
 (0)