Skip to content

Commit

Permalink
rustfmt coherence::builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
arielb1 committed Jan 3, 2017
1 parent 243e45a commit e41920a
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions src/librustc_typeck/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ use rustc::hir::{self, ItemImpl};

pub fn check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
if let Some(drop_trait) = tcx.lang_items.drop_trait() {
tcx.lookup_trait_def(drop_trait).for_each_impl(tcx, |impl_did| {
visit_implementation_of_drop(tcx, impl_did)
});
tcx.lookup_trait_def(drop_trait)
.for_each_impl(tcx, |impl_did| visit_implementation_of_drop(tcx, impl_did));
}

if let Some(copy_trait) = tcx.lang_items.copy_trait() {
tcx.lookup_trait_def(copy_trait).for_each_impl(tcx, |impl_did| {
visit_implementation_of_copy(tcx, impl_did)
});
tcx.lookup_trait_def(copy_trait)
.for_each_impl(tcx, |impl_did| visit_implementation_of_copy(tcx, impl_did));
}

if let Some(coerce_unsized_trait) = tcx.lang_items.coerce_unsized_trait() {
Expand All @@ -48,8 +46,10 @@ pub fn check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
};

tcx.lookup_trait_def(coerce_unsized_trait).for_each_impl(tcx, |impl_did| {
visit_implementation_of_coerce_unsized(tcx, impl_did,
unsize_trait, coerce_unsized_trait)
visit_implementation_of_coerce_unsized(tcx,
impl_did,
unsize_trait,
coerce_unsized_trait)
});
}
}
Expand Down Expand Up @@ -81,8 +81,7 @@ fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
E0120,
"the Drop trait may only be implemented on \
structures")
.span_label(span,
&format!("implementing Drop requires a struct"))
.span_label(span, &format!("implementing Drop requires a struct"))
.emit();
}
_ => {
Expand Down Expand Up @@ -173,10 +172,10 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
}
}

fn visit_implementation_of_coerce_unsized<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: DefId,
unsize_trait: DefId, coerce_unsized_trait: DefId)
{
fn visit_implementation_of_coerce_unsized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
impl_did: DefId,
unsize_trait: DefId,
coerce_unsized_trait: DefId) {
debug!("visit_implementation_of_coerce_unsized: impl_did={:?}",
impl_did);

Expand Down Expand Up @@ -212,10 +211,10 @@ fn visit_implementation_of_coerce_unsized<'a, 'tcx>(
mk_ptr: &Fn(Ty<'tcx>) -> Ty<'tcx>| {
if (mt_a.mutbl, mt_b.mutbl) == (hir::MutImmutable, hir::MutMutable) {
infcx.report_mismatched_types(&cause,
mk_ptr(mt_b.ty),
target,
ty::error::TypeError::Mutability)
.emit();
mk_ptr(mt_b.ty),
target,
ty::error::TypeError::Mutability)
.emit();
}
(mt_a.ty, mt_b.ty, unsize_trait, None)
};
Expand All @@ -232,8 +231,8 @@ fn visit_implementation_of_coerce_unsized<'a, 'tcx>(
check_mutbl(mt_a, mt_b, &|ty| tcx.mk_imm_ptr(ty))
}

(&ty::TyAdt(def_a, substs_a), &ty::TyAdt(def_b, substs_b))
if def_a.is_struct() && def_b.is_struct() => {
(&ty::TyAdt(def_a, substs_a), &ty::TyAdt(def_b, substs_b)) if def_a.is_struct() &&
def_b.is_struct() => {
if def_a != def_b {
let source_path = tcx.item_path_str(def_a.did);
let target_path = tcx.item_path_str(def_b.did);
Expand Down Expand Up @@ -299,11 +298,11 @@ fn visit_implementation_of_coerce_unsized<'a, 'tcx>(
err.note(&format!("currently, {} fields need coercions: {}",
diff_fields.len(),
diff_fields.iter()
.map(|&(i, a, b)| {
format!("{} ({} to {})", fields[i].name, a, b)
})
.collect::<Vec<_>>()
.join(", ")));
.map(|&(i, a, b)| {
format!("{} ({} to {})", fields[i].name, a, b)
})
.collect::<Vec<_>>()
.join(", ")));
err.span_label(span, &format!("requires multiple coercions"));
err.emit();
return;
Expand All @@ -328,8 +327,7 @@ fn visit_implementation_of_coerce_unsized<'a, 'tcx>(

// Register an obligation for `A: Trait<B>`.
let cause = traits::ObligationCause::misc(span, impl_node_id);
let predicate =
tcx.predicate_for_trait_def(cause, trait_def_id, 0, source, &[target]);
let predicate = tcx.predicate_for_trait_def(cause, trait_def_id, 0, source, &[target]);
fulfill_cx.register_predicate_obligation(&infcx, predicate);

// Check that all transitive obligations are satisfied.
Expand All @@ -340,7 +338,7 @@ fn visit_implementation_of_coerce_unsized<'a, 'tcx>(
// Finally, resolve all regions.
let mut free_regions = FreeRegionMap::new();
free_regions.relate_free_regions_from_predicates(&infcx.parameter_environment
.caller_bounds);
.caller_bounds);
infcx.resolve_regions_and_report_errors(&free_regions, impl_node_id);

if let Some(kind) = kind {
Expand Down

0 comments on commit e41920a

Please sign in to comment.