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
|
@ -164,11 +164,7 @@ fn lit_to_mir_constant<'tcx>(
|
|||
})?,
|
||||
(ast::LitKind::Bool(b), ty::Bool) => ConstValue::Scalar(Scalar::from_bool(*b)),
|
||||
(ast::LitKind::Char(c), ty::Char) => ConstValue::Scalar(Scalar::from_char(*c)),
|
||||
(ast::LitKind::Err, _) => {
|
||||
return Err(LitToConstError::Reported(
|
||||
tcx.dcx().delayed_bug("encountered LitKind::Err during mir build"),
|
||||
));
|
||||
}
|
||||
(ast::LitKind::Err(guar), _) => return Err(LitToConstError::Reported(*guar)),
|
||||
_ => return Err(LitToConstError::TypeError),
|
||||
};
|
||||
|
||||
|
|
|
@ -71,11 +71,7 @@ pub(crate) fn lit_to_const<'tcx>(
|
|||
ty::ValTree::from_scalar_int(bits)
|
||||
}
|
||||
(ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()),
|
||||
(ast::LitKind::Err, _) => {
|
||||
return Err(LitToConstError::Reported(
|
||||
tcx.dcx().delayed_bug("encountered LitKind::Err during mir build"),
|
||||
));
|
||||
}
|
||||
(ast::LitKind::Err(guar), _) => return Err(LitToConstError::Reported(*guar)),
|
||||
_ => return Err(LitToConstError::TypeError),
|
||||
};
|
||||
|
||||
|
|
|
@ -897,12 +897,14 @@ impl<'tcx> Cx<'tcx> {
|
|||
let hir_id = self.tcx.local_def_id_to_hir_id(def_id.expect_local());
|
||||
let generics = self.tcx.generics_of(hir_id.owner);
|
||||
let Some(&index) = generics.param_def_id_to_index.get(&def_id) else {
|
||||
self.tcx.dcx().has_errors().unwrap();
|
||||
let guar = self.tcx.dcx().has_errors().unwrap();
|
||||
// We already errored about a late bound const
|
||||
return ExprKind::Literal {
|
||||
lit: &Spanned { span: DUMMY_SP, node: LitKind::Err },
|
||||
neg: false,
|
||||
};
|
||||
|
||||
let lit = self
|
||||
.tcx
|
||||
.hir_arena
|
||||
.alloc(Spanned { span: DUMMY_SP, node: LitKind::Err(guar) });
|
||||
return ExprKind::Literal { lit, neg: false };
|
||||
};
|
||||
let name = self.tcx.hir().name(hir_id);
|
||||
let param = ty::ParamConst::new(index, name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue