Skip to content

Commit adfab7d

Browse files
committed
review
1 parent 1bc6243 commit adfab7d

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

compiler/rustc_infer/src/infer/combine.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,16 @@ impl<'tcx> InferCtxt<'tcx> {
326326
) -> RelateResult<'tcx, ty::Const<'tcx>> {
327327
let span =
328328
self.inner.borrow_mut().const_unification_table().probe_value(target_vid).origin.span;
329-
let Generalization { value, needs_wf: _ } = generalize::generalize(
329+
// FIXME(generic_const_exprs): Occurs check failures for unevaluated
330+
// constants and generic expressions are not yet handled correctly.
331+
let Generalization { value_may_be_infer: value, needs_wf: _ } = generalize::generalize(
330332
self,
331333
&mut CombineDelegate { infcx: self, span, param_env },
332334
ct,
333335
target_vid,
334336
ty::Variance::Invariant,
335337
)?;
336338

337-
// FIXME(generic_const_exprs): Occurs check failures for unevaluated
338-
// constants and generic expressions are not yet handled correctly.
339-
let value = value.may_be_infer();
340-
341339
self.inner.borrow_mut().const_unification_table().union_value(
342340
target_vid,
343341
ConstVarValue {
@@ -449,7 +447,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
449447
// `'?2` and `?3` are fresh region/type inference
450448
// variables. (Down below, we will relate `a_ty <: b_ty`,
451449
// adding constraints like `'x: '?2` and `?1 <: ?3`.)
452-
let Generalization { value, needs_wf } = generalize::generalize(
450+
let Generalization { value_may_be_infer: b_ty, needs_wf } = generalize::generalize(
453451
self.infcx,
454452
&mut CombineDelegate {
455453
infcx: self.infcx,
@@ -461,7 +459,6 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
461459
ambient_variance,
462460
)?;
463461

464-
let b_ty = value.may_be_infer(); // we handle this further down.
465462
self.infcx.inner.borrow_mut().type_variables().instantiate(b_vid, b_ty);
466463

467464
if needs_wf {
@@ -501,6 +498,11 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
501498
}
502499
}
503500
}
501+
502+
// FIXME: This does not handle subtyping correctly, we should switch to
503+
// alias-relate in the new solver and could instead create a new inference
504+
// variable for `a_ty`, emitting `Projection(a_ty, a_infer)` and
505+
// `a_infer <: b_ty`.
504506
self.obligations.push(Obligation::new(
505507
self.tcx(),
506508
self.trace.cause.clone(),

compiler/rustc_infer/src/infer/generalize.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ pub(super) fn generalize<'tcx, D: GeneralizerDelegate<'tcx>, T: Into<Term<'tcx>>
4747
};
4848

4949
assert!(!term.has_escaping_bound_vars());
50-
let value = generalizer.relate(term, term)?;
50+
let value_may_be_infer = generalizer.relate(term, term)?;
5151
let needs_wf = generalizer.needs_wf;
52-
Ok(Generalization { value: HandleProjection(value), needs_wf })
52+
Ok(Generalization { value_may_be_infer, needs_wf })
5353
}
5454

5555
/// Abstracts the handling of region vars between HIR and MIR/NLL typechecking
@@ -500,20 +500,20 @@ where
500500
}
501501
}
502502

503-
#[derive(Debug)]
504-
pub(super) struct HandleProjection<T>(T);
505-
impl<T> HandleProjection<T> {
506-
pub(super) fn may_be_infer(self) -> T {
507-
self.0
508-
}
509-
}
510-
511503
/// Result from a generalization operation. This includes
512504
/// not only the generalized type, but also a bool flag
513505
/// indicating whether further WF checks are needed.
514506
#[derive(Debug)]
515507
pub(super) struct Generalization<T> {
516-
pub(super) value: HandleProjection<T>,
508+
/// When generalizing `<?0 as Trait>::Assoc` or
509+
/// `<T as Bar<<?0 as Foo>::Assoc>>::Assoc`
510+
/// for `?0` generalization returns an inference
511+
/// variable.
512+
///
513+
/// This has to be handled wotj care as it can
514+
/// otherwise very easily result in infinite
515+
/// recursion.
516+
pub(super) value_may_be_infer: T,
517517

518518
/// If true, then the generalized type may not be well-formed,
519519
/// even if the source type is well-formed, so we should add an

compiler/rustc_infer/src/infer/nll_relate/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,14 @@ where
217217
}
218218

219219
fn generalize(&mut self, ty: Ty<'tcx>, for_vid: ty::TyVid) -> RelateResult<'tcx, Ty<'tcx>> {
220-
let Generalization { value, needs_wf: _ } = generalize::generalize(
220+
let Generalization { value_may_be_infer: ty, needs_wf: _ } = generalize::generalize(
221221
self.infcx,
222222
&mut self.delegate,
223223
ty,
224224
for_vid,
225225
self.ambient_variance,
226226
)?;
227227

228-
let ty = value.may_be_infer();
229228
if ty.is_ty_var() {
230229
span_bug!(self.delegate.span(), "occurs check failure in MIR typeck");
231230
}

0 commit comments

Comments
 (0)