Skip to content

Commit 3d8a073

Browse files
committed
Remove dead ScopeTree code
1 parent 52d628f commit 3d8a073

File tree

12 files changed

+57
-374
lines changed

12 files changed

+57
-374
lines changed

src/librustc_infer/infer/error_reporting/mod.rs

+38-101
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6161
use rustc_hir as hir;
6262
use rustc_hir::def_id::DefId;
6363
use rustc_hir::Node;
64-
use rustc_middle::middle::region;
6564
use rustc_middle::ty::error::TypeError;
6665
use rustc_middle::ty::{
6766
self,
@@ -81,7 +80,6 @@ pub mod nice_region_error;
8180

8281
pub(super) fn note_and_explain_region(
8382
tcx: TyCtxt<'tcx>,
84-
region_scope_tree: &region::ScopeTree,
8583
err: &mut DiagnosticBuilder<'_>,
8684
prefix: &str,
8785
region: ty::Region<'tcx>,
@@ -239,7 +237,6 @@ fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option
239237

240238
pub fn unexpected_hidden_region_diagnostic(
241239
tcx: TyCtxt<'tcx>,
242-
region_scope_tree: Option<&region::ScopeTree>,
243240
span: Span,
244241
hidden_ty: Ty<'tcx>,
245242
hidden_region: ty::Region<'tcx>,
@@ -264,78 +261,53 @@ pub fn unexpected_hidden_region_diagnostic(
264261
err.span_note(span, &message);
265262
}
266263
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic | ty::ReEmpty(_) => {
267-
// Assuming regionck succeeded (*), we ought to always be
268-
// capturing *some* region from the fn header, and hence it
269-
// ought to be free. So under normal circumstances, we will go
270-
// down this path which gives a decent human readable
271-
// explanation.
272-
//
273-
// (*) if not, the `tainted_by_errors` field would be set to
274-
// `Some(ErrorReported)` in any case, so we wouldn't be here at all.
275-
note_and_explain_free_region(
276-
tcx,
277-
&mut err,
278-
&format!("hidden type `{}` captures ", hidden_ty),
279-
hidden_region,
280-
"",
281-
);
264+
// Assuming regionck succeeded (*), we ought to always be
265+
// capturing *some* region from the fn header, and hence it
266+
// ought to be free. So under normal circumstances, we will go
267+
// down this path which gives a decent human readable
268+
// explanation.
269+
//
270+
// (*) if not, the `tainted_by_errors` field would be set to
271+
// `Some(ErrorReported)` in any case, so we wouldn't be here at all.
272+
note_and_explain_free_region(
273+
tcx,
274+
&mut err,
275+
&format!("hidden type `{}` captures ", hidden_ty),
276+
hidden_region,
277+
"",
278+
);
282279
}
283280
_ => {
284-
// Ugh. This is a painful case: the hidden region is not one
285-
// that we can easily summarize or explain. This can happen
286-
// in a case like
287-
// `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
288-
//
289-
// ```
290-
// fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
291-
// if condition() { a } else { b }
292-
// }
293-
// ```
294-
//
295-
// Here the captured lifetime is the intersection of `'a` and
296-
// `'b`, which we can't quite express.
297-
298-
if let Some(region_scope_tree) = region_scope_tree {
299-
// If the `region_scope_tree` is available, this is being
300-
// invoked from the "region inferencer error". We can at
301-
// least report a really cryptic error for now.
281+
// Ugh. This is a painful case: the hidden region is not one
282+
// that we can easily summarize or explain. This can happen
283+
// in a case like
284+
// `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
285+
//
286+
// ```
287+
// fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
288+
// if condition() { a } else { b }
289+
// }
290+
// ```
291+
//
292+
// Here the captured lifetime is the intersection of `'a` and
293+
// `'b`, which we can't quite express.
294+
295+
// We can at least report a really cryptic error for now.
302296
note_and_explain_region(
303297
tcx,
304-
region_scope_tree,
305298
&mut err,
306299
&format!("hidden type `{}` captures ", hidden_ty),
307300
hidden_region,
308301
"",
309302
);
310-
} else {
311-
// If the `region_scope_tree` is *unavailable*, this is
312-
// being invoked by the code that comes *after* region
313-
// inferencing. This is a bug, as the region inferencer
314-
// ought to have noticed the failed constraint and invoked
315-
// error reporting, which in turn should have prevented us
316-
// from getting trying to infer the hidden type
317-
// completely.
318-
tcx.sess.delay_span_bug(
319-
span,
320-
&format!(
321-
"hidden type captures unexpected lifetime `{:?}` \
322-
but no region inference failure",
323-
hidden_region,
324-
),
325-
);
326303
}
327304
}
328-
}
329305

330306
err
331307
}
332308

333309
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
334-
pub fn report_region_errors(
335-
&self,
336-
region_scope_tree: &region::ScopeTree,
337-
errors: &Vec<RegionResolutionError<'tcx>>,
338-
) {
310+
pub fn report_region_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>) {
339311
debug!("report_region_errors(): {} errors to start", errors.len());
340312

341313
// try to pre-process the errors, which will group some of them
@@ -358,17 +330,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
358330
// general bit of code that displays the error information
359331
RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
360332
if sub.is_placeholder() || sup.is_placeholder() {
361-
self.report_placeholder_failure(region_scope_tree, origin, sub, sup)
362-
.emit();
333+
self.report_placeholder_failure(origin, sub, sup).emit();
363334
} else {
364-
self.report_concrete_failure(region_scope_tree, origin, sub, sup)
365-
.emit();
335+
self.report_concrete_failure(origin, sub, sup).emit();
366336
}
367337
}
368338

369339
RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => {
370340
self.report_generic_bound_failure(
371-
region_scope_tree,
372341
origin.span(),
373342
Some(origin),
374343
param_ty,
@@ -385,29 +354,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
385354
sup_r,
386355
) => {
387356
if sub_r.is_placeholder() {
388-
self.report_placeholder_failure(
389-
region_scope_tree,
390-
sub_origin,
391-
sub_r,
392-
sup_r,
393-
)
394-
.emit();
357+
self.report_placeholder_failure(sub_origin, sub_r, sup_r).emit();
395358
} else if sup_r.is_placeholder() {
396-
self.report_placeholder_failure(
397-
region_scope_tree,
398-
sup_origin,
399-
sub_r,
400-
sup_r,
401-
)
402-
.emit();
359+
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
403360
} else {
404361
self.report_sub_sup_conflict(
405-
region_scope_tree,
406-
var_origin,
407-
sub_origin,
408-
sub_r,
409-
sup_origin,
410-
sup_r,
362+
var_origin, sub_origin, sub_r, sup_origin, sup_r,
411363
);
412364
}
413365
}
@@ -428,13 +380,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
428380
// value.
429381
let sub_r = self.tcx.mk_region(ty::ReEmpty(var_universe));
430382

431-
self.report_placeholder_failure(
432-
region_scope_tree,
433-
sup_origin,
434-
sub_r,
435-
sup_r,
436-
)
437-
.emit();
383+
self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
438384
}
439385

440386
RegionResolutionError::MemberConstraintFailure {
@@ -445,7 +391,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
445391
let hidden_ty = self.resolve_vars_if_possible(&hidden_ty);
446392
unexpected_hidden_region_diagnostic(
447393
self.tcx,
448-
Some(region_scope_tree),
449394
span,
450395
hidden_ty,
451396
member_region,
@@ -1722,19 +1667,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17221667

17231668
pub fn report_generic_bound_failure(
17241669
&self,
1725-
region_scope_tree: &region::ScopeTree,
17261670
span: Span,
17271671
origin: Option<SubregionOrigin<'tcx>>,
17281672
bound_kind: GenericKind<'tcx>,
17291673
sub: Region<'tcx>,
17301674
) {
1731-
self.construct_generic_bound_failure(region_scope_tree, span, origin, bound_kind, sub)
1732-
.emit();
1675+
self.construct_generic_bound_failure(span, origin, bound_kind, sub).emit();
17331676
}
17341677

17351678
pub fn construct_generic_bound_failure(
17361679
&self,
1737-
region_scope_tree: &region::ScopeTree,
17381680
span: Span,
17391681
origin: Option<SubregionOrigin<'tcx>>,
17401682
bound_kind: GenericKind<'tcx>,
@@ -1886,7 +1828,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
18861828
));
18871829
note_and_explain_region(
18881830
self.tcx,
1889-
region_scope_tree,
18901831
&mut err,
18911832
&format!("{} must be valid for ", labeled_user_string),
18921833
sub,
@@ -1904,7 +1845,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19041845

19051846
fn report_sub_sup_conflict(
19061847
&self,
1907-
region_scope_tree: &region::ScopeTree,
19081848
var_origin: RegionVariableOrigin,
19091849
sub_origin: SubregionOrigin<'tcx>,
19101850
sub_region: Region<'tcx>,
@@ -1915,7 +1855,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19151855

19161856
note_and_explain_region(
19171857
self.tcx,
1918-
region_scope_tree,
19191858
&mut err,
19201859
"first, the lifetime cannot outlive ",
19211860
sup_region,
@@ -1941,7 +1880,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19411880
if sub_expected == sup_expected && sub_found == sup_found {
19421881
note_and_explain_region(
19431882
self.tcx,
1944-
region_scope_tree,
19451883
&mut err,
19461884
"...but the lifetime must also be valid for ",
19471885
sub_region,
@@ -1963,7 +1901,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19631901

19641902
note_and_explain_region(
19651903
self.tcx,
1966-
region_scope_tree,
19671904
&mut err,
19681905
"but, the lifetime must be valid for ",
19691906
sub_region,

0 commit comments

Comments
 (0)