@@ -710,32 +710,36 @@ all the following rules apply when type-checking:
7107102 . The expression ` def ` must coerce to the type ` ty ` .
711711
7127123 . Generic parameters of the current items are accessible
713- ``` rust
714- struct Bar <const A : usize > {
715- field : usize = A ,
716- }
717- ```
713+ ``` rust
714+ struct Bar <const A : usize > {
715+ field : usize = A ,
716+ }
717+ ```
718718
7197194 . Default const expressions are * not* evaluated at definition time, only
720720 during instantiation. This means that the following will not fail to compile:
721- ``` rust
722- struct Bar {
723- field1 : usize = panic! (),
724- field2 : usize = 42 ,
725- }
721+ ``` rust
722+ struct Bar {
723+ field1 : usize = panic! (),
724+ field2 : usize = 42 ,
725+ }
726726
727- let _ = Bar { field1 : 0 , .. };
728- ```
727+ let _ = Bar { field1 : 0 , .. };
728+ ```
729+ Having said that, it can be possible to proactivelly attempt to evaluate the
730+ default values and emit a lint in a case where the expression is assured to always
731+ fail (which would only be possible for expressions that do not reference ` const `
732+ parameters).
729733
7307345 . The ` struct ` 's parameters are properly propagated, meaning the following is
731735 possible:
732- ``` rust
733- struct Bar <T > {
734- field : Vec <T > = Vec :: new (),
735- }
736+ ``` rust
737+ struct Bar <T > {
738+ field : Vec <T > = Vec :: new (),
739+ }
736740
737- let _ = Bar :: <i32 > { .. };
738- ```
741+ let _ = Bar :: <i32 > { .. };
742+ ```
739743
740744When lints check attributes such as ` #[allow(lint_name)] ` are placed on a
741745` RecordField ` , it also applies to ` def ` if it exists.
0 commit comments