Skip to content

Commit cbf5f7d

Browse files
committedFeb 29, 2020
Use TypeRelating for instantiating query responses
1 parent 04e7f96 commit cbf5f7d

File tree

2 files changed

+111
-7
lines changed

2 files changed

+111
-7
lines changed
 

‎src/librustc_infer/infer/canonical/query_response.rs

+78-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ use crate::infer::canonical::{
1212
Canonical, CanonicalVarValues, CanonicalizedQueryResponse, Certainty, OriginalQueryValues,
1313
QueryOutlivesConstraint, QueryRegionConstraints, QueryResponse,
1414
};
15+
use crate::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate};
1516
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
16-
use crate::infer::InferCtxtBuilder;
17-
use crate::infer::{InferCtxt, InferOk, InferResult};
17+
use crate::infer::{InferCtxt, InferCtxtBuilder, InferOk, InferResult, NLLRegionVariableOrigin};
1818
use crate::traits::query::{Fallible, NoSolution};
19-
use crate::traits::TraitEngine;
19+
use crate::traits::{DomainGoal, TraitEngine};
2020
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
2121
use rustc::arena::ArenaAllocatable;
2222
use rustc::ty::fold::TypeFoldable;
23+
use rustc::ty::relate::TypeRelation;
2324
use rustc::ty::subst::{GenericArg, GenericArgKind};
2425
use rustc::ty::{self, BoundVar, Ty, TyCtxt};
2526
use rustc_data_structures::captures::Captures;
@@ -304,13 +305,31 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
304305
}
305306

306307
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
307-
let ok = self.at(cause, param_env).eq(v1, v2)?;
308-
obligations.extend(ok.into_obligations());
308+
TypeRelating::new(
309+
self,
310+
QueryTypeRelatingDelegate {
311+
infcx: self,
312+
param_env,
313+
cause,
314+
obligations: &mut obligations,
315+
},
316+
ty::Variance::Invariant,
317+
)
318+
.relate(&v1, &v2)?;
309319
}
310320

311321
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
312-
let ok = self.at(cause, param_env).eq(v1, v2)?;
313-
obligations.extend(ok.into_obligations());
322+
TypeRelating::new(
323+
self,
324+
QueryTypeRelatingDelegate {
325+
infcx: self,
326+
param_env,
327+
cause,
328+
obligations: &mut obligations,
329+
},
330+
ty::Variance::Invariant,
331+
)
332+
.relate(&v1, &v2)?;
314333
}
315334

316335
_ => {
@@ -656,3 +675,55 @@ pub fn make_query_region_constraints<'tcx>(
656675

657676
QueryRegionConstraints { outlives, member_constraints: member_constraints.clone() }
658677
}
678+
679+
struct QueryTypeRelatingDelegate<'a, 'tcx> {
680+
infcx: &'a InferCtxt<'a, 'tcx>,
681+
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
682+
param_env: ty::ParamEnv<'tcx>,
683+
cause: &'a ObligationCause<'tcx>,
684+
}
685+
686+
impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
687+
fn create_next_universe(&mut self) -> ty::UniverseIndex {
688+
self.infcx.create_next_universe()
689+
}
690+
691+
fn next_existential_region_var(&mut self, from_forall: bool) -> ty::Region<'tcx> {
692+
let origin = NLLRegionVariableOrigin::Existential { from_forall };
693+
self.infcx.next_nll_region_var(origin)
694+
}
695+
696+
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> {
697+
self.infcx.tcx.mk_region(ty::RePlaceholder(placeholder))
698+
}
699+
700+
fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> {
701+
self.infcx.next_nll_region_var_in_universe(
702+
NLLRegionVariableOrigin::Existential { from_forall: false },
703+
universe,
704+
)
705+
}
706+
707+
fn push_outlives(&mut self, sup: ty::Region<'tcx>, sub: ty::Region<'tcx>) {
708+
self.obligations.push(Obligation {
709+
cause: self.cause.clone(),
710+
param_env: self.param_env,
711+
predicate: ty::Predicate::RegionOutlives(ty::Binder::dummy(ty::OutlivesPredicate(
712+
sup, sub,
713+
))),
714+
recursion_depth: 0,
715+
});
716+
}
717+
718+
fn push_domain_goal(&mut self, _: DomainGoal<'tcx>) {
719+
bug!("should never be invoked with eager normalization")
720+
}
721+
722+
fn normalization() -> NormalizationStrategy {
723+
NormalizationStrategy::Eager
724+
}
725+
726+
fn forbid_inference_vars() -> bool {
727+
true
728+
}
729+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Regression test for issue #69490
2+
3+
// check-pass
4+
5+
pub trait Trait<T> {
6+
const S: &'static str;
7+
}
8+
9+
impl<T> Trait<()> for T
10+
where
11+
T: for<'a> Trait<&'a ()>,
12+
{
13+
// Use of `T::S` here caused an ICE
14+
const S: &'static str = T::S;
15+
}
16+
17+
// Some similar cases that didn't ICE:
18+
19+
impl<'a, T> Trait<()> for (T,)
20+
where
21+
T: Trait<&'a ()>,
22+
{
23+
const S: &'static str = T::S;
24+
}
25+
26+
impl<T> Trait<()> for [T; 1]
27+
where
28+
T: Trait<for<'a> fn(&'a ())>,
29+
{
30+
const S: &'static str = T::S;
31+
}
32+
33+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.