Skip to content

Commit 5b06025

Browse files
committed
is_reported flag
1 parent e4379e6 commit 5b06025

File tree

3 files changed

+34
-49
lines changed

3 files changed

+34
-49
lines changed

src/librustc_mir/borrow_check/diagnostics/region_errors.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,10 @@ crate enum RegionErrorKind<'tcx> {
103103
longer_fr: RegionVid,
104104
/// The region that should be shorter, but we can't prove it
105105
shorter_fr: RegionVid,
106+
/// Indicates whether this is a reported error. We currently only report the first error
107+
/// encountered and leave the rest unreported so as not to overwhelm the user.
108+
is_reported: bool,
106109
},
107-
108-
/// The same as `RegionError`, but this is an unreported error. We currently only report the
109-
/// first error encountered and leave the rest unreported so as not to overwhelm the user.
110-
UnreportedError {
111-
/// The origin of the region
112-
fr_origin: NLLRegionVariableOrigin,
113-
/// The region that should outlive `shorter_fr`
114-
longer_fr: RegionVid,
115-
/// The region that should be shorter, but we can't prove it
116-
shorter_fr: RegionVid,
117-
}
118110
}
119111

120112
/// Various pieces of state used when reporting borrow checker errors.

src/librustc_mir/borrow_check/mod.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,35 +1648,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16481648
}
16491649

16501650
RegionErrorKind::RegionError {
1651-
fr_origin, longer_fr, shorter_fr,
1651+
fr_origin, longer_fr, shorter_fr, is_reported,
16521652
} => {
1653-
let db = self.nonlexical_regioncx.report_error(
1654-
&self.body,
1655-
&self.local_names,
1656-
&self.upvars,
1657-
self.infcx,
1658-
self.mir_def_id,
1659-
longer_fr,
1660-
fr_origin,
1661-
shorter_fr,
1662-
&mut outlives_suggestion,
1663-
&mut region_naming,
1664-
);
1665-
1666-
db.buffer(&mut self.errors_buffer);
1667-
}
1653+
if is_reported {
1654+
let db = self.nonlexical_regioncx.report_error(
1655+
&self.body,
1656+
&self.local_names,
1657+
&self.upvars,
1658+
self.infcx,
1659+
self.mir_def_id,
1660+
longer_fr,
1661+
fr_origin,
1662+
shorter_fr,
1663+
&mut outlives_suggestion,
1664+
&mut region_naming,
1665+
);
16681666

1669-
RegionErrorKind::UnreportedError {
1670-
longer_fr, shorter_fr,
1671-
fr_origin: _,
1672-
} => {
1673-
// FIXME: currently we do nothing with these, but perhaps we can do better?
1674-
// FIXME: try collecting these constraints on the outlives suggestion builder.
1675-
// Does it make the suggestions any better?
1676-
debug!(
1677-
"Unreported region error: can't prove that {:?}: {:?}",
1678-
longer_fr, shorter_fr
1679-
);
1667+
db.buffer(&mut self.errors_buffer);
1668+
} else {
1669+
// FIXME: currently we do nothing with these, but perhaps we can do better?
1670+
// FIXME: try collecting these constraints on the outlives suggestion
1671+
// builder. Does it make the suggestions any better?
1672+
debug!(
1673+
"Unreported region error: can't prove that {:?}: {:?}",
1674+
longer_fr, shorter_fr
1675+
);
1676+
}
16801677
}
16811678
}
16821679
}

src/librustc_mir/borrow_check/region_infer/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
13991399
longer_fr: *longer_fr,
14001400
shorter_fr: *shorter_fr,
14011401
fr_origin: NLLRegionVariableOrigin::FreeRegion,
1402+
is_reported: true,
14021403
});
14031404
}
14041405
}
@@ -1464,6 +1465,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
14641465
longer_fr,
14651466
shorter_fr: representative,
14661467
fr_origin: NLLRegionVariableOrigin::FreeRegion,
1468+
is_reported: true,
14671469
});
14681470
}
14691471
return;
@@ -1482,17 +1484,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
14821484
// We only report the first region error. Subsequent errors are hidden so as
14831485
// not to overwhelm the user, but we do record them so as to potentially print
14841486
// better diagnostics elsewhere...
1485-
if error_reported {
1486-
errors_buffer.push(RegionErrorKind::UnreportedError {
1487-
longer_fr, shorter_fr,
1488-
fr_origin: NLLRegionVariableOrigin::FreeRegion,
1489-
});
1490-
} else {
1491-
errors_buffer.push(RegionErrorKind::RegionError {
1492-
longer_fr, shorter_fr,
1493-
fr_origin: NLLRegionVariableOrigin::FreeRegion,
1494-
});
1495-
}
1487+
errors_buffer.push(RegionErrorKind::RegionError {
1488+
longer_fr, shorter_fr,
1489+
fr_origin: NLLRegionVariableOrigin::FreeRegion,
1490+
is_reported: !error_reported,
1491+
});
14961492

14971493
error_reported = true;
14981494
}

0 commit comments

Comments
 (0)