add test for let-bindings
This commit is contained in:
parent
c7d16df1d8
commit
82ebbd7d6b
|
@ -1693,25 +1693,27 @@ pub fn const_evaluatable_predicates_of<'tcx>(
|
||||||
) -> impl Iterator<Item = (ty::Predicate<'tcx>, Span)> {
|
) -> impl Iterator<Item = (ty::Predicate<'tcx>, Span)> {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ConstCollector<'tcx> {
|
struct ConstCollector<'tcx> {
|
||||||
ct: SmallVec<[(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>); 4]>,
|
ct: SmallVec<[(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>, Span); 4]>,
|
||||||
|
curr_span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeVisitor<'tcx> for ConstCollector<'tcx> {
|
impl<'tcx> TypeVisitor<'tcx> for ConstCollector<'tcx> {
|
||||||
fn visit_const(&mut self, ct: &'tcx Const<'tcx>) -> bool {
|
fn visit_const(&mut self, ct: &'tcx Const<'tcx>) -> bool {
|
||||||
if let ty::ConstKind::Unevaluated(def, substs, None) = ct.val {
|
if let ty::ConstKind::Unevaluated(def, substs, None) = ct.val {
|
||||||
self.ct.push((def, substs));
|
self.ct.push((def, substs, self.curr_span));
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut collector = ConstCollector::default();
|
let mut collector = ConstCollector::default();
|
||||||
for (pred, _span) in predicates.predicates.iter() {
|
for &(pred, span) in predicates.predicates.iter() {
|
||||||
|
collector.curr_span = span;
|
||||||
pred.visit_with(&mut collector);
|
pred.visit_with(&mut collector);
|
||||||
}
|
}
|
||||||
warn!("const_evaluatable_predicates_of({:?}) = {:?}", def_id, collector.ct);
|
warn!("const_evaluatable_predicates_of({:?}) = {:?}", def_id, collector.ct);
|
||||||
collector.ct.into_iter().map(move |(def_id, subst)| {
|
collector.ct.into_iter().map(move |(def_id, subst, span)| {
|
||||||
(ty::PredicateAtom::ConstEvaluatable(def_id, subst).to_predicate(tcx), DUMMY_SP)
|
(ty::PredicateAtom::ConstEvaluatable(def_id, subst).to_predicate(tcx), span)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#![feature(const_generics, const_evaluatable_checked)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
// We do not yet want to support let-bindings in abstract consts,
|
||||||
|
// so this test should keep failing for now.
|
||||||
|
fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
|
||||||
|
//~^ ERROR constant expression depends
|
||||||
|
//~| ERROR constant expression depends
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = test::<31>();
|
||||||
|
assert_eq!(x, [0; 32]);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
error: constant expression depends on a generic parameter
|
||||||
|
--> $DIR/let-bindings.rs:6:91
|
||||||
|
|
|
||||||
|
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
|
||||||
|
| ^^^^^^^ required by this bound in `test::{{constant}}#0`
|
||||||
|
|
|
||||||
|
= note: this may fail depending on what value the parameter takes
|
||||||
|
|
||||||
|
error: constant expression depends on a generic parameter
|
||||||
|
--> $DIR/let-bindings.rs:6:30
|
||||||
|
|
|
||||||
|
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: this may fail depending on what value the parameter takes
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
Loading…
Reference in New Issue