Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistent_struct_constructor: try to make message and lint description a bit clearer #6892

Merged
merged 1 commit into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions clippy_lints/src/inconsistent_struct_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use if_chain::if_chain;
use crate::utils::{snippet, span_lint_and_sugg};

declare_clippy_lint! {
/// **What it does:** Checks for struct constructors where the order of the field init
/// shorthand in the constructor is inconsistent with the order in the struct definition.
/// **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.
///
/// **Why is this bad?** Since the order of fields in a constructor doesn't affect the
/// resulted instance as the below example indicates,
Expand All @@ -25,11 +26,11 @@ declare_clippy_lint! {
/// let x = 1;
/// let y = 2;
///
/// // This assertion never fails.
/// // This assertion never fails:
/// assert_eq!(Foo { x, y }, Foo { y, x });
/// ```
///
/// inconsistent order means nothing and just decreases readability and consistency.
/// inconsistent order can be confusing and decreases readability and consistency.
///
/// **Known problems:** None.
///
Expand All @@ -42,6 +43,7 @@ declare_clippy_lint! {
/// }
/// let x = 1;
/// let y = 2;
///
/// Foo { y, x };
/// ```
///
Expand Down Expand Up @@ -107,7 +109,7 @@ impl LateLintPass<'_> for InconsistentStructConstructor {
cx,
INCONSISTENT_STRUCT_CONSTRUCTOR,
expr.span,
"inconsistent struct constructor",
"struct constructor field order is inconsistent with struct definition field order",
"try",
sugg,
Applicability::MachineApplicable,
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/inconsistent_struct_constructor.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error: inconsistent struct constructor
error: struct constructor field order is inconsistent with struct definition field order
--> $DIR/inconsistent_struct_constructor.rs:25:9
|
LL | Foo { y, x, z };
| ^^^^^^^^^^^^^^^ help: try: `Foo { x, y, z }`
|
= note: `-D clippy::inconsistent-struct-constructor` implied by `-D warnings`

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