Skip to content

Commit ff83ef0

Browse files
committed
merge wellformed(wc)s
1 parent dabd3f6 commit ff83ef0

File tree

5 files changed

+24
-38
lines changed

5 files changed

+24
-38
lines changed

src/librustc_traits/lowering.rs

+17-25
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
1313
use rustc::hir::map::definitions::DefPathData;
1414
use rustc::hir::{self, ImplPolarity};
1515
use rustc::traits::{
16-
Clause, Clauses, DomainGoal, FromEnv, Goal, PolyDomainGoal, ProgramClause, WellFormed,
17-
WhereClause,
16+
Clause, Clauses, DomainGoal, Goal, PolyDomainGoal, ProgramClause, WhereClauseAtom,
1817
};
19-
use rustc::ty::query::Providers;
18+
use rustc::ty::subst::Substs;
2019
use rustc::ty::{self, Slice, TyCtxt};
2120
use rustc_data_structures::fx::FxHashSet;
2221
use std::mem;
@@ -278,21 +277,15 @@ fn program_clauses_for_trait<'a, 'tcx>(
278277
hypotheses,
279278
}))
280279
.map(|wc| implied_bound_from_trait(tcx, trait_pred, wc));
281-
let wellformed_clauses = where_clauses[1..]
282-
.into_iter()
283-
.map(|wc| wellformed_from_bound(tcx, trait_pred, wc));
284-
tcx.mk_clauses(
285-
clauses
286-
.chain(implied_bound_clauses)
287-
.chain(wellformed_clauses),
288-
)
280+
let wellformed_clauses = wellformed_from_bound(tcx, trait_pred, &where_clauses[1..]);
281+
tcx.mk_clauses(clauses.chain(implied_bound_clauses).chain(wellformed_clauses))
289282
}
290283

291284
fn wellformed_from_bound<'a, 'tcx>(
292285
tcx: TyCtxt<'a, 'tcx, 'tcx>,
293286
trait_pred: ty::TraitPredicate<'tcx>,
294-
where_clause: &ty::Predicate<'tcx>,
295-
) -> Clause<'tcx> {
287+
where_clauses: &[ty::Predicate<'tcx>],
288+
) -> iter::Once<Clause<'tcx>> {
296289
// Rule WellFormed-TraitRef
297290
//
298291
// For each where clause WC:
@@ -309,18 +302,17 @@ fn wellformed_from_bound<'a, 'tcx>(
309302
.lower()
310303
.map_bound(|wc| wc.into_wellformed_goal());
311304
// Implemented(Self: Trait<P1..Pn>) && WellFormed(WC)
312-
let mut where_clauses = vec![impl_trait];
313-
where_clauses.push(wellformed_wc);
314-
Clause::ForAll(where_clause.lower().map_bound(|_| {
315-
ProgramClause {
316-
goal: wellformed_trait,
317-
hypotheses: tcx.mk_goals(
318-
where_clauses
319-
.into_iter()
320-
.map(|wc| Goal::from_poly_domain_goal(wc, tcx)),
321-
),
322-
}
323-
}))
305+
let mut wcs = vec![impl_trait];
306+
wcs.extend(wellformed_wcs);
307+
308+
let clause = ProgramClause {
309+
goal: wellformed_trait,
310+
hypotheses: tcx.mk_goals(
311+
wcs.into_iter()
312+
.map(|wc| Goal::from_poly_domain_goal(wc, tcx)),
313+
),
314+
};
315+
iter::once(Clause::ForAll(ty::Binder::dummy(clause)))
324316
}
325317

326318
fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Clauses<'tcx> {

src/test/ui/chalkify/lower_env1.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
77
= note: FromEnv(Self: Foo) :- FromEnv(Self: Bar).
88
= note: FromEnv(Self: Foo) :- FromEnv(Self: Bar).
99
= note: Implemented(Self: Bar) :- FromEnv(Self: Bar).
10-
= note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Bar).
11-
= note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Foo).
10+
= note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Bar), WellFormed(Self: Foo).
1211

