Skip to content

Commit ffe87f6

Browse files
committed
rustfmt error_reporting/mod.rs and dropck.rs
Pacify the mercilous tidy.
1 parent f87189d commit ffe87f6

File tree

2 files changed

+138
-107
lines changed

2 files changed

+138
-107
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 69 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@
5555
//! ported to this system, and which relies on string concatenation at the
5656
//! time of error detection.
5757
58-
use infer::{self, SuppressRegionErrors};
59-
use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
60-
use super::region_constraints::GenericKind;
6158
use super::lexical_region_resolve::RegionResolutionError;
59+
use super::region_constraints::GenericKind;
60+
use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
61+
use infer::{self, SuppressRegionErrors};
6262

63-
use std::{cmp, fmt};
63+
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6464
use hir;
65-
use hir::Node;
6665
use hir::def_id::DefId;
66+
use hir::Node;
6767
use middle::region;
68-
use traits::{ObligationCause, ObligationCauseCode};
69-
use ty::{self, subst::Subst, Region, Ty, TyCtxt, TypeFoldable, TyKind};
70-
use ty::error::TypeError;
68+
use std::{cmp, fmt};
7169
use syntax::ast::DUMMY_NODE_ID;
7270
use syntax_pos::{Pos, Span};
73-
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
71+
use traits::{ObligationCause, ObligationCauseCode};
72+
use ty::error::TypeError;
73+
use ty::{self, subst::Subst, Region, Ty, TyCtxt, TyKind, TypeFoldable};
7474

7575
mod note;
7676

@@ -152,8 +152,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
152152
}
153153

154154
// We shouldn't encounter an error message with ReClosureBound.
155-
ty::ReCanonical(..) |
156-
ty::ReClosureBound(..) => {
155+
ty::ReCanonical(..) | ty::ReClosureBound(..) => {
157156
bug!("encountered unexpected ReClosureBound: {:?}", region,);
158157
}
159158
};
@@ -175,9 +174,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
175174

176175
fn msg_span_from_free_region(self, region: ty::Region<'tcx>) -> (String, Option<Span>) {
177176
match *region {
178-
ty::ReEarlyBound(_) | ty::ReFree(_) => {
177+
ty::ReEarlyBound(_) | ty::ReFree(_) => {
179178
self.msg_span_from_early_bound_and_free_regions(region)
180-
},
179+
}
181180
ty::ReStatic => ("the static lifetime".to_owned(), None),
182181
_ => bug!("{:?}", region),
183182
}
@@ -196,25 +195,28 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
196195
Some(Node::Item(it)) => Self::item_scope_tag(&it),
197196
Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it),
198197
Some(Node::ImplItem(it)) => Self::impl_item_scope_tag(&it),
199-
_ => unreachable!()
198+
_ => unreachable!(),
200199
};
201200
let (prefix, span) = match *region {
202201
ty::ReEarlyBound(ref br) => {
203202
let mut sp = cm.def_span(self.hir.span(node));
204-
if let Some(param) = self.hir.get_generics(scope).and_then(|generics| {
205-
generics.get_named(&br.name)
206-
}) {
203+
if let Some(param) = self.hir
204+
.get_generics(scope)
205+
.and_then(|generics| generics.get_named(&br.name))
206+
{
207207
sp = param.span;
208208
}
209209
(format!("the lifetime {} as defined on", br.name), sp)
210210
}
211211
ty::ReFree(ty::FreeRegion {
212-
bound_region: ty::BoundRegion::BrNamed(_, ref name), ..
212+
bound_region: ty::BoundRegion::BrNamed(_, ref name),
213+
..
213214
}) => {
214215
let mut sp = cm.def_span(self.hir.span(node));
215-
if let Some(param) = self.hir.get_generics(scope).and_then(|generics| {
216-
generics.get_named(&name)
217-
}) {
216+
if let Some(param) = self.hir
217+
.get_generics(scope)
218+
.and_then(|generics| generics.get_named(&name))
219+
{
218220
sp = param.span;
219221
}
220222
(format!("the lifetime {} as defined on", name), sp)
@@ -277,9 +279,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
277279
fn impl_item_scope_tag(item: &hir::ImplItem) -> &'static str {
278280
match item.node {
279281
hir::ImplItemKind::Method(..) => "method body",
280-
hir::ImplItemKind::Const(..) |
281-
hir::ImplItemKind::Existential(..) |
282-
hir::ImplItemKind::Type(..) => "associated item",
282+
hir::ImplItemKind::Const(..)
283+
| hir::ImplItemKind::Existential(..)
284+
| hir::ImplItemKind::Type(..) => "associated item",
283285
}
284286
}
285287

@@ -299,7 +301,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
299301
errors: &Vec<RegionResolutionError<'tcx>>,
300302
suppress: SuppressRegionErrors,
301303
) {
302-
debug!("report_region_errors(): {} errors to start, suppress = {:?}", errors.len(), suppress);
304+
debug!(
305+
"report_region_errors(): {} errors to start, suppress = {:?}",
306+
errors.len(),
307+
suppress
308+
);
303309

304310
if suppress.suppressed() {
305311
return;
@@ -473,17 +479,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
473479
} else {
474480
err.span_label(arm_span, msg);
475481
}
476-
},
477-
hir::MatchSource::TryDesugar => { // Issue #51632
482+
}
483+
hir::MatchSource::TryDesugar => {
484+
// Issue #51632
478485
if let Ok(try_snippet) = self.tcx.sess.source_map().span_to_snippet(arm_span) {
479486
err.span_suggestion_with_applicability(
480487
arm_span,
481488
"try wrapping with a success variant",
482489
format!("Ok({})", try_snippet),
483-
Applicability::MachineApplicable
490+
Applicability::MachineApplicable,
484491
);
485492
}
486-
},
493+
}
487494
_ => {
488495
let msg = "match arm with an incompatible type";
489496
if self.tcx.sess.source_map().is_multiline(arm_span) {
@@ -632,16 +639,21 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
632639
fn strip_generic_default_params(
633640
&self,
634641
def_id: DefId,
635-
substs: &ty::subst::Substs<'tcx>
642+
substs: &ty::subst::Substs<'tcx>,
636643
) -> &'tcx ty::subst::Substs<'tcx> {
637644
let generics = self.tcx.generics_of(def_id);
638645
let mut num_supplied_defaults = 0;
639-
let mut type_params = generics.params.iter().rev().filter_map(|param| match param.kind {
640-
ty::GenericParamDefKind::Lifetime => None,
641-
ty::GenericParamDefKind::Type { has_default, .. } => {
642-
Some((param.def_id, has_default))
643-
}
644-
}).peekable();
646+
let mut type_params = generics
647+
.params
648+
.iter()
649+
.rev()
650+
.filter_map(|param| match param.kind {
651+
ty::GenericParamDefKind::Lifetime => None,
652+
ty::GenericParamDefKind::Type { has_default, .. } => {
653+
Some((param.def_id, has_default))
654+
}
655+
})
656+
.peekable();
645657
let has_default = {
646658
let has_default = type_params.peek().map(|(_, has_default)| has_default);
647659
*has_default.unwrap_or(&false)
@@ -675,10 +687,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
675687
| (&ty::Infer(ty::InferTy::IntVar(_)), &ty::Infer(ty::InferTy::IntVar(_)))
676688
| (&ty::Float(_), &ty::Infer(ty::InferTy::FloatVar(_)))
677689
| (&ty::Infer(ty::InferTy::FloatVar(_)), &ty::Float(_))
678-
| (
679-
&ty::Infer(ty::InferTy::FloatVar(_)),
680-
&ty::Infer(ty::InferTy::FloatVar(_)),
681-
) => true,
690+
| (&ty::Infer(ty::InferTy::FloatVar(_)), &ty::Infer(ty::InferTy::FloatVar(_))) => {
691+
true
692+
}
682693
_ => false,
683694
}
684695
}
@@ -694,11 +705,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
694705
"&{}{}{}",
695706
r,
696707
if r == "" { "" } else { " " },
697-
if mutbl == hir::MutMutable {
698-
"mut "
699-
} else {
700-
""
701-
}
708+
if mutbl == hir::MutMutable { "mut " } else { "" }
702709
));
703710
s.push_normal(ty.to_string());
704711
}
@@ -729,9 +736,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
729736
let common_len = cmp::min(len1, len2);
730737
let remainder1: Vec<_> = sub1.types().skip(common_len).collect();
731738
let remainder2: Vec<_> = sub2.types().skip(common_len).collect();
732-
let common_default_params =
733-
remainder1.iter().rev().zip(remainder2.iter().rev())
734-
.filter(|(a, b)| a == b).count();
739+
let common_default_params = remainder1
740+
.iter()
741+
.rev()
742+
.zip(remainder2.iter().rev())
743+
.filter(|(a, b)| a == b)
744+
.count();
735745
let len = sub1.len() - common_default_params;
736746

