Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
57e0dea
Document requirements for unsized {Rc,Arc}::from_raw
udoprog Jan 28, 2024
d4adb3a
Add examples for unsized {Rc,Arc}::from_raw
udoprog Jan 28, 2024
23c83fa
Tidy up
udoprog Jan 28, 2024
d63384d
Fix doctest
udoprog Jan 28, 2024
eebc720
Replicate documentation in {Rc,Arc}::from_raw_in
udoprog Jan 28, 2024
bdbbf04
Fix doctest
udoprog Jan 28, 2024
adb7607
Fix BTreeMap's Cursor::remove_{next,prev}
Amanieu Jan 30, 2024
6686ca0
std::thread update freebsd stack guard handling.
devnexen Feb 5, 2024
369fff6
Implicitly enable evex512 if avx512 is enabled
nikic Feb 14, 2024
ddec8c5
Ignore unsized types when trying to determine the size of a type
Urgau Feb 14, 2024
8d4d572
Fix msg for verbose suggestions with confusable capitalization
estebank Feb 14, 2024
c1bb352
Continue compilation even if inherent impl checks fail
oli-obk Feb 14, 2024
8b35f8e
Remove `LitError::LexerError`.
nnethercote Feb 14, 2024
a513bb2
Make `report_lit_error` return `ErrorGuaranteed`.
nnethercote Feb 14, 2024
332c577
Make `emit_unescape_error` return `Option<ErrorGuaranteed>`.
nnethercote Feb 14, 2024
25ed6e4
Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.
nnethercote Feb 14, 2024
ac47f6c
Add suffixes to `LitError`.
nnethercote Feb 15, 2024
9fdab38
Rollup merge of #120449 - udoprog:document-unsized-rc-arc-from-raw, r…
GuillaumeGomez Feb 15, 2024
472c820
Rollup merge of #120505 - Amanieu:fix-btreemap-cursor-remove, r=m-ou-se
GuillaumeGomez Feb 15, 2024
bf323ba
Rollup merge of #120672 - devnexen:update_thread_stack_guardpages_fbs…
GuillaumeGomez Feb 15, 2024
7d6c99d
Rollup merge of #121088 - nikic:evex512, r=Amanieu
GuillaumeGomez Feb 15, 2024
12d70af
Rollup merge of #121104 - Urgau:bigger_layout-fix-fp, r=compiler-errors
GuillaumeGomez Feb 15, 2024
3c87054
Rollup merge of #121107 - estebank:capitalization-suggestion, r=micha…
GuillaumeGomez Feb 15, 2024
e878439
Rollup merge of #121113 - oli-obk:track_errors10, r=compiler-errors
GuillaumeGomez Feb 15, 2024
06f53dd
Rollup merge of #121120 - nnethercote:LitKind-Err-guar, r=fmease
GuillaumeGomez Feb 15, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make emit_unescape_error return Option<ErrorGuaranteed>.
And use the result in `cook_common` to decide whether to return an error token.
  • Loading branch information
nnethercote committed Feb 15, 2024
commit 332c57723a03e97497d6fba6636e31c2e41fefe9
16 changes: 8 additions & 8 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,15 +691,14 @@ impl<'sess, 'src> StringReader<'sess, 'src> {

fn cook_common(
&self,
kind: token::LitKind,
mut kind: token::LitKind,
mode: Mode,
start: BytePos,
end: BytePos,
prefix_len: u32,
postfix_len: u32,
unescape: fn(&str, Mode, &mut dyn FnMut(Range<usize>, Result<(), EscapeError>)),
) -> (token::LitKind, Symbol) {
let mut has_fatal_err = false;
let content_start = start + BytePos(prefix_len);
let content_end = end - BytePos(postfix_len);
let lit_content = self.str_from_to(content_start, content_end);
Expand All @@ -711,24 +710,25 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
let lo = content_start + BytePos(start);
let hi = lo + BytePos(end - start);
let span = self.mk_sp(lo, hi);
if err.is_fatal() {
has_fatal_err = true;
}
emit_unescape_error(
let is_fatal = err.is_fatal();
if let Some(_guar) = emit_unescape_error(
self.dcx(),
lit_content,
span_with_quotes,
span,
mode,
range,
err,
);
) {
assert!(is_fatal);
kind = token::Err;
}
}
});

// We normally exclude the quotes for the symbol, but for errors we
// include it because it results in clearer error messages.
if !has_fatal_err {
if kind != token::Err {
(kind, Symbol::intern(lit_content))
} else {
(token::Err, self.symbol_from_to(start, end))
Expand Down
58 changes: 26 additions & 32 deletions compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::iter::once;
use std::ops::Range;

use rustc_errors::{Applicability, DiagCtxt};
use rustc_errors::{Applicability, DiagCtxt, ErrorGuaranteed};
use rustc_lexer::unescape::{EscapeError, Mode};
use rustc_span::{BytePos, Span};

Expand All @@ -21,7 +21,7 @@ pub(crate) fn emit_unescape_error(
// range of the error inside `lit`
range: Range<usize>,
error: EscapeError,
) {
) -> Option<ErrorGuaranteed> {
debug!(
"emit_unescape_error: {:?}, {:?}, {:?}, {:?}, {:?}",
lit, full_lit_span, mode, range, error
Expand All @@ -31,12 +31,12 @@ pub(crate) fn emit_unescape_error(
let span = err_span.with_lo(err_span.hi() - BytePos(c.len_utf8() as u32));
(c, span)
};
match error {
Some(match error {
EscapeError::LoneSurrogateUnicodeEscape => {
dcx.emit_err(UnescapeError::InvalidUnicodeEscape { span: err_span, surrogate: true });
dcx.emit_err(UnescapeError::InvalidUnicodeEscape { span: err_span, surrogate: true })
}
EscapeError::OutOfRangeUnicodeEscape => {
dcx.emit_err(UnescapeError::InvalidUnicodeEscape { span: err_span, surrogate: false });
dcx.emit_err(UnescapeError::InvalidUnicodeEscape { span: err_span, surrogate: false })
}
EscapeError::MoreThanOneChar => {
use unicode_normalization::{char::is_combining_mark, UnicodeNormalization};
Expand Down Expand Up @@ -106,7 +106,7 @@ pub(crate) fn emit_unescape_error(
span: full_lit_span,
note,
suggestion: sugg,
});
})
}
EscapeError::EscapeOnlyChar => {
let (c, char_span) = last_char();
Expand All @@ -116,15 +116,15 @@ pub(crate) fn emit_unescape_error(
escaped_sugg: c.escape_default().to_string(),
escaped_msg: escaped_char(c),
byte: mode == Mode::Byte,
});
})
}
EscapeError::BareCarriageReturn => {
let double_quotes = mode.in_double_quotes();
dcx.emit_err(UnescapeError::BareCr { span: err_span, double_quotes });
dcx.emit_err(UnescapeError::BareCr { span: err_span, double_quotes })
}
EscapeError::BareCarriageReturnInRawString => {
assert!(mode.in_double_quotes());
dcx.emit_err(UnescapeError::BareCrRawString(err_span));
dcx.emit_err(UnescapeError::BareCrRawString(err_span))
}
EscapeError::InvalidEscape => {
let (c, span) = last_char();
Expand Down Expand Up @@ -161,16 +161,14 @@ pub(crate) fn emit_unescape_error(
<https://doc.rust-lang.org/reference/tokens.html#literals>",
);
}
diag.emit();
}
EscapeError::TooShortHexEscape => {
dcx.emit_err(UnescapeError::TooShortHexEscape(err_span));
diag.emit()
}
EscapeError::TooShortHexEscape => dcx.emit_err(UnescapeError::TooShortHexEscape(err_span)),
EscapeError::InvalidCharInHexEscape | EscapeError::InvalidCharInUnicodeEscape => {
let (c, span) = last_char();
let is_hex = error == EscapeError::InvalidCharInHexEscape;
let ch = escaped_char(c);
dcx.emit_err(UnescapeError::InvalidCharInEscape { span, is_hex, ch });
dcx.emit_err(UnescapeError::InvalidCharInEscape { span, is_hex, ch })
}
EscapeError::NonAsciiCharInByte => {
let (c, span) = last_char();
Expand Down Expand Up @@ -213,23 +211,23 @@ pub(crate) fn emit_unescape_error(
Applicability::MaybeIncorrect,
);
}
err.emit();
err.emit()
}
EscapeError::OutOfRangeHexEscape => {
dcx.emit_err(UnescapeError::OutOfRangeHexEscape(err_span));
dcx.emit_err(UnescapeError::OutOfRangeHexEscape(err_span))
}
EscapeError::LeadingUnderscoreUnicodeEscape => {
let (c, span) = last_char();
dcx.emit_err(UnescapeError::LeadingUnderscoreUnicodeEscape {
span,
ch: escaped_char(c),
});
})
}
EscapeError::OverlongUnicodeEscape => {
dcx.emit_err(UnescapeError::OverlongUnicodeEscape(err_span));
dcx.emit_err(UnescapeError::OverlongUnicodeEscape(err_span))
}
EscapeError::UnclosedUnicodeEscape => {
dcx.emit_err(UnescapeError::UnclosedUnicodeEscape(err_span, err_span.shrink_to_hi()));
dcx.emit_err(UnescapeError::UnclosedUnicodeEscape(err_span, err_span.shrink_to_hi()))
}
EscapeError::NoBraceInUnicodeEscape => {
let mut suggestion = "\\u{".to_owned();
Expand All @@ -248,35 +246,31 @@ pub(crate) fn emit_unescape_error(
} else {
(Some(err_span), NoBraceUnicodeSub::Help)
};
dcx.emit_err(UnescapeError::NoBraceInUnicodeEscape { span: err_span, label, sub });
dcx.emit_err(UnescapeError::NoBraceInUnicodeEscape { span: err_span, label, sub })
}
EscapeError::UnicodeEscapeInByte => {
dcx.emit_err(UnescapeError::UnicodeEscapeInByte(err_span));
dcx.emit_err(UnescapeError::UnicodeEscapeInByte(err_span))
}
EscapeError::EmptyUnicodeEscape => {
dcx.emit_err(UnescapeError::EmptyUnicodeEscape(err_span));
}
EscapeError::ZeroChars => {
dcx.emit_err(UnescapeError::ZeroChars(err_span));
}
EscapeError::LoneSlash => {
dcx.emit_err(UnescapeError::LoneSlash(err_span));
}
EscapeError::NulInCStr => {
dcx.emit_err(UnescapeError::NulInCStr { span: err_span });
dcx.emit_err(UnescapeError::EmptyUnicodeEscape(err_span))
}
EscapeError::ZeroChars => dcx.emit_err(UnescapeError::ZeroChars(err_span)),
EscapeError::LoneSlash => dcx.emit_err(UnescapeError::LoneSlash(err_span)),
EscapeError::NulInCStr => dcx.emit_err(UnescapeError::NulInCStr { span: err_span }),
EscapeError::UnskippedWhitespaceWarning => {
let (c, char_span) = last_char();
dcx.emit_warn(UnescapeError::UnskippedWhitespace {
span: err_span,
ch: escaped_char(c),
char_span,
});
return None;
}
EscapeError::MultipleSkippedLinesWarning => {
dcx.emit_warn(UnescapeError::MultipleSkippedLinesWarning(err_span));
return None;
}
}
})
}

/// Pushes a character to a message string for error reporting
Expand Down