Add has_default to GenericParamDefKind::Const
This currently creates a field which is always false on GenericParamDefKind for future use when consts are permitted to have defaults Update const_generics:default locations Previously just ignored them, now actually do something about them. Fix using type check instead of value Add parsing This adds all the necessary changes to lower const-generics defaults from parsing. Change P<Expr> to AnonConst This matches the arguments passed to instantiations of const generics, and makes it specific to just anonymous constants. Attempt to fix lowering bugs
This commit is contained in:
parent
79e5814f45
commit
e4e5db4e42
39 changed files with 158 additions and 77 deletions
15
src/test/ui/const-generics/defaults/const-default.rs
Normal file
15
src/test/ui/const-generics/defaults/const-default.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// check-pass
|
||||
|
||||
#![feature(const_generics)]
|
||||
#![feature(const_generic_defaults)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ConstDefault<const N: usize = 3> {
|
||||
items: [u32; N]
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let s = ConstDefault::default();
|
||||
}
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
#![feature(const_generic_defaults)]
|
||||
#![feature(min_const_generics)]
|
||||
|
||||
fn foo<const SIZE: usize = 5>() {}
|
||||
//~^ ERROR default values for const generic parameters are experimental
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,2 @@
|
|||
trait Foo<const KIND: bool = true> {}
|
||||
//~^ ERROR default values for const generic parameters are experimental
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
#![feature(min_const_generics)]
|
||||
#![crate_type="lib"]
|
||||
|
||||
struct A<const N: usize = 3>;
|
||||
//~^ ERROR default values for
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
error: default values for const generic parameters are unstable
|
||||
--> $DIR/feature-gate-const_generic_defaults.rs:4:27
|
||||
|
|
||||
LL | struct A<const N: usize = 3>;
|
||||
| ^
|
||||
|
|
||||
= note: to enable them use #![feature(const_generic_defaults)]
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -408,6 +408,10 @@ pub fn eq_use_tree(l: &UseTree, r: &UseTree) -> bool {
|
|||
eq_path(&l.prefix, &r.prefix) && eq_use_tree_kind(&l.kind, &r.kind)
|
||||
}
|
||||
|
||||
pub fn eq_anon_const(l: &AnonConst, r: &AnonConst) -> bool {
|
||||
eq_expr(&l.value, &r.value)
|
||||
}
|
||||
|
||||
pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
|
||||
use UseTreeKind::*;
|
||||
match (l, r) {
|
||||
|
|
@ -418,10 +422,6 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn eq_anon_const(l: &AnonConst, r: &AnonConst) -> bool {
|
||||
eq_expr(&l.value, &r.value)
|
||||
}
|
||||
|
||||
pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool {
|
||||
matches!(
|
||||
(l, r),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue