From ec47293998c32aab48bd85a418298a868b1e360a Mon Sep 17 00:00:00 2001 From: JoshBrudnak Date: Sun, 19 Aug 2018 12:40:30 -0400 Subject: [PATCH] Fix compile panic on non existant type return #53300 --- src/librustc_typeck/collect.rs | 20 +++++++++++++++++++- src/test/compile-fail/issue-53300.rs | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/issue-53300.rs diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 44a1960ea185..e404eb4ecca4 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1163,7 +1163,25 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { ItemKind::Existential(hir::ExistTy { impl_trait_fn: Some(owner), .. - }) => tcx.typeck_tables_of(owner).concrete_existential_types[&def_id], + }) => { + tcx.typeck_tables_of(owner) + .concrete_existential_types + .get(&def_id) + .cloned() + .unwrap_or_else(|| { + // This can occur if some error in the + // owner fn prevented us from populating + // the `concrete_existential_types` table. + tcx.sess.delay_span_bug( + DUMMY_SP, + &format!( + "owner {:?} has no existential type for {:?} in its tables", + owner, def_id, + ), + ); + tcx.types.err + }) + } ItemKind::Trait(..) | ItemKind::TraitAlias(..) | ItemKind::Mod(..) diff --git a/src/test/compile-fail/issue-53300.rs b/src/test/compile-fail/issue-53300.rs new file mode 100644 index 000000000000..d055a6f12c17 --- /dev/null +++ b/src/test/compile-fail/issue-53300.rs @@ -0,0 +1,22 @@ +// Copyright 2012-2014 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. + +// issue 53300 + +pub trait A { + fn add(&self, b: i32) -> i32; +} + +fn addition() -> Wrapper {} +//~^ ERROR cannot find type `Wrapper` in this scope [E0412] + +fn main() { + let res = addition(); +}