Skip to content

Commit 71c6346

Browse files
committedJan 17, 2020
Auto merge of #68285 - oli-obk:specialization_regression, r=davidtwco
Array repeat expression lengths must be monomorphic at MIR building time fixes #67743
2 parents 2480c9e + eed0d33 commit 71c6346

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed
 

‎src/librustc_mir_build/hair/cx/expr.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -411,18 +411,21 @@ fn make_mirror_unadjusted<'a, 'tcx>(
411411
let def_id = cx.tcx.hir().local_def_id(count.hir_id);
412412
let substs = InternalSubsts::identity_for_item(cx.tcx, def_id);
413413
let span = cx.tcx.def_span(def_id);
414-
let count =
415-
match cx.tcx.const_eval_resolve(cx.param_env, def_id, substs, None, Some(span)) {
416-
Ok(cv) => cv.eval_usize(cx.tcx, cx.param_env),
417-
Err(ErrorHandled::Reported) => 0,
418-
Err(ErrorHandled::TooGeneric) => {
419-
let span = cx.tcx.def_span(def_id);
420-
cx.tcx
421-
.sess
422-
.span_err(span, "array lengths can't depend on generic parameters");
423-
0
424-
}
425-
};
414+
let count = match cx.tcx.const_eval_resolve(
415+
ty::ParamEnv::reveal_all(),
416+
def_id,
417+
substs,
418+
None,
419+
Some(span),
420+
) {
421+
Ok(cv) => cv.eval_usize(cx.tcx, ty::ParamEnv::reveal_all()),
422+
Err(ErrorHandled::Reported) => 0,
423+
Err(ErrorHandled::TooGeneric) => {
424+
let span = cx.tcx.def_span(def_id);
425+
cx.tcx.sess.span_err(span, "array lengths can't depend on generic parameters");
426+
0
427+
}
428+
};
426429

427430
ExprKind::Repeat { value: v.to_ref(), count }
428431
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// check-pass
2+
3+
trait TraitA {
4+
const VALUE: usize;
5+
}
6+
7+
struct A;
8+
impl TraitA for A {
9+
const VALUE: usize = 1;
10+
}
11+
12+
trait TraitB {
13+
type MyA: TraitA;
14+
const VALUE: usize = Self::MyA::VALUE;
15+
}
16+
17+
struct B;
18+
impl TraitB for B {
19+
type MyA = A;
20+
}
21+
22+
fn main() {
23+
let _ = [0; A::VALUE];
24+
let _ = [0; B::VALUE]; // Indirectly refers to `A::VALUE`
25+
}

0 commit comments

Comments
 (0)