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
#[derive(Default)]structPet{name:Option<String>,// impl Default for Pet will use Default::default() for nameage:i128 = 42,// impl Default for Pet will use the literal 42 for age}// This works and produces:// `Pet { name: Some(""), age: 42 }`let _ = Pet{name:Some(String::new()), .. }// Compilation error: `name` needs to be specifiedlet _ = Pet{ .. }
Desirable SemVer major, deny by default lints:
default value removed from struct field, where the field continues to exist and the struct is still externally constructible with a literal
Witness: constructing the struct with { .. } syntax now requires supplying a value for that field.
It doesn't matter if the field is Default, since Default doesn't matter { .. }-style construction.
default value removed from enum struct variant field, where the field continues to exist and the variant is still constructible with a literal
Witness: constructing the variant with a literal now requires supplying a value for that field
Desirable SemVer major, warn by default lints:
default value changed on a struct field, from one explicitly-specified value to another
Reason to warn instead of error: it's possible the intended SemVer contract was "a default exists" rather than some specific value. It's situational, maintainers can promote this to error.
default value changed on an enum variant struct field, from one explicitly-specified value to another
Analogous to above case.
default value for a field (either struct or enum struct variant) changed from implicit Default::default() to a different, explicitly-specified value
Difficult! Need to determine if impl Default on the struct/enum is derived (hand-impls might not use the Default::default() for the field!), and also need to determine what Default::default() would return for the field's type. Default::default() isn't const in general, so we'd probably have to hardcode defaults for common built-in types.
Progress:
Waiting on RFC implementation in rustc
Waiting on rustdoc JSON to include field defaults
Need new schema in trustfall-rustdoc-adapter
Ready to write lints
The text was updated successfully, but these errors were encountered:
cc @estebank in case any SemVer edge cases I didn't notice jump out at you. No worries if you're too swamped with other work, just wanted to make you aware of this issue and give you the option to take a look! I like this feature and I'd like cargo-semver-checks support for it to be top-notch 😇
RFC link; Tracking issue (not for discussion, just tracking): rust-lang/rust#132162
In short:
Desirable SemVer major, deny by default lints:
{ .. }
syntax now requires supplying a value for that field.Default
, sinceDefault
doesn't matter{ .. }
-style construction.Desirable SemVer major, warn by default lints:
Default::default()
to a different, explicitly-specified valueimpl Default
on the struct/enum is derived (hand-impls might not use theDefault::default()
for the field!), and also need to determine whatDefault::default()
would return for the field's type.Default::default()
isn'tconst
in general, so we'd probably have to hardcode defaults for common built-in types.Progress:
trustfall-rustdoc-adapter
The text was updated successfully, but these errors were encountered: