Skip to content

Commit

Permalink
Rollup merge of #74516 - lcnr:min-specialization-ice, r=matthewjasper
Browse files Browse the repository at this point in the history
do not try fetching the ancestors of errored trait impls

fixes #74483

While building the specialization graph, we use `tcx.all_impls` which discards impls with incorrect self types,
we do however call `trait_def.ancestors` with these impls which caused an ICE as they aren't part of the
specialization graph.
  • Loading branch information
Manishearth committed Jul 20, 2020
2 parents 3981386 + 455e614 commit 55c4057
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/librustc_middle/traits/specialization_graph.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::ich::{self, StableHashingContext};
use crate::ty::fast_reject::SimplifiedType;
use crate::ty::fold::TypeFoldable;
use crate::ty::{self, TyCtxt};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand Down Expand Up @@ -226,7 +227,8 @@ pub fn ancestors(
start_from_impl: DefId,
) -> Result<Ancestors<'tcx>, ErrorReported> {
let specialization_graph = tcx.specialization_graph_of(trait_def_id);
if specialization_graph.has_errored {

if specialization_graph.has_errored || tcx.type_of(start_from_impl).references_error() {
Err(ErrorReported)
} else {
Ok(Ancestors {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![feature(min_specialization)]

trait Trait {}
impl Trait for NonExistent {}
//~^ ERROR cannot find type `NonExistent` in this scope

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0412]: cannot find type `NonExistent` in this scope
--> $DIR/impl-on-nonexisting.rs:4:16
|
LL | impl Trait for NonExistent {}
| ^^^^^^^^^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0412`.

0 comments on commit 55c4057

Please sign in to comment.