Skip to content

Commit 4f8d1c5

Browse files
committed
add additional lints
1 parent 4f9ba87 commit 4f8d1c5

14 files changed

Lines changed: 49 additions & 38 deletions

File tree

.cargo/config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
[target.x86_64-unknown-redox]
22
linker = "x86_64-unknown-redox-gcc"
3+
4+
[target.'cfg(feature = "cargo-clippy")']
5+
rustflags = [
6+
"-Wclippy::use_self",
7+
"-Wclippy::needless_pass_by_value",
8+
"-Wclippy::semicolon_if_nothing_returned",
9+
"-Wclippy::single_char_pattern",
10+
"-Wclippy::explicit_iter_loop",
11+
]

src/bin/coreutils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn main() {
8787
};
8888

8989
if util == "completion" {
90-
gen_completions(args, utils);
90+
gen_completions(args, &utils);
9191
}
9292

9393
match utils.get(util) {
@@ -132,7 +132,7 @@ fn main() {
132132
/// Prints completions for the utility in the first parameter for the shell in the second parameter to stdout
133133
fn gen_completions<T: uucore::Args>(
134134
args: impl Iterator<Item = OsString>,
135-
util_map: UtilityMap<T>,
135+
util_map: &UtilityMap<T>,
136136
) -> ! {
137137
let all_utilities: Vec<_> = std::iter::once("coreutils")
138138
.chain(util_map.keys().copied())
@@ -168,9 +168,9 @@ fn gen_completions<T: uucore::Args>(
168168
process::exit(0);
169169
}
170170

171-
fn gen_coreutils_app<T: uucore::Args>(util_map: UtilityMap<T>) -> App<'static> {
171+
fn gen_coreutils_app<T: uucore::Args>(util_map: &UtilityMap<T>) -> App<'static> {
172172
let mut app = App::new("coreutils");
173-
for (_, (_, sub_app)) in &util_map {
173+
for (_, (_, sub_app)) in util_map {
174174
app = app.subcommand(sub_app());
175175
}
176176
app

src/uu/chroot/src/chroot.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ fn set_main_group(group: &str) -> UResult<()> {
201201
}
202202

203203
#[cfg(any(target_vendor = "apple", target_os = "freebsd"))]
204-
fn set_groups(groups: Vec<libc::gid_t>) -> libc::c_int {
204+
fn set_groups(groups: &[libc::gid_t]) -> libc::c_int {
205205
unsafe { setgroups(groups.len() as libc::c_int, groups.as_ptr()) }
206206
}
207207

208208
#[cfg(target_os = "linux")]
209-
fn set_groups(groups: Vec<libc::gid_t>) -> libc::c_int {
209+
fn set_groups(groups: &[libc::gid_t]) -> libc::c_int {
210210
unsafe { setgroups(groups.len() as libc::size_t, groups.as_ptr()) }
211211
}
212212

@@ -220,7 +220,7 @@ fn set_groups_from_str(groups: &str) -> UResult<()> {
220220
};
221221
groups_vec.push(gid);
222222
}
223-
let err = set_groups(groups_vec);
223+
let err = set_groups(&groups_vec);
224224
if err != 0 {
225225
return Err(ChrootError::SetGroupsFailed(Error::last_os_error()).into());
226226
}

src/uu/du/src/du.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl Stat {
144144
#[cfg(windows)]
145145
let file_info = get_file_info(&path);
146146
#[cfg(windows)]
147-
Ok(Stat {
147+
Ok(Self {
148148
path,
149149
is_dir: metadata.is_dir(),
150150
size: metadata.len(),

src/uu/env/src/env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ fn load_config_file(opts: &mut Options) -> UResult<()> {
104104
}
105105

106106
#[cfg(not(windows))]
107+
#[allow(clippy::ptr_arg)]
107108
fn build_command<'a, 'b>(args: &'a mut Vec<&'b str>) -> (Cow<'b, str>, &'a [&'b str]) {
108109
let progname = Cow::from(args[0]);
109110
(progname, &args[1..])

src/uu/kill/src/kill.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
7474
table();
7575
Ok(())
7676
}
77-
Mode::List => list(pids_or_signals.get(0).cloned()),
77+
Mode::List => list(pids_or_signals.get(0)),
7878
}
7979
}
8080

@@ -168,9 +168,9 @@ fn print_signals() {
168168
println!();
169169
}
170170

171-
fn list(arg: Option<String>) -> UResult<()> {
171+
fn list(arg: Option<&String>) -> UResult<()> {
172172
match arg {
173-
Some(ref x) => print_signal(x),
173+
Some(x) => print_signal(x),
174174
None => {
175175
print_signals();
176176
Ok(())

src/uu/split/src/number.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ impl Number {
9696
#[allow(dead_code)]
9797
fn digits(&self) -> &Vec<u8> {
9898
match self {
99-
Number::FixedWidth(number) => &number.digits,
100-
Number::DynamicWidth(number) => &number.digits,
99+
Self::FixedWidth(number) => &number.digits,
100+
Self::DynamicWidth(number) => &number.digits,
101101
}
102102
}
103103

@@ -136,17 +136,17 @@ impl Number {
136136
/// ```
137137
pub fn increment(&mut self) -> Result<(), Overflow> {
138138
match self {
139-
Number::FixedWidth(number) => number.increment(),
140-
Number::DynamicWidth(number) => number.increment(),
139+
Self::FixedWidth(number) => number.increment(),
140+
Self::DynamicWidth(number) => number.increment(),
141141
}
142142
}
143143
}
144144

145145
impl Display for Number {
146146
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
147147
match self {
148-
Number::FixedWidth(number) => number.fmt(f),
149-
Number::DynamicWidth(number) => number.fmt(f),
148+
Self::FixedWidth(number) => number.fmt(f),
149+
Self::DynamicWidth(number) => number.fmt(f),
150150
}
151151
}
152152
}
@@ -183,8 +183,8 @@ pub struct FixedWidthNumber {
183183

184184
impl FixedWidthNumber {
185185
/// Instantiate a number of the given radix and width.
186-
pub fn new(radix: u8, width: usize) -> FixedWidthNumber {
187-
FixedWidthNumber {
186+
pub fn new(radix: u8, width: usize) -> Self {
187+
Self {
188188
radix,
189189
digits: vec![0; width],
190190
}
@@ -286,8 +286,8 @@ impl DynamicWidthNumber {
286286
///
287287
/// This associated function returns a new instance of the struct
288288
/// with the given radix and a width of two digits, both 0.
289-
pub fn new(radix: u8) -> DynamicWidthNumber {
290-
DynamicWidthNumber {
289+
pub fn new(radix: u8) -> Self {
290+
Self {
291291
radix,
292292
digits: vec![0, 0],
293293
}
@@ -404,7 +404,7 @@ mod tests {
404404
fn num(n: usize) -> Number {
405405
let mut number = Number::DynamicWidth(DynamicWidthNumber::new(26));
406406
for _ in 0..n {
407-
number.increment().unwrap()
407+
number.increment().unwrap();
408408
}
409409
number
410410
}
@@ -428,7 +428,7 @@ mod tests {
428428
fn num(n: usize) -> Number {
429429
let mut number = Number::DynamicWidth(DynamicWidthNumber::new(10));
430430
for _ in 0..n {
431-
number.increment().unwrap()
431+
number.increment().unwrap();
432432
}
433433
number
434434
}

src/uu/split/src/split.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
6262
.override_usage(&usage[..])
6363
.after_help(&long_usage[..])
6464
.get_matches_from(args);
65-
let settings = Settings::from(matches)?;
65+
let settings = Settings::from(&matches)?;
6666
split(&settings)
6767
}
6868

@@ -232,7 +232,7 @@ struct Settings {
232232

233233
impl Settings {
234234
/// Parse a strategy from the command-line arguments.
235-
fn from(matches: ArgMatches) -> UResult<Self> {
235+
fn from(matches: &ArgMatches) -> UResult<Self> {
236236
let result = Self {
237237
suffix_length: matches
238238
.value_of(OPT_SUFFIX_LENGTH)
@@ -242,7 +242,7 @@ impl Settings {
242242
numeric_suffix: matches.occurrences_of(OPT_NUMERIC_SUFFIXES) > 0,
243243
additional_suffix: matches.value_of(OPT_ADDITIONAL_SUFFIX).unwrap().to_owned(),
244244
verbose: matches.occurrences_of("verbose") > 0,
245-
strategy: Strategy::from(&matches)?,
245+
strategy: Strategy::from(matches)?,
246246
input: matches.value_of(ARG_INPUT).unwrap().to_owned(),
247247
prefix: matches.value_of(ARG_PREFIX).unwrap().to_owned(),
248248
filter: matches.value_of(OPT_FILTER).map(|s| s.to_owned()),

src/uu/tail/src/platform/unix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ impl ProcessChecker {
3030
}
3131

3232
// Borrowing mutably to be aligned with Windows implementation
33+
#[allow(clippy::wrong_self_convention)]
3334
pub fn is_dead(&mut self) -> bool {
3435
unsafe { libc::kill(self.pid, 0) != 0 && get_errno() != libc::EPERM }
3536
}

src/uu/tail/src/platform/windows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ pub struct ProcessChecker {
2424
}
2525

2626
impl ProcessChecker {
27-
pub fn new(process_id: self::Pid) -> ProcessChecker {
27+
pub fn new(process_id: self::Pid) -> Self {
2828
#[allow(non_snake_case)]
2929
let FALSE = 0i32;
3030
let h = unsafe { OpenProcess(SYNCHRONIZE, FALSE, process_id as DWORD) };
31-
ProcessChecker {
31+
Self {
3232
dead: h.is_null(),
3333
handle: h,
3434
}

0 commit comments

Comments
 (0)