diff --git a/master/index.html b/master/index.html index 8dc6ae9b31ff..ea198c6750a3 100644 --- a/master/index.html +++ b/master/index.html @@ -4367,9 +4367,9 @@

Example

61_864_918_973_511
 
Applicability: MaybeIncorrect(?)
Added in: pre 1.29.0
Related Issues
View Source

What it does

-

Checks for struct constructors where all fields are shorthand and -the order of the field init shorthand in the constructor is inconsistent -with the order in the struct definition.

+

Checks for struct constructors where the order of the field +init in the constructor is inconsistent with the order in the +struct definition.

Why is this bad?

Since the order of fields in a constructor doesn’t affect the resulted instance as the below example indicates,

@@ -4398,7 +4398,24 @@

Example

Use instead:

Foo { x, y };
 
-
Applicability: MachineApplicable(?)
Added in: 1.52.0

What it does

+

Configuration

+
    +
  • lint-inconsistent-struct-field-initializers: Whether to suggest reordering constructor fields when initializers are present.
  • +
+

Warnings produced by this configuration aren’t necessarily fixed by just reordering the fields. Even if the +suggested code would compile, it can change semantics if the initializer expressions have side effects. The +following example from rust-clippy#11846 shows how the suggestion can run into borrow check errors:

+
struct MyStruct {
+    vector: Vec<u32>,
+    length: usize
+}
+fn main() {
+    let vector = vec![1,2,3];
+    MyStruct { length: vector.len(), vector};
+}
+
+

(default: false)

+
Applicability: MachineApplicable(?)
Added in: 1.52.0

What it does

The lint checks for slice bindings in patterns that are only used to access individual slice values.

Why is this bad?