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:
Nicholas Nethercote 2024-02-14 20:12:05 +11:00
parent b3b9f31a86
commit 33603a6d80
4 changed files with 5 additions and 4 deletions

View file

@ -295,7 +295,8 @@ impl<'a> NormalizedPat<'a> {
LitKind::Char(val) => Self::LitInt(val.into()),
LitKind::Int(val, _) => Self::LitInt(val.get()),
LitKind::Bool(val) => Self::LitBool(val),
LitKind::Float(..) | LitKind::Err => Self::Wild,
LitKind::Float(..) => Self::Wild,
LitKind::Err(guar) => Self::Err(guar),
},
_ => Self::Wild,
},

View file

@ -200,7 +200,7 @@ impl LateLintPass<'_> for RedundantTypeAnnotations {
span_lint(cx, REDUNDANT_TYPE_ANNOTATIONS, local.span, "redundant type annotation");
}
},
LitKind::Err => (),
LitKind::Err(_) => (),
LitKind::ByteStr(..) => {
// We only lint if the type annotation is an array type (e.g. &[u8; 4]).
// If instead it is a slice (e.g. &[u8]) it may not be redundant, so we

View file

@ -279,7 +279,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
match lit.value.node {
LitKind::Bool(val) => kind!("Bool({val:?})"),
LitKind::Char(c) => kind!("Char({c:?})"),
LitKind::Err => kind!("Err"),
LitKind::Err(_) => kind!("Err"),
LitKind::Byte(b) => kind!("Byte({b})"),
LitKind::Int(i, suffix) => {
let int_ty = match suffix {

View file

@ -286,7 +286,7 @@ pub fn lit_to_mir_constant<'tcx>(lit: &LitKind, ty: Option<Ty<'tcx>>) -> Constan
_ => bug!(),
},
LitKind::Bool(b) => Constant::Bool(b),
LitKind::Err => Constant::Err,
LitKind::Err(_) => Constant::Err,
}
}