Skip to content

Commit ec73624

Browse files
committed
Return an instantiated environment instead of a generic one
1 parent 8cadd59 commit ec73624

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

src/librustc/ty/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ define_queries! { <'tcx>
684684
) -> Clauses<'tcx>,
685685

686686
// Get the chalk-style environment of the given item.
687-
[] fn environment: Environment(DefId) -> ty::Binder<traits::Environment<'tcx>>,
687+
[] fn environment: Environment(DefId) -> traits::Environment<'tcx>,
688688
},
689689

690690
Linking {

src/librustc_traits/chalk_context/program_clauses.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
256256
) -> Vec<Clause<'tcx>> {
257257
use rustc::traits::WhereClause::*;
258258

259+
debug!("program_clauses(goal = {:?})", goal);
260+
259261
let mut clauses = match goal {
260262
DomainGoal::Holds(Implemented(trait_predicate)) => {
261263
// These come from:
@@ -345,20 +347,21 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
345347
self.infcx.tcx.program_clauses_for(data.item_def_id)
346348
}
347349

348-
// These types are always WF and non-parametric.
350+
// These types are always WF.
349351
ty::Bool |
350352
ty::Char |
351353
ty::Int(..) |
352354
ty::Uint(..) |
353355
ty::Float(..) |
354356
ty::Str |
357+
ty::Param(..) |
355358
ty::Never => {
356359
let wf_clause = ProgramClause {
357360
goal: DomainGoal::WellFormed(WellFormed::Ty(ty)),
358361
hypotheses: ty::List::empty(),
359362
category: ProgramClauseCategory::WellFormed,
360363
};
361-
let wf_clause = Clause::ForAll(ty::Binder::dummy(wf_clause));
364+
let wf_clause = Clause::Implies(wf_clause);
362365

363366
self.infcx.tcx.mk_clauses(iter::once(wf_clause))
364367
}
@@ -415,7 +418,6 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
415418
ty::UnnormalizedProjection(..) |
416419
ty::Infer(..) |
417420
ty::Bound(..) |
418-
ty::Param(..) |
419421
ty::Error => {
420422
bug!("unexpected type {:?}", ty)
421423
}
@@ -458,13 +460,18 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
458460
}
459461
};
460462

463+
debug!("program_clauses: clauses = {:?}", clauses);
464+
debug!("program_clauses: adding clauses from environment = {:?}", environment);
465+
461466
let environment = self.infcx.tcx.lift_to_global(environment)
462467
.expect("environment is not global");
463-
clauses.extend(
464-
self.infcx.tcx.program_clauses_for_env(environment)
465-
.into_iter()
466-
.cloned()
467-
);
468+
469+
let env_clauses = self.infcx.tcx.program_clauses_for_env(environment);
470+
471+
debug!("program_clauses: env_clauses = {:?}", env_clauses);
472+
473+
clauses.extend(env_clauses.into_iter().cloned());
474+
clauses.extend(environment.clauses.iter().cloned());
468475
clauses
469476
}
470477
}

src/librustc_traits/lowering/environment.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ impl ClauseVisitor<'set, 'a, 'tcx> {
105105
ty::Never |
106106
ty::Infer(..) |
107107
ty::Placeholder(..) |
108+
ty::Param(..) |
108109
ty::Bound(..) => (),
109110

110111
ty::GeneratorWitness(..) |
111112
ty::UnnormalizedProjection(..) |
112-
ty::Param(..) |
113113
ty::Error => {
114114
bug!("unexpected type {:?}", ty);
115115
}
@@ -192,25 +192,23 @@ crate fn program_clauses_for_env<'a, 'tcx>(
192192
crate fn environment<'a, 'tcx>(
193193
tcx: TyCtxt<'a, 'tcx, 'tcx>,
194194
def_id: DefId
195-
) -> ty::Binder<Environment<'tcx>> {
195+
) -> Environment<'tcx> {
196196
use super::{Lower, IntoFromEnvGoal};
197197
use rustc::hir::{Node, TraitItemKind, ImplItemKind, ItemKind, ForeignItemKind};
198-
use rustc::ty::subst::{Subst, Substs};
198+
199+
debug!("environment(def_id = {:?})", def_id);
199200

200201
// The environment of an impl Trait type is its defining function's environment.
201202
if let Some(parent) = ty::is_impl_trait_defn(tcx, def_id) {
202203
return environment(tcx, parent);
203204
}
204205

205-
let bound_vars = Substs::bound_vars_for_item(tcx, def_id);
206-
207206
// Compute the bounds on `Self` and the type parameters.
208207
let ty::InstantiatedPredicates { predicates } = tcx.predicates_of(def_id)
209208
.instantiate_identity(tcx);
210209

211210
let clauses = predicates.into_iter()
212211
.map(|predicate| predicate.lower())
213-
.map(|predicate| predicate.subst(tcx, bound_vars))
214212
.map(|domain_goal| domain_goal.map_bound(|bound| bound.into_from_env_goal()))
215213
.map(|domain_goal| domain_goal.map_bound(|bound| bound.into_program_clause()))
216214

@@ -255,20 +253,18 @@ crate fn environment<'a, 'tcx>(
255253
// are well-formed.
256254
if is_impl {
257255
let trait_ref = tcx.impl_trait_ref(def_id)
258-
.expect("not an impl")
259-
.subst(tcx, bound_vars);
256+
.expect("not an impl");
260257

261258
input_tys.extend(
262-
trait_ref.substs.types().flat_map(|ty| ty.walk())
259+
trait_ref.input_types().flat_map(|ty| ty.walk())
263260
);
264261
}
265262

266263
// In an fn, we assume that the arguments and all their constituents are
267264
// well-formed.
268265
if is_fn {
269-
// `skip_binder` because we move region parameters to the root binder,
270-
// restored in the return type of this query
271-
let fn_sig = tcx.fn_sig(def_id).skip_binder().subst(tcx, bound_vars);
266+
let fn_sig = tcx.fn_sig(def_id);
267+
let fn_sig = tcx.liberate_late_bound_regions(def_id, &fn_sig);
272268

273269
input_tys.extend(
274270
fn_sig.inputs().iter().flat_map(|ty| ty.walk())
@@ -277,17 +273,14 @@ crate fn environment<'a, 'tcx>(
277273

278274
let clauses = clauses.chain(
279275
input_tys.into_iter()
280-
// Filter out type parameters
281-
.filter(|ty| match ty.sty {
282-
ty::Bound(..) => false,
283-
_ => true,
284-
})
285276
.map(|ty| DomainGoal::FromEnv(FromEnv::Ty(ty)))
286277
.map(|domain_goal| domain_goal.into_program_clause())
287278
.map(Clause::Implies)
288279
);
289280

290-
ty::Binder::bind(Environment {
281+
debug!("environment: clauses = {:?}", clauses);
282+
283+
Environment {
291284
clauses: tcx.mk_clauses(clauses),
292-
})
285+
}
293286
}

src/librustc_traits/lowering/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl<'a, 'tcx> ClauseDumper<'a, 'tcx> {
626626

627627
if attr.check_name("rustc_dump_env_program_clauses") {
628628
let environment = self.tcx.environment(def_id);
629-
clauses = Some(self.tcx.program_clauses_for_env(*environment.skip_binder()));
629+
clauses = Some(self.tcx.program_clauses_for_env(environment));
630630
}
631631

632632
if let Some(clauses) = clauses {

0 commit comments

Comments
 (0)