Skip to content

Commit cb563a9

Browse files
committed
adding macro, cleaning up code
1 parent b569094 commit cb563a9

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

src/librustc/infer/error_reporting/anon_anon_conflict.rs

+11-17
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
4646
};
4747

4848
// Determine whether the sub and sup consist of both anonymous (elided) regions.
49-
let (ty_sup, ty_sub, scope_def_id_sup, scope_def_id_sub, bregion_sup, bregion_sub) =
50-
if let (Some(anon_reg_sup), Some(anon_reg_sub)) =
51-
(self.is_suitable_anonymous_region(sup), self.is_suitable_anonymous_region(sub)) {
52-
let (def_id_sup, br_sup, def_id_sub, br_sub) = (anon_reg_sup.def_id,
53-
anon_reg_sup.boundregion,
54-
anon_reg_sub.def_id,
55-
anon_reg_sub.boundregion);
56-
if let (Some(anonarg_sup), Some(anonarg_sub)) =
57-
(self.find_anon_type(sup, &br_sup), self.find_anon_type(sub, &br_sub)) {
58-
(anonarg_sup, anonarg_sub, def_id_sup, def_id_sub, br_sup, br_sub)
59-
} else {
60-
return false;
61-
}
62-
} else {
63-
return false;
64-
};
49+
let anon_reg_sup = or_false!(self.is_suitable_anonymous_region(sup));
50+
51+
let anon_reg_sub = or_false!(self.is_suitable_anonymous_region(sub));
52+
let scope_def_id_sup = anon_reg_sup.def_id;
53+
let bregion_sup = anon_reg_sup.boundregion;
54+
let scope_def_id_sub = anon_reg_sub.def_id;
55+
let bregion_sub = anon_reg_sub.boundregion;
56+
57+
let ty_sup = or_false!(self.find_anon_type(sup, &bregion_sup));
58+
59+
let ty_sub = or_false!(self.find_anon_type(sub, &bregion_sub));
6560

6661
let (main_label, label1, label2) = if let (Some(sup_arg), Some(sub_arg)) =
6762
(self.find_arg_with_anonymous_region(sup, sup),
@@ -105,7 +100,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
105100
return false;
106101
};
107102

108-
109103
struct_span_err!(self.tcx.sess, span, E0623, "lifetime mismatch")
110104
.span_label(ty_sup.span, main_label)
111105
.span_label(ty_sub.span, format!(""))

src/librustc/infer/error_reporting/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ use errors::{DiagnosticBuilder, DiagnosticStyledString};
7575
mod note;
7676

7777
mod need_type_info;
78-
mod util;
78+
7979
mod named_anon_conflict;
80+
#[macro_use]
81+
mod util;
8082
mod anon_anon_conflict;
8183

8284
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

src/librustc/infer/error_reporting/util.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ use ty::{self, Region};
1616
use hir::def_id::DefId;
1717
use hir::map as hir_map;
1818

19+
macro_rules! or_false {
20+
($v:expr) => {
21+
match $v {
22+
Some(v) => v,
23+
None => return false,
24+
}
25+
}
26+
}
27+
1928
// The struct contains the information about the anonymous region
2029
// we are searching for.
2130
pub struct AnonymousArgInfo<'tcx> {
@@ -59,7 +68,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
5968
-> Option<AnonymousArgInfo> {
6069

6170
if let ty::ReFree(ref free_region) = *anon_region {
62-
6371
let id = free_region.scope;
6472
let hir = &self.tcx.hir;
6573
if let Some(node_id) = hir.as_local_node_id(id) {

0 commit comments

Comments
 (0)