add 'ty_error_with_guaranteed' and 'const_error_with_guaranteed'
This commit is contained in:
parent
57d3c58ed6
commit
1f21b96dce
15 changed files with 68 additions and 47 deletions
|
@ -299,8 +299,8 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
||||||
if errors.is_empty() {
|
if errors.is_empty() {
|
||||||
definition_ty
|
definition_ty
|
||||||
} else {
|
} else {
|
||||||
infcx.err_ctxt().report_fulfillment_errors(&errors, None);
|
let reported = infcx.err_ctxt().report_fulfillment_errors(&errors, None);
|
||||||
self.tcx.ty_error()
|
self.tcx.ty_error_with_guaranteed(reported)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,12 +247,13 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
|
||||||
.and(type_op::normalize::Normalize::new(ty))
|
.and(type_op::normalize::Normalize::new(ty))
|
||||||
.fully_perform(self.infcx)
|
.fully_perform(self.infcx)
|
||||||
.unwrap_or_else(|_| {
|
.unwrap_or_else(|_| {
|
||||||
self.infcx
|
let reported = self
|
||||||
|
.infcx
|
||||||
.tcx
|
.tcx
|
||||||
.sess
|
.sess
|
||||||
.delay_span_bug(span, &format!("failed to normalize {:?}", ty));
|
.delay_span_bug(span, &format!("failed to normalize {:?}", ty));
|
||||||
TypeOpOutput {
|
TypeOpOutput {
|
||||||
output: self.infcx.tcx.ty_error(),
|
output: self.infcx.tcx.ty_error_with_guaranteed(reported),
|
||||||
constraints: None,
|
constraints: None,
|
||||||
error_info: None,
|
error_info: None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,11 +233,11 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||||
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
|
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
|
||||||
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
|
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
|
||||||
if hidden_type.has_non_region_infer() {
|
if hidden_type.has_non_region_infer() {
|
||||||
infcx.tcx.sess.delay_span_bug(
|
let reported = infcx.tcx.sess.delay_span_bug(
|
||||||
decl.hidden_type.span,
|
decl.hidden_type.span,
|
||||||
&format!("could not resolve {:#?}", hidden_type.ty.kind()),
|
&format!("could not resolve {:#?}", hidden_type.ty.kind()),
|
||||||
);
|
);
|
||||||
hidden_type.ty = infcx.tcx.ty_error();
|
hidden_type.ty = infcx.tcx.ty_error_with_guaranteed(reported);
|
||||||
}
|
}
|
||||||
|
|
||||||
(opaque_type_key, (hidden_type, decl.origin))
|
(opaque_type_key, (hidden_type, decl.origin))
|
||||||
|
|
|
@ -482,9 +482,9 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
|
||||||
/// In the meantime, though, callsites are required to deal with the "bug"
|
/// In the meantime, though, callsites are required to deal with the "bug"
|
||||||
/// locally in whichever way makes the most sense.
|
/// locally in whichever way makes the most sense.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn delay_as_bug(&mut self) {
|
pub fn delay_as_bug(&mut self) -> G {
|
||||||
self.downgrade_to_delayed_bug();
|
self.downgrade_to_delayed_bug();
|
||||||
self.emit();
|
self.emit()
|
||||||
}
|
}
|
||||||
|
|
||||||
forward!(
|
forward!(
|
||||||
|
|
|
@ -1201,7 +1201,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
(_, _) => {
|
(_, _) => {
|
||||||
let got = if let Some(_) = term.ty() { "type" } else { "constant" };
|
let got = if let Some(_) = term.ty() { "type" } else { "constant" };
|
||||||
let expected = def_kind.descr(assoc_item_def_id);
|
let expected = def_kind.descr(assoc_item_def_id);
|
||||||
tcx.sess
|
let reported = tcx
|
||||||
|
.sess
|
||||||
.struct_span_err(
|
.struct_span_err(
|
||||||
binding.span,
|
binding.span,
|
||||||
&format!("expected {expected} bound, found {got}"),
|
&format!("expected {expected} bound, found {got}"),
|
||||||
|
@ -1212,11 +1213,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
term = match def_kind {
|
term = match def_kind {
|
||||||
hir::def::DefKind::AssocTy => tcx.ty_error().into(),
|
hir::def::DefKind::AssocTy => {
|
||||||
|
tcx.ty_error_with_guaranteed(reported).into()
|
||||||
|
}
|
||||||
hir::def::DefKind::AssocConst => tcx
|
hir::def::DefKind::AssocConst => tcx
|
||||||
.const_error(
|
.const_error_with_guaranteed(
|
||||||
tcx.bound_type_of(assoc_item_def_id)
|
tcx.bound_type_of(assoc_item_def_id)
|
||||||
.subst(tcx, projection_ty.skip_binder().substs),
|
.subst(tcx, projection_ty.skip_binder().substs),
|
||||||
|
reported,
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
@ -1334,8 +1338,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
.map(|&(trait_ref, _, _)| trait_ref.def_id())
|
.map(|&(trait_ref, _, _)| trait_ref.def_id())
|
||||||
.find(|&trait_ref| tcx.is_trait_alias(trait_ref))
|
.find(|&trait_ref| tcx.is_trait_alias(trait_ref))
|
||||||
.map(|trait_ref| tcx.def_span(trait_ref));
|
.map(|trait_ref| tcx.def_span(trait_ref));
|
||||||
tcx.sess.emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span });
|
let reported =
|
||||||
return tcx.ty_error();
|
tcx.sess.emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span });
|
||||||
|
return tcx.ty_error_with_guaranteed(reported);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that there are no gross object safety violations;
|
// Check that there are no gross object safety violations;
|
||||||
|
@ -1345,14 +1350,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
let object_safety_violations =
|
let object_safety_violations =
|
||||||
astconv_object_safety_violations(tcx, item.trait_ref().def_id());
|
astconv_object_safety_violations(tcx, item.trait_ref().def_id());
|
||||||
if !object_safety_violations.is_empty() {
|
if !object_safety_violations.is_empty() {
|
||||||
report_object_safety_error(
|
let reported = report_object_safety_error(
|
||||||
tcx,
|
tcx,
|
||||||
span,
|
span,
|
||||||
item.trait_ref().def_id(),
|
item.trait_ref().def_id(),
|
||||||
&object_safety_violations,
|
&object_safety_violations,
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
return tcx.ty_error();
|
return tcx.ty_error_with_guaranteed(reported);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2112,13 +2117,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
"Type"
|
"Type"
|
||||||
};
|
};
|
||||||
|
|
||||||
self.report_ambiguous_associated_type(
|
let reported = self.report_ambiguous_associated_type(
|
||||||
span,
|
span,
|
||||||
type_name,
|
type_name,
|
||||||
&path_str,
|
&path_str,
|
||||||
item_segment.ident.name,
|
item_segment.ident.name,
|
||||||
);
|
);
|
||||||
return tcx.ty_error();
|
return tcx.ty_error_with_guaranteed(reported)
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!("qpath_to_ty: self_type={:?}", self_ty);
|
debug!("qpath_to_ty: self_type={:?}", self_ty);
|
||||||
|
@ -2560,8 +2565,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
{
|
{
|
||||||
err.span_note(impl_.self_ty.span, "not a concrete type");
|
err.span_note(impl_.self_ty.span, "not a concrete type");
|
||||||
}
|
}
|
||||||
err.emit();
|
tcx.ty_error_with_guaranteed(err.emit())
|
||||||
tcx.ty_error()
|
|
||||||
} else {
|
} else {
|
||||||
self.normalize_ty(span, ty)
|
self.normalize_ty(span, ty)
|
||||||
}
|
}
|
||||||
|
|
|
@ -611,11 +611,11 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
|
||||||
collected_tys.insert(def_id, ty);
|
collected_tys.insert(def_id, ty);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
tcx.sess.delay_span_bug(
|
let reported = tcx.sess.delay_span_bug(
|
||||||
return_span,
|
return_span,
|
||||||
format!("could not fully resolve: {ty} => {err:?}"),
|
format!("could not fully resolve: {ty} => {err:?}"),
|
||||||
);
|
);
|
||||||
collected_tys.insert(def_id, tcx.ty_error());
|
collected_tys.insert(def_id, tcx.ty_error_with_guaranteed(reported));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -512,8 +512,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
err.emit();
|
self.tcx().ty_error_with_guaranteed(err.emit())
|
||||||
self.tcx().ty_error()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -698,7 +698,7 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(hidden) = locator.found else {
|
let Some(hidden) = locator.found else {
|
||||||
tcx.sess.emit_err(UnconstrainedOpaqueType {
|
let reported = tcx.sess.emit_err(UnconstrainedOpaqueType {
|
||||||
span: tcx.def_span(def_id),
|
span: tcx.def_span(def_id),
|
||||||
name: tcx.item_name(tcx.local_parent(def_id).to_def_id()),
|
name: tcx.item_name(tcx.local_parent(def_id).to_def_id()),
|
||||||
what: match tcx.hir().get(scope) {
|
what: match tcx.hir().get(scope) {
|
||||||
|
@ -708,7 +708,7 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
|
||||||
_ => "item",
|
_ => "item",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return tcx.ty_error();
|
return tcx.ty_error_with_guaranteed(reported);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only check against typeck if we didn't already error
|
// Only check against typeck if we didn't already error
|
||||||
|
|
|
@ -1639,9 +1639,9 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
||||||
if visitor.ret_exprs.len() > 0 && let Some(expr) = expression {
|
if visitor.ret_exprs.len() > 0 && let Some(expr) = expression {
|
||||||
self.note_unreachable_loop_return(&mut err, &expr, &visitor.ret_exprs);
|
self.note_unreachable_loop_return(&mut err, &expr, &visitor.ret_exprs);
|
||||||
}
|
}
|
||||||
err.emit_unless(unsized_return);
|
let reported = err.emit_unless(unsized_return);
|
||||||
|
|
||||||
self.final_ty = Some(fcx.tcx.ty_error());
|
self.final_ty = Some(fcx.tcx.ty_error_with_guaranteed(reported));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,14 +80,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// coercions from ! to `expected`.
|
// coercions from ! to `expected`.
|
||||||
if ty.is_never() {
|
if ty.is_never() {
|
||||||
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
|
if let Some(adjustments) = self.typeck_results.borrow().adjustments().get(expr.hir_id) {
|
||||||
self.tcx().sess.delay_span_bug(
|
let reported = self.tcx().sess.delay_span_bug(
|
||||||
expr.span,
|
expr.span,
|
||||||
"expression with never type wound up being adjusted",
|
"expression with never type wound up being adjusted",
|
||||||
);
|
);
|
||||||
return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
|
return if let [Adjustment { kind: Adjust::NeverToAny, target }] = &adjustments[..] {
|
||||||
target.to_owned()
|
target.to_owned()
|
||||||
} else {
|
} else {
|
||||||
self.tcx().ty_error()
|
self.tcx().ty_error_with_guaranteed(reported)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,8 +396,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
{
|
{
|
||||||
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
|
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
|
||||||
}
|
}
|
||||||
err.emit();
|
oprnd_t = tcx.ty_error_with_guaranteed(err.emit());
|
||||||
oprnd_t = tcx.ty_error();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::UnOp::Not => {
|
hir::UnOp::Not => {
|
||||||
|
@ -1097,12 +1096,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
// If the assignment expression itself is ill-formed, don't
|
// If the assignment expression itself is ill-formed, don't
|
||||||
// bother emitting another error
|
// bother emitting another error
|
||||||
if lhs_ty.references_error() || rhs_ty.references_error() {
|
let reported = if lhs_ty.references_error() || rhs_ty.references_error() {
|
||||||
err.delay_as_bug()
|
err.delay_as_bug()
|
||||||
} else {
|
} else {
|
||||||
err.emit();
|
err.emit()
|
||||||
}
|
};
|
||||||
return self.tcx.ty_error();
|
return self.tcx.ty_error_with_guaranteed(reported);
|
||||||
}
|
}
|
||||||
|
|
||||||
let lhs_ty = self.check_expr_with_needs(&lhs, Needs::MutPlace);
|
let lhs_ty = self.check_expr_with_needs(&lhs, Needs::MutPlace);
|
||||||
|
@ -2777,8 +2776,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err.emit();
|
let reported = err.emit();
|
||||||
self.tcx.ty_error()
|
self.tcx.ty_error_with_guaranteed(reported)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1212,9 +1212,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err.emit();
|
let reported = err.emit();
|
||||||
|
return (tcx.ty_error_with_guaranteed(reported), res);
|
||||||
return (tcx.ty_error(), res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -529,8 +529,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err.emit();
|
let reported = err.emit();
|
||||||
self.tcx.ty_error()
|
self.tcx.ty_error_with_guaranteed(reported)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1278,12 +1278,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let element_tys = tcx.mk_type_list(element_tys_iter);
|
let element_tys = tcx.mk_type_list(element_tys_iter);
|
||||||
let pat_ty = tcx.mk_ty(ty::Tuple(element_tys));
|
let pat_ty = tcx.mk_ty(ty::Tuple(element_tys));
|
||||||
if let Some(mut err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, ti) {
|
if let Some(mut err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, ti) {
|
||||||
err.emit();
|
let reported = err.emit();
|
||||||
// Walk subpatterns with an expected type of `err` in this case to silence
|
// Walk subpatterns with an expected type of `err` in this case to silence
|
||||||
// further errors being emitted when using the bindings. #50333
|
// further errors being emitted when using the bindings. #50333
|
||||||
let element_tys_iter = (0..max_len).map(|_| tcx.ty_error());
|
let element_tys_iter = (0..max_len).map(|_| tcx.ty_error_with_guaranteed(reported));
|
||||||
for (_, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) {
|
for (_, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) {
|
||||||
self.check_pat(elem, tcx.ty_error(), def_bm, ti);
|
self.check_pat(elem, tcx.ty_error_with_guaranteed(reported), def_bm, ti);
|
||||||
}
|
}
|
||||||
tcx.mk_tup(element_tys_iter)
|
tcx.mk_tup(element_tys_iter)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -90,8 +90,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
err.emit();
|
let reported = err.emit();
|
||||||
Some((self.tcx.ty_error(), self.tcx.ty_error()))
|
Some((
|
||||||
|
self.tcx.ty_error_with_guaranteed(reported),
|
||||||
|
self.tcx.ty_error_with_guaranteed(reported),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// To type-check `base_expr[index_expr]`, we progressively autoderef
|
/// To type-check `base_expr[index_expr]`, we progressively autoderef
|
||||||
|
|
|
@ -1283,6 +1283,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
|
||||||
|
#[track_caller]
|
||||||
|
pub fn ty_error_with_guaranteed(self, reported: ErrorGuaranteed) -> Ty<'tcx> {
|
||||||
|
self.mk_ty(Error(reported))
|
||||||
|
}
|
||||||
|
|
||||||
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
|
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn ty_error(self) -> Ty<'tcx> {
|
pub fn ty_error(self) -> Ty<'tcx> {
|
||||||
|
@ -1297,6 +1303,16 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.mk_ty(Error(reported))
|
self.mk_ty(Error(reported))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
|
||||||
|
#[track_caller]
|
||||||
|
pub fn const_error_with_guaranteed(
|
||||||
|
self,
|
||||||
|
ty: Ty<'tcx>,
|
||||||
|
reported: ErrorGuaranteed,
|
||||||
|
) -> Const<'tcx> {
|
||||||
|
self.mk_const(ty::ConstS { kind: ty::ConstKind::Error(reported), ty })
|
||||||
|
}
|
||||||
|
|
||||||
/// Like [TyCtxt::ty_error] but for constants.
|
/// Like [TyCtxt::ty_error] but for constants.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn const_error(self, ty: Ty<'tcx>) -> Const<'tcx> {
|
pub fn const_error(self, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue