adding macro, cleaning up code

This commit is contained in:
gaurikholkar 2017-08-24 01:18:20 +05:30
parent b569094d94
commit cb563a93dc
3 changed files with 23 additions and 19 deletions

View File

@ -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!(""))

View File

@ -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> {

View File

@ -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<AnonymousArgInfo> {
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) {