1312
error: program clause dump
1413
--> $DIR/lower_env1.rs:19:1
@@ -21,8 +20,9 @@ LL | #[rustc_dump_env_program_clauses] //~ ERROR program clause dump
2120
= note: Implemented(Self: Bar) :- FromEnv(Self: Bar).
2221
= note: Implemented(Self: Foo) :- FromEnv(Self: Foo).
2322
= note: Implemented(Self: std::marker::Sized) :- FromEnv(Self: std::marker::Sized).
24-
= note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Bar).
25-
= note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Foo).
23+
= note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Bar), WellFormed(Self: Foo).
24+
= note: WellFormed(Self: Foo) :- Implemented(Self: Foo).
25+
= note: WellFormed(Self: std::marker::Sized) :- Implemented(Self: std::marker::Sized).
2626

2727
error: aborting due to 2 previous errors
2828

src/test/ui/chalkify/lower_trait.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
88
= note: FromEnv(T: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
99
= note: FromEnv(U: std::marker::Sized) :- FromEnv(Self: Foo<S, T, U>).
1010
= note: Implemented(Self: Foo<S, T, U>) :- FromEnv(Self: Foo<S, T, U>).
11-
= note: WellFormed(Self: Foo<S, T, U>) :- Implemented(Self: Foo<S, T, U>), WellFormed(S: std::marker::Sized).
12-
= note: WellFormed(Self: Foo<S, T, U>) :- Implemented(Self: Foo<S, T, U>), WellFormed(T: std::marker::Sized).
13-
= note: WellFormed(Self: Foo<S, T, U>) :- Implemented(Self: Foo<S, T, U>), WellFormed(U: std::marker::Sized).
11+
= note: WellFormed(Self: Foo<S, T, U>) :- Implemented(Self: Foo<S, T, U>), WellFormed(S: std::marker::Sized), WellFormed(T: std::marker::Sized), WellFormed(U: std::marker::Sized).
1412

1513
error: aborting due to previous error
1614

src/test/ui/chalkify/lower_trait_higher_rank.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
1111
= note: WellFormed(Self: Foo<F>) :- Implemented(Self: Foo<F>), WellFormed(F: std::marker::Sized).
1212
= note: WellFormed(Self: Foo<F>) :- Implemented(Self: Foo<F>), forall<> { WellFormed(<F as std::ops::FnOnce<(&'a (u8, u16),)>>::Output == &'a u8) }.
1313
= note: WellFormed(Self: Foo<F>) :- Implemented(Self: Foo<F>), forall<> { WellFormed(F: std::ops::Fn<(&'a (u8, u16),)>) }.
14+
= note: WellFormed(Self: Foo<F>) :- Implemented(Self: Foo<F>), WellFormed(F: std::marker::Sized), forall<> { WellFormed(F: std::ops::Fn<(&'a (u8, u16),)>) }, forall<> { WellFormed(<F as std::ops::FnOnce<(&'a (u8, u16),)>>::Output == &'a u8) }.
1415

1516
error: aborting due to previous error
1617

src/test/ui/chalkify/lower_trait_where_clause.stderr

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump
1111
= note: Implemented(Self: Foo<'a, 'b, S, T, U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
1212
= note: RegionOutlives('a : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
1313
= note: TypeOutlives(U : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>).
14-
= note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), RegionOutlives('a : 'b).
15-
= note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), TypeOutlives(U : 'b).
16-
= note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(S: std::fmt::Debug).
17-
= note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(S: std::marker::Sized).
18-
= note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(T: std::borrow::Borrow<U>).
19-
= note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(T: std::marker::Sized).
14+
= note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(S: std::marker::Sized), WellFormed(T: std::marker::Sized), WellFormed(S: std::fmt::Debug), WellFormed(T: std::borrow::Borrow<U>), RegionOutlives('a : 'b), TypeOutlives(U : 'b).
2015

2116
error: aborting due to previous error
2217

0 commit comments

Comments
 (0)