diff --git a/src/librustc/infer/error_reporting/anon_anon_conflict.rs b/src/librustc/infer/error_reporting/anon_anon_conflict.rs index 3821bf766b96..c5e26f431207 100644 --- a/src/librustc/infer/error_reporting/anon_anon_conflict.rs +++ b/src/librustc/infer/error_reporting/anon_anon_conflict.rs @@ -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; diff --git a/src/librustc/infer/error_reporting/named_anon_conflict.rs b/src/librustc/infer/error_reporting/named_anon_conflict.rs index f46855502ea4..005eb900c118 100644 --- a/src/librustc/infer/error_reporting/named_anon_conflict.rs +++ b/src/librustc/infer/error_reporting/named_anon_conflict.rs @@ -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 { diff --git a/src/librustc/infer/error_reporting/util.rs b/src/librustc/infer/error_reporting/util.rs index 21a6e8e050a1..902e388ca7bf 100644 --- a/src/librustc/infer/error_reporting/util.rs +++ b/src/librustc/infer/error_reporting/util.rs @@ -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 { 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 }