Skip to content

Commit 23f042c

Browse files
committed
Rollup merge of #32164 - nikomatsakis:fewer-errors, r=eddyb
Do not report errors from regionck if other errors were already reported Do not report errors from regionck if other errors were already reported during the lifetime of this inferencer. Fixes #30580. r? @arielb1
2 parents 5d443c6 + 0ddc17d commit 23f042c

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/librustc/middle/infer/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,11 +1120,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11201120
.map(|method| resolve_ty(method.ty)))
11211121
}
11221122

1123+
pub fn errors_since_creation(&self) -> bool {
1124+
self.tcx.sess.err_count() - self.err_count_on_creation != 0
1125+
}
1126+
11231127
pub fn node_type(&self, id: ast::NodeId) -> Ty<'tcx> {
11241128
match self.tables.borrow().node_types.get(&id) {
11251129
Some(&t) => t,
11261130
// FIXME
1127-
None if self.tcx.sess.err_count() - self.err_count_on_creation != 0 =>
1131+
None if self.errors_since_creation() =>
11281132
self.tcx.types.err,
11291133
None => {
11301134
self.tcx.sess.bug(
@@ -1147,7 +1151,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11471151
free_regions: &FreeRegionMap,
11481152
subject_node_id: ast::NodeId) {
11491153
let errors = self.region_vars.resolve_regions(free_regions, subject_node_id);
1150-
self.report_region_errors(&errors); // see error_reporting.rs
1154+
if !self.errors_since_creation() {
1155+
// As a heuristic, just skip reporting region errors
1156+
// altogether if other errors have been reported while
1157+
// this infcx was in use. This is totally hokey but
1158+
// otherwise we have a hard time separating legit region
1159+
// errors from silly ones.
1160+
self.report_region_errors(&errors); // see error_reporting.rs
1161+
}
11511162
}
11521163

11531164
pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {

src/test/compile-fail/issue-30580.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we do not see uninformative region-related errors
12+
// when we get some basic type-checking failure. See #30580.
13+
14+
pub struct Foo { a: u32 }
15+
pub struct Pass<'a, 'tcx: 'a>(&'a mut &'a (), &'a &'tcx ());
16+
17+
impl<'a, 'tcx> Pass<'a, 'tcx>
18+
{
19+
pub fn tcx(&self) -> &'a &'tcx () { self.1 }
20+
fn lol(&mut self, b: &Foo)
21+
{
22+
b.c; //~ ERROR no field with that name was found
23+
self.tcx();
24+
}
25+
}
26+
27+
fn main() {}

0 commit comments

Comments
 (0)