Deduplicate the error printing code for hidden type mismatches
This commit is contained in:
parent
25876b3541
commit
7d2cad68d2
3 changed files with 24 additions and 25 deletions
|
@ -128,17 +128,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
if let Some(prev) = result.get_mut(&opaque_type_key.def_id) {
|
if let Some(prev) = result.get_mut(&opaque_type_key.def_id) {
|
||||||
if prev.ty != ty {
|
if prev.ty != ty {
|
||||||
if !ty.references_error() {
|
if !ty.references_error() {
|
||||||
let mut err = infcx.tcx.sess.struct_span_err(
|
prev.report_mismatch(
|
||||||
concrete_type.span,
|
&OpaqueHiddenType { ty, span: concrete_type.span },
|
||||||
"concrete type differs from previous defining opaque type use",
|
infcx.tcx,
|
||||||
);
|
);
|
||||||
err.span_label(prev.span, format!("expected `{}`, got `{}`", prev.ty, ty));
|
|
||||||
if prev.span == concrete_type.span {
|
|
||||||
err.span_label(prev.span, "this expression supplies two conflicting concrete types for the same opaque type");
|
|
||||||
} else {
|
|
||||||
err.span_note(prev.span, "previous use here");
|
|
||||||
}
|
|
||||||
err.emit();
|
|
||||||
}
|
}
|
||||||
prev.ty = infcx.tcx.ty_error();
|
prev.ty = infcx.tcx.ty_error();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1112,6 +1112,26 @@ pub struct OpaqueHiddenType<'tcx> {
|
||||||
pub ty: Ty<'tcx>,
|
pub ty: Ty<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> OpaqueHiddenType<'tcx> {
|
||||||
|
pub fn report_mismatch(&self, other: &Self, tcx: TyCtxt<'tcx>) {
|
||||||
|
// Found different concrete types for the opaque type.
|
||||||
|
let mut err = tcx.sess.struct_span_err(
|
||||||
|
other.span,
|
||||||
|
"concrete type differs from previous defining opaque type use",
|
||||||
|
);
|
||||||
|
err.span_label(other.span, format!("expected `{}`, got `{}`", self.ty, other.ty));
|
||||||
|
if self.span == other.span {
|
||||||
|
err.span_label(
|
||||||
|
self.span,
|
||||||
|
"this expression supplies two conflicting concrete types for the same opaque type",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
err.span_note(self.span, "previous use here");
|
||||||
|
}
|
||||||
|
err.emit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rustc_index::newtype_index! {
|
rustc_index::newtype_index! {
|
||||||
/// "Universes" are used during type- and trait-checking in the
|
/// "Universes" are used during type- and trait-checking in the
|
||||||
/// presence of `for<..>` binders to control what sets of names are
|
/// presence of `for<..>` binders to control what sets of names are
|
||||||
|
|
|
@ -601,21 +601,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
|
||||||
|
|
||||||
if let Some(prev) = self.found {
|
if let Some(prev) = self.found {
|
||||||
if concrete_type.ty != prev.ty && !(concrete_type, prev).references_error() {
|
if concrete_type.ty != prev.ty && !(concrete_type, prev).references_error() {
|
||||||
// Found different concrete types for the opaque type.
|
prev.report_mismatch(&concrete_type, self.tcx);
|
||||||
let mut err = self.tcx.sess.struct_span_err(
|
|
||||||
concrete_type.span,
|
|
||||||
"concrete type differs from previous defining opaque type use",
|
|
||||||
);
|
|
||||||
err.span_label(
|
|
||||||
concrete_type.span,
|
|
||||||
format!("expected `{}`, got `{}`", prev.ty, concrete_type.ty),
|
|
||||||
);
|
|
||||||
if prev.span == concrete_type.span {
|
|
||||||
err.span_label(prev.span, "this expression supplies two conflicting concrete types for the same opaque type");
|
|
||||||
} else {
|
|
||||||
err.span_note(prev.span, "previous use here");
|
|
||||||
}
|
|
||||||
err.emit();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.found = Some(concrete_type);
|
self.found = Some(concrete_type);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue