1
Fork 0

Rollup merge of #106361 - clubby789:int-literal-too-large, r=estebank

Note maximum integer literal for `IntLiteralTooLarge`

Closes #105908

`@rustbot` label +A-diagnostics
This commit is contained in:
Matthias Krüger 2023-01-04 07:28:56 +01:00 committed by GitHub
commit 11020b93b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 88 additions and 32 deletions

View file

@ -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 });
}
}
}