Rollup merge of #109151 - compiler-errors:debug-assert-alias, r=WaffleLapkin
Assert def-kind is correct for alias types
Make sure we're not constructing alias types for the wrong def-kind, at least for debug cases 😅
This commit is contained in:
commit
9d5d447421
@ -84,7 +84,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
|
|
||||||
pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
|
pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
@ -233,7 +232,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
|
|||||||
where
|
where
|
||||||
T: ToTrace<'tcx>,
|
T: ToTrace<'tcx>,
|
||||||
{
|
{
|
||||||
let trace = ToTrace::to_trace(self.infcx.tcx, self.cause, a_is_expected, a, b);
|
let trace = ToTrace::to_trace(self.cause, a_is_expected, a, b);
|
||||||
Trace { at: self, trace, a_is_expected }
|
Trace { at: self, trace, a_is_expected }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -306,7 +305,6 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for ImplSubject<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for ImplSubject<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
@ -314,10 +312,10 @@ impl<'tcx> ToTrace<'tcx> for ImplSubject<'tcx> {
|
|||||||
) -> TypeTrace<'tcx> {
|
) -> TypeTrace<'tcx> {
|
||||||
match (a, b) {
|
match (a, b) {
|
||||||
(ImplSubject::Trait(trait_ref_a), ImplSubject::Trait(trait_ref_b)) => {
|
(ImplSubject::Trait(trait_ref_a), ImplSubject::Trait(trait_ref_b)) => {
|
||||||
ToTrace::to_trace(tcx, cause, a_is_expected, trait_ref_a, trait_ref_b)
|
ToTrace::to_trace(cause, a_is_expected, trait_ref_a, trait_ref_b)
|
||||||
}
|
}
|
||||||
(ImplSubject::Inherent(ty_a), ImplSubject::Inherent(ty_b)) => {
|
(ImplSubject::Inherent(ty_a), ImplSubject::Inherent(ty_b)) => {
|
||||||
ToTrace::to_trace(tcx, cause, a_is_expected, ty_a, ty_b)
|
ToTrace::to_trace(cause, a_is_expected, ty_a, ty_b)
|
||||||
}
|
}
|
||||||
(ImplSubject::Trait(_), ImplSubject::Inherent(_))
|
(ImplSubject::Trait(_), ImplSubject::Inherent(_))
|
||||||
| (ImplSubject::Inherent(_), ImplSubject::Trait(_)) => {
|
| (ImplSubject::Inherent(_), ImplSubject::Trait(_)) => {
|
||||||
@ -329,7 +327,6 @@ impl<'tcx> ToTrace<'tcx> for ImplSubject<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
_: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
@ -344,7 +341,6 @@ impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
_: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
@ -356,7 +352,6 @@ impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for Const<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for Const<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
_: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
@ -371,7 +366,6 @@ impl<'tcx> ToTrace<'tcx> for Const<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
_: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
@ -399,7 +393,6 @@ impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
_: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
@ -411,7 +404,6 @@ impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
_: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
@ -426,7 +418,6 @@ impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
_: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
@ -441,24 +432,17 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
|
|||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
b: Self,
|
b: Self,
|
||||||
) -> TypeTrace<'tcx> {
|
) -> TypeTrace<'tcx> {
|
||||||
let a_ty = tcx.mk_projection(a.def_id, a.substs);
|
TypeTrace { cause: cause.clone(), values: Aliases(ExpectedFound::new(a_is_expected, a, b)) }
|
||||||
let b_ty = tcx.mk_projection(b.def_id, b.substs);
|
|
||||||
TypeTrace {
|
|
||||||
cause: cause.clone(),
|
|
||||||
values: Terms(ExpectedFound::new(a_is_expected, a_ty.into(), b_ty.into())),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
|
impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
|
||||||
fn to_trace(
|
fn to_trace(
|
||||||
_: TyCtxt<'tcx>,
|
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
a_is_expected: bool,
|
a_is_expected: bool,
|
||||||
a: Self,
|
a: Self,
|
||||||
|
@ -1568,6 +1568,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
ValuePairs::TraitRefs(_) | ValuePairs::PolyTraitRefs(_) => {
|
ValuePairs::TraitRefs(_) | ValuePairs::PolyTraitRefs(_) => {
|
||||||
(false, Mismatch::Fixed("trait"))
|
(false, Mismatch::Fixed("trait"))
|
||||||
}
|
}
|
||||||
|
ValuePairs::Aliases(infer::ExpectedFound { expected, .. }) => {
|
||||||
|
(false, Mismatch::Fixed(self.tcx.def_descr(expected.def_id)))
|
||||||
|
}
|
||||||
ValuePairs::Regions(_) => (false, Mismatch::Fixed("lifetime")),
|
ValuePairs::Regions(_) => (false, Mismatch::Fixed("lifetime")),
|
||||||
};
|
};
|
||||||
let Some(vals) = self.values_str(values) else {
|
let Some(vals) = self.values_str(values) else {
|
||||||
@ -2124,6 +2127,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
match values {
|
match values {
|
||||||
infer::Regions(exp_found) => self.expected_found_str(exp_found),
|
infer::Regions(exp_found) => self.expected_found_str(exp_found),
|
||||||
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
|
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
|
||||||
|
infer::Aliases(exp_found) => self.expected_found_str(exp_found),
|
||||||
infer::TraitRefs(exp_found) => {
|
infer::TraitRefs(exp_found) => {
|
||||||
let pretty_exp_found = ty::error::ExpectedFound {
|
let pretty_exp_found = ty::error::ExpectedFound {
|
||||||
expected: exp_found.expected.print_only_trait_path(),
|
expected: exp_found.expected.print_only_trait_path(),
|
||||||
|
@ -338,6 +338,7 @@ pub struct InferCtxt<'tcx> {
|
|||||||
pub enum ValuePairs<'tcx> {
|
pub enum ValuePairs<'tcx> {
|
||||||
Regions(ExpectedFound<ty::Region<'tcx>>),
|
Regions(ExpectedFound<ty::Region<'tcx>>),
|
||||||
Terms(ExpectedFound<ty::Term<'tcx>>),
|
Terms(ExpectedFound<ty::Term<'tcx>>),
|
||||||
|
Aliases(ExpectedFound<ty::AliasTy<'tcx>>),
|
||||||
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
|
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
|
||||||
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
|
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
|
||||||
Sigs(ExpectedFound<ty::FnSig<'tcx>>),
|
Sigs(ExpectedFound<ty::FnSig<'tcx>>),
|
||||||
|
@ -71,6 +71,7 @@ use rustc_type_ir::WithCachedTypeInfo;
|
|||||||
use rustc_type_ir::{CollectAndApply, DynKind, Interner, TypeFlags};
|
use rustc_type_ir::{CollectAndApply, DynKind, Interner, TypeFlags};
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
use std::assert_matches::debug_assert_matches;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@ -2049,6 +2050,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> {
|
pub fn mk_alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> {
|
||||||
|
debug_assert_matches!(
|
||||||
|
(kind, self.def_kind(alias_ty.def_id)),
|
||||||
|
(ty::Opaque, DefKind::OpaqueTy)
|
||||||
|
| (ty::Projection, DefKind::AssocTy)
|
||||||
|
| (ty::Opaque | ty::Projection, DefKind::ImplTraitPlaceholder)
|
||||||
|
);
|
||||||
self.mk_ty_from_kind(Alias(kind, alias_ty))
|
self.mk_ty_from_kind(Alias(kind, alias_ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user