Skip to content

Commit 8b89f31

Browse files
committed
code review fixes
1 parent b1cee11 commit 8b89f31

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

src/librustc/infer/error_reporting/anon_anon_conflict.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
5050
if let (Some(anon_reg_sup), Some(anon_reg_sub)) =
5151
(self.is_suitable_anonymous_region(sup, true),
5252
self.is_suitable_anonymous_region(sub, true)) {
53-
let ((def_id_sup, br_sup), (def_id_sub, br_sub)) = (anon_reg_sup, anon_reg_sub);
53+
let (def_id_sup, br_sup, def_id_sub, br_sub) = (anon_reg_sup.def_id,
54+
anon_reg_sup.boundregion,
55+
anon_reg_sub.def_id,
56+
anon_reg_sub.boundregion);
5457
if let (Some(anonarg_sup), Some(anonarg_sub)) =
5558
(self.find_anon_type(sup, &br_sup), self.find_anon_type(sub, &br_sub)) {
5659
(anonarg_sup, anonarg_sub, def_id_sup, def_id_sub, br_sup, br_sub)
@@ -124,7 +127,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
124127
/// for e.g. `&u8` and Vec<`&u8`.
125128
pub fn find_anon_type(&self, region: Region<'tcx>, br: &ty::BoundRegion) -> Option<&hir::Ty> {
126129
if let Some(anon_reg) = self.is_suitable_anonymous_region(region, true) {
127-
let (def_id, _) = anon_reg;
130+
let def_id = anon_reg.def_id;
128131
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
129132
let ret_ty = self.tcx.type_of(def_id);
130133
if let ty::TyFnDef(_, _) = ret_ty.sty {

src/librustc/infer/error_reporting/named_anon_conflict.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,26 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
2929
// where the anonymous region appears (there must always be one; we
3030
// only introduced anonymous regions in parameters) as well as a
3131
// version new_ty of its type where the anonymous region is replaced
32-
// with the named one.
33-
let (named, anon_arg_info, (scope_def_id, _)) = if
34-
sub.is_named_region() && self.is_suitable_anonymous_region(sup, false).is_some() {
35-
(sub,
36-
self.find_arg_with_anonymous_region(sup, sub).unwrap(),
37-
self.is_suitable_anonymous_region(sup, false).unwrap())
38-
} else if
39-
sup.is_named_region() && self.is_suitable_anonymous_region(sub, false).is_some() {
40-
(sup,
41-
self.find_arg_with_anonymous_region(sub, sup).unwrap(),
42-
self.is_suitable_anonymous_region(sub, false).unwrap())
43-
} else {
44-
return false; // inapplicable
45-
};
32+
// with the named one.//scope_def_id
33+
let (named, anon_arg_info, region_info) =
34+
if sub.is_named_region() && self.is_suitable_anonymous_region(sup, false).is_some() {
35+
(sub,
36+
self.find_arg_with_anonymous_region(sup, sub).unwrap(),
37+
self.is_suitable_anonymous_region(sup, false).unwrap())
38+
} else if sup.is_named_region() &&
39+
self.is_suitable_anonymous_region(sub, false).is_some() {
40+
(sup,
41+
self.find_arg_with_anonymous_region(sub, sup).unwrap(),
42+
self.is_suitable_anonymous_region(sub, false).unwrap())
43+
} else {
44+
return false; // inapplicable
45+
};
4646

47-
let (arg, new_ty, br, is_first) = (anon_arg_info.arg,
48-
anon_arg_info.arg_ty,
49-
anon_arg_info.bound_region,
50-
anon_arg_info.is_first);
47+
let (arg, new_ty, br, is_first, scope_def_id) = (anon_arg_info.arg,
48+
anon_arg_info.arg_ty,
49+
anon_arg_info.bound_region,
50+
anon_arg_info.is_first,
51+
region_info.def_id);
5152
if self.is_return_type_anon(scope_def_id, br) || self.is_self_anon(is_first, scope_def_id) {
5253
return false;
5354
} else {

src/librustc/infer/error_reporting/util.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ pub struct AnonymousArgInfo<'tcx> {
3030
pub is_first: bool,
3131
}
3232

33+
// This struct contains information regarding the
34+
// Refree((FreeRegion) corresponding to lifetime conflict
35+
pub struct FreeRegionInfo {
36+
// def id corresponding to FreeRegion
37+
pub def_id: DefId,
38+
// the bound region corresponding to FreeRegion
39+
pub boundregion: ty::BoundRegion,
40+
}
41+
3342
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
3443
// This method walks the Type of the function body arguments using
3544
// `fold_regions()` function and returns the
@@ -102,7 +111,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
102111
pub fn is_suitable_anonymous_region(&self,
103112
region: Region<'tcx>,
104113
is_anon_anon: bool)
105-
-> Option<(DefId, ty::BoundRegion)> {
114+
-> Option<FreeRegionInfo> {
106115
if let ty::ReFree(ref free_region) = *region {
107116
if let ty::BrAnon(..) = free_region.bound_region {
108117
let anonymous_region_binding_scope = free_region.scope;
@@ -136,7 +145,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
136145
_ => return None, // inapplicable
137146
// we target only top-level functions
138147
}
139-
return Some((anonymous_region_binding_scope, free_region.bound_region));
148+
return Some(FreeRegionInfo {
149+
def_id: anonymous_region_binding_scope,
150+
boundregion: free_region.bound_region,
151+
});
140152
}
141153
}
142154
None

0 commit comments

Comments
 (0)