Skip to content

Commit a6e4db2

Browse files
cursed
1 parent 6578893 commit a6e4db2

File tree

3 files changed

+58
-14
lines changed

3 files changed

+58
-14
lines changed

compiler/rustc_infer/src/infer/at.rs

+23
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,29 @@ impl<'tcx> ToTrace<'tcx> for Const<'tcx> {
368368
}
369369
}
370370

371+
impl<'tcx> ToTrace<'tcx> for GenericArg<'tcx> {
372+
fn to_trace(
373+
tcx: TyCtxt<'tcx>,
374+
cause: &ObligationCause<'tcx>,
375+
a_is_expected: bool,
376+
a: Self,
377+
b: Self,
378+
) -> TypeTrace<'tcx> {
379+
match (a.unpack(), b.unpack()) {
380+
(GenericArgKind::Type(a), GenericArgKind::Type(b)) => {
381+
<_>::to_trace(tcx, cause, a_is_expected, a, b)
382+
}
383+
(GenericArgKind::Lifetime(a), GenericArgKind::Lifetime(b)) => {
384+
<_>::to_trace(tcx, cause, a_is_expected, a, b)
385+
}
386+
(GenericArgKind::Const(a), GenericArgKind::Const(b)) => {
387+
<_>::to_trace(tcx, cause, a_is_expected, a, b)
388+
}
389+
_ => bug!("cannot trace GenericArgs of different kinds"),
390+
}
391+
}
392+
}
393+
371394
impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
372395
fn to_trace(
373396
_: TyCtxt<'tcx>,

compiler/rustc_typeck/src/check/expr.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16561656
self.resolve_vars_if_possible(fresh_base_ty),
16571657
|_| {},
16581658
);
1659+
// ...
1660+
let variances = tcx.variances_of(adt.did());
1661+
let constrained_substs = self.resolve_vars_with_obligations(fresh_substs);
1662+
for i in 0..substs.len() {
1663+
if constrained_substs[i] == fresh_substs[i] {
1664+
match self.at(&self.misc(base_expr.span), self.param_env).relate(
1665+
substs[i],
1666+
variances[i],
1667+
constrained_substs[i],
1668+
) {
1669+
Ok(InferOk { obligations, value: () }) => {
1670+
self.register_predicates(obligations)
1671+
}
1672+
Err(_) => {
1673+
bug!();
1674+
}
1675+
}
1676+
}
1677+
}
16591678
fru_tys
16601679
} else {
16611680
// Check the base_expr, regardless of a bad expected adt_ty, so we can get

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,40 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8080
/// version (resolve_vars_if_possible), this version will
8181
/// also select obligations if it seems useful, in an effort
8282
/// to get more type information.
83-
pub(in super::super) fn resolve_vars_with_obligations(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
84-
self.resolve_vars_with_obligations_and_mutate_fulfillment(ty, |_| {})
83+
pub(in super::super) fn resolve_vars_with_obligations<T: TypeFoldable<'tcx>>(&self, t: T) -> T {
84+
self.resolve_vars_with_obligations_and_mutate_fulfillment(t, |_| {})
8585
}
8686

8787
#[instrument(skip(self, mutate_fulfillment_errors), level = "debug")]
88-
pub(in super::super) fn resolve_vars_with_obligations_and_mutate_fulfillment(
88+
pub(in super::super) fn resolve_vars_with_obligations_and_mutate_fulfillment<
89+
T: TypeFoldable<'tcx>,
90+
>(
8991
&self,
90-
mut ty: Ty<'tcx>,
92+
mut t: T,
9193
mutate_fulfillment_errors: impl Fn(&mut Vec<traits::FulfillmentError<'tcx>>),
92-
) -> Ty<'tcx> {
94+
) -> T {
9395
// No Infer()? Nothing needs doing.
94-
if !ty.has_infer_types_or_consts() {
96+
if !t.has_infer_types_or_consts() {
9597
debug!("no inference var, nothing needs doing");
96-
return ty;
98+
return t;
9799
}
98100

99101
// If `ty` is a type variable, see whether we already know what it is.
100-
ty = self.resolve_vars_if_possible(ty);
101-
if !ty.has_infer_types_or_consts() {
102-
debug!(?ty);
103-
return ty;
102+
t = self.resolve_vars_if_possible(t);
103+
if !t.has_infer_types_or_consts() {
104+
debug!(?t);
105+
return t;
104106
}
105107

106108
// If not, try resolving pending obligations as much as
107109
// possible. This can help substantially when there are
108110
// indirect dependencies that don't seem worth tracking
109111
// precisely.
110112
self.select_obligations_where_possible(false, mutate_fulfillment_errors);
111-
ty = self.resolve_vars_if_possible(ty);
113+
t = self.resolve_vars_if_possible(t);
112114

113-
debug!(?ty);
114-
ty
115+
debug!(?t);
116+
t
115117
}
116118

117119
pub(in super::super) fn record_deferred_call_resolution(

0 commit comments

Comments
 (0)