737747
// Only draw `<...>` if there're lifetime/type arguments.
@@ -857,8 +867,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
857867
}
858868

859869
// When encountering &T != &mut T, highlight only the borrow
860-
(&ty::Ref(r1, ref_ty1, mutbl1),
861-
&ty::Ref(r2, ref_ty2, mutbl2)) if equals(&ref_ty1, &ref_ty2) => {
870+
(&ty::Ref(r1, ref_ty1, mutbl1), &ty::Ref(r2, ref_ty2, mutbl2))
871+
if equals(&ref_ty1, &ref_ty2) =>
872+
{
862873
let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new());
863874
push_ty_ref(&r1, ref_ty1, mutbl1, &mut values.0);
864875
push_ty_ref(&r2, ref_ty2, mutbl2, &mut values.1);
@@ -1059,11 +1070,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10591070
bound_kind: GenericKind<'tcx>,
10601071
sub: Region<'tcx>,
10611072
) {
1062-
self.construct_generic_bound_failure(region_scope_tree,
1063-
span,
1064-
origin,
1065-
bound_kind,
1066-
sub)
1073+
self.construct_generic_bound_failure(region_scope_tree, span, origin, bound_kind, sub)
10671074
.emit()
10681075
}
10691076

@@ -1074,8 +1081,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10741081
origin: Option<SubregionOrigin<'tcx>>,
10751082
bound_kind: GenericKind<'tcx>,
10761083
sub: Region<'tcx>,
1077-
) -> DiagnosticBuilder<'a>
1078-
{
1084+
) -> DiagnosticBuilder<'a> {
10791085
// Attempt to obtain the span of the parameter so we can
10801086
// suggest adding an explicit lifetime bound to it.
10811087
let type_param_span = match (self.in_progress_tables, bound_kind) {
@@ -1152,8 +1158,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11521158
let tail = if has_lifetimes { " + " } else { "" };
11531159
let suggestion = format!("{}: {}{}", bound_kind, sub, tail);
11541160
err.span_suggestion_short_with_applicability(
1155-
sp, consider, suggestion,
1156-
Applicability::MaybeIncorrect // Issue #41966
1161+
sp,
1162+
consider,
1163+
suggestion,
1164+
Applicability::MaybeIncorrect, // Issue #41966
11571165
);
11581166
} else {
11591167
err.help(consider);
@@ -1349,12 +1357,10 @@ impl<'tcx> ObligationCause<'tcx> {
13491357
match self.code {
13501358
CompareImplMethodObligation { .. } => Error0308("method not compatible with trait"),
13511359
MatchExpressionArm { source, .. } => Error0308(match source {
1352-
hir::MatchSource::IfLetDesugar { .. } => {
1353-
"`if let` arms have incompatible types"
1354-
},
1360+
hir::MatchSource::IfLetDesugar { .. } => "`if let` arms have incompatible types",
13551361
hir::MatchSource::TryDesugar => {
13561362
"try expression alternatives have incompatible types"
1357-
},
1363+
}
13581364
_ => "match arms have incompatible types",
13591365
}),
13601366
IfExpression => Error0308("if and else have incompatible types"),

0 commit comments

Comments
 (0)