Skip to content

Commit a01aa95

Browse files
committed
use Option<ErrorReported> instead of bool
Also allows us to replace `or_false` with `?`. No functional change
1 parent 02c419c commit a01aa95

File tree

4 files changed

+25
-34
lines changed

4 files changed

+25
-34
lines changed

src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
//! Error Reporting for Anonymous Region Lifetime Errors
1212
//! where both the regions are anonymous.
13+
1314
use infer::error_reporting::nice_region_error::NiceRegionError;
1415
use infer::error_reporting::nice_region_error::util::AnonymousArgInfo;
16+
use util::common::ErrorReported;
1517

1618
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
1719
/// Print the error message for lifetime errors when both the concerned regions are anonymous.
@@ -50,21 +52,21 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
5052
/// ````
5153
///
5254
/// It will later be extended to trait objects.
53-
pub(super) fn try_report_anon_anon_conflict(&self) -> bool {
55+
pub(super) fn try_report_anon_anon_conflict(&self) -> Option<ErrorReported> {
5456
let NiceRegionError { span, sub, sup, .. } = *self;
5557

5658
// Determine whether the sub and sup consist of both anonymous (elided) regions.
57-
let anon_reg_sup = or_false!(self.is_suitable_region(sup));
59+
let anon_reg_sup = self.is_suitable_region(sup)?;
5860

59-
let anon_reg_sub = or_false!(self.is_suitable_region(sub));
61+
let anon_reg_sub = self.is_suitable_region(sub)?;
6062
let scope_def_id_sup = anon_reg_sup.def_id;
6163
let bregion_sup = anon_reg_sup.boundregion;
6264
let scope_def_id_sub = anon_reg_sub.def_id;
6365
let bregion_sub = anon_reg_sub.boundregion;
6466

65-
let ty_sup = or_false!(self.find_anon_type(sup, &bregion_sup));
67+
let ty_sup = self.find_anon_type(sup, &bregion_sup)?;
6668

67-
let ty_sub = or_false!(self.find_anon_type(sub, &bregion_sub));
69+
let ty_sub = self.find_anon_type(sub, &bregion_sub)?;
6870

6971
debug!(
7072
"try_report_anon_anon_conflict: found_arg1={:?} sup={:?} br1={:?}",
@@ -84,10 +86,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
8486

8587
let AnonymousArgInfo {
8688
arg: anon_arg_sup, ..
87-
} = or_false!(self.find_arg_with_region(sup, sup));
89+
} = self.find_arg_with_region(sup, sup)?;
8890
let AnonymousArgInfo {
8991
arg: anon_arg_sub, ..
90-
} = or_false!(self.find_arg_with_region(sub, sub));
92+
} = self.find_arg_with_region(sub, sub)?;
9193

9294
let sup_is_ret_type =
9395
self.is_return_type_anon(scope_def_id_sup, bregion_sup, ty_fndecl_sup);
@@ -157,6 +159,6 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
157159
.span_label(span_2, format!(""))
158160
.span_label(span, span_label)
159161
.emit();
160-
return true;
162+
return Some(ErrorReported);
161163
}
162164
}

src/librustc/infer/error_reporting/nice_region_error/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ use infer::lexical_region_resolve::RegionResolutionError;
1313
use infer::lexical_region_resolve::RegionResolutionError::*;
1414
use syntax::codemap::Span;
1515
use ty::{self, TyCtxt};
16+
use util::common::ErrorReported;
1617

17-
#[macro_use]
18-
mod util;
19-
20-
mod find_anon_type;
2118
mod different_lifetimes;
19+
mod find_anon_type;
2220
mod named_anon_conflict;
21+
mod util;
2322

2423
impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
2524
pub fn try_report_nice_region_error(&self, error: &RegionResolutionError<'tcx>) -> bool {
@@ -31,9 +30,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
3130

3231
if let Some(tables) = self.in_progress_tables {
3332
let tables = tables.borrow();
34-
NiceRegionError::new(self.tcx, span, sub, sup, Some(&tables)).try_report()
33+
NiceRegionError::new(self.tcx, span, sub, sup, Some(&tables)).try_report().is_some()
3534
} else {
36-
NiceRegionError::new(self.tcx, span, sub, sup, None).try_report()
35+
NiceRegionError::new(self.tcx, span, sub, sup, None).try_report().is_some()
3736
}
3837
}
3938
}
@@ -57,7 +56,8 @@ impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
5756
Self { tcx, span, sub, sup, tables }
5857
}
5958

60-
pub fn try_report(&self) -> bool {
61-
self.try_report_anon_anon_conflict() || self.try_report_named_anon_conflict()
59+
pub fn try_report(&self) -> Option<ErrorReported> {
60+
self.try_report_anon_anon_conflict()
61+
.or_else(|| self.try_report_named_anon_conflict())
6262
}
6363
}

src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
//! where one region is named and the other is anonymous.
1313
use infer::error_reporting::nice_region_error::NiceRegionError;
1414
use ty;
15+
use util::common::ErrorReported;
1516

1617
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
1718
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
1819
/// an anonymous region, emit an descriptive diagnostic error.
19-
pub(super) fn try_report_named_anon_conflict(&self) -> bool {
20+
pub(super) fn try_report_named_anon_conflict(&self) -> Option<ErrorReported> {
2021
let NiceRegionError { span, sub, sup, .. } = *self;
2122

2223
debug!(
@@ -51,7 +52,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
5152
self.is_suitable_region(sub).unwrap(),
5253
)
5354
} else {
54-
return false; // inapplicable
55+
return None; // inapplicable
5556
};
5657

5758
debug!("try_report_named_anon_conflict: named = {:?}", named);
@@ -77,20 +78,20 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
7778
_ => {
7879
/* not an anonymous region */
7980
debug!("try_report_named_anon_conflict: not an anonymous region");
80-
return false;
81+
return None;
8182
}
8283
}
8384

8485
if is_impl_item {
8586
debug!("try_report_named_anon_conflict: impl item, bail out");
86-
return false;
87+
return None;
8788
}
8889

8990
if let Some((_, fndecl)) = self.find_anon_type(anon, &br) {
9091
if self.is_return_type_anon(scope_def_id, br, fndecl).is_some()
9192
|| self.is_self_anon(is_first, scope_def_id)
9293
{
93-
return false;
94+
return None;
9495
}
9596
}
9697

@@ -115,6 +116,6 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
115116
)
116117
.span_label(span, format!("lifetime `{}` required", named))
117118
.emit();
118-
return true;
119+
return Some(ErrorReported);
119120
}
120121
}

src/librustc/infer/error_reporting/nice_region_error/util.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ use hir::def_id::DefId;
1717
use hir::map as hir_map;
1818
use syntax_pos::Span;
1919

20-
macro_rules! or_false {
21-
($v:expr) => {
22-
match $v {
23-
Some(v) => v,
24-
None => {
25-
debug!("or_false failed: {}", stringify!($v));
26-
return false;
27-
}
28-
}
29-
}
30-
}
31-
3220
// The struct contains the information about the anonymous region
3321
// we are searching for.
3422
#[derive(Debug)]

0 commit comments

Comments
 (0)