Skip to content

Commit 01ca85b

Browse files
committed
Auto merge of #55093 - nikomatsakis:nll-issue-54574-multisegment-path, r=pnkfelix
nll type annotations in multisegment path This turned out to be sort of tricky. The problem is that if you have a path like ``` <Foo<&'static u32>>::bar ``` and it comes from an impl like `impl<T> Foo<T>` then the self-type the user gave doesn't *directly* map to the substitutions that the impl wants. To handle this, then, we have to preserve not just the "user-given substs" we used to do, but also a "user-given self-ty", which we have to apply later. This PR makes those changes. It also removes the code from NLL relate-ops that handled canonical variables and moves to use normal inference variables instead. This simplifies a few things and gives us a bit more flexibility (for example, I predict we are going to have to start normalizing at some point, and it would be easy now). r? @matthewjasper -- you were just touching this code, do you feel comfortable reviewing this? Fixes #54574
2 parents bef62cc + b70b4a6 commit 01ca85b

31 files changed

+1260
-848
lines changed

Diff for: src/librustc/ich/impls_mir.rs

+21
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,24 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::ClosureOutlivesSubj
587587
}
588588

589589
impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted });
590+
591+
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::UserTypeAnnotation<'gcx> {
592+
fn hash_stable<W: StableHasherResult>(&self,
593+
hcx: &mut StableHashingContext<'a>,
594+
hasher: &mut StableHasher<W>) {
595+
mem::discriminant(self).hash_stable(hcx, hasher);
596+
match *self {
597+
mir::UserTypeAnnotation::Ty(ref ty) => {
598+
ty.hash_stable(hcx, hasher);
599+
}
600+
mir::UserTypeAnnotation::FnDef(ref def_id, ref substs) => {
601+
def_id.hash_stable(hcx, hasher);
602+
substs.hash_stable(hcx, hasher);
603+
}
604+
mir::UserTypeAnnotation::AdtDef(ref def_id, ref substs) => {
605+
def_id.hash_stable(hcx, hasher);
606+
substs.hash_stable(hcx, hasher);
607+
}
608+
}
609+
}
610+
}

Diff for: src/librustc/ich/impls_ty.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1417,3 +1417,8 @@ impl_stable_hash_for!(enum traits::QuantifierKind {
14171417
Universal,
14181418
Existential
14191419
});
1420+
1421+
impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty });
1422+
1423+
impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty });
1424+

Diff for: src/librustc/infer/canonical/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,14 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
241241
/// canonicalized) then represents the values that you computed
242242
/// for each of the canonical inputs to your query.
243243
244-
pub(in infer) fn instantiate_canonical_with_fresh_inference_vars<T>(
244+
pub fn instantiate_canonical_with_fresh_inference_vars<T>(
245245
&self,
246246
span: Span,
247247
canonical: &Canonical<'tcx, T>,
248248
) -> (T, CanonicalVarValues<'tcx>)
249249
where
250250
T: TypeFoldable<'tcx>,
251251
{
252-
assert_eq!(self.universe(), ty::UniverseIndex::ROOT, "infcx not newly created");
253-
assert_eq!(self.type_variables.borrow().num_vars(), 0, "infcx not newly created");
254-
255252
let canonical_inference_vars =
256253
self.fresh_inference_vars_for_canonical_vars(span, canonical.variables);
257254
let result = canonical.substitute(self.tcx, &canonical_inference_vars);

Diff for: src/librustc/infer/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod higher_ranked;
6262
pub mod lattice;
6363
mod lexical_region_resolve;
6464
mod lub;
65+
pub mod nll_relate;
6566
pub mod opaque_types;
6667
pub mod outlives;
6768
pub mod region_constraints;

0 commit comments

Comments
 (0)