Skip to content

Commit 65d046c

Browse files
committed
Auto merge of rust-lang#6892 - matthiaskrgr:inc_struct_ctor, r=Y-Nak
inconsistent_struct_constructor: try to make message and lint description a bit clearer changelog: inconsistent_struct_constructor: try to make message and lint description a bit clearer r? `@ghost`
2 parents d219888 + 6bc5fe4 commit 65d046c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

clippy_lints/src/inconsistent_struct_constructor.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use if_chain::if_chain;
1010
use crate::utils::{snippet, span_lint_and_sugg};
1111

1212
declare_clippy_lint! {
13-
/// **What it does:** Checks for struct constructors where the order of the field init
14-
/// shorthand in the constructor is inconsistent with the order in the struct definition.
13+
/// **What it does:** Checks for struct constructors where all fields are shorthand and
14+
/// the order of the field init shorthand in the constructor is inconsistent
15+
/// with the order in the struct definition.
1516
///
1617
/// **Why is this bad?** Since the order of fields in a constructor doesn't affect the
1718
/// resulted instance as the below example indicates,
@@ -25,11 +26,11 @@ declare_clippy_lint! {
2526
/// let x = 1;
2627
/// let y = 2;
2728
///
28-
/// // This assertion never fails.
29+
/// // This assertion never fails:
2930
/// assert_eq!(Foo { x, y }, Foo { y, x });
3031
/// ```
3132
///
32-
/// inconsistent order means nothing and just decreases readability and consistency.
33+
/// inconsistent order can be confusing and decreases readability and consistency.
3334
///
3435
/// **Known problems:** None.
3536
///
@@ -42,6 +43,7 @@ declare_clippy_lint! {
4243
/// }
4344
/// let x = 1;
4445
/// let y = 2;
46+
///
4547
/// Foo { y, x };
4648
/// ```
4749
///
@@ -107,7 +109,7 @@ impl LateLintPass<'_> for InconsistentStructConstructor {
107109
cx,
108110
INCONSISTENT_STRUCT_CONSTRUCTOR,
109111
expr.span,
110-
"inconsistent struct constructor",
112+
"struct constructor field order is inconsistent with struct definition field order",
111113
"try",
112114
sugg,
113115
Applicability::MachineApplicable,

tests/ui/inconsistent_struct_constructor.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error: inconsistent struct constructor
1+
error: struct constructor field order is inconsistent with struct definition field order
22
--> $DIR/inconsistent_struct_constructor.rs:25:9
33
|
44
LL | Foo { y, x, z };
55
| ^^^^^^^^^^^^^^^ help: try: `Foo { x, y, z }`
66
|
77
= note: `-D clippy::inconsistent-struct-constructor` implied by `-D warnings`
88

9-
error: inconsistent struct constructor
9+
error: struct constructor field order is inconsistent with struct definition field order
1010
--> $DIR/inconsistent_struct_constructor.rs:43:9
1111
|
1212
LL | / Foo {

0 commit comments

Comments
 (0)