about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshBrudnak <jobrud314@gmail.com>2018-08-19 12:40:30 -0400
committerjosh <joshuabrudnak@oakland.edu>2018-08-21 12:45:51 -0400
commitec47293998c32aab48bd85a418298a868b1e360a (patch)
tree2175cf62988e384764a475e3d90269994e2d77ed
parent588e6e969eeb61460fdd6132f9f50295ec246b44 (diff)
downloadrust-ec47293998c32aab48bd85a418298a868b1e360a.tar.gz
rust-ec47293998c32aab48bd85a418298a868b1e360a.zip
Fix compile panic on non existant type return #53300
-rw-r--r--src/librustc_typeck/collect.rs20
-rw-r--r--src/test/compile-fail/issue-53300.rs22
2 files changed, 41 insertions, 1 deletions
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 44a1960ea18..e404eb4ecca 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 00000000000..d055a6f12c1
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<impl A> {}
+//~^ ERROR cannot find type `Wrapper` in this scope [E0412]
+
+fn main() {
+    let res = addition();
+}