code review fixes

This commit is contained in:
gaurikholkar 2017-08-17 22:15:18 +05:30
parent fe9c68a051
commit b1cee113c7
3 changed files with 31 additions and 9 deletions

View file

@ -65,8 +65,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
(self.find_arg_with_anonymous_region(sup, sup),
self.find_arg_with_anonymous_region(sub, sub)) {
let ((anon_arg_sup, _, _, is_first_sup), (anon_arg_sub, _, _, is_first_sub)) =
(sup_arg, sub_arg);
let (anon_arg_sup, is_first_sup, anon_arg_sub, is_first_sub) =
(sup_arg.arg, sup_arg.is_first, sub_arg.arg, sub_arg.is_first);
if self.is_self_anon(is_first_sup, scope_def_id_sup) ||
self.is_self_anon(is_first_sub, scope_def_id_sub) {
return false;

View file

@ -30,7 +30,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// 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, (arg, new_ty, br, is_first), (scope_def_id, _)) = if
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(),
@ -44,6 +44,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
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);
if self.is_return_type_anon(scope_def_id, br) || self.is_self_anon(is_first, scope_def_id) {
return false;
} else {

View file

@ -16,6 +16,20 @@ use ty::{self, Region};
use hir::def_id::DefId;
use hir::map as hir_map;
// The struct contains the information about the anonymous region
// we are searching for.
pub struct AnonymousArgInfo<'tcx> {
// the argument corresponding to the anonymous region
pub arg: &'tcx hir::Arg,
// the type corresponding to the anonymopus region argument
pub arg_ty: ty::Ty<'tcx>,
// the ty::BoundRegion corresponding to the anonymous region
pub bound_region: ty::BoundRegion,
// corresponds to id the argument is the first parameter
// in the declaration
pub is_first: bool,
}
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
@ -28,11 +42,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// i32, which is the type of y but with the anonymous region replaced
// with 'a, the corresponding bound region and is_first which is true if
// the hir::Arg is the first argument in the function declaration.
pub fn find_arg_with_anonymous_region
(&self,
anon_region: Region<'tcx>,
replace_region: Region<'tcx>)
-> Option<(&hir::Arg, ty::Ty<'tcx>, ty::BoundRegion, bool)> {
pub fn find_arg_with_anonymous_region(&self,
anon_region: Region<'tcx>,
replace_region: Region<'tcx>)
-> Option<AnonymousArgInfo> {
if let ty::ReFree(ref free_region) = *anon_region {
@ -57,7 +70,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
});
if found_anon_region {
let is_first = index == 0;
Some((arg, new_arg_ty, free_region.bound_region, is_first))
Some(AnonymousArgInfo {
arg: arg,
arg_ty: new_arg_ty,
bound_region: free_region.bound_region,
is_first: is_first,
})
} else {
None
}