Skip to content

Commit ec47293

Browse files
committed
Fix compile panic on non existant type return #53300
1 parent 588e6e9 commit ec47293

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/librustc_typeck/collect.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,25 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> {
11631163
ItemKind::Existential(hir::ExistTy {
11641164
impl_trait_fn: Some(owner),
11651165
..
1166-
}) => tcx.typeck_tables_of(owner).concrete_existential_types[&def_id],
1166+
}) => {
1167+
tcx.typeck_tables_of(owner)
1168+
.concrete_existential_types
1169+
.get(&def_id)
1170+
.cloned()
1171+
.unwrap_or_else(|| {
1172+
// This can occur if some error in the
1173+
// owner fn prevented us from populating
1174+
// the `concrete_existential_types` table.
1175+
tcx.sess.delay_span_bug(
1176+
DUMMY_SP,
1177+
&format!(
1178+
"owner {:?} has no existential type for {:?} in its tables",
1179+
owner, def_id,
1180+
),
1181+
);
1182+
tcx.types.err
1183+
})
1184+
}
11671185
ItemKind::Trait(..)
11681186
| ItemKind::TraitAlias(..)
11691187
| ItemKind::Mod(..)

src/test/compile-fail/issue-53300.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2012-2014 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+
// issue 53300
12+
13+
pub trait A {
14+
fn add(&self, b: i32) -> i32;
15+
}
16+
17+
fn addition() -> Wrapper<impl A> {}
18+
//~^ ERROR cannot find type `Wrapper` in this scope [E0412]
19+
20+
fn main() {
21+
let res = addition();
22+
}

0 commit comments

Comments
 (0)