1
Fork 0

Print correct base for too-large literals

Also update tests
This commit is contained in:
clubby789 2023-01-02 05:07:02 +00:00
parent cafdd2f7bb
commit 537c7f4fa9
10 changed files with 87 additions and 33 deletions

View file

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