Skip to content

Commit 95bec31

Browse files
Rollup merge of rust-lang#37752 - arielb1:incoherent-error, r=nikomatsakis
coherence: skip impls with an erroneous trait ref Impls with a erroneous trait ref are already ignored in the first part of coherence, so ignore them in the second part too. This avoids cascading coherence errors when 1 impl of a trait has an error. r? @nikomatsakis
2 parents 5bd1e7f + b8fc512 commit 95bec31

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/librustc_typeck/coherence/overlap.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
use hir::def_id::DefId;
1616
use rustc::traits::{self, Reveal};
17-
use rustc::ty::{self, TyCtxt};
17+
use rustc::ty::{self, TyCtxt, TypeFoldable};
1818
use syntax::ast;
1919
use rustc::dep_graph::DepNode;
2020
use rustc::hir;
@@ -134,6 +134,12 @@ impl<'cx, 'tcx, 'v> intravisit::Visitor<'v> for OverlapChecker<'cx, 'tcx> {
134134
let trait_ref = self.tcx.impl_trait_ref(impl_def_id).unwrap();
135135
let trait_def_id = trait_ref.def_id;
136136

137+
if trait_ref.references_error() {
138+
debug!("coherence: skipping impl {:?} with error {:?}",
139+
impl_def_id, trait_ref);
140+
return
141+
}
142+
137143
let _task =
138144
self.tcx.dep_graph.in_task(DepNode::CoherenceOverlapCheck(trait_def_id));
139145

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2016 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+
// check that error types in coherence do not cause error cascades.
12+
13+
trait Foo {}
14+
15+
impl Foo for i8 {}
16+
impl Foo for i16 {}
17+
impl Foo for i32 {}
18+
impl Foo for i64 {}
19+
impl Foo for DoesNotExist {} //~ ERROR `DoesNotExist` is undefined
20+
impl Foo for u8 {}
21+
impl Foo for u16 {}
22+
impl Foo for u32 {}
23+
impl Foo for u64 {}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)