Skip to content

Commit d88818d

Browse files
authored
Rename inconsistent_struct_constructor configuration; don't suggest deprecated configurations (rust-lang#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 [rust-lang#13737](rust-lang/rust-clippy#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 ca48e46 + 315e9aa commit d88818d

File tree

7 files changed

+83
-61
lines changed

7 files changed

+83
-61
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6347,6 +6347,7 @@ Released 2018-09-13
63476347
[`await-holding-invalid-types`]: https://doc.rust-lang.org/clippy/lint_configuration.html#await-holding-invalid-types
63486348
[`cargo-ignore-publish`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cargo-ignore-publish
63496349
[`check-incompatible-msrv-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-incompatible-msrv-in-tests
6350+
[`check-inconsistent-struct-field-initializers`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-inconsistent-struct-field-initializers
63506351
[`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items
63516352
[`cognitive-complexity-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cognitive-complexity-threshold
63526353
[`disallowed-macros`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-macros
@@ -6364,7 +6365,6 @@ Released 2018-09-13
63646365
[`ignore-interior-mutability`]: https://doc.rust-lang.org/clippy/lint_configuration.html#ignore-interior-mutability
63656366
[`large-error-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#large-error-threshold
63666367
[`lint-commented-code`]: https://doc.rust-lang.org/clippy/lint_configuration.html#lint-commented-code
6367-
[`lint-inconsistent-struct-field-initializers`]: https://doc.rust-lang.org/clippy/lint_configuration.html#lint-inconsistent-struct-field-initializers
63686368
[`literal-representation-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#literal-representation-threshold
63696369
[`matches-for-let-else`]: https://doc.rust-lang.org/clippy/lint_configuration.html#matches-for-let-else
63706370
[`max-fn-params-bools`]: https://doc.rust-lang.org/clippy/lint_configuration.html#max-fn-params-bools

book/src/lint_configuration.md

+27-27
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

@@ -624,33 +651,6 @@ that would be collapsed.
624651
* [`collapsible_if`](https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if)
625652

626653

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

clippy.toml

+1-1
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

+47-19
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,26 @@ define_Conf! {
474474
/// Whether to check MSRV compatibility in `#[test]` and `#[cfg(test)]` code.
475475
#[lints(incompatible_msrv)]
476476
check_incompatible_msrv_in_tests: bool = false,
477+
/// Whether to suggest reordering constructor fields when initializers are present.
478+
///
479+
/// Warnings produced by this configuration aren't necessarily fixed by just reordering the fields. Even if the
480+
/// suggested code would compile, it can change semantics if the initializer expressions have side effects. The
481+
/// following example [from rust-clippy#11846] shows how the suggestion can run into borrow check errors:
482+
///
483+
/// ```rust
484+
/// struct MyStruct {
485+
/// vector: Vec<u32>,
486+
/// length: usize
487+
/// }
488+
/// fn main() {
489+
/// let vector = vec![1,2,3];
490+
/// MyStruct { length: vector.len(), vector};
491+
/// }
492+
/// ```
493+
///
494+
/// [from rust-clippy#11846]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924
495+
#[lints(inconsistent_struct_constructor)]
496+
check_inconsistent_struct_field_initializers: bool = false,
477497
/// Whether to also run the listed lints on private items.
478498
#[lints(missing_errors_doc, missing_panics_doc, missing_safety_doc, unnecessary_safety_doc)]
479499
check_private_items: bool = false,
@@ -554,24 +574,10 @@ define_Conf! {
554574
#[lints(collapsible_if)]
555575
lint_commented_code: bool = false,
556576
/// Whether to suggest reordering constructor fields when initializers are present.
577+
/// DEPRECATED CONFIGURATION: lint-inconsistent-struct-field-initializers
557578
///
558-
/// Warnings produced by this configuration aren't necessarily fixed by just reordering the fields. Even if the
559-
/// suggested code would compile, it can change semantics if the initializer expressions have side effects. The
560-
/// following example [from rust-clippy#11846] shows how the suggestion can run into borrow check errors:
561-
///
562-
/// ```rust
563-
/// struct MyStruct {
564-
/// vector: Vec<u32>,
565-
/// length: usize
566-
/// }
567-
/// fn main() {
568-
/// let vector = vec![1,2,3];
569-
/// MyStruct { length: vector.len(), vector};
570-
/// }
571-
/// ```
572-
///
573-
/// [from rust-clippy#11846]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924
574-
#[lints(inconsistent_struct_constructor)]
579+
/// Use the `check-inconsistent-struct-field-initializers` configuration instead.
580+
#[conf_deprecated("Please use `check-inconsistent-struct-field-initializers` instead", check_inconsistent_struct_field_initializers)]
575581
lint_inconsistent_struct_field_initializers: bool = false,
576582
/// The lower bound for linting decimal literals
577583
#[lints(decimal_literal_representation)]
@@ -986,7 +992,23 @@ impl serde::de::Error for FieldError {
986992
// set and allows it.
987993
use fmt::Write;
988994

989-
let mut expected = expected.to_vec();
995+
let metadata = get_configuration_metadata();
996+
let deprecated = metadata
997+
.iter()
998+
.filter_map(|conf| {
999+
if conf.deprecation_reason.is_some() {
1000+
Some(conf.name.as_str())
1001+
} else {
1002+
None
1003+
}
1004+
})
1005+
.collect::<Vec<_>>();
1006+
1007+
let mut expected = expected
1008+
.iter()
1009+
.copied()
1010+
.filter(|name| !deprecated.contains(name))
1011+
.collect::<Vec<_>>();
9901012
expected.sort_unstable();
9911013

9921014
let (rows, column_widths) = calculate_dimensions(&expected);
@@ -1069,7 +1091,13 @@ mod tests {
10691091
fn configs_are_tested() {
10701092
let mut names: HashSet<String> = crate::get_configuration_metadata()
10711093
.into_iter()
1072-
.map(|meta| meta.name.replace('_', "-"))
1094+
.filter_map(|meta| {
1095+
if meta.deprecation_reason.is_none() {
1096+
Some(meta.name.replace('_', "-"))
1097+
} else {
1098+
None
1099+
}
1100+
})
10731101
.collect();
10741102

10751103
let toml_files = WalkDir::new("../tests")

clippy_lints/src/inconsistent_struct_constructor.rs

+3-3
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;
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

+3-9
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
@@ -50,7 +49,6 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
5049
ignore-interior-mutability
5150
large-error-threshold
5251
lint-commented-code
53-
lint-inconsistent-struct-field-initializers
5452
literal-representation-threshold
5553
matches-for-let-else
5654
max-fn-params-bools
@@ -123,12 +121,11 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
123121
array-size-threshold
124122
avoid-breaking-exported-api
125123
await-holding-invalid-types
126-
blacklisted-names
127124
cargo-ignore-publish
128125
check-incompatible-msrv-in-tests
126+
check-inconsistent-struct-field-initializers
129127
check-private-items
130128
cognitive-complexity-threshold
131-
cyclomatic-complexity-threshold
132129
disallowed-macros
133130
disallowed-methods
134131
disallowed-names
@@ -144,7 +141,6 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
144141
ignore-interior-mutability
145142
large-error-threshold
146143
lint-commented-code
147-
lint-inconsistent-struct-field-initializers
148144
literal-representation-threshold
149145
matches-for-let-else
150146
max-fn-params-bools
@@ -217,12 +213,11 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
217213
array-size-threshold
218214
avoid-breaking-exported-api
219215
await-holding-invalid-types
220-
blacklisted-names
221216
cargo-ignore-publish
222217
check-incompatible-msrv-in-tests
218+
check-inconsistent-struct-field-initializers
223219
check-private-items
224220
cognitive-complexity-threshold
225-
cyclomatic-complexity-threshold
226221
disallowed-macros
227222
disallowed-methods
228223
disallowed-names
@@ -238,7 +233,6 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
238233
ignore-interior-mutability
239234
large-error-threshold
240235
lint-commented-code
241-
lint-inconsistent-struct-field-initializers
242236
literal-representation-threshold
243237
matches-for-let-else
244238
max-fn-params-bools

0 commit comments

Comments
 (0)