Skip to content

Commit d023c9b

Browse files
authored
Rename inconsistent_struct_constructor configuration; don't suggest deprecated configurations (#14280)
This PR does two things: - It renames `inconsistent_struct_constructor`'s configuration from `lint-inconsistent-struct-field-initializers` to `check-inconsistent-struct-field-initializers`. (I should have suggested `check-...` in [#13737](#13737 (comment)).) - It causes Clippy to no longer suggest deprecated configurations. (Previously, Clippy would suggest `cyclomatic-complexity-threshold`, for example.) r? @y21 changelog: Rename `lint-inconsistent-struct-field-initializers` to `check-inconsistent-struct-field-initializers` changelog: No longer suggest deprecated configurations
2 parents f83c94c + 79e5125 commit d023c9b

File tree

7 files changed

+76
-61
lines changed

7 files changed

+76
-61
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6345,6 +6345,7 @@ Released 2018-09-13
63456345
[`await-holding-invalid-types`]: https://doc.rust-lang.org/clippy/lint_configuration.html#await-holding-invalid-types
63466346
[`cargo-ignore-publish`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cargo-ignore-publish
63476347
[`check-incompatible-msrv-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-incompatible-msrv-in-tests
6348+
[`check-inconsistent-struct-field-initializers`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-inconsistent-struct-field-initializers
63486349
[`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items
63496350
[`cognitive-complexity-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cognitive-complexity-threshold
63506351
[`disallowed-macros`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-macros
@@ -6361,7 +6362,6 @@ Released 2018-09-13
63616362
[`future-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#future-size-threshold
63626363
[`ignore-interior-mutability`]: https://doc.rust-lang.org/clippy/lint_configuration.html#ignore-interior-mutability
63636364
[`large-error-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#large-error-threshold
6364-
[`lint-inconsistent-struct-field-initializers`]: https://doc.rust-lang.org/clippy/lint_configuration.html#lint-inconsistent-struct-field-initializers
63656365
[`literal-representation-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#literal-representation-threshold
63666366
[`matches-for-let-else`]: https://doc.rust-lang.org/clippy/lint_configuration.html#matches-for-let-else
63676367
[`max-fn-params-bools`]: https://doc.rust-lang.org/clippy/lint_configuration.html#max-fn-params-bools

book/src/lint_configuration.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,33 @@ Whether to check MSRV compatibility in `#[test]` and `#[cfg(test)]` code.
425425
* [`incompatible_msrv`](https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv)
426426

427427

428+
## `check-inconsistent-struct-field-initializers`
429+
Whether to suggest reordering constructor fields when initializers are present.
430+
431+
Warnings produced by this configuration aren't necessarily fixed by just reordering the fields. Even if the
432+
suggested code would compile, it can change semantics if the initializer expressions have side effects. The
433+
following example [from rust-clippy#11846] shows how the suggestion can run into borrow check errors:
434+
435+
```rust
436+
struct MyStruct {
437+
vector: Vec<u32>,
438+
length: usize
439+
}
440+
fn main() {
441+
let vector = vec![1,2,3];
442+
MyStruct { length: vector.len(), vector};
443+
}
444+
```
445+
446+
[from rust-clippy#11846]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924
447+
448+
**Default Value:** `false`
449+
450+
---
451+
**Affected lints:**
452+
* [`inconsistent_struct_constructor`](https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_struct_constructor)
453+
454+
428455
## `check-private-items`
429456
Whether to also run the listed lints on private items.
430457

@@ -613,33 +640,6 @@ The maximum size of the `Err`-variant in a `Result` returned from a function
613640
* [`result_large_err`](https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err)
614641

615642

616-
## `lint-inconsistent-struct-field-initializers`
617-
Whether to suggest reordering constructor fields when initializers are present.
618-
619-
Warnings produced by this configuration aren't necessarily fixed by just reordering the fields. Even if the
620-
suggested code would compile, it can change semantics if the initializer expressions have side effects. The
621-
following example [from rust-clippy#11846] shows how the suggestion can run into borrow check errors:
622-
623-
```rust
624-
struct MyStruct {
625-
vector: Vec<u32>,
626-
length: usize
627-
}
628-
fn main() {
629-
let vector = vec![1,2,3];
630-
MyStruct { length: vector.len(), vector};
631-
}
632-
```
633-
634-
[from rust-clippy#11846]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924
635-
636-
**Default Value:** `false`
637-
638-
---
639-
**Affected lints:**
640-
* [`inconsistent_struct_constructor`](https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_struct_constructor)
641-
642-
643643
## `literal-representation-threshold`
644644
The lower bound for linting decimal literals
645645

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
avoid-breaking-exported-api = false
22

3-
lint-inconsistent-struct-field-initializers = true
3+
check-inconsistent-struct-field-initializers = true
44

55
[[disallowed-methods]]
66
path = "rustc_lint::context::LintContext::lint"

clippy_config/src/conf.rs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,26 @@ define_Conf! {
467467
/// Whether to check MSRV compatibility in `#[test]` and `#[cfg(test)]` code.
468468
#[lints(incompatible_msrv)]
469469
check_incompatible_msrv_in_tests: bool = false,
470+
/// Whether to suggest reordering constructor fields when initializers are present.
471+
///
472+
/// Warnings produced by this configuration aren't necessarily fixed by just reordering the fields. Even if the
473+
/// suggested code would compile, it can change semantics if the initializer expressions have side effects. The
474+
/// following example [from rust-clippy#11846] shows how the suggestion can run into borrow check errors:
475+
///
476+
/// ```rust
477+
/// struct MyStruct {
478+
/// vector: Vec<u32>,
479+
/// length: usize
480+
/// }
481+
/// fn main() {
482+
/// let vector = vec![1,2,3];
483+
/// MyStruct { length: vector.len(), vector};
484+
/// }
485+
/// ```
486+
///
487+
/// [from rust-clippy#11846]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924
488+
#[lints(inconsistent_struct_constructor)]
489+
check_inconsistent_struct_field_initializers: bool = false,
470490
/// Whether to also run the listed lints on private items.
471491
#[lints(missing_errors_doc, missing_panics_doc, missing_safety_doc, unnecessary_safety_doc)]
472492
check_private_items: bool = false,
@@ -542,25 +562,10 @@ define_Conf! {
542562
/// The maximum size of the `Err`-variant in a `Result` returned from a function
543563
#[lints(result_large_err)]
544564
large_error_threshold: u64 = 128,
545-
/// Whether to suggest reordering constructor fields when initializers are present.
546-
///
547-
/// Warnings produced by this configuration aren't necessarily fixed by just reordering the fields. Even if the
548-
/// suggested code would compile, it can change semantics if the initializer expressions have side effects. The
549-
/// following example [from rust-clippy#11846] shows how the suggestion can run into borrow check errors:
565+
/// DEPRECATED CONFIGURATION: lint-inconsistent-struct-field-initializers
550566
///
551-
/// ```rust
552-
/// struct MyStruct {
553-
/// vector: Vec<u32>,
554-
/// length: usize
555-
/// }
556-
/// fn main() {
557-
/// let vector = vec![1,2,3];
558-
/// MyStruct { length: vector.len(), vector};
559-
/// }
560-
/// ```
561-
///
562-
/// [from rust-clippy#11846]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924
563-
#[lints(inconsistent_struct_constructor)]
567+
/// Use the `check-inconsistent-struct-field-initializers` configuration instead.
568+
#[conf_deprecated("Please use `check-inconsistent-struct-field-initializers` instead", check_inconsistent_struct_field_initializers)]
564569
lint_inconsistent_struct_field_initializers: bool = false,
565570
/// The lower bound for linting decimal literals
566571
#[lints(decimal_literal_representation)]
@@ -935,7 +940,23 @@ impl serde::de::Error for FieldError {
935940
// set and allows it.
936941
use fmt::Write;
937942

938-
let mut expected = expected.to_vec();
943+
let metadata = get_configuration_metadata();
944+
let deprecated = metadata
945+
.iter()
946+
.filter_map(|conf| {
947+
if conf.deprecation_reason.is_some() {
948+
Some(conf.name.as_str())
949+
} else {
950+
None
951+
}
952+
})
953+
.collect::<Vec<_>>();
954+
955+
let mut expected = expected
956+
.iter()
957+
.copied()
958+
.filter(|name| !deprecated.contains(name))
959+
.collect::<Vec<_>>();
939960
expected.sort_unstable();
940961

941962
let (rows, column_widths) = calculate_dimensions(&expected);

clippy_lints/src/inconsistent_struct_constructor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ declare_clippy_lint! {
6565
}
6666

6767
pub struct InconsistentStructConstructor {
68-
lint_inconsistent_struct_field_initializers: bool,
68+
check_inconsistent_struct_field_initializers: bool,
6969
}
7070

7171
impl InconsistentStructConstructor {
7272
pub fn new(conf: &'static Conf) -> Self {
7373
Self {
74-
lint_inconsistent_struct_field_initializers: conf.lint_inconsistent_struct_field_initializers,
74+
check_inconsistent_struct_field_initializers: conf.check_inconsistent_struct_field_initializers,
7575
}
7676
}
7777
}
@@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor {
8686
let all_fields_are_shorthand = fields.iter().all(|f| f.is_shorthand);
8787
let applicability = if all_fields_are_shorthand {
8888
Applicability::MachineApplicable
89-
} else if self.lint_inconsistent_struct_field_initializers {
89+
} else if self.check_inconsistent_struct_field_initializers {
9090
Applicability::MaybeIncorrect
9191
} else {
9292
return;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lint-inconsistent-struct-field-initializers = true
1+
check-inconsistent-struct-field-initializers = true

tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
2929
array-size-threshold
3030
avoid-breaking-exported-api
3131
await-holding-invalid-types
32-
blacklisted-names
3332
cargo-ignore-publish
3433
check-incompatible-msrv-in-tests
34+
check-inconsistent-struct-field-initializers
3535
check-private-items
3636
cognitive-complexity-threshold
37-
cyclomatic-complexity-threshold
3837
disallowed-macros
3938
disallowed-methods
4039
disallowed-names
@@ -49,7 +48,6 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
4948
future-size-threshold
5049
ignore-interior-mutability
5150
large-error-threshold
52-
lint-inconsistent-struct-field-initializers
5351
literal-representation-threshold
5452
matches-for-let-else
5553
max-fn-params-bools
@@ -121,12 +119,11 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
121119
array-size-threshold
122120
avoid-breaking-exported-api
123121
await-holding-invalid-types
124-
blacklisted-names
125122
cargo-ignore-publish
126123
check-incompatible-msrv-in-tests
124+
check-inconsistent-struct-field-initializers
127125
check-private-items
128126
cognitive-complexity-threshold
129-
cyclomatic-complexity-threshold
130127
disallowed-macros
131128
disallowed-methods
132129
disallowed-names
@@ -141,7 +138,6 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
141138
future-size-threshold
142139
ignore-interior-mutability
143140
large-error-threshold
144-
lint-inconsistent-struct-field-initializers
145141
literal-representation-threshold
146142
matches-for-let-else
147143
max-fn-params-bools
@@ -213,12 +209,11 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
213209
array-size-threshold
214210
avoid-breaking-exported-api
215211
await-holding-invalid-types
216-
blacklisted-names
217212
cargo-ignore-publish
218213
check-incompatible-msrv-in-tests
214+
check-inconsistent-struct-field-initializers
219215
check-private-items
220216
cognitive-complexity-threshold
221-
cyclomatic-complexity-threshold
222217
disallowed-macros
223218
disallowed-methods
224219
disallowed-names
@@ -233,7 +228,6 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
233228
future-size-threshold
234229
ignore-interior-mutability
235230
large-error-threshold
236-
lint-inconsistent-struct-field-initializers
237231
literal-representation-threshold
238232
matches-for-let-else
239233
max-fn-params-bools

0 commit comments

Comments
 (0)