Skip to content

Commit 94639ca

Browse files
committed
rustfmt lowering.rs
1 parent 09bd6f3 commit 94639ca

File tree

1 file changed

+59
-50
lines changed

1 file changed

+59
-50
lines changed

src/librustc_traits/lowering.rs

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc::hir::{self, ImplPolarity};
1211
use rustc::hir::def_id::DefId;
1312
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
14-
use rustc::ty::{self, Slice, TyCtxt};
13+
use rustc::traits::{Clause, DomainGoal, Goal, PolyDomainGoal, ProgramClause, WhereClauseAtom};
1514
use rustc::ty::subst::Substs;
16-
use rustc::traits::{WhereClauseAtom, PolyDomainGoal, DomainGoal, ProgramClause, Clause, Goal};
17-
use syntax::ast;
15+
use rustc::ty::{self, Slice, TyCtxt};
1816
use rustc_data_structures::sync::Lrc;
17+
use syntax::ast;
18+
use syntax::ast;
1919

2020
use std::iter;
2121

@@ -24,7 +24,10 @@ trait Lower<T> {
2424
fn lower(&self) -> T;
2525
}
2626

27-
impl<T, U> Lower<Vec<U>> for Vec<T> where T: Lower<U> {
27+
impl<T, U> Lower<Vec<U>> for Vec<T>
28+
where
29+
T: Lower<U>,
30+
{
2831
fn lower(&self) -> Vec<U> {
2932
self.iter().map(|item| item.lower()).collect()
3033
}
@@ -42,7 +45,10 @@ impl<'tcx> Lower<WhereClauseAtom<'tcx>> for ty::ProjectionPredicate<'tcx> {
4245
}
4346
}
4447

45-
impl<'tcx, T> Lower<DomainGoal<'tcx>> for T where T: Lower<WhereClauseAtom<'tcx>> {
48+
impl<'tcx, T> Lower<DomainGoal<'tcx>> for T
49+
where
50+
T: Lower<WhereClauseAtom<'tcx>>,
51+
{
4652
fn lower(&self) -> DomainGoal<'tcx> {
4753
DomainGoal::Holds(self.lower())
4854
}
@@ -67,7 +73,8 @@ impl<'tcx> Lower<DomainGoal<'tcx>> for ty::TypeOutlivesPredicate<'tcx> {
6773
/// `forall<'a> { T: Fn(&'a i32) }` which corresponds to something like
6874
/// `Binder<Holds(Implemented(TraitPredicate))>`.
6975
impl<'tcx, T> Lower<PolyDomainGoal<'tcx>> for ty::Binder<T>
70-
where T: Lower<DomainGoal<'tcx>> + ty::fold::TypeFoldable<'tcx>
76+
where
77+
T: Lower<DomainGoal<'tcx>> + ty::fold::TypeFoldable<'tcx>,
7178
{
7279
fn lower(&self) -> PolyDomainGoal<'tcx> {
7380
self.map_bound_ref(|p| p.lower())
@@ -84,10 +91,9 @@ impl<'tcx> Lower<PolyDomainGoal<'tcx>> for ty::Predicate<'tcx> {
8491
TypeOutlives(predicate) => predicate.lower(),
8592
Projection(predicate) => predicate.lower(),
8693
WellFormed(ty) => ty::Binder::dummy(DomainGoal::WellFormedTy(*ty)),
87-
ObjectSafe(..) |
88-
ClosureKind(..) |
89-
Subtype(..) |
90-
ConstEvaluatable(..) => unimplemented!(),
94+
ObjectSafe(..) | ClosureKind(..) | Subtype(..) | ConstEvaluatable(..) => {
95+
unimplemented!()
96+
}
9197
}
9298
}
9399
}
@@ -104,44 +110,41 @@ impl<'tcx> IntoFromEnvGoal for DomainGoal<'tcx> {
104110
use self::DomainGoal::*;
105111
match self {
106112
Holds(wc_atom) => FromEnv(wc_atom),
107-
WellFormed(..) |
108-
FromEnv(..) |
109-
WellFormedTy(..) |
110-
FromEnvTy(..) |
111-
Normalize(..) |
112-
RegionOutlives(..) |
113-
TypeOutlives(..) => self,
113+
WellFormed(..) | FromEnv(..) | WellFormedTy(..) | FromEnvTy(..) | Normalize(..)
114+
| RegionOutlives(..) | TypeOutlives(..) => self,
114115
}
115116
}
116117
}
117118

