Add query for const_param_default

This commit is contained in:
kadmin 2021-03-03 06:38:02 +00:00
parent 0e56a086f7
commit 9fe793ae5d
17 changed files with 108 additions and 27 deletions

View file

@ -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
}
}

View 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);
}

View file

@ -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])
}