Skip to content

Commit d855782

Browse files
committed
convert hrtb error
1 parent a155a9b commit d855782

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

src/librustc_mir/borrow_check/diagnostics/region_errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ crate enum RegionErrorKind<'tcx> {
9898
member_region: ty::Region<'tcx>,
9999
},
100100

101+
/// Higher-ranked subtyping error
102+
BoundUniversalRegionError {
103+
/// The placeholder free region.
104+
longer_fr: RegionVid,
105+
/// The region that erroneously must be outlived by `longer_fr`.
106+
error_region: RegionVid,
107+
/// The origin of the placeholder region
108+
fr_origin: NLLRegionVariableOrigin,
109+
},
110+
101111
/// Any other lifetime error
102112
RegionError {
103113
/// The origin of the region

src/librustc_mir/borrow_check/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,25 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16471647
.buffer(&mut self.errors_buffer);
16481648
}
16491649

1650+
RegionErrorKind::BoundUniversalRegionError {
1651+
longer_fr, fr_origin, error_region,
1652+
} => {
1653+
// Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
1654+
let (_, span) = self.nonlexical_regioncx.find_outlives_blame_span(
1655+
&self.body,
1656+
longer_fr,
1657+
fr_origin,
1658+
error_region,
1659+
);
1660+
1661+
// FIXME: improve this error message
1662+
self.infcx
1663+
.tcx
1664+
.sess
1665+
.struct_span_err(span, "higher-ranked subtype error")
1666+
.buffer(&mut self.errors_buffer);
1667+
}
1668+
16501669
RegionErrorKind::RegionError {
16511670
fr_origin, longer_fr, shorter_fr, is_reported,
16521671
} => {

src/librustc_mir/borrow_check/region_infer/mod.rs

+9-27
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc::mir::{
99
ConstraintCategory, Local, Location,
1010
};
1111
use rustc::ty::{self, subst::SubstsRef, RegionVid, Ty, TyCtxt, TypeFoldable};
12-
use rustc_errors::DiagnosticBuilder;
1312
use rustc_data_structures::binary_search_util;
1413
use rustc_index::bit_set::BitSet;
1514
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -435,7 +434,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
435434
}
436435

437436
/// Adds annotations for `#[rustc_regions]`; see `UniversalRegions::annotate`.
438-
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut DiagnosticBuilder<'_>) {
437+
crate fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut rustc_errors::DiagnosticBuilder<'_>) {
439438
self.universal_regions.annotate(tcx, err)
440439
}
441440

@@ -507,18 +506,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
507506
// constraints were too strong, and if so, emit or propagate those errors.
508507
if infcx.tcx.sess.opts.debugging_opts.polonius {
509508
self.check_polonius_subset_errors(
510-
infcx,
511509
body,
512-
mir_def_id,
513510
outlives_requirements.as_mut(),
514511
&mut errors_buffer,
515512
polonius_output.expect("Polonius output is unavailable despite `-Z polonius`"),
516513
);
517514
} else {
518515
self.check_universal_regions(
519-
infcx,
520516
body,
521-
mir_def_id,
522517
outlives_requirements.as_mut(),
523518
&mut errors_buffer,
524519
);
@@ -1291,9 +1286,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12911286
/// report them as errors.
12921287
fn check_universal_regions(
12931288
&self,
1294-
infcx: &InferCtxt<'_, 'tcx>,
12951289
body: &Body<'tcx>,
1296-
mir_def_id: DefId,
12971290
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
12981291
errors_buffer: &mut RegionErrors<'tcx>,
12991292
) {
@@ -1312,7 +1305,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
13121305
}
13131306

13141307
NLLRegionVariableOrigin::Placeholder(placeholder) => {
1315-
self.check_bound_universal_region(infcx, body, mir_def_id, fr, placeholder);
1308+
self.check_bound_universal_region(fr, placeholder, errors_buffer);
13161309
}
13171310

13181311
NLLRegionVariableOrigin::Existential { .. } => {
@@ -1345,9 +1338,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
13451338
/// report them as errors.
13461339
fn check_polonius_subset_errors(
13471340
&self,
1348-
infcx: &InferCtxt<'_, 'tcx>,
13491341
body: &Body<'tcx>,
1350-
mir_def_id: DefId,
13511342
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
13521343
errors_buffer: &mut RegionErrors<'tcx>,
13531344
polonius_output: Rc<PoloniusOutput>,
@@ -1413,7 +1404,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
14131404
}
14141405

14151406
NLLRegionVariableOrigin::Placeholder(placeholder) => {
1416-
self.check_bound_universal_region(infcx, body, mir_def_id, fr, placeholder);
1407+
self.check_bound_universal_region(fr, placeholder, errors_buffer);
14171408
}
14181409

14191410
NLLRegionVariableOrigin::Existential { .. } => {
@@ -1573,11 +1564,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
15731564

15741565
fn check_bound_universal_region(
15751566
&self,
1576-
infcx: &InferCtxt<'_, 'tcx>,
1577-
body: &Body<'tcx>,
1578-
_mir_def_id: DefId,
15791567
longer_fr: RegionVid,
15801568
placeholder: ty::PlaceholderRegion,
1569+
errors_buffer: &mut RegionErrors<'tcx>,
15811570
) {
15821571
debug!("check_bound_universal_region(fr={:?}, placeholder={:?})", longer_fr, placeholder,);
15831572

@@ -1614,18 +1603,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
16141603
.unwrap(),
16151604
};
16161605

1617-
// Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
1618-
let (_, span) = self.find_outlives_blame_span(
1619-
body, longer_fr, NLLRegionVariableOrigin::Placeholder(placeholder), error_region
1620-
);
1621-
1622-
// Obviously, this error message is far from satisfactory.
1623-
// At present, though, it only appears in unit tests --
1624-
// the AST-based checker uses a more conservative check,
1625-
// so to even see this error, one must pass in a special
1626-
// flag.
1627-
let mut diag = infcx.tcx.sess.struct_span_err(span, "higher-ranked subtype error");
1628-
diag.emit();
1606+
errors_buffer.push(RegionErrorKind::BoundUniversalRegionError {
1607+
longer_fr,
1608+
error_region,
1609+
fr_origin: NLLRegionVariableOrigin::Placeholder(placeholder),
1610+
});
16291611
}
16301612

16311613
fn check_member_constraints(

0 commit comments

Comments
 (0)