diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-12-10 19:21:07 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-12-10 19:21:07 +0000 |
| commit | 979eb4e98eac8b9888fedd8ebd0a0e354b82fe21 (patch) | |
| tree | 7df9cb40b3793ec997386c135293497f40f450ac | |
| parent | 5eac9c00561751c78cc3f9dd914600c1ddff827b (diff) | |
| download | rust-979eb4e98eac8b9888fedd8ebd0a0e354b82fe21.tar.gz rust-979eb4e98eac8b9888fedd8ebd0a0e354b82fe21.zip | |
Further document default field test
| -rw-r--r-- | tests/ui/structs/default-field-values-support.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/tests/ui/structs/default-field-values-support.rs b/tests/ui/structs/default-field-values-support.rs index 9efba3ca2ce..8209d6dd4a0 100644 --- a/tests/ui/structs/default-field-values-support.rs +++ b/tests/ui/structs/default-field-values-support.rs @@ -1,3 +1,6 @@ +// Exercise the `default_field_values` feature to confirm it interacts correctly with other nightly +// features. In particular, we want to verify that interaction with consts coming from different +// contexts are usable as a default field value. //@ run-pass //@ aux-build:struct_field_default.rs #![feature(const_trait_impl, default_field_values, generic_const_exprs)] @@ -7,12 +10,14 @@ extern crate struct_field_default as xc; pub struct S; +// Basic expressions and `Default` expansion #[derive(Default)] pub struct Foo { pub bar: S = S, pub baz: i32 = 42 + 3, } +// Enum support for deriving `Default` when all fields have default values #[derive(Default)] pub enum Bar { #[default] @@ -33,13 +38,13 @@ impl const ConstDefault for i32 { } pub struct Qux<A, const C: i32, X: const ConstDefault> { - bar: S = Qux::<A, C, X>::S, - baz: i32 = foo(), - bat: i32 = <Qux<A, C, X> as T>::K, - baq: i32 = Self::K, - bay: i32 = C, - bak: Vec<A> = Vec::new(), - ban: X = X::value(), + bar: S = Qux::<A, C, X>::S, // Associated constant from inherent impl + baz: i32 = foo(), // Constant function + bat: i32 = <Qux<A, C, X> as T>::K, // Associated constant from explicit trait + baq: i32 = Self::K, // Associated constant from implicit trait + bay: i32 = C, // `const` parameter + bak: Vec<A> = Vec::new(), // Associated constant function + ban: X = X::value(), // Associated constant function from `const` trait parameter } impl<A, const C: i32, X: const ConstDefault> Qux<A, C, X> { |
