Add ErrorGuaranteed
to ast::LitKind::Err
, token::LitKind::Err
.
This mostly works well, and eliminates a couple of delayed bugs. One annoying thing is that we should really also add an `ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`, so we have to fake it.
This commit is contained in:
parent
332c57723a
commit
25ed6e43b0
26 changed files with 85 additions and 64 deletions
|
@ -1266,7 +1266,7 @@ pub fn expr_to_spanned_string<'a>(
|
|||
);
|
||||
Some((err, true))
|
||||
}
|
||||
Ok(ast::LitKind::Err) => None,
|
||||
Ok(ast::LitKind::Err(_)) => None,
|
||||
Err(err) => {
|
||||
report_lit_error(&cx.sess.parse_sess, err, token_lit, expr.span);
|
||||
None
|
||||
|
|
|
@ -10,7 +10,7 @@ use rustc_ast::util::literal::escape_byte_str_symbol;
|
|||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{MultiSpan, PResult};
|
||||
use rustc_errors::{ErrorGuaranteed, MultiSpan, PResult};
|
||||
use rustc_parse::lexer::nfc_normalize;
|
||||
use rustc_parse::parse_stream_from_source_str;
|
||||
use rustc_session::parse::ParseSess;
|
||||
|
@ -63,7 +63,12 @@ impl FromInternal<token::LitKind> for LitKind {
|
|||
token::ByteStrRaw(n) => LitKind::ByteStrRaw(n),
|
||||
token::CStr => LitKind::CStr,
|
||||
token::CStrRaw(n) => LitKind::CStrRaw(n),
|
||||
token::Err => LitKind::Err,
|
||||
token::Err(_guar) => {
|
||||
// This is the only place a `pm::bridge::LitKind::ErrWithGuar`
|
||||
// is constructed. Note that an `ErrorGuaranteed` is available,
|
||||
// as required. See the comment in `to_internal`.
|
||||
LitKind::ErrWithGuar
|
||||
}
|
||||
token::Bool => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +87,16 @@ impl ToInternal<token::LitKind> for LitKind {
|
|||
LitKind::ByteStrRaw(n) => token::ByteStrRaw(n),
|
||||
LitKind::CStr => token::CStr,
|
||||
LitKind::CStrRaw(n) => token::CStrRaw(n),
|
||||
LitKind::Err => token::Err,
|
||||
LitKind::ErrWithGuar => {
|
||||
// This is annoying but valid. `LitKind::ErrWithGuar` would
|
||||
// have an `ErrorGuaranteed` except that type isn't available
|
||||
// in that crate. So we have to fake one. And we don't want to
|
||||
// use a delayed bug because there might be lots of these,
|
||||
// which would be expensive.
|
||||
#[allow(deprecated)]
|
||||
let guar = ErrorGuaranteed::unchecked_error_guaranteed();
|
||||
token::Err(guar)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -477,7 +491,7 @@ impl server::FreeFunctions for Rustc<'_, '_> {
|
|||
| token::LitKind::ByteStrRaw(_)
|
||||
| token::LitKind::CStr
|
||||
| token::LitKind::CStrRaw(_)
|
||||
| token::LitKind::Err => return Err(()),
|
||||
| token::LitKind::Err(_) => return Err(()),
|
||||
token::LitKind::Integer | token::LitKind::Float => {}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue