Skip to content

Commit 4b67324

Browse files
committed
Fix type_dependent_defs ICE on method calls
1 parent 75af15e commit 4b67324

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/librustc_passes/rvalue_promotion.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,14 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node
373373
}
374374
}
375375
hir::ExprMethodCall(..) => {
376-
let def_id = v.tables.type_dependent_defs()[e.hir_id].def_id();
377-
match v.tcx.associated_item(def_id).container {
378-
ty::ImplContainer(_) => v.handle_const_fn_call(def_id, node_ty),
379-
ty::TraitContainer(_) => v.promotable = false
376+
if let Some(def) = v.tables.type_dependent_defs().get(e.hir_id) {
377+
let def_id = def.def_id();
378+
match v.tcx.associated_item(def_id).container {
379+
ty::ImplContainer(_) => v.handle_const_fn_call(def_id, node_ty),
380+
ty::TraitContainer(_) => v.promotable = false
381+
}
382+
} else {
383+
v.tcx.sess.delay_span_bug(e.span, "no type-dependent def for method call");
380384
}
381385
}
382386
hir::ExprStruct(..) => {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2018 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+
fn main() {
12+
let v = vec![0];
13+
const l: usize = v.count(); //~ ERROR can't capture dynamic environment in a fn item
14+
let s: [u32; l] = v.into_iter().collect(); //~ ERROR constant evaluation error
15+
}

0 commit comments

Comments
 (0)