118-
crate fn program_clauses_for<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
119-
-> Lrc<&'tcx Slice<Clause<'tcx>>>
120-
{
119+
crate fn program_clauses_for<'a, 'tcx>(
120+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
121+
def_id: DefId,
122+
) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
121123
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
122124
let node = tcx.hir.find(node_id).unwrap();
123125
match node {
124126
hir::map::Node::NodeItem(item) => match item.node {
125127
hir::ItemTrait(..) => program_clauses_for_trait(tcx, def_id),
126128
hir::ItemImpl(..) => program_clauses_for_impl(tcx, def_id),
127129
_ => Lrc::new(tcx.mk_clauses(iter::empty::<Clause>())),
128-
}
130+
},
129131
hir::map::Node::NodeImplItem(item) => {
130132
if let hir::ImplItemKind::Type(..) = item.node {
131133
program_clauses_for_associated_type_value(tcx, def_id)
132134
} else {
133135
Lrc::new(tcx.mk_clauses(iter::empty::<Clause>()))
134136
}
135-
},
137+
}
136138

137139
// FIXME: other constructions e.g. traits, associated types...
138140
_ => Lrc::new(tcx.mk_clauses(iter::empty::<Clause>())),
139141
}
140142
}
141143

142-
fn program_clauses_for_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
143-
-> Lrc<&'tcx Slice<Clause<'tcx>>>
144-
{
144+
fn program_clauses_for_trait<'a, 'tcx>(
145+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
146+
def_id: DefId,
147+
) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
145148
// `trait Trait<P1..Pn> where WC { .. } // P0 == Self`
146149

147150
// Rule Implemented-From-Env (see rustc guide)
@@ -156,8 +159,8 @@ fn program_clauses_for_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefI
156159
let trait_pred = ty::TraitPredicate {
157160
trait_ref: ty::TraitRef {
158161
def_id,
159-
substs: Substs::identity_for_item(tcx, def_id)
160-
}
162+
substs: Substs::identity_for_item(tcx, def_id),
163+
},
161164
};
162165
// `FromEnv(Self: Trait<P1..Pn>)`
163166
let from_env = Goal::from(DomainGoal::FromEnv(trait_pred.lower()));
@@ -169,9 +172,7 @@ fn program_clauses_for_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefI
169172
goal: impl_trait,
170173
hypotheses: tcx.mk_goals(iter::once(from_env)),
171174
};
172-
let clauses = iter::once(
173-
Clause::ForAll(ty::Binder::dummy(implemented_from_env))
174-
);
175+
let clauses = iter::once(Clause::ForAll(ty::Binder::dummy(implemented_from_env)));
175176

176177
// Rule Implied-Bound-From-Trait
177178
//
@@ -186,8 +187,8 @@ fn program_clauses_for_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefI
186187
// FIXME: Remove the [1..] slice; this is a hack because the query
187188
// predicates_of currently includes the trait itself (`Self: Trait<P1..Pn>`).
188189
let where_clauses = &tcx.predicates_of(def_id).predicates;
189-
let implied_bound_clauses =
190-
where_clauses[1..].into_iter()
190+
let implied_bound_clauses = where_clauses[1..]
191+
.into_iter()
191192
.map(|wc| implied_bound_from_trait(tcx, trait_pred, wc));
192193

193194
Lrc::new(tcx.mk_clauses(clauses.chain(implied_bound_clauses)))
@@ -203,17 +204,16 @@ fn implied_bound_from_trait<'a, 'tcx>(
203204
let impl_trait = DomainGoal::FromEnv(WhereClauseAtom::Implemented(trait_pred));
204205

205206
// `FromEnv(WC) :- FromEnv(Self: Trait<P1..Pn>)`
206-
Clause::ForAll(
207-
where_clause.lower().map_bound(|goal| ProgramClause {
208-
goal: goal.into_from_env_goal(),
209-
hypotheses: tcx.mk_goals(iter::once(Goal::from(impl_trait))),
210-
})
211-
)
207+
Clause::ForAll(where_clause.lower().map_bound(|goal| ProgramClause {
208+
goal: goal.into_from_env_goal(),
209+
hypotheses: tcx.mk_goals(iter::once(Goal::from(impl_trait))),
210+
}))
212211
}
213212

214-
fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
215-
-> Lrc<&'tcx Slice<Clause<'tcx>>>
216-
{
213+
fn program_clauses_for_impl<'a, 'tcx>(
214+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
215+
def_id: DefId,
216+
) -> Lrc<&'tcx Slice<Clause<'tcx>>> {
217217
if let ImplPolarity::Negative = tcx.impl_polarity(def_id) {
218218
return Lrc::new(tcx.mk_clauses(iter::empty::<Clause>()));
219219
}
@@ -231,15 +231,17 @@ fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId
231231
let trait_ref = tcx.impl_trait_ref(def_id).unwrap();
232232
// `Implemented(A0: Trait<A1..An>)`
233233
let trait_pred = ty::TraitPredicate { trait_ref }.lower();
234-
// `WC`
234+
// `WC`
235235
let where_clauses = tcx.predicates_of(def_id).predicates.lower();
236236

237-
// `Implemented(A0: Trait<A1..An>) :- WC`
237+
// `Implemented(A0: Trait<A1..An>) :- WC`
238238
let clause = ProgramClause {
239239
goal: trait_pred,
240240
hypotheses: tcx.mk_goals(
241-
where_clauses.into_iter().map(|wc| Goal::from_poly_domain_goal(wc, tcx))
242-
)
241+
where_clauses
242+
.into_iter()
243+
.map(|wc| Goal::from_poly_domain_goal(wc, tcx)),
244+
),
243245
};
244246
Lrc::new(tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::dummy(clause)))))
245247
}
@@ -290,7 +292,9 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>(
290292
let clause = ProgramClause {
291293
goal: normalize_goal,
292294
hypotheses: tcx.mk_goals(
293-
where_clauses.into_iter().map(|wc| Goal::from_poly_domain_goal(wc, tcx))
295+
where_clauses
296+
.into_iter()
297+
.map(|wc| Goal::from_poly_domain_goal(wc, tcx)),
294298
),
295299
};
296300
Lrc::new(tcx.mk_clauses(iter::once(Clause::ForAll(ty::Binder::dummy(clause)))))
@@ -302,14 +306,16 @@ pub fn dump_program_clauses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
302306
}
303307

304308
let mut visitor = ClauseDumper { tcx };
305-
tcx.hir.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
309+
tcx.hir
310+
.krate()
311+
.visit_all_item_likes(&mut visitor.as_deep_visitor());
306312
}
307313

308314
struct ClauseDumper<'a, 'tcx: 'a> {
309315
tcx: TyCtxt<'a, 'tcx, 'tcx>,
310316
}
311317

312-
impl<'a, 'tcx> ClauseDumper<'a, 'tcx > {
318+
impl<'a, 'tcx> ClauseDumper<'a, 'tcx> {
313319
fn process_attrs(&mut self, node_id: ast::NodeId, attrs: &[ast::Attribute]) {
314320
let def_id = self.tcx.hir.local_def_id(node_id);
315321
for attr in attrs {
@@ -321,7 +327,10 @@ impl<'a, 'tcx> ClauseDumper<'a, 'tcx > {
321327
Clause::Implies(program_clause) => program_clause,
322328
Clause::ForAll(program_clause) => program_clause.skip_binder(),
323329
};
324-
self.tcx.sess.struct_span_err(attr.span, &format!("{}", program_clause)).emit();
330+
self.tcx
331+
.sess
332+
.struct_span_err(attr.span, &format!("{}", program_clause))
333+
.emit();
325334
}
326335
}
327336
}

0 commit comments

Comments
 (0)