From ff83ef0c24f866ff1b07fd27bbce5b931b9dc065 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Fri, 11 May 2018 18:32:51 +0800 Subject: [PATCH] merge wellformed(wc)s --- src/librustc_traits/lowering.rs | 42 ++++++++----------- src/test/ui/chalkify/lower_env1.stderr | 8 ++-- src/test/ui/chalkify/lower_trait.stderr | 4 +- .../chalkify/lower_trait_higher_rank.stderr | 1 + .../chalkify/lower_trait_where_clause.stderr | 7 +--- 5 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/librustc_traits/lowering.rs b/src/librustc_traits/lowering.rs index c8192f214186..cc12a2e1dcdf 100644 --- a/src/librustc_traits/lowering.rs +++ b/src/librustc_traits/lowering.rs @@ -13,10 +13,9 @@ use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::hir::map::definitions::DefPathData; use rustc::hir::{self, ImplPolarity}; use rustc::traits::{ - Clause, Clauses, DomainGoal, FromEnv, Goal, PolyDomainGoal, ProgramClause, WellFormed, - WhereClause, + Clause, Clauses, DomainGoal, Goal, PolyDomainGoal, ProgramClause, WhereClauseAtom, }; -use rustc::ty::query::Providers; +use rustc::ty::subst::Substs; use rustc::ty::{self, Slice, TyCtxt}; use rustc_data_structures::fx::FxHashSet; use std::mem; @@ -278,21 +277,15 @@ fn program_clauses_for_trait<'a, 'tcx>( hypotheses, })) .map(|wc| implied_bound_from_trait(tcx, trait_pred, wc)); - let wellformed_clauses = where_clauses[1..] - .into_iter() - .map(|wc| wellformed_from_bound(tcx, trait_pred, wc)); - tcx.mk_clauses( - clauses - .chain(implied_bound_clauses) - .chain(wellformed_clauses), - ) + let wellformed_clauses = wellformed_from_bound(tcx, trait_pred, &where_clauses[1..]); + tcx.mk_clauses(clauses.chain(implied_bound_clauses).chain(wellformed_clauses)) } fn wellformed_from_bound<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_pred: ty::TraitPredicate<'tcx>, - where_clause: &ty::Predicate<'tcx>, -) -> Clause<'tcx> { + where_clauses: &[ty::Predicate<'tcx>], +) -> iter::Once> { // Rule WellFormed-TraitRef // // For each where clause WC: @@ -309,18 +302,17 @@ fn wellformed_from_bound<'a, 'tcx>( .lower() .map_bound(|wc| wc.into_wellformed_goal()); // Implemented(Self: Trait) && WellFormed(WC) - let mut where_clauses = vec![impl_trait]; - where_clauses.push(wellformed_wc); - Clause::ForAll(where_clause.lower().map_bound(|_| { - ProgramClause { - goal: wellformed_trait, - hypotheses: tcx.mk_goals( - where_clauses - .into_iter() - .map(|wc| Goal::from_poly_domain_goal(wc, tcx)), - ), - } - })) + let mut wcs = vec![impl_trait]; + wcs.extend(wellformed_wcs); + + let clause = ProgramClause { + goal: wellformed_trait, + hypotheses: tcx.mk_goals( + wcs.into_iter() + .map(|wc| Goal::from_poly_domain_goal(wc, tcx)), + ), + }; + iter::once(Clause::ForAll(ty::Binder::dummy(clause))) } fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Clauses<'tcx> { diff --git a/src/test/ui/chalkify/lower_env1.stderr b/src/test/ui/chalkify/lower_env1.stderr index e32df036ef4b..e688d9e8b49e 100644 --- a/src/test/ui/chalkify/lower_env1.stderr +++ b/src/test/ui/chalkify/lower_env1.stderr @@ -7,8 +7,7 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump = note: FromEnv(Self: Foo) :- FromEnv(Self: Bar). = note: FromEnv(Self: Foo) :- FromEnv(Self: Bar). = note: Implemented(Self: Bar) :- FromEnv(Self: Bar). - = note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Bar). - = note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Foo). + = note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Bar), WellFormed(Self: Foo). error: program clause dump --> $DIR/lower_env1.rs:19:1 @@ -21,8 +20,9 @@ LL | #[rustc_dump_env_program_clauses] //~ ERROR program clause dump = note: Implemented(Self: Bar) :- FromEnv(Self: Bar). = note: Implemented(Self: Foo) :- FromEnv(Self: Foo). = note: Implemented(Self: std::marker::Sized) :- FromEnv(Self: std::marker::Sized). - = note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Bar). - = note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Foo). + = note: WellFormed(Self: Bar) :- Implemented(Self: Bar), WellFormed(Self: Bar), WellFormed(Self: Foo). + = note: WellFormed(Self: Foo) :- Implemented(Self: Foo). + = note: WellFormed(Self: std::marker::Sized) :- Implemented(Self: std::marker::Sized). error: aborting due to 2 previous errors diff --git a/src/test/ui/chalkify/lower_trait.stderr b/src/test/ui/chalkify/lower_trait.stderr index 4e03fc634cc5..c4e768415d60 100644 --- a/src/test/ui/chalkify/lower_trait.stderr +++ b/src/test/ui/chalkify/lower_trait.stderr @@ -8,9 +8,7 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump = note: FromEnv(T: std::marker::Sized) :- FromEnv(Self: Foo). = note: FromEnv(U: std::marker::Sized) :- FromEnv(Self: Foo). = note: Implemented(Self: Foo) :- FromEnv(Self: Foo). - = note: WellFormed(Self: Foo) :- Implemented(Self: Foo), WellFormed(S: std::marker::Sized). - = note: WellFormed(Self: Foo) :- Implemented(Self: Foo), WellFormed(T: std::marker::Sized). - = note: WellFormed(Self: Foo) :- Implemented(Self: Foo), WellFormed(U: std::marker::Sized). + = note: WellFormed(Self: Foo) :- Implemented(Self: Foo), WellFormed(S: std::marker::Sized), WellFormed(T: std::marker::Sized), WellFormed(U: std::marker::Sized). error: aborting due to previous error diff --git a/src/test/ui/chalkify/lower_trait_higher_rank.stderr b/src/test/ui/chalkify/lower_trait_higher_rank.stderr index 891f0453561e..ab86b6fdb258 100644 --- a/src/test/ui/chalkify/lower_trait_higher_rank.stderr +++ b/src/test/ui/chalkify/lower_trait_higher_rank.stderr @@ -11,6 +11,7 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump = note: WellFormed(Self: Foo) :- Implemented(Self: Foo), WellFormed(F: std::marker::Sized). = note: WellFormed(Self: Foo) :- Implemented(Self: Foo), forall<> { WellFormed(>::Output == &'a u8) }. = note: WellFormed(Self: Foo) :- Implemented(Self: Foo), forall<> { WellFormed(F: std::ops::Fn<(&'a (u8, u16),)>) }. + = note: WellFormed(Self: Foo) :- Implemented(Self: Foo), WellFormed(F: std::marker::Sized), forall<> { WellFormed(F: std::ops::Fn<(&'a (u8, u16),)>) }, forall<> { WellFormed(>::Output == &'a u8) }. error: aborting due to previous error diff --git a/src/test/ui/chalkify/lower_trait_where_clause.stderr b/src/test/ui/chalkify/lower_trait_where_clause.stderr index db5a795e3011..5ea397d424b6 100644 --- a/src/test/ui/chalkify/lower_trait_where_clause.stderr +++ b/src/test/ui/chalkify/lower_trait_where_clause.stderr @@ -11,12 +11,7 @@ LL | #[rustc_dump_program_clauses] //~ ERROR program clause dump = note: Implemented(Self: Foo<'a, 'b, S, T, U>) :- FromEnv(Self: Foo<'a, 'b, S, T, U>). = note: RegionOutlives('a : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>). = note: TypeOutlives(U : 'b) :- FromEnv(Self: Foo<'a, 'b, S, T, U>). - = note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), RegionOutlives('a : 'b). - = note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), TypeOutlives(U : 'b). - = note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(S: std::fmt::Debug). - = note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(S: std::marker::Sized). - = note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(T: std::borrow::Borrow). - = note: WellFormed(Self: Foo<'a, 'b, S, T, U>) :- Implemented(Self: Foo<'a, 'b, S, T, U>), WellFormed(T: std::marker::Sized). + = 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), RegionOutlives('a : 'b), TypeOutlives(U : 'b). error: aborting due to previous error