Skip to content

Commit 5dfb505

Browse files
author
Alexander Regueiro
committed
Ran rustfmt.
1 parent 0155e75 commit 5dfb505

File tree

7 files changed

+102
-125
lines changed

7 files changed

+102
-125
lines changed

src/librustc_codegen_ssa/base.rs

+15-22
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ pub fn unsized_info<'tcx, 'a, Bx: BuilderMethods<'a, 'tcx>>(
166166
let target_ptr = if let Some(target_trait_ref) = target_data.principal() {
167167
// Find the offset of the supertrait's vtable within the subtrait (parent) vtable.
168168
let trait_ref = target_trait_ref.with_self_ty(tcx, source);
169-
let vtable = tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref))
169+
let vtable = tcx
170+
.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref))
170171
.unwrap_or_else(|| bug!("unsized_info: vtable not found"));
171172
let offset = match vtable {
172173
Vtable::VtableObject(ref data) => data.vtable_base,
@@ -271,19 +272,14 @@ pub fn coerce_ptr_unsized<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
271272
// existing vtable. See the `get_vtable` fn in `meth.rs` for more details of vtable
272273
// layout.
273274

274-
let base = bx.pointercast(
275-
base,
276-
bx.cx().scalar_pair_element_backend_type(dst, 0, true),
277-
);
275+
let base = bx.pointercast(base, bx.cx().scalar_pair_element_backend_type(dst, 0, true));
278276
let info = match (&src.ty.kind, &dst.ty.kind) {
279-
(&ty::Ref(_, a, _),
280-
&ty::Ref(_, b, _)) |
281-
(&ty::Ref(_, a, _),
282-
&ty::RawPtr(ty::TypeAndMut { ty: b, .. })) |
283-
(&ty::RawPtr(ty::TypeAndMut { ty: a, .. }),
284-
&ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
285-
unsized_info(bx, a, b, Some(info))
286-
}
277+
(&ty::Ref(_, a, _), &ty::Ref(_, b, _))
278+
| (&ty::Ref(_, a, _), &ty::RawPtr(ty::TypeAndMut { ty: b, .. }))
279+
| (
280+
&ty::RawPtr(ty::TypeAndMut { ty: a, .. }),
281+
&ty::RawPtr(ty::TypeAndMut { ty: b, .. }),
282+
) => unsized_info(bx, a, b, Some(info)),
287283
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
288284
assert_eq!(def_a, def_b);
289285

@@ -313,17 +309,14 @@ pub fn coerce_ptr_unsized<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
313309
// HACK(eddyb) have to bitcast pointers until LLVM removes pointee types.
314310
// FIXME(eddyb) move these out of this `match` arm, so they're always
315311
// applied, uniformly, no matter the source/destination types.
316-
(bx.bitcast(base, bx.cx().scalar_pair_element_backend_type(dst, 0, true)),
317-
bx.bitcast(info, bx.cx().scalar_pair_element_backend_type(dst, 1, true)))
318-
}
319-
OperandValue::Immediate(base) => {
320-
unsize_thin_ptr(bx, base, src.ty, dst.ty)
312+
(
313+
bx.bitcast(base, bx.cx().scalar_pair_element_backend_type(dst, 0, true)),
314+
bx.bitcast(info, bx.cx().scalar_pair_element_backend_type(dst, 1, true)),
315+
)
321316
}
317+
OperandValue::Immediate(base) => unsize_thin_ptr(bx, base, src.ty, dst.ty),
322318
OperandValue::Ref(..) => {
323-
bug!(
324-
"coerce_ptr_unsized: unexpected by-ref operand {:?}",
325-
op
326-
);
319+
bug!("coerce_ptr_unsized: unexpected by-ref operand {:?}", op);
327320
}
328321
};
329322
OperandValue::Pair(base, info)

src/librustc_infer/infer/error_reporting/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1588,9 +1588,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15881588
self.suggest_as_ref_where_appropriate(span, &exp_found, diag);
15891589

15901590
if let &TypeError::Traits(ref exp_found_traits) = terr {
1591-
self.note_enable_trait_upcasting_where_appropriate(
1592-
&exp_found_traits, diag
1593-
);
1591+
self.note_enable_trait_upcasting_where_appropriate(&exp_found_traits, diag);
15941592
}
15951593
}
15961594

@@ -1686,7 +1684,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16861684
if supertraits.into_iter().any(|trait_ref| trait_ref.def_id() == exp_found.expected) {
16871685
diag.note(
16881686
"add `#![feature(trait_upcasting)]` to the crate attributes to enable \
1689-
trait upcasting");
1687+
trait upcasting",
1688+
);
16901689
}
16911690
}
16921691

src/librustc_infer/traits/util.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@ pub fn elaborate_obligations<'tcx>(
138138
) -> Elaborator<'tcx> {
139139
let mut visited = PredicateSet::new(tcx);
140140
obligations.retain(|obligation| visited.insert(&obligation.predicate));
141-
Elaborator {
142-
stack: obligations,
143-
visited,
144-
allow_repetitions: false,
145-
}
141+
Elaborator { stack: obligations, visited, allow_repetitions: false }
146142
}
147143

148144
fn predicate_obligation<'tcx>(
@@ -153,12 +149,7 @@ fn predicate_obligation<'tcx>(
153149
if let Some(span) = span {
154150
cause.span = span;
155151
}
156-
Obligation {
157-
cause,
158-
param_env: ty::ParamEnv::empty(),
159-
recursion_depth: 0,
160-
predicate,
161-
}
152+
Obligation { cause, param_env: ty::ParamEnv::empty(), recursion_depth: 0, predicate }
162153
}
163154

164155
impl Elaborator<'tcx> {
@@ -187,8 +178,9 @@ impl Elaborator<'tcx> {
187178
// cases. One common case is when people define
188179
// `trait Sized: Sized { }` rather than `trait Sized { }`.
189180
let visited = &mut self.visited;
190-
let obligations =
191-
obligations.filter(|obligation| allow_repetitions || visited.insert(&obligation.predicate));
181+
let obligations = obligations.filter(|obligation| {
182+
allow_repetitions || visited.insert(&obligation.predicate)
183+
});
192184

193185
self.stack.extend(obligations);
194186
}

src/librustc_mir/interpret/traits.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5858
let vtable = self.memory.allocate(
5959
// Compute size of vtable, including 3 entries per supertrait for (drop, size, align)
6060
// metadata.
61-
ptr_size * (
62-
methods
61+
ptr_size
62+
* (methods
6363
.iter()
6464
.map(|l| u64::try_from(l.len()).unwrap().checked_add(3).unwrap())
65-
.sum()
66-
),
65+
.sum()),
6766
ptr_align,
6867
MemoryKind::Vtable,
6968
);
@@ -73,9 +72,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7372
// one pointer size each time.
7473
let mut cur_ptr = vtable;
7574
let mut write_ptr = |memory: &mut Memory<'mir, 'tcx, M>, val| -> InterpResult<'_> {
76-
let res = memory
77-
.get_raw_mut(cur_ptr.alloc_id)?
78-
.write_ptr_sized(tcx, cur_ptr, val)?;
75+
let res = memory.get_raw_mut(cur_ptr.alloc_id)?.write_ptr_sized(tcx, cur_ptr, val)?;
7976
cur_ptr = cur_ptr.offset(ptr_size, tcx)?;
8077
Ok(res)
8178
};

src/librustc_trait_selection/traits/mod.rs

+45-46
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ pub use self::util::{
6666
get_vtable_index_of_object_method, impl_item_is_final, predicate_for_trait_def, upcast_choices,
6767
};
6868
pub use self::util::{
69-
supertraits, supertraits_with_repetitions, supertrait_def_ids, transitive_bounds, Supertraits,
70-
SupertraitDefIds,
69+
supertrait_def_ids, supertraits, supertraits_with_repetitions, transitive_bounds,
70+
SupertraitDefIds, Supertraits,
7171
};
7272

7373
pub use rustc_infer::traits::*;
@@ -472,52 +472,51 @@ fn vtable_methods<'tcx>(
472472
) -> &'tcx [&'tcx [Option<(DefId, SubstsRef<'tcx>)>]] {
473473
debug!("vtable_methods({:?})", trait_ref);
474474

475-
tcx.arena.alloc_from_iter(supertraits_with_repetitions(tcx, trait_ref)
476-
.map(move |trait_ref| {
477-
let trait_methods = tcx
478-
.associated_items(trait_ref.def_id())
479-
.in_definition_order()
480-
.filter(|item| item.kind == ty::AssocKind::Fn);
481-
482-
// Now, list each method's `DefId` and `InternalSubsts` (for within its trait).
483-
// If the method can never be called from this object, produce `None`.
484-
&*tcx.arena.alloc_from_iter(trait_methods.map(move |trait_method| {
485-
debug!("vtable_methods: trait_method={:?}", trait_method);
486-
let def_id = trait_method.def_id;
487-
488-
// Some methods cannot be called on an object; skip those.
489-
if !is_vtable_safe_method(tcx, trait_ref.def_id(), &trait_method) {
490-
debug!("vtable_methods: not vtable safe");
491-
return None;
492-
}
475+
tcx.arena.alloc_from_iter(supertraits_with_repetitions(tcx, trait_ref).map(move |trait_ref| {
476+
let trait_methods = tcx
477+
.associated_items(trait_ref.def_id())
478+
.in_definition_order()
479+
.filter(|item| item.kind == ty::AssocKind::Fn);
480+
481+
// Now, list each method's `DefId` and `InternalSubsts` (for within its trait).
482+
// If the method can never be called from this object, produce `None`.
483+
&*tcx.arena.alloc_from_iter(trait_methods.map(move |trait_method| {
484+
debug!("vtable_methods: trait_method={:?}", trait_method);
485+
let def_id = trait_method.def_id;
486+
487+
// Some methods cannot be called on an object; skip those.
488+
if !is_vtable_safe_method(tcx, trait_ref.def_id(), &trait_method) {
489+
debug!("vtable_methods: not vtable safe");
490+
return None;
491+
}
493492

494-
// The method may have some early-bound lifetimes; add regions for those.
495-
let substs = trait_ref.map_bound(|trait_ref| {
496-
InternalSubsts::for_item(tcx, def_id, |param, _| match param.kind {
497-
GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
498-
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => {
499-
trait_ref.substs[param.index as usize]
500-
}
501-
})
502-
});
503-
504-
// The trait type may have higher-ranked lifetimes in it;
505-
// erase them if they appear, so that we get the type
506-
// at some particular call site.
507-
let substs =
508-
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &substs);
509-
510-
// It's possible that the method relies on where-clauses that
511-
// do not hold for this particular set of type parameters.
512-
// Note that this method could then never be called, so we
513-
// do not want to try and codegen it, in that case (see #23435).
514-
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
515-
if !normalize_and_test_predicates(tcx, predicates.predicates) {
516-
debug!("vtable_methods: predicates do not hold");
517-
return None;
518-
}
493+
// The method may have some early-bound lifetimes; add regions for those.
494+
let substs = trait_ref.map_bound(|trait_ref| {
495+
InternalSubsts::for_item(tcx, def_id, |param, _| match param.kind {
496+
GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
497+
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const => {
498+
trait_ref.substs[param.index as usize]
499+
}
500+
})
501+
});
502+
503+
// The trait type may have higher-ranked lifetimes in it;
504+
// erase them if they appear, so that we get the type
505+
// at some particular call site.
506+
let substs =
507+
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &substs);
508+
509+
// It's possible that the method relies on where-clauses that
510+
// do not hold for this particular set of type parameters.
511+
// Note that this method could then never be called, so we
512+
// do not want to try and codegen it, in that case (see #23435).
513+
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
514+
if !normalize_and_test_predicates(tcx, predicates.predicates) {
515+
debug!("vtable_methods: predicates do not hold");
516+
return None;
517+
}
519518

520-
Some((def_id, substs))
519+
Some((def_id, substs))
521520
}))
522521
}))
523522
}

src/librustc_trait_selection/traits/select.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -1868,8 +1868,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18681868
true
18691869
} else {
18701870
// Just allow upcast kinds 2 and 3 from above.
1871-
data_a.principal_def_id() == data_b.principal_def_id() &&
1872-
data_b.auto_traits()
1871+
data_a.principal_def_id() == data_b.principal_def_id()
1872+
&& data_b
1873+
.auto_traits()
18731874
// All of a's auto traits need to be in b's auto traits.
18741875
.all(|b| data_a.auto_traits().any(|a| a == b))
18751876
}
@@ -2695,27 +2696,30 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26952696
// where we can unify, because otherwise select would have
26962697
// reported an ambiguity. (When we do find a match, also
26972698
// record it for later.)
2698-
let nonmatching = util::supertraits_with_repetitions(tcx, poly_trait_ref)
2699-
.take_while(
2700-
|&trait_ref| match self.infcx.commit_if_ok(
2701-
|_| self.match_poly_trait_ref(obligation, trait_ref)
2702-
) {
2699+
let nonmatching =
2700+
util::supertraits_with_repetitions(tcx, poly_trait_ref).take_while(|&trait_ref| {
2701+
match self
2702+
.infcx
2703+
.commit_if_ok(|_| self.match_poly_trait_ref(obligation, trait_ref))
2704+
{
27032705
Ok(obligations) => {
27042706
upcast_trait_ref = Some(trait_ref);
27052707
nested.extend(obligations);
27062708
false
27072709
}
27082710
Err(_) => true,
2709-
},
2710-
);
2711+
}
2712+
});
27112713

27122714
// Additionally, for each of the non-matching predicates that
27132715
// we pass over, we sum up the set of number of vtable
27142716
// entries, so that we can compute the offset for the selected
27152717
// trait.
27162718
vtable_base = nonmatching
27172719
// Skip 3 entries in vtable per supertrait for `(drop, size, align)` metadata.
2718-
.map(|trait_ref| util::count_own_vtable_entries(tcx, trait_ref).checked_add(3).unwrap())
2720+
.map(|trait_ref| {
2721+
util::count_own_vtable_entries(tcx, trait_ref).checked_add(3).unwrap()
2722+
})
27192723
.sum();
27202724
}
27212725

@@ -2955,16 +2959,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
29552959
let iter = data_a
29562960
.principal()
29572961
.map(ty::ExistentialPredicate::Trait)
2958-
.into_iter().chain(
2962+
.into_iter()
2963+
.chain(
29592964
data_a
29602965
.projection_bounds()
29612966
.map(|x| ty::ExistentialPredicate::Projection(x)),
29622967
)
2963-
.chain(
2964-
data_b
2965-
.auto_traits()
2966-
.map(ty::ExistentialPredicate::AutoTrait),
2967-
);
2968+
.chain(data_b.auto_traits().map(ty::ExistentialPredicate::AutoTrait));
29682969
tcx.mk_existential_predicates(iter)
29692970
});
29702971
let source_with_target_auto_traits =
@@ -2994,24 +2995,24 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
29942995
// (it doesn't matter which one we choose), but rather than resolve that in the
29952996
// general case (which is subtle), we can screen it out here easily enough.
29962997
nested.extend(
2997-
data_b.iter()
2998+
data_b
2999+
.iter()
29983000
// HACK(alexreg | nikomatsakis): we handle auto traits specially here
29993001
// because of cases like like `dyn Foo + Send + 'a` ->
30003002
// `dyn Foo + Send + 'b`, which requires proving the obligation
30013003
// `dyn Foo + Send: Send`. This is unfortunately ambiguous under the
30023004
// current trait solver model: it holds both because `Send` is a
30033005
// supertrait of `Foo + Send` and because there's an automatic impl of
30043006
// `Send` for the trait object.
3005-
.filter(|predicate| {
3006-
match predicate.skip_binder() {
3007-
ty::ExistentialPredicate::AutoTrait(did) =>
3008-
!data_a.auto_traits().any(|did_a| did_a == *did),
3009-
_ => true,
3007+
.filter(|predicate| match predicate.skip_binder() {
3008+
ty::ExistentialPredicate::AutoTrait(did) => {
3009+
!data_a.auto_traits().any(|did_a| did_a == *did)
30103010
}
3011+
_ => true,
30113012
})
3012-
.map(|predicate|
3013+
.map(|predicate| {
30133014
predicate_to_obligation(predicate.with_self_ty(tcx, source))
3014-
),
3015+
}),
30153016
);
30163017
} else {
30173018
// Require that the traits involved in this upcast are **equal**;
@@ -3030,7 +3031,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
30303031
// because I want to continue rejecting that test (as we have
30313032
// done for quite some time) before we are firmly comfortable
30323033
// with what our behavior should be there. -nikomatsakis
3033-
let InferOk { obligations, .. } = self.infcx
3034+
let InferOk { obligations, .. } = self
3035+
.infcx
30343036
.at(&obligation.cause, obligation.param_env)
30353037
.eq(target, source_with_target_auto_traits) // FIXME: see above.
30363038
.map_err(|_| Unimplemented)?;
@@ -3039,9 +3041,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
30393041

30403042
// Register an obligation for `'a: 'b`.
30413043
let outlives = ty::OutlivesPredicate(region_a, region_b);
3042-
nested.push(predicate_to_obligation(
3043-
ty::Binder::bind(outlives).to_predicate(),
3044-
));
3044+
nested.push(predicate_to_obligation(ty::Binder::bind(outlives).to_predicate()));
30453045
}
30463046

30473047
// `T` -> `Trait`

src/librustc_typeck/astconv.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ pub trait AstConv<'tcx> {
6363
fn get_type_parameter_bounds(&self, span: Span, def_id: DefId) -> ty::GenericPredicates<'tcx>;
6464

6565
/// Returns the lifetime to use when a lifetime is omitted (and not elided).
66-
fn re_infer(
67-
&self,
68-
param: Option<&ty::GenericParamDef>,
69-
span: Span,
70-
) -> Option<ty::Region<'tcx>>;
66+
fn re_infer(&self, param: Option<&ty::GenericParamDef>, span: Span)
67+
-> Option<ty::Region<'tcx>>;
7168

7269
/// Returns the type to use when a type is omitted.
7370
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>;

0 commit comments

Comments
 (0)