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);
|
let leaf = leaf.subst(tcx, ct.substs);
|
||||||
self.visit_const(leaf)
|
self.visit_const(leaf)
|
||||||
}
|
}
|
||||||
ACNode::Binop(..)
|
ACNode::Cast(_, _, ty) => self.visit_ty(ty),
|
||||||
| ACNode::UnaryOp(..)
|
ACNode::Binop(..) | ACNode::UnaryOp(..) | ACNode::FunctionCall(_, _) => {
|
||||||
| ACNode::FunctionCall(_, _)
|
ControlFlow::CONTINUE
|
||||||
| ACNode::Cast(_, _, _) => ControlFlow::CONTINUE,
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,10 +97,19 @@ enum FailureKind {
|
|||||||
|
|
||||||
ControlFlow::CONTINUE
|
ControlFlow::CONTINUE
|
||||||
}
|
}
|
||||||
Node::Binop(_, _, _)
|
Node::Cast(_, _, ty) => {
|
||||||
| Node::UnaryOp(_, _)
|
let ty = ty.subst(tcx, ct.substs);
|
||||||
| Node::FunctionCall(_, _)
|
if ty.has_infer_types_or_consts() {
|
||||||
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
|
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 {
|
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);
|
let leaf = leaf.subst(self.tcx, ct.substs);
|
||||||
self.visit_const(leaf)
|
self.visit_const(leaf)
|
||||||
}
|
}
|
||||||
Node::Binop(..)
|
Node::Cast(_, _, ty) => self.visit_ty(ty),
|
||||||
| Node::UnaryOp(..)
|
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
|
||||||
| Node::FunctionCall(_, _)
|
ControlFlow::CONTINUE
|
||||||
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ControlFlow::CONTINUE
|
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);
|
let leaf = leaf.subst(self.tcx, ct.substs);
|
||||||
self.visit_const(leaf)
|
self.visit_const(leaf)
|
||||||
}
|
}
|
||||||
Node::Binop(..)
|
Node::Cast(_, _, ty) => self.visit_ty(ty),
|
||||||
| Node::UnaryOp(..)
|
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
|
||||||
| Node::FunctionCall(_, _)
|
ControlFlow::CONTINUE
|
||||||
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ControlFlow::CONTINUE
|
ControlFlow::CONTINUE
|
||||||
|
@ -1,13 +1,20 @@
|
|||||||
#![feature(const_evaluatable_checked, const_generics)]
|
#![feature(const_evaluatable_checked, const_generics)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
trait Evaluatable<const N: u128> {}
|
struct Evaluatable<const N: u128> {}
|
||||||
impl<const N: u128> Evaluatable<N> for () {}
|
|
||||||
|
|
||||||
struct Foo<const N: u8>([u8; N as usize])
|
struct Foo<const N: u8>([u8; N as usize])
|
||||||
//~^ Error: unconstrained generic constant
|
//~^ Error: unconstrained generic constant
|
||||||
//~| help: try adding a `where` bound using this expression: `where [(); N as usize]:`
|
//~| help: try adding a `where` bound using this expression: `where [(); N as usize]:`
|
||||||
where
|
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() {}
|
fn main() {}
|
||||||
|
@ -1,10 +1,26 @@
|
|||||||
error: unconstrained generic constant
|
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])
|
LL | struct Foo<const N: u8>([u8; N as usize])
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= help: try adding a `where` bound using this expression: `where [(); 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
|
where
|
||||||
[(); N as usize]:;
|
[(); 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() {}
|
fn main() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user