Skip to content

Commit 041cbfb

Browse files
author
Alexander Regueiro
committed
Ran rustfmt.
1 parent 394a970 commit 041cbfb

File tree

7 files changed

+101
-124
lines changed

7 files changed

+101
-124
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
@@ -1591,9 +1591,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15911591
self.suggest_as_ref_where_appropriate(span, &exp_found, diag);
15921592

15931593
if let &TypeError::Traits(ref exp_found_traits) = terr {
1594-
self.note_enable_trait_upcasting_where_appropriate(
1595-
&exp_found_traits, diag
1596-
);
1594+
self.note_enable_trait_upcasting_where_appropriate(&exp_found_traits, diag);
15971595
}
15981596
}
15991597

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

src/librustc_infer/traits/util.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,7 @@ pub fn elaborate_obligations<'tcx>(
136136
) -> Elaborator<'tcx> {
137137
let mut visited = PredicateSet::new(tcx);
138138
obligations.retain(|obligation| visited.insert(&obligation.predicate));
139-
Elaborator {
140-
stack: obligations,
141-
visited,
142-
allow_repetitions: false,
143-
}
139+
Elaborator { stack: obligations, visited, allow_repetitions: false }
144140
}
145141

146142
fn predicate_obligation<'tcx>(
@@ -151,12 +147,7 @@ fn predicate_obligation<'tcx>(
151147
if let Some(span) = span {
152148
cause.span = span;
153149
}
154-
Obligation {
155-
cause,
156-
param_env: ty::ParamEnv::empty(),
157-
recursion_depth: 0,
158-
predicate,
159-
}
150+
Obligation { cause, param_env: ty::ParamEnv::empty(), recursion_depth: 0, predicate }
160151
}
161152

162153
impl Elaborator<'tcx> {
@@ -185,7 +176,8 @@ impl Elaborator<'tcx> {
185176
// cases. One common case is when people define
186177
// `trait Sized: Sized { }` rather than `trait Sized { }`.
187178
let visited = &mut self.visited;
188-
let obligations = obligations.filter(|o| allow_repetitions || visited.insert(&o.predicate));
179+
let obligations =
180+
obligations.filter(|o| allow_repetitions || visited.insert(&o.predicate));
189181

190182
self.stack.extend(obligations);
191183
}

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
@@ -1869,8 +1869,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18691869
true
18701870
} else {
18711871
// Just allow upcast kinds 2 and 3 from above.
1872-
data_a.principal_def_id() == data_b.principal_def_id() &&
1873-
data_b.auto_traits()
1872+
data_a.principal_def_id() == data_b.principal_def_id()
1873+
&& data_b
1874+
.auto_traits()
18741875
// All of a's auto traits need to be in b's auto traits.
18751876
.all(|b| data_a.auto_traits().any(|a| a == b))
18761877
}
@@ -2696,27 +2697,30 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26962697
// where we can unify, because otherwise select would have
26972698
// reported an ambiguity. (When we do find a match, also
26982699
// record it for later.)
2699-
let nonmatching = util::supertraits_with_repetitions(tcx, poly_trait_ref)
2700-
.take_while(
2701-
|&trait_ref| match self.infcx.commit_if_ok(
2702-
|_| self.match_poly_trait_ref(obligation, trait_ref)
2703-
) {
2700+
let nonmatching =
2701+
util::supertraits_with_repetitions(tcx, poly_trait_ref).take_while(|&trait_ref| {
2702+
match self
2703+
.infcx
2704+
.commit_if_ok(|_| self.match_poly_trait_ref(obligation, trait_ref))
2705+
{
27042706
Ok(obligations) => {
27052707
upcast_trait_ref = Some(trait_ref);
27062708
nested.extend(obligations);
27072709
false
27082710
}
27092711
Err(_) => true,
2710-
},
2711-
);
2712+
}
2713+
});
27122714

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

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

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

30483048
// `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)