Auto merge of #121142 - GuillaumeGomez:rollup-5qmksjw, r=GuillaumeGomez
Rollup of 8 pull requests Successful merges: - #120449 (Document requirements for unsized {Rc,Arc}::from_raw) - #120505 (Fix BTreeMap's Cursor::remove_{next,prev}) - #120672 (std::thread update freebsd stack guard handling.) - #121088 (Implicitly enable evex512 if avx512 is enabled) - #121104 (Ignore unsized types when trying to determine the size of the original type) - #121107 (Fix msg for verbose suggestions with confusable capitalization) - #121113 (Continue compilation even if inherent impl checks fail) - #121120 (Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
cbddf31863
58 changed files with 630 additions and 277 deletions
|
@ -3,7 +3,8 @@ use std::num::NonZeroU32;
|
|||
use rustc_ast::token;
|
||||
use rustc_ast::util::literal::LitError;
|
||||
use rustc_errors::{
|
||||
codes::*, DiagCtxt, DiagnosticBuilder, DiagnosticMessage, IntoDiagnostic, Level, MultiSpan,
|
||||
codes::*, DiagCtxt, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, IntoDiagnostic,
|
||||
Level, MultiSpan,
|
||||
};
|
||||
use rustc_macros::Diagnostic;
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
@ -344,7 +345,12 @@ pub(crate) struct BinaryFloatLiteralNotSupported {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span: Span) {
|
||||
pub fn report_lit_error(
|
||||
sess: &ParseSess,
|
||||
err: LitError,
|
||||
lit: token::Lit,
|
||||
span: Span,
|
||||
) -> ErrorGuaranteed {
|
||||
// Checks if `s` looks like i32 or u1234 etc.
|
||||
fn looks_like_width_suffix(first_chars: &[char], s: &str) -> bool {
|
||||
s.len() > 1 && s.starts_with(first_chars) && s[1..].chars().all(|c| c.is_ascii_digit())
|
||||
|
@ -372,47 +378,37 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span:
|
|||
valid.then(|| format!("0{}{}", base_char.to_ascii_lowercase(), &suffix[1..]))
|
||||
}
|
||||
|
||||
let token::Lit { kind, symbol, suffix, .. } = lit;
|
||||
let dcx = &sess.dcx;
|
||||
match err {
|
||||
// `LexerError` is an error, but it was already reported
|
||||
// by lexer, so here we don't report it the second time.
|
||||
LitError::LexerError => {}
|
||||
LitError::InvalidSuffix => {
|
||||
if let Some(suffix) = suffix {
|
||||
dcx.emit_err(InvalidLiteralSuffix { span, kind: kind.descr(), suffix });
|
||||
}
|
||||
LitError::InvalidSuffix(suffix) => {
|
||||
dcx.emit_err(InvalidLiteralSuffix { span, kind: lit.kind.descr(), suffix })
|
||||
}
|
||||
LitError::InvalidIntSuffix => {
|
||||
let suf = suffix.expect("suffix error with no suffix");
|
||||
let suf = suf.as_str();
|
||||
LitError::InvalidIntSuffix(suffix) => {
|
||||
let suf = suffix.as_str();
|
||||
if looks_like_width_suffix(&['i', 'u'], suf) {
|
||||
// If it looks like a width, try to be helpful.
|
||||
dcx.emit_err(InvalidIntLiteralWidth { span, width: suf[1..].into() });
|
||||
} else if let Some(fixed) = fix_base_capitalisation(symbol.as_str(), suf) {
|
||||
dcx.emit_err(InvalidNumLiteralBasePrefix { span, fixed });
|
||||
dcx.emit_err(InvalidIntLiteralWidth { span, width: suf[1..].into() })
|
||||
} else if let Some(fixed) = fix_base_capitalisation(lit.symbol.as_str(), suf) {
|
||||
dcx.emit_err(InvalidNumLiteralBasePrefix { span, fixed })
|
||||
} else {
|
||||
dcx.emit_err(InvalidNumLiteralSuffix { span, suffix: suf.to_string() });
|
||||
dcx.emit_err(InvalidNumLiteralSuffix { span, suffix: suf.to_string() })
|
||||
}
|
||||
}
|
||||
LitError::InvalidFloatSuffix => {
|
||||
let suf = suffix.expect("suffix error with no suffix");
|
||||
let suf = suf.as_str();
|
||||
LitError::InvalidFloatSuffix(suffix) => {
|
||||
let suf = suffix.as_str();
|
||||
if looks_like_width_suffix(&['f'], suf) {
|
||||
// If it looks like a width, try to be helpful.
|
||||
dcx.emit_err(InvalidFloatLiteralWidth { span, width: suf[1..].to_string() });
|
||||
dcx.emit_err(InvalidFloatLiteralWidth { span, width: suf[1..].to_string() })
|
||||
} else {
|
||||
dcx.emit_err(InvalidFloatLiteralSuffix { span, suffix: suf.to_string() });
|
||||
dcx.emit_err(InvalidFloatLiteralSuffix { span, suffix: suf.to_string() })
|
||||
}
|
||||
}
|
||||
LitError::NonDecimalFloat(base) => {
|
||||
match base {
|
||||
16 => dcx.emit_err(HexadecimalFloatLiteralNotSupported { span }),
|
||||
8 => dcx.emit_err(OctalFloatLiteralNotSupported { span }),
|
||||
2 => dcx.emit_err(BinaryFloatLiteralNotSupported { span }),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
LitError::NonDecimalFloat(base) => match base {
|
||||
16 => dcx.emit_err(HexadecimalFloatLiteralNotSupported { span }),
|
||||
8 => dcx.emit_err(OctalFloatLiteralNotSupported { span }),
|
||||
2 => dcx.emit_err(BinaryFloatLiteralNotSupported { span }),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
LitError::IntTooLarge(base) => {
|
||||
let max = u128::MAX;
|
||||
let limit = match base {
|
||||
|
@ -421,7 +417,7 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span:
|
|||
16 => format!("{max:#x}"),
|
||||
_ => format!("{max}"),
|
||||
};
|
||||
dcx.emit_err(IntLiteralTooLarge { span, limit });
|
||||
dcx.emit_err(IntLiteralTooLarge { span, limit })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue