You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 03cbd41
Browse filesBrowse the repository at this point in the historyBrowse files
Auto merge of #163235 - estebank:default-field-values-lint, r=fmease
Lint default field values in types with type or const parameters as they won't be evaluated pre-mono
Default field values in types that have const generics are no longer being evaluated until mono. Emit a warn-by-default lint so that API designers are not caught of guard by this behavior.
```
warning: field `multiline_field` has a default value that is only checked when a value of `Z` is constructed
--> $DIR/field-references-param-accurate-span.rs:9:15
|
LL | struct Z<const X: usize> {
LL | multiline_field:
LL | ()
LL | = {
| _______________^
LL | | f::<X>();
LL | | panic!();
LL | | },
| |_____________^ this can't be const-evaluated until use
|
= help: structs and enums with type and const parameters only evaluate their default field values during construction, not eagerly when declared
= note: `#[warn(unevaluated_default_field_value)]` on by default
help: if this behavior is acceptable, allow the lint and preferably write a test relying on the default value
|
LL + #[expect(unevaluated_default_field_value)]
LL | struct Z<const X: usize> {
|
```
Support `Span` context in lints.
Fixes#146496.
Part of #132162.
Alternative to #163182.
CC @fmease@BoxyUwU
0 commit comments