Skip to content

Commit d54f74e

Browse files
committed
Rollup merge of #49244 - varkor:type_dependent_defs_ExprMethodCall, r=estebank
Fix type_dependent_defs ICE on method calls Fixes #49241.
2 parents eb99deb + 3272b63 commit d54f74e

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

src/librustc_passes/rvalue_promotion.rs

+8-4
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(..) => {
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0434]: can't capture dynamic environment in a fn item
2+
--> $DIR/type-dependent-def-issue-49241.rs:13:22
3+
|
4+
LL | const l: usize = v.count(); //~ ERROR can't capture dynamic environment in a fn item
5+
| ^
6+
|
7+
= help: use the `|| { ... }` closure form instead
8+
9+
error[E0080]: constant evaluation error
10+
--> $DIR/type-dependent-def-issue-49241.rs:14:18
11+
|
12+
LL | let s: [u32; l] = v.into_iter().collect(); //~ ERROR constant evaluation error
13+
| ^ encountered constants with type errors, stopping evaluation
14+
15+
error: aborting due to 2 previous errors
16+
17+
Some errors occurred: E0080, E0434.
18+
For more information about an error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)