Skip to content

Commit 3db8e0d

Browse files
committed
nice_region_error: rustfmt
1 parent 0659be9 commit 3db8e0d

File tree

3 files changed

+98
-83
lines changed

3 files changed

+98
-83
lines changed

src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
7272

7373
let ty_sub = or_false!(self.find_anon_type(sub, &bregion_sub));
7474

75-
debug!("try_report_anon_anon_conflict: found_arg1={:?} sup={:?} br1={:?}",
76-
ty_sub,
77-
sup,
78-
bregion_sup);
79-
debug!("try_report_anon_anon_conflict: found_arg2={:?} sub={:?} br2={:?}",
80-
ty_sup,
81-
sub,
82-
bregion_sub);
75+
debug!(
76+
"try_report_anon_anon_conflict: found_arg1={:?} sup={:?} br1={:?}",
77+
ty_sub,
78+
sup,
79+
bregion_sup
80+
);
81+
debug!(
82+
"try_report_anon_anon_conflict: found_arg2={:?} sub={:?} br2={:?}",
83+
ty_sup,
84+
sub,
85+
bregion_sub
86+
);
8387

8488
let (ty_sup, ty_fndecl_sup) = ty_sup;
8589
let (ty_sub, ty_fndecl_sub) = ty_sub;
8690

87-
let AnonymousArgInfo { arg: anon_arg_sup, .. } =
88-
or_false!(self.find_arg_with_region(sup, sup));
89-
let AnonymousArgInfo { arg: anon_arg_sub, .. } =
90-
or_false!(self.find_arg_with_region(sub, sub));
91+
let AnonymousArgInfo {
92+
arg: anon_arg_sup, ..
93+
} = or_false!(self.find_arg_with_region(sup, sup));
94+
let AnonymousArgInfo {
95+
arg: anon_arg_sub, ..
96+
} = or_false!(self.find_arg_with_region(sub, sub));
9197

9298
let sup_is_ret_type =
9399
self.is_return_type_anon(scope_def_id_sup, bregion_sup, ty_fndecl_sup);
@@ -110,34 +116,45 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
110116
let (span_1, span_2, main_label, span_label) = match (sup_is_ret_type, sub_is_ret_type) {
111117
(None, None) => {
112118
let (main_label_1, span_label_1) = if ty_sup == ty_sub {
113-
114-
(format!("this type is declared with multiple lifetimes..."),
115-
format!("...but data{} flows{} here",
116-
format!(" with one lifetime"),
117-
format!(" into the other")))
119+
(
120+
format!("this type is declared with multiple lifetimes..."),
121+
format!(
122+
"...but data{} flows{} here",
123+
format!(" with one lifetime"),
124+
format!(" into the other")
125+
),
126+
)
118127
} else {
119-
(format!("these two types are declared with different lifetimes..."),
120-
format!("...but data{} flows{} here",
121-
span_label_var1,
122-
span_label_var2))
128+
(
129+
format!("these two types are declared with different lifetimes..."),
130+
format!(
131+
"...but data{} flows{} here",
132+
span_label_var1,
133+
span_label_var2
134+
),
135+
)
123136
};
124137
(ty_sup.span, ty_sub.span, main_label_1, span_label_1)
125138
}
126139

127-
(Some(ret_span), _) => {
128-
(ty_sub.span,
129-
ret_span,
130-
format!("this parameter and the return type are declared \
131-
with different lifetimes...",),
132-
format!("...but data{} is returned here", span_label_var1))
133-
}
134-
(_, Some(ret_span)) => {
135-
(ty_sup.span,
136-
ret_span,
137-
format!("this parameter and the return type are declared \
138-
with different lifetimes...",),
139-
format!("...but data{} is returned here", span_label_var1))
140-
}
140+
(Some(ret_span), _) => (
141+
ty_sub.span,
142+
ret_span,
143+
format!(
144+
"this parameter and the return type are declared \
145+
with different lifetimes...",
146+
),
147+
format!("...but data{} is returned here", span_label_var1),
148+
),
149+
(_, Some(ret_span)) => (
150+
ty_sup.span,
151+
ret_span,
152+
format!(
153+
"this parameter and the return type are declared \
154+
with different lifetimes...",
155+
),
156+
format!("...but data{} is returned here", span_label_var1),
157+
),
141158
};
142159

143160

@@ -149,4 +166,3 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
149166
return true;
150167
}
151168
}
152-

src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use infer::InferCtxt;
1313
use ty::{self, Region};
1414
use hir::map as hir_map;
1515
use middle::resolve_lifetime as rl;
16-
use hir::intravisit::{self, Visitor, NestedVisitorMap};
16+
use hir::intravisit::{self, NestedVisitorMap, Visitor};
1717

1818
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1919
/// This function calls the `visit_ty` method for the parameters

src/librustc/infer/error_reporting/nice_region_error/util.rs

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
6868
// i32, which is the type of y but with the anonymous region replaced
6969
// with 'a, the corresponding bound region and is_first which is true if
7070
// the hir::Arg is the first argument in the function declaration.
71-
pub(super) fn find_arg_with_region(&self,
72-
anon_region: Region<'tcx>,
73-
replace_region: Region<'tcx>)
74-
-> Option<AnonymousArgInfo> {
75-
71+
pub(super) fn find_arg_with_region(
72+
&self,
73+
anon_region: Region<'tcx>,
74+
replace_region: Region<'tcx>,
75+
) -> Option<AnonymousArgInfo> {
7676
let (id, bound_region) = match *anon_region {
7777
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
78-
ty::ReEarlyBound(ref ebr) => {
79-
(self.tcx.parent_def_id(ebr.def_id).unwrap(),
80-
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name))
81-
}
78+
ty::ReEarlyBound(ref ebr) => (
79+
self.tcx.parent_def_id(ebr.def_id).unwrap(),
80+
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
81+
),
8282
_ => return None, // not a free region
8383
};
8484

@@ -94,21 +94,22 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
9494
// May return None; sometimes the tables are not yet populated.
9595
let ty = tables.borrow().node_id_to_type_opt(arg.hir_id)?;
9696
let mut found_anon_region = false;
97-
let new_arg_ty = self.tcx
98-
.fold_regions(&ty, &mut false, |r, _| if *r == *anon_region {
97+
let new_arg_ty = self.tcx.fold_regions(&ty, &mut false, |r, _| {
98+
if *r == *anon_region {
9999
found_anon_region = true;
100100
replace_region
101101
} else {
102102
r
103-
});
103+
}
104+
});
104105
if found_anon_region {
105106
let is_first = index == 0;
106107
Some(AnonymousArgInfo {
107-
arg: arg,
108-
arg_ty: new_arg_ty,
109-
bound_region: bound_region,
110-
is_first: is_first,
111-
})
108+
arg: arg,
109+
arg_ty: new_arg_ty,
110+
bound_region: bound_region,
111+
is_first: is_first,
112+
})
112113
} else {
113114
None
114115
}
@@ -127,13 +128,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
127128

128129
// This method returns the DefId and the BoundRegion corresponding to the given region.
129130
pub(super) fn is_suitable_region(&self, region: Region<'tcx>) -> Option<FreeRegionInfo> {
130-
131131
let (suitable_region_binding_scope, bound_region) = match *region {
132132
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
133-
ty::ReEarlyBound(ref ebr) => {
134-
(self.tcx.parent_def_id(ebr.def_id).unwrap(),
135-
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name))
136-
}
133+
ty::ReEarlyBound(ref ebr) => (
134+
self.tcx.parent_def_id(ebr.def_id).unwrap(),
135+
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
136+
),
137137
_ => return None, // not a free region
138138
};
139139

@@ -142,31 +142,29 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
142142
.as_local_node_id(suitable_region_binding_scope)
143143
.unwrap();
144144
let is_impl_item = match self.tcx.hir.find(node_id) {
145-
146-
Some(hir_map::NodeItem(..)) |
147-
Some(hir_map::NodeTraitItem(..)) => false,
145+
Some(hir_map::NodeItem(..)) | Some(hir_map::NodeTraitItem(..)) => false,
148146
Some(hir_map::NodeImplItem(..)) => {
149147
self.is_bound_region_in_impl_item(suitable_region_binding_scope)
150148
}
151149
_ => return None,
152150
};
153151

154152
return Some(FreeRegionInfo {
155-
def_id: suitable_region_binding_scope,
156-
boundregion: bound_region,
157-
is_impl_item: is_impl_item,
158-
});
159-
153+
def_id: suitable_region_binding_scope,
154+
boundregion: bound_region,
155+
is_impl_item: is_impl_item,
156+
});
160157
}
161158

162159
// Here, we check for the case where the anonymous region
163160
// is in the return type.
164161
// FIXME(#42703) - Need to handle certain cases here.
165-
pub(super) fn is_return_type_anon(&self,
166-
scope_def_id: DefId,
167-
br: ty::BoundRegion,
168-
decl: &hir::FnDecl)
169-
-> Option<Span> {
162+
pub(super) fn is_return_type_anon(
163+
&self,
164+
scope_def_id: DefId,
165+
br: ty::BoundRegion,
166+
decl: &hir::FnDecl,
167+
) -> Option<Span> {
170168
let ret_ty = self.tcx.type_of(scope_def_id);
171169
match ret_ty.sty {
172170
ty::TyFnDef(_, _) => {
@@ -186,14 +184,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
186184
// FIXME(#42700) - Need to format self properly to
187185
// enable E0621 for it.
188186
pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool {
189-
is_first &&
190-
self.tcx
191-
.opt_associated_item(scope_def_id)
192-
.map(|i| i.method_has_self_argument) == Some(true)
187+
is_first
188+
&& self.tcx
189+
.opt_associated_item(scope_def_id)
190+
.map(|i| i.method_has_self_argument) == Some(true)
193191
}
194192

195193
// Here we check if the bound region is in Impl Item.
196-
pub(super) fn is_bound_region_in_impl_item(&self, suitable_region_binding_scope: DefId) -> bool {
194+
pub(super) fn is_bound_region_in_impl_item(
195+
&self,
196+
suitable_region_binding_scope: DefId,
197+
) -> bool {
197198
let container_id = self.tcx
198199
.associated_item(suitable_region_binding_scope)
199200
.container
@@ -213,12 +214,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
213214
// This method returns whether the given Region is Named
214215
pub(super) fn is_named_region(&self, region: Region<'tcx>) -> bool {
215216
match *region {
216-
ty::ReFree(ref free_region) => {
217-
match free_region.bound_region {
218-
ty::BrNamed(..) => true,
219-
_ => false,
220-
}
221-
}
217+
ty::ReFree(ref free_region) => match free_region.bound_region {
218+
ty::BrNamed(..) => true,
219+
_ => false,
220+
},
222221
ty::ReEarlyBound(_) => true,
223222
_ => false,
224223
}

0 commit comments

Comments
 (0)