Add more tests + visit_ty in some places
This commit is contained in:
parent
8e7299dfcd
commit
c318364d48
@ -156,10 +156,10 @@ fn visit_abstract_const_expr(
|
||||
let leaf = leaf.subst(tcx, ct.substs);
|
||||
self.visit_const(leaf)
|
||||
}
|
||||
ACNode::Binop(..)
|
||||
| ACNode::UnaryOp(..)
|
||||
| ACNode::FunctionCall(_, _)
|
||||
| ACNode::Cast(_, _, _) => ControlFlow::CONTINUE,
|
||||
ACNode::Cast(_, _, ty) => self.visit_ty(ty),
|
||||
ACNode::Binop(..) | ACNode::UnaryOp(..) | ACNode::FunctionCall(_, _) => {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -97,10 +97,19 @@ enum FailureKind {
|
||||
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
Node::Binop(_, _, _)
|
||||
| Node::UnaryOp(_, _)
|
||||
| Node::FunctionCall(_, _)
|
||||
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
|
||||
Node::Cast(_, _, ty) => {
|
||||
let ty = ty.subst(tcx, ct.substs);
|
||||
if ty.has_infer_types_or_consts() {
|
||||
failure_kind = FailureKind::MentionsInfer;
|
||||
} else if ty.has_param_types_or_consts() {
|
||||
failure_kind = cmp::min(failure_kind, FailureKind::MentionsParam);
|
||||
}
|
||||
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
Node::Binop(_, _, _) | Node::UnaryOp(_, _) | Node::FunctionCall(_, _) => {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
});
|
||||
|
||||
match failure_kind {
|
||||
|
@ -838,10 +838,10 @@ fn visit_const(&mut self, ct: &ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
let leaf = leaf.subst(self.tcx, ct.substs);
|
||||
self.visit_const(leaf)
|
||||
}
|
||||
Node::Binop(..)
|
||||
| Node::UnaryOp(..)
|
||||
| Node::FunctionCall(_, _)
|
||||
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
|
||||
Node::Cast(_, _, ty) => self.visit_ty(ty),
|
||||
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
})
|
||||
} else {
|
||||
ControlFlow::CONTINUE
|
||||
@ -860,10 +860,10 @@ fn visit_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ControlFlow<Self::Br
|
||||
let leaf = leaf.subst(self.tcx, ct.substs);
|
||||
self.visit_const(leaf)
|
||||
}
|
||||
Node::Binop(..)
|
||||
| Node::UnaryOp(..)
|
||||
| Node::FunctionCall(_, _)
|
||||
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
|
||||
Node::Cast(_, _, ty) => self.visit_ty(ty),
|
||||
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
|
||||
ControlFlow::CONTINUE
|
||||
}
|
||||
})
|
||||
} else {
|
||||
ControlFlow::CONTINUE
|
||||
|
@ -1,13 +1,20 @@
|
||||
#![feature(const_evaluatable_checked, const_generics)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait Evaluatable<const N: u128> {}
|
||||
impl<const N: u128> Evaluatable<N> for () {}
|
||||
struct Evaluatable<const N: u128> {}
|
||||
|
||||
struct Foo<const N: u8>([u8; N as usize])
|
||||
//~^ Error: unconstrained generic constant
|
||||
//~| help: try adding a `where` bound using this expression: `where [(); N as usize]:`
|
||||
where
|
||||
(): Evaluatable<{N as u128}>;
|
||||
Evaluatable<{N as u128}>:;
|
||||
|
||||
struct Foo2<const N: u8>(Evaluatable::<{N as u128}>) where Evaluatable<{N as usize as u128 }>:;
|
||||
//~^ Error: unconstrained generic constant
|
||||
//~| help: try adding a `where` bound using this expression: `where [(); {N as u128}]:`
|
||||
|
||||
struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 1) as usize]:;
|
||||
//~^ unconstrained generic constant
|
||||
//~| help: try adding a `where` bound using this expression: `where [(); (N + 2) as usize]:`
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,10 +1,26 @@
|
||||
error: unconstrained generic constant
|
||||
--> $DIR/abstract-const-as-cast-2.rs:7:25
|
||||
--> $DIR/abstract-const-as-cast-2.rs:6:25
|
||||
|
|
||||
LL | struct Foo<const N: u8>([u8; N as usize])
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try adding a `where` bound using this expression: `where [(); N as usize]:`
|
||||
|
||||
error: aborting due to previous error
|
||||
error: unconstrained generic constant
|
||||
--> $DIR/abstract-const-as-cast-2.rs:12:26
|
||||
|
|
||||
LL | struct Foo2<const N: u8>(Evaluatable::<{N as u128}>) where Evaluatable<{N as usize as u128 }>:;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try adding a `where` bound using this expression: `where [(); {N as u128}]:`
|
||||
|
||||
error: unconstrained generic constant
|
||||
--> $DIR/abstract-const-as-cast-2.rs:16:25
|
||||
|
|
||||
LL | struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 1) as usize]:;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: try adding a `where` bound using this expression: `where [(); (N + 2) as usize]:`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -6,4 +6,13 @@
|
||||
where
|
||||
[(); N as usize]:;
|
||||
|
||||
|
||||
// unifying with subtrees
|
||||
struct Evaluatable<const N: u16>;
|
||||
fn foo<const N: u8>() where Evaluatable<{N as usize as u16 }>: {
|
||||
let _ = Foo::<N>([1; N as usize]);
|
||||
}
|
||||
|
||||
struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 2) as usize]:;
|
||||
|
||||
fn main() {}
|
||||
|
Loading…
Reference in New Issue
Block a user