fix: derive Default when possible

Ref https://rust-lang.github.io/rust-clippy/master/index.html#/derivable_impls
This commit is contained in:
xtqqczze
2025-11-29 19:11:38 +00:00
committed by GitHub
parent 57c190d56e
commit cd1f981bea

View File

@@ -229,13 +229,14 @@ pub(crate) enum GenerateMode {
} }
/// Indicates how ripgrep should treat binary data. /// Indicates how ripgrep should treat binary data.
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Default, Eq, PartialEq)]
pub(crate) enum BinaryMode { pub(crate) enum BinaryMode {
/// Automatically determine the binary mode to use. Essentially, when /// Automatically determine the binary mode to use. Essentially, when
/// a file is searched explicitly, then it will be searched using the /// a file is searched explicitly, then it will be searched using the
/// `SearchAndSuppress` strategy. Otherwise, it will be searched in a way /// `SearchAndSuppress` strategy. Otherwise, it will be searched in a way
/// that attempts to skip binary files as much as possible. That is, once /// that attempts to skip binary files as much as possible. That is, once
/// a file is classified as binary, searching will immediately stop. /// a file is classified as binary, searching will immediately stop.
#[default]
Auto, Auto,
/// Search files even when they have binary data, but if a match is found, /// Search files even when they have binary data, but if a match is found,
/// suppress it and emit a warning. /// suppress it and emit a warning.
@@ -251,12 +252,6 @@ pub(crate) enum BinaryMode {
AsText, AsText,
} }
impl Default for BinaryMode {
fn default() -> BinaryMode {
BinaryMode::Auto
}
}
/// Indicates what kind of boundary mode to use (line or word). /// Indicates what kind of boundary mode to use (line or word).
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub(crate) enum BoundaryMode { pub(crate) enum BoundaryMode {
@@ -269,10 +264,11 @@ pub(crate) enum BoundaryMode {
/// Indicates the buffer mode that ripgrep should use when printing output. /// Indicates the buffer mode that ripgrep should use when printing output.
/// ///
/// The default is `Auto`. /// The default is `Auto`.
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Default, Eq, PartialEq)]
pub(crate) enum BufferMode { pub(crate) enum BufferMode {
/// Select the buffer mode, 'line' or 'block', automatically based on /// Select the buffer mode, 'line' or 'block', automatically based on
/// whether stdout is connected to a tty. /// whether stdout is connected to a tty.
#[default]
Auto, Auto,
/// Flush the output buffer whenever a line terminator is seen. /// Flush the output buffer whenever a line terminator is seen.
/// ///
@@ -287,18 +283,13 @@ pub(crate) enum BufferMode {
Block, Block,
} }
impl Default for BufferMode {
fn default() -> BufferMode {
BufferMode::Auto
}
}
/// Indicates the case mode for how to interpret all patterns given to ripgrep. /// Indicates the case mode for how to interpret all patterns given to ripgrep.
/// ///
/// The default is `Sensitive`. /// The default is `Sensitive`.
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Default, Eq, PartialEq)]
pub(crate) enum CaseMode { pub(crate) enum CaseMode {
/// Patterns are matched case sensitively. i.e., `a` does not match `A`. /// Patterns are matched case sensitively. i.e., `a` does not match `A`.
#[default]
Sensitive, Sensitive,
/// Patterns are matched case insensitively. i.e., `a` does match `A`. /// Patterns are matched case insensitively. i.e., `a` does match `A`.
Insensitive, Insensitive,
@@ -308,21 +299,16 @@ pub(crate) enum CaseMode {
Smart, Smart,
} }
impl Default for CaseMode {
fn default() -> CaseMode {
CaseMode::Sensitive
}
}
/// Indicates whether ripgrep should include color/hyperlinks in its output. /// Indicates whether ripgrep should include color/hyperlinks in its output.
/// ///
/// The default is `Auto`. /// The default is `Auto`.
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Default, Eq, PartialEq)]
pub(crate) enum ColorChoice { pub(crate) enum ColorChoice {
/// Color and hyperlinks will never be used. /// Color and hyperlinks will never be used.
Never, Never,
/// Color and hyperlinks will be used only when stdout is connected to a /// Color and hyperlinks will be used only when stdout is connected to a
/// tty. /// tty.
#[default]
Auto, Auto,
/// Color will always be used. /// Color will always be used.
Always, Always,
@@ -335,12 +321,6 @@ pub(crate) enum ColorChoice {
Ansi, Ansi,
} }
impl Default for ColorChoice {
fn default() -> ColorChoice {
ColorChoice::Auto
}
}
impl ColorChoice { impl ColorChoice {
/// Convert this color choice to the corresponding termcolor type. /// Convert this color choice to the corresponding termcolor type.
pub(crate) fn to_termcolor(&self) -> termcolor::ColorChoice { pub(crate) fn to_termcolor(&self) -> termcolor::ColorChoice {
@@ -529,9 +509,10 @@ impl ContextSeparator {
/// The encoding mode the searcher will use. /// The encoding mode the searcher will use.
/// ///
/// The default is `Auto`. /// The default is `Auto`.
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Default, Eq, PartialEq)]
pub(crate) enum EncodingMode { pub(crate) enum EncodingMode {
/// Use only BOM sniffing to auto-detect an encoding. /// Use only BOM sniffing to auto-detect an encoding.
#[default]
Auto, Auto,
/// Use an explicit encoding forcefully, but let BOM sniffing override it. /// Use an explicit encoding forcefully, but let BOM sniffing override it.
Some(grep::searcher::Encoding), Some(grep::searcher::Encoding),
@@ -541,21 +522,16 @@ pub(crate) enum EncodingMode {
Disabled, Disabled,
} }
impl Default for EncodingMode {
fn default() -> EncodingMode {
EncodingMode::Auto
}
}
/// The regex engine to use. /// The regex engine to use.
/// ///
/// The default is `Default`. /// The default is `Default`.
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Default, Eq, PartialEq)]
pub(crate) enum EngineChoice { pub(crate) enum EngineChoice {
/// Uses the default regex engine: Rust's `regex` crate. /// Uses the default regex engine: Rust's `regex` crate.
/// ///
/// (Well, technically it uses `regex-automata`, but `regex-automata` is /// (Well, technically it uses `regex-automata`, but `regex-automata` is
/// the implementation of the `regex` crate.) /// the implementation of the `regex` crate.)
#[default]
Default, Default,
/// Dynamically select the right engine to use. /// Dynamically select the right engine to use.
/// ///
@@ -566,12 +542,6 @@ pub(crate) enum EngineChoice {
PCRE2, PCRE2,
} }
impl Default for EngineChoice {
fn default() -> EngineChoice {
EngineChoice::Default
}
}
/// The field context separator to use to between metadata for each contextual /// The field context separator to use to between metadata for each contextual
/// line. /// line.
/// ///
@@ -651,10 +621,11 @@ pub(crate) enum LoggingMode {
/// Indicates when to use memory maps. /// Indicates when to use memory maps.
/// ///
/// The default is `Auto`. /// The default is `Auto`.
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Default, Eq, PartialEq)]
pub(crate) enum MmapMode { pub(crate) enum MmapMode {
/// This instructs ripgrep to use heuristics for selecting when to and not /// This instructs ripgrep to use heuristics for selecting when to and not
/// to use memory maps for searching. /// to use memory maps for searching.
#[default]
Auto, Auto,
/// This instructs ripgrep to always try memory maps when possible. (Memory /// This instructs ripgrep to always try memory maps when possible. (Memory
/// maps are not possible to use in all circumstances, for example, for /// maps are not possible to use in all circumstances, for example, for
@@ -666,12 +637,6 @@ pub(crate) enum MmapMode {
Never, Never,
} }
impl Default for MmapMode {
fn default() -> MmapMode {
MmapMode::Auto
}
}
/// Represents a source of patterns that ripgrep should search for. /// Represents a source of patterns that ripgrep should search for.
/// ///
/// The reason to unify these is so that we can retain the order of `-f/--flag` /// The reason to unify these is so that we can retain the order of `-f/--flag`