Skip to content

Commit 59279b5

Browse files
committed
Do not report errors from regionck if other errors were already
reported during the lifetime of this inferencer. Fixes #30580.
1 parent cbbd3d9 commit 59279b5

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/librustc/middle/infer/mod.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1107,11 +1107,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11071107
.map(|method| resolve_ty(method.ty)))
11081108
}
11091109

1110+
pub fn errors_since_creation(&self) -> bool {
1111+
self.tcx.sess.err_count() - self.err_count_on_creation != 0
1112+
}
1113+
11101114
pub fn node_type(&self, id: ast::NodeId) -> Ty<'tcx> {
11111115
match self.tables.borrow().node_types.get(&id) {
11121116
Some(&t) => t,
11131117
// FIXME
1114-
None if self.tcx.sess.err_count() - self.err_count_on_creation != 0 =>
1118+
None if self.errors_since_creation() =>
11151119
self.tcx.types.err,
11161120
None => {
11171121
self.tcx.sess.bug(
@@ -1134,7 +1138,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11341138
free_regions: &FreeRegionMap,
11351139
subject_node_id: ast::NodeId) {
11361140
let errors = self.region_vars.resolve_regions(free_regions, subject_node_id);
1137-
self.report_region_errors(&errors); // see error_reporting.rs
1141+
if !self.errors_since_creation() {
1142+
// As a heuristic, just skip reporting region errors
1143+
// altogether if other errors have been reported while
1144+
// this infcx was in use. This is totally hokey but
1145+
// otherwise we have a hard time separating legit region
1146+
// errors from silly ones.
1147+
self.report_region_errors(&errors); // see error_reporting.rs
1148+
}
11381149
}
11391150

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

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

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
pub struct Foo { a: u32 }
12+
pub struct Pass<'a, 'tcx: 'a>(&'a mut &'a (), &'a &'tcx ());
13+
14+
impl<'a, 'tcx> Pass<'a, 'tcx>
15+
{
16+
pub fn tcx(&self) -> &'a &'tcx () { self.1 }
17+
fn lol(&mut self, b: &Foo)
18+
{
19+
b.c; //~ ERROR no field with that name was found
20+
self.tcx();
21+
}
22+
}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)