diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 37bbfb4e967f7..62edbeedb3262 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -137,6 +137,10 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { let impl_did = tcx.map.local_def_id(item.id); let self_type = tcx.lookup_item_type(impl_did); + if let ty::TyError = self_type.ty.sty { + return; + } + // If there are no traits, then this implementation must have a // base type. diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 411e1a4e480fc..b85e0775b9e9c 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -219,6 +219,9 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> { // "Trait" impl debug!("coherence2::orphan check: trait impl {}", self.tcx.map.node_to_string(item.id)); + if let ty::TyError = self.tcx.lookup_item_type(def_id).ty.sty { + return; + } let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap(); let trait_def_id = trait_ref.def_id; match traits::orphan_check(self.tcx, def_id) { diff --git a/src/test/compile-fail/issue-30589.rs b/src/test/compile-fail/issue-30589.rs new file mode 100644 index 0000000000000..88def039ece67 --- /dev/null +++ b/src/test/compile-fail/issue-30589.rs @@ -0,0 +1,19 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct X; + +impl From for Y { //~ ERROR use of undeclared type name `Y` + fn from(i: i32) -> X { + X + } +} + +fn main() {}