code review fixes
This commit is contained in:
parent
b1cee113c7
commit
8b89f3168d
3 changed files with 38 additions and 22 deletions
|
|
@ -50,7 +50,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
if let (Some(anon_reg_sup), Some(anon_reg_sub)) =
|
||||
(self.is_suitable_anonymous_region(sup, true),
|
||||
self.is_suitable_anonymous_region(sub, true)) {
|
||||
let ((def_id_sup, br_sup), (def_id_sub, br_sub)) = (anon_reg_sup, anon_reg_sub);
|
||||
let (def_id_sup, br_sup, def_id_sub, br_sub) = (anon_reg_sup.def_id,
|
||||
anon_reg_sup.boundregion,
|
||||
anon_reg_sub.def_id,
|
||||
anon_reg_sub.boundregion);
|
||||
if let (Some(anonarg_sup), Some(anonarg_sub)) =
|
||||
(self.find_anon_type(sup, &br_sup), self.find_anon_type(sub, &br_sub)) {
|
||||
(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> {
|
|||
/// for e.g. `&u8` and Vec<`&u8`.
|
||||
pub fn find_anon_type(&self, region: Region<'tcx>, br: &ty::BoundRegion) -> Option<&hir::Ty> {
|
||||
if let Some(anon_reg) = self.is_suitable_anonymous_region(region, true) {
|
||||
let (def_id, _) = anon_reg;
|
||||
let def_id = anon_reg.def_id;
|
||||
if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
|
||||
let ret_ty = self.tcx.type_of(def_id);
|
||||
if let ty::TyFnDef(_, _) = ret_ty.sty {
|
||||
|
|
|
|||
|
|
@ -29,25 +29,26 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// where the anonymous region appears (there must always be one; we
|
||||
// only introduced anonymous regions in parameters) as well as a
|
||||
// version new_ty of its type where the anonymous region is replaced
|
||||
// with the named one.
|
||||
let (named, anon_arg_info, (scope_def_id, _)) = if
|
||||
sub.is_named_region() && self.is_suitable_anonymous_region(sup, false).is_some() {
|
||||
(sub,
|
||||
self.find_arg_with_anonymous_region(sup, sub).unwrap(),
|
||||
self.is_suitable_anonymous_region(sup, false).unwrap())
|
||||
} else if
|
||||
sup.is_named_region() && self.is_suitable_anonymous_region(sub, false).is_some() {
|
||||
(sup,
|
||||
self.find_arg_with_anonymous_region(sub, sup).unwrap(),
|
||||
self.is_suitable_anonymous_region(sub, false).unwrap())
|
||||
} else {
|
||||
return false; // inapplicable
|
||||
};
|
||||
// with the named one.//scope_def_id
|
||||
let (named, anon_arg_info, region_info) =
|
||||
if sub.is_named_region() && self.is_suitable_anonymous_region(sup, false).is_some() {
|
||||
(sub,
|
||||
self.find_arg_with_anonymous_region(sup, sub).unwrap(),
|
||||
self.is_suitable_anonymous_region(sup, false).unwrap())
|
||||
} else if sup.is_named_region() &&
|
||||
self.is_suitable_anonymous_region(sub, false).is_some() {
|
||||
(sup,
|
||||
self.find_arg_with_anonymous_region(sub, sup).unwrap(),
|
||||
self.is_suitable_anonymous_region(sub, false).unwrap())
|
||||
} else {
|
||||
return false; // inapplicable
|
||||
};
|
||||
|
||||
let (arg, new_ty, br, is_first) = (anon_arg_info.arg,
|
||||
anon_arg_info.arg_ty,
|
||||
anon_arg_info.bound_region,
|
||||
anon_arg_info.is_first);
|
||||
let (arg, new_ty, br, is_first, scope_def_id) = (anon_arg_info.arg,
|
||||
anon_arg_info.arg_ty,
|
||||
anon_arg_info.bound_region,
|
||||
anon_arg_info.is_first,
|
||||
region_info.def_id);
|
||||
if self.is_return_type_anon(scope_def_id, br) || self.is_self_anon(is_first, scope_def_id) {
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,15 @@ pub struct AnonymousArgInfo<'tcx> {
|
|||
pub is_first: bool,
|
||||
}
|
||||
|
||||
// This struct contains information regarding the
|
||||
// Refree((FreeRegion) corresponding to lifetime conflict
|
||||
pub struct FreeRegionInfo {
|
||||
// def id corresponding to FreeRegion
|
||||
pub def_id: DefId,
|
||||
// the bound region corresponding to FreeRegion
|
||||
pub boundregion: ty::BoundRegion,
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
// This method walks the Type of the function body arguments using
|
||||
// `fold_regions()` function and returns the
|
||||
|
|
@ -102,7 +111,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
pub fn is_suitable_anonymous_region(&self,
|
||||
region: Region<'tcx>,
|
||||
is_anon_anon: bool)
|
||||
-> Option<(DefId, ty::BoundRegion)> {
|
||||
-> Option<FreeRegionInfo> {
|
||||
if let ty::ReFree(ref free_region) = *region {
|
||||
if let ty::BrAnon(..) = free_region.bound_region {
|
||||
let anonymous_region_binding_scope = free_region.scope;
|
||||
|
|
@ -136,7 +145,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
_ => return None, // inapplicable
|
||||
// we target only top-level functions
|
||||
}
|
||||
return Some((anonymous_region_binding_scope, free_region.bound_region));
|
||||
return Some(FreeRegionInfo {
|
||||
def_id: anonymous_region_binding_scope,
|
||||
boundregion: free_region.bound_region,
|
||||
});
|
||||
}
|
||||
}
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue