diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-01-04 07:28:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-04 07:28:56 +0100 |
| commit | 11020b93b670d7091bf933da8231f28debdd5e00 (patch) | |
| tree | 06fc1c7d1705c11abde4b1aea227156f2c0348ee /compiler/rustc_session/src | |
| parent | d24b2290723406f16373a3d7db99da7c7e9e5982 (diff) | |
| parent | 537c7f4fa95f4c5b0a6259ee7badae5ad57d0940 (diff) | |
| download | rust-11020b93b670d7091bf933da8231f28debdd5e00.tar.gz rust-11020b93b670d7091bf933da8231f28debdd5e00.zip | |
Rollup merge of #106361 - clubby789:int-literal-too-large, r=estebank
Note maximum integer literal for `IntLiteralTooLarge` Closes #105908 `@rustbot` label +A-diagnostics
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/errors.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index e72b76cfee9..f5a72573d58 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -260,9 +260,11 @@ pub(crate) struct InvalidFloatLiteralSuffix { #[derive(Diagnostic)] #[diag(session_int_literal_too_large)] +#[note] pub(crate) struct IntLiteralTooLarge { #[primary_span] pub span: Span, + pub limit: String, } #[derive(Diagnostic)] @@ -361,8 +363,15 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span: _ => unreachable!(), }; } - LitError::IntTooLarge => { - sess.emit_err(IntLiteralTooLarge { span }); + LitError::IntTooLarge(base) => { + let max = u128::MAX; + let limit = match base { + 2 => format!("{max:#b}"), + 8 => format!("{max:#o}"), + 16 => format!("{max:#x}"), + _ => format!("{max}"), + }; + sess.emit_err(IntLiteralTooLarge { span, limit }); } } } |
