Skip to content

Commit 57fb2f1

Browse files
committed
Address review comments
#13737 (comment)
1 parent 7d99b5d commit 57fb2f1

File tree

6 files changed

+16
-44
lines changed

6 files changed

+16
-44
lines changed

book/src/lint_configuration.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,10 @@ A list of paths to types that should be treated as if they do not contain interi
563563

564564

565565
## `initializer-suggestions`
566-
Suggestion behavior when initializers are present. Options are:
566+
Whether to suggest reordering constructor fields when initializers are present.
567567

568-
- "none": do not suggest
569-
- "maybe-incorrect": suggest, but do not apply suggestions with `--fix`
570-
- "machine-applicable": suggest and apply suggestions with `--fix`
571-
572-
The following example [due to @ronnodas] shows why "maybe-incorrect" may be the right choice.
573-
Swapping the fields in the constructor produces incompilable code:
568+
Note that such suggestions are not applied automatically with `--fix`. The following example
569+
[due to @ronnodas] shows why. Swapping the fields in the constructor produces incompilable code:
574570

575571
```rust
576572
struct MyStruct {
@@ -585,7 +581,7 @@ fn main() {
585581

586582
[due to @ronnodas]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924
587583

588-
**Default Value:** `"none"`
584+
**Default Value:** `false`
589585

590586
---
591587
**Affected lints:**

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-
initializer-suggestions = "machine-applicable"
3+
initializer-suggestions = true
44

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

clippy_config/src/conf.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::ClippyConfiguration;
22
use crate::types::{
3-
DisallowedPath, InitializerSuggestionApplicability, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour,
4-
Rename, SourceItemOrdering, SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings,
5-
SourceItemOrderingModuleItemKind, SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds,
3+
DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename, SourceItemOrdering,
4+
SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind,
5+
SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds,
66
};
77
use clippy_utils::msrvs::Msrv;
88
use rustc_errors::Applicability;
@@ -526,14 +526,10 @@ define_Conf! {
526526
/// A list of paths to types that should be treated as if they do not contain interior mutability
527527
#[lints(borrow_interior_mutable_const, declare_interior_mutable_const, ifs_same_cond, mutable_key_type)]
528528
ignore_interior_mutability: Vec<String> = Vec::from(["bytes::Bytes".into()]),
529-
/// Suggestion behavior when initializers are present. Options are:
529+
/// Whether to suggest reordering constructor fields when initializers are present.
530530
///
531-
/// - "none": do not suggest
532-
/// - "maybe-incorrect": suggest, but do not apply suggestions with `--fix`
533-
/// - "machine-applicable": suggest and apply suggestions with `--fix`
534-
///
535-
/// The following example [due to @ronnodas] shows why "maybe-incorrect" may be the right choice.
536-
/// Swapping the fields in the constructor produces incompilable code:
531+
/// Note that such suggestions are not applied automatically with `--fix`. The following example
532+
/// [due to @ronnodas] shows why. Swapping the fields in the constructor produces incompilable code:
537533
///
538534
/// ```rust
539535
/// struct MyStruct {
@@ -548,7 +544,7 @@ define_Conf! {
548544
///
549545
/// [due to @ronnodas]: https://github.com/rust-lang/rust-clippy/issues/11846#issuecomment-1820747924
550546
#[lints(inconsistent_struct_constructor)]
551-
initializer_suggestions: InitializerSuggestionApplicability = InitializerSuggestionApplicability::None,
547+
initializer_suggestions: bool = false,
552548
/// The maximum size of the `Err`-variant in a `Result` returned from a function
553549
#[lints(result_large_err)]
554550
large_error_threshold: u64 = 128,

clippy_config/src/types.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::def_path_def_ids;
2-
use rustc_errors::Applicability;
32
use rustc_hir::def_id::DefIdMap;
43
use rustc_middle::ty::TyCtxt;
54
use serde::de::{self, Deserializer, Visitor};
@@ -47,24 +46,6 @@ pub fn create_disallowed_map(
4746
.collect()
4847
}
4948

50-
#[derive(Clone, Copy, Deserialize, Serialize)]
51-
#[serde(rename_all = "kebab-case")]
52-
pub enum InitializerSuggestionApplicability {
53-
None,
54-
MaybeIncorrect,
55-
MachineApplicable,
56-
}
57-
58-
impl InitializerSuggestionApplicability {
59-
pub fn to_applicability(self) -> Option<Applicability> {
60-
match self {
61-
InitializerSuggestionApplicability::None => None,
62-
InitializerSuggestionApplicability::MaybeIncorrect => Some(Applicability::MaybeIncorrect),
63-
InitializerSuggestionApplicability::MachineApplicable => Some(Applicability::MachineApplicable),
64-
}
65-
}
66-
}
67-
6849
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
6950
pub enum MatchLintBehaviour {
7051
AllTypes,

clippy_lints/src/inconsistent_struct_constructor.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_config::Conf;
2-
use clippy_config::types::InitializerSuggestionApplicability;
32
use clippy_utils::diagnostics::span_lint_and_sugg;
43
use clippy_utils::fulfill_or_allowed;
54
use clippy_utils::source::snippet_opt;
@@ -66,7 +65,7 @@ declare_clippy_lint! {
6665
}
6766

6867
pub struct InconsistentStructConstructor {
69-
initializer_suggestions: InitializerSuggestionApplicability,
68+
initializer_suggestions: bool,
7069
}
7170

7271
impl InconsistentStructConstructor {
@@ -86,8 +85,8 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentStructConstructor {
8685
};
8786
let applicability = if fields.iter().all(|f| f.is_shorthand) {
8887
Applicability::MachineApplicable
89-
} else if let Some(applicability) = self.initializer_suggestions.to_applicability() {
90-
applicability
88+
} else if self.initializer_suggestions {
89+
Applicability::MaybeIncorrect
9190
} else {
9291
return;
9392
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
initializer-suggestions = "machine-applicable"
1+
initializer-suggestions = true

0 commit comments

Comments
 (0)