Skip to content

Fix clippy::new_without_default #322

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

Merged
merged 4 commits into from
Oct 13, 2024
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
24 changes: 12 additions & 12 deletions display/printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ struct ConvSpec {
zero_pad: bool,
}

impl ConvSpec {
fn new() -> ConvSpec {
ConvSpec {
impl Default for ConvSpec {
fn default() -> Self {
Self {
spec: ' ',
width: None,
precision: None,
left_justify: false,
sign: false,
space: false,
alt_form: false,
zero_pad: false,
width: Default::default(),
precision: Default::default(),
left_justify: Default::default(),
sign: Default::default(),
space: Default::default(),
alt_form: Default::default(),
zero_pad: Default::default(),
}
}
}
Expand Down Expand Up @@ -81,7 +81,7 @@ fn escaped_char(c: char) -> char {
fn tokenize_format_str(format: &str) -> Vec<Token> {
let mut tokens: Vec<Token> = Vec::new();
let mut literal = String::with_capacity(format.len());
let mut conversion = ConvSpec::new();
let mut conversion = ConvSpec::default();
let mut width = String::with_capacity(8);
let mut precision = String::with_capacity(8);
let mut state = ParseState::Literal;
Expand Down Expand Up @@ -164,7 +164,7 @@ fn tokenize_format_str(format: &str) -> Vec<Token> {
ParseState::Specifier => {
conversion.spec = c;
tokens.push(Token::Conversion(conversion));
conversion = ConvSpec::new();
conversion = ConvSpec::default();
state = ParseState::Literal;
done_with_char = true;
}
Expand Down
26 changes: 13 additions & 13 deletions file/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,20 @@ struct Config {
notrunc: bool,
}

impl Config {
fn new() -> Config {
Config {
ifile: String::new(),
ofile: String::new(),
impl Default for Config {
fn default() -> Self {
Self {
ifile: Default::default(),
ofile: Default::default(),
ibs: DEF_BLOCK_SIZE,
obs: DEF_BLOCK_SIZE,
cbs: 0,
seek: 0,
skip: 0,
count: 0,
conversions: Vec::new(),
noerror: false,
notrunc: false,
cbs: Default::default(),
seek: Default::default(),
skip: Default::default(),
count: Default::default(),
conversions: Default::default(),
noerror: Default::default(),
notrunc: Default::default(),
}
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ fn parse_block_size(s: &str) -> Result<usize, Box<dyn std::error::Error>> {
}

fn parse_cmdline(args: &[String]) -> Result<Config, Box<dyn std::error::Error>> {
let mut config = Config::new();
let mut config = Config::default();

for arg in args {
// Split arg into option and argument
Expand Down
11 changes: 2 additions & 9 deletions file/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,11 @@ struct TeeFile {
f: File,
}

#[derive(Default)]
struct TeeInfo {
outputs: Vec<TeeFile>,
}

impl TeeInfo {
fn new() -> TeeInfo {
TeeInfo {
outputs: Vec::new(),
}
}
}

fn open_outputs(args: &Args, info: &mut TeeInfo) -> io::Result<()> {
for filename in &args.files {
let f_res = OpenOptions::new()
Expand Down Expand Up @@ -113,7 +106,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}

let mut state = TeeInfo::new();
let mut state = TeeInfo::default();

open_outputs(&args, &mut state)?;
tee_stdin(&mut state)?;
Expand Down
64 changes: 14 additions & 50 deletions plib/src/modestr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ use libc::{
S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR,
};

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Default)]
pub enum ChmodActionOp {
Add,
Remove,
#[default]
Set,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ChmodAction {
pub op: ChmodActionOp,

Expand All @@ -37,25 +38,7 @@ pub struct ChmodAction {
dirty: bool,
}

impl ChmodAction {
pub fn new() -> ChmodAction {
ChmodAction {
op: ChmodActionOp::Set,
copy_user: false,
copy_group: false,
copy_others: false,
read: false,
write: false,
execute: false,
execute_dir: false,
setuid: false,
sticky: false,
dirty: false,
}
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ChmodClause {
// wholist
pub user: bool,
Expand All @@ -68,39 +51,20 @@ pub struct ChmodClause {
dirty: bool,
}

impl ChmodClause {
pub fn new() -> ChmodClause {
ChmodClause {
user: false,
group: false,
others: false,
actions: Vec::new(),
dirty: false,
}
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ChmodSymbolic {
pub clauses: Vec<ChmodClause>,
}

impl ChmodSymbolic {
pub fn new() -> ChmodSymbolic {
ChmodSymbolic {
clauses: Vec::new(),
}
}
}

#[derive(Debug)]
pub enum ChmodMode {
Absolute(u32),
Symbolic(ChmodSymbolic),
}

#[derive(Debug)]
#[derive(Debug, Default)]
enum ParseState {
#[default]
Wholist,
Actionlist,
ListOrCopy,
Expand All @@ -114,11 +78,11 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
return Ok(ChmodMode::Absolute(m));
}

let mut state = ParseState::Wholist;
let mut done_with_char;
let mut symbolic = ChmodSymbolic::new();
let mut clause = ChmodClause::new();
let mut action = ChmodAction::new();
let mut state = ParseState::default();
let mut symbolic = ChmodSymbolic::default();
let mut clause = ChmodClause::default();
let mut action = ChmodAction::default();

for c in mode.chars() {
done_with_char = false;
Expand Down Expand Up @@ -156,7 +120,7 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
action.dirty = false;
done_with_char = false;
symbolic.clauses.push(clause);
clause = ChmodClause::new();
clause = ChmodClause::default();
state = ParseState::NextClause;
}
}
Expand All @@ -177,7 +141,7 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
done_with_char = false;
clause.actions.push(action);
clause.dirty = true;
action = ChmodAction::new();
action = ChmodAction::default();
state = ParseState::Actionlist;
}
}
Expand All @@ -196,7 +160,7 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
done_with_char = false;
clause.actions.push(action);
clause.dirty = true;
action = ChmodAction::new();
action = ChmodAction::default();
state = ParseState::Actionlist;
}
}
Expand Down
12 changes: 7 additions & 5 deletions text/asa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ struct AsaState {
lines: Vec<String>,
}

impl AsaState {
fn new() -> AsaState {
AsaState {
impl Default for AsaState {
fn default() -> Self {
Self {
first_line: true,
lines: Vec::new(),
lines: Default::default(),
}
}
}

impl AsaState {
fn push(&mut self, line: &str) {
self.lines.push(line.to_string());
if self.first_line {
Expand Down Expand Up @@ -69,7 +71,7 @@ impl AsaState {
fn asa_file(pathname: &PathBuf) -> io::Result<()> {
let mut reader = plib::io::input_reader(pathname, false)?;
let mut line_no: usize = 0;
let mut state = AsaState::new();
let mut state = AsaState::default();

loop {
line_no += 1;
Expand Down
19 changes: 2 additions & 17 deletions text/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Args {
}

/// A struct representing a range field with various sorting and comparison options.
#[derive(Clone)]
#[derive(Clone, Default)]
struct RangeField {
/// The number of the field to be considered in the range.
field_number: usize,
Expand Down Expand Up @@ -149,21 +149,6 @@ struct RangeField {
dictionary_order: bool,
}

impl RangeField {
fn new() -> RangeField {
Self {
field_number: 0,
first_character: 0,
numeric_sort: false,
ignore_leading_blanks: false,
reverse: false,
ignore_nonprintable: false,
fold_case: false,
dictionary_order: false,
}
}
}

/// Updates two RangeField objects based on their comparison options.
///
/// This function takes two RangeField objects, compares their fields, and updates the fields
Expand Down Expand Up @@ -744,7 +729,7 @@ fn create_ranges(
let mut key_ranges = key_ranges.iter();

// Convert key ranges to numeric representations
let mut ranges: (RangeField, Option<RangeField>) = (RangeField::new(), None);
let mut ranges: (RangeField, Option<RangeField>) = (RangeField::default(), None);

ranges.0 = {
let key_range = key_ranges.next().unwrap().to_string();
Expand Down
33 changes: 4 additions & 29 deletions tree/ls_util/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ impl Entry {
}
}

// Used for padding in long format
/// Used for padding in long format
#[derive(Default)]
pub struct LongFormatPadding {
pub blocks_str_width: usize,
pub inode_str_width: usize,
Expand All @@ -477,22 +478,6 @@ pub struct LongFormatPadding {
pub time_width: usize,
}

impl Default for LongFormatPadding {
fn default() -> Self {
Self {
blocks_str_width: 0,
inode_str_width: 0,
num_links_width: 0,
owner_name_width: 0,
group_name_width: 0,
file_size_width: 0,
device_id_major_width: 0,
device_id_minor_width: 0,
time_width: 0,
}
}
}

impl LongFormatPadding {
/// Get the maximum padding for each field.
pub fn update_maximum(&mut self, other: &LongFormatPadding) {
Expand Down Expand Up @@ -525,25 +510,15 @@ impl LongFormatPadding {
}
}

// Used for padding in multi-column format
/// Used for padding in multi-column format
#[derive(Default)]
pub struct MultiColumnPadding {
pub total_width: usize,
pub inode_str_width: usize,
pub blocks_str_width: usize,
pub file_name_width: usize,
}

impl Default for MultiColumnPadding {
fn default() -> Self {
Self {
total_width: 0,
inode_str_width: 0,
blocks_str_width: 0,
file_name_width: 0,
}
}
}

impl MultiColumnPadding {
pub fn update_maximum(&mut self, other: &MultiColumnPadding) {
self.total_width = usize::max(self.total_width, other.total_width);
Expand Down
1 change: 1 addition & 0 deletions users/talk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ pub struct Osockaddr {
pub sa_data: [u8; 14],
}

#[allow(clippy::derivable_impls)]
impl Default for Osockaddr {
fn default() -> Self {
Osockaddr {
Expand Down