diff options
| author | clubby789 <jamie@hill-daniel.co.uk> | 2023-01-02 05:07:02 +0000 |
|---|---|---|
| committer | clubby789 <jamie@hill-daniel.co.uk> | 2023-01-02 11:43:07 +0000 |
| commit | 537c7f4fa95f4c5b0a6259ee7badae5ad57d0940 (patch) | |
| tree | 2de3397d26bfd7836e2e7fb3ae72e7afaa87f1bb /compiler/rustc_session/src | |
| parent | cafdd2f7bb1be0fa888e0aecafa3adde1a4b5476 (diff) | |
| download | rust-537c7f4fa95f4c5b0a6259ee7badae5ad57d0940.tar.gz rust-537c7f4fa95f4c5b0a6259ee7badae5ad57d0940.zip | |
Print correct base for too-large literals
Also update tests
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/errors.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index effb561688c..f5a72573d58 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -264,6 +264,7 @@ pub(crate) struct InvalidFloatLiteralSuffix { pub(crate) struct IntLiteralTooLarge { #[primary_span] pub span: Span, + pub limit: String, } #[derive(Diagnostic)] @@ -362,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 }); } } } |
