From cb563a93dcb076f2afe97d272591d71486906fc2 Mon Sep 17 00:00:00 2001 From: gaurikholkar Date: Thu, 24 Aug 2017 01:18:20 +0530 Subject: [PATCH] adding macro, cleaning up code --- .../error_reporting/anon_anon_conflict.rs | 28 ++++++++----------- src/librustc/infer/error_reporting/mod.rs | 4 ++- src/librustc/infer/error_reporting/util.rs | 10 ++++++- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/librustc/infer/error_reporting/anon_anon_conflict.rs b/src/librustc/infer/error_reporting/anon_anon_conflict.rs index 08be7587cb4..c80ce3c96f1 100644 --- a/src/librustc/infer/error_reporting/anon_anon_conflict.rs +++ b/src/librustc/infer/error_reporting/anon_anon_conflict.rs @@ -46,22 +46,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { }; // Determine whether the sub and sup consist of both anonymous (elided) regions. - let (ty_sup, ty_sub, scope_def_id_sup, scope_def_id_sub, bregion_sup, bregion_sub) = - if let (Some(anon_reg_sup), Some(anon_reg_sub)) = - (self.is_suitable_anonymous_region(sup), self.is_suitable_anonymous_region(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) - } else { - return false; - } - } else { - return false; - }; + let anon_reg_sup = or_false!(self.is_suitable_anonymous_region(sup)); + + let anon_reg_sub = or_false!(self.is_suitable_anonymous_region(sub)); + let scope_def_id_sup = anon_reg_sup.def_id; + let bregion_sup = anon_reg_sup.boundregion; + let scope_def_id_sub = anon_reg_sub.def_id; + let bregion_sub = anon_reg_sub.boundregion; + + let ty_sup = or_false!(self.find_anon_type(sup, &bregion_sup)); + + let ty_sub = or_false!(self.find_anon_type(sub, &bregion_sub)); let (main_label, label1, label2) = if let (Some(sup_arg), Some(sub_arg)) = (self.find_arg_with_anonymous_region(sup, sup), @@ -105,7 +100,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { return false; }; - struct_span_err!(self.tcx.sess, span, E0623, "lifetime mismatch") .span_label(ty_sup.span, main_label) .span_label(ty_sub.span, format!("")) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 9f70b4834dd..195609992f7 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -75,8 +75,10 @@ use errors::{DiagnosticBuilder, DiagnosticStyledString}; mod note; mod need_type_info; -mod util; + mod named_anon_conflict; +#[macro_use] +mod util; mod anon_anon_conflict; impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { diff --git a/src/librustc/infer/error_reporting/util.rs b/src/librustc/infer/error_reporting/util.rs index 3d5dcf37c48..635d0e8eb27 100644 --- a/src/librustc/infer/error_reporting/util.rs +++ b/src/librustc/infer/error_reporting/util.rs @@ -16,6 +16,15 @@ use ty::{self, Region}; use hir::def_id::DefId; use hir::map as hir_map; +macro_rules! or_false { + ($v:expr) => { + match $v { + Some(v) => v, + None => return false, + } + } +} + // The struct contains the information about the anonymous region // we are searching for. pub struct AnonymousArgInfo<'tcx> { @@ -59,7 +68,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { -> Option { if let ty::ReFree(ref free_region) = *anon_region { - let id = free_region.scope; let hir = &self.tcx.hir; if let Some(node_id) = hir.as_local_node_id(id) {