mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
Array repeat expression lengths must be monomorphic at MIR building time
This commit is contained in:
parent
9fe05e9456
commit
eed0d33a65
@ -411,18 +411,21 @@ fn make_mirror_unadjusted<'a, 'tcx>(
|
||||
let def_id = cx.tcx.hir().local_def_id(count.hir_id);
|
||||
let substs = InternalSubsts::identity_for_item(cx.tcx, def_id);
|
||||
let span = cx.tcx.def_span(def_id);
|
||||
let count =
|
||||
match cx.tcx.const_eval_resolve(cx.param_env, def_id, substs, None, Some(span)) {
|
||||
Ok(cv) => cv.eval_usize(cx.tcx, cx.param_env),
|
||||
Err(ErrorHandled::Reported) => 0,
|
||||
Err(ErrorHandled::TooGeneric) => {
|
||||
let span = cx.tcx.def_span(def_id);
|
||||
cx.tcx
|
||||
.sess
|
||||
.span_err(span, "array lengths can't depend on generic parameters");
|
||||
0
|
||||
}
|
||||
};
|
||||
let count = match cx.tcx.const_eval_resolve(
|
||||
ty::ParamEnv::reveal_all(),
|
||||
def_id,
|
||||
substs,
|
||||
None,
|
||||
Some(span),
|
||||
) {
|
||||
Ok(cv) => cv.eval_usize(cx.tcx, ty::ParamEnv::reveal_all()),
|
||||
Err(ErrorHandled::Reported) => 0,
|
||||
Err(ErrorHandled::TooGeneric) => {
|
||||
let span = cx.tcx.def_span(def_id);
|
||||
cx.tcx.sess.span_err(span, "array lengths can't depend on generic parameters");
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
ExprKind::Repeat { value: v.to_ref(), count }
|
||||
}
|
||||
|
25
src/test/ui/consts/associated_const_generic.rs
Normal file
25
src/test/ui/consts/associated_const_generic.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// check-pass
|
||||
|
||||
trait TraitA {
|
||||
const VALUE: usize;
|
||||
}
|
||||
|
||||
struct A;
|
||||
impl TraitA for A {
|
||||
const VALUE: usize = 1;
|
||||
}
|
||||
|
||||
trait TraitB {
|
||||
type MyA: TraitA;
|
||||
const VALUE: usize = Self::MyA::VALUE;
|
||||
}
|
||||
|
||||
struct B;
|
||||
impl TraitB for B {
|
||||
type MyA = A;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = [0; A::VALUE];
|
||||
let _ = [0; B::VALUE]; // Indirectly refers to `A::VALUE`
|
||||
}
|
Loading…
Reference in New Issue
Block a user