Add query for const_param_default
This commit is contained in:
parent
0e56a086f7
commit
9fe793ae5d
17 changed files with 108 additions and 27 deletions
|
|
@ -0,0 +1,15 @@
|
|||
#![feature(const_generics)]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
pub struct Defaulted<const N: usize=3>;
|
||||
impl Defaulted {
|
||||
pub fn new() -> Self {
|
||||
Defaulted
|
||||
}
|
||||
}
|
||||
impl<const N: usize> Defaulted<N> {
|
||||
pub fn value(&self) -> usize {
|
||||
N
|
||||
}
|
||||
}
|
||||
27
src/test/ui/const-generics/defaults/external.rs
Normal file
27
src/test/ui/const-generics/defaults/external.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// aux-build:const_defaulty.rs
|
||||
// check-pass
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
extern crate const_defaulty;
|
||||
use const_defaulty::Defaulted;
|
||||
|
||||
struct Local<const N: usize=4>;
|
||||
impl Local {
|
||||
fn new() -> Self {
|
||||
Local
|
||||
}
|
||||
}
|
||||
impl<const N: usize>Local<N> {
|
||||
fn value(&self) -> usize {
|
||||
N
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let v = Defaulted::new();
|
||||
assert_eq!(v.value(), 3);
|
||||
|
||||
let l = Local::new();
|
||||
assert_eq!(l.value(), 4);
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
// check-pass
|
||||
#![crate_type = "lib"]
|
||||
#![feature(const_generics_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct Both<T=u32, const N: usize=3> {
|
||||
arr: [T; N]
|
||||
}
|
||||
|
||||
trait BothTrait<T=u32, const N: usize=3> {}
|
||||
|
||||
enum BothEnum<T=u32, const N: usize=3> {
|
||||
Dummy([T; N])
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue