Skip to content

Commit e8b8f30

Browse files
committed
Code review fixes
1 parent 9540901 commit e8b8f30

File tree

4 files changed

+34
-53
lines changed

4 files changed

+34
-53
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ mod note;
7676

7777
mod need_type_info;
7878
mod named_anon_conflict;
79-
mod util;
8079

8180

8281
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

src/librustc/infer/error_reporting/named_anon_conflict.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
4141
let id = free_region.scope;
4242
let node_id = self.tcx.hir.as_local_node_id(id).unwrap();
4343
let body_id = self.tcx.hir.maybe_body_owned_by(node_id).unwrap();
44-
let mut is_first = false;
4544
let body = self.tcx.hir.body(body_id);
4645
if let Some(tables) = self.in_progress_tables {
4746
body.arguments
4847
.iter()
49-
.filter_map(|arg| {
48+
.enumerate()
49+
.filter_map(|(index, arg)| {
5050
let ty = tables.borrow().node_id_to_type(arg.id);
5151
let mut found_anon_region = false;
5252
let new_arg_ty = self.tcx
@@ -57,9 +57,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
5757
r
5858
});
5959
if found_anon_region {
60-
if body.arguments.iter().nth(0) == Some(&arg) {
61-
is_first = true;
62-
}
60+
let is_first = index == 0;
6361
Some((arg, new_arg_ty, free_region.bound_region, is_first))
6462
} else {
6563
None
@@ -91,19 +89,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
9189
// only introduced anonymous regions in parameters) as well as a
9290
// version new_ty of its type where the anonymous region is replaced
9391
// with the named one.
94-
let (named, (arg, new_ty, br, is_first), scope_def_id) = if
95-
self.is_named_region(sub) && self.is_suitable_anonymous_region(sup).is_some() {
96-
(sub,
97-
self.find_arg_with_anonymous_region(sup, sub).unwrap(),
98-
self.is_suitable_anonymous_region(sup).unwrap())
99-
} else if
100-
self.is_named_region(sup) && self.is_suitable_anonymous_region(sub).is_some() {
101-
(sup,
102-
self.find_arg_with_anonymous_region(sub, sup).unwrap(),
103-
self.is_suitable_anonymous_region(sub).unwrap())
104-
} else {
105-
return false; // inapplicable
106-
};
92+
let (named, (arg, new_ty, br, is_first), scope_def_id) =
93+
if sub.is_named_region() && self.is_suitable_anonymous_region(sup).is_some() {
94+
(sub,
95+
self.find_arg_with_anonymous_region(sup, sub).unwrap(),
96+
self.is_suitable_anonymous_region(sup).unwrap())
97+
} else if sup.is_named_region() && self.is_suitable_anonymous_region(sub).is_some() {
98+
(sup,
99+
self.find_arg_with_anonymous_region(sub, sup).unwrap(),
100+
self.is_suitable_anonymous_region(sub).unwrap())
101+
} else {
102+
return false; // inapplicable
103+
};
107104

108105
// Here, we check for the case where the anonymous region
109106
// is in the return type.
@@ -179,8 +176,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
179176
// proceed ahead //
180177
}
181178
Some(hir_map::NodeImplItem(..)) => {
182-
if self.tcx.impl_trait_ref(self.tcx.
183-
associated_item(anonymous_region_binding_scope).container.id()).is_some() {
179+
let container_id = self.tcx
180+
.associated_item(anonymous_region_binding_scope)
181+
.container
182+
.id();
183+
if self.tcx.impl_trait_ref(container_id).is_some() {
184184
// For now, we do not try to target impls of traits. This is
185185
// because this message is going to suggest that the user
186186
// change the fn signature, but they may not be free to do so,
@@ -189,8 +189,6 @@ associated_item(anonymous_region_binding_scope).container.id()).is_some() {
189189
// FIXME(#42706) -- in some cases, we could do better here.
190190
return None;
191191
}
192-
else{ }
193-
194192
}
195193
_ => return None, // inapplicable
196194
// we target only top-level functions

src/librustc/infer/error_reporting/util.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/librustc/ty/sty.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,20 @@ impl RegionKind {
990990

991991
flags
992992
}
993+
994+
// This method returns whether the given Region is Named
995+
pub fn is_named_region(&self) -> bool {
996+
997+
match *self {
998+
ty::ReFree(ref free_region) => {
999+
match free_region.bound_region {
1000+
ty::BrNamed(..) => true,
1001+
_ => false,
1002+
}
1003+
}
1004+
_ => false,
1005+
}
1006+
}
9931007
}
9941008

9951009
/// Type utilities

0 commit comments

Comments
 (0)