Skip to content

Commit 45b626e

Browse files
authored
Merge pull request #46 from Tim-Zhang/fix-clippy-for-rust-1.52
Fix clippy for rust 1.52
2 parents 5bb27a2 + 0e2430f commit 45b626e

File tree

7 files changed

+18
-19
lines changed

7 files changed

+18
-19
lines changed

.clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
upper-case-acronyms-aggressive = true

src/cgroup.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,8 @@ impl Cgroup {
311311

312312
pub const UNIFIED_MOUNTPOINT: &str = "/sys/fs/cgroup";
313313

314-
fn enable_controllers(controllers: &[String], path: &PathBuf) {
315-
let mut f = path.clone();
316-
f.push("cgroup.subtree_control");
314+
fn enable_controllers(controllers: &[String], path: &Path) {
315+
let f = path.join("cgroup.subtree_control");
317316
for c in controllers {
318317
let body = format!("+{}", c);
319318
let _rest = fs::write(f.as_path(), body.as_bytes());

src/cgroup_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ impl DeviceResourceBuilder {
240240
access: Vec<crate::devices::DevicePermissions>,
241241
) -> DeviceResourceBuilder {
242242
self.cgroup.resources.devices.devices.push(DeviceResource {
243+
allow,
244+
devtype,
243245
major,
244246
minor,
245-
devtype,
246-
allow,
247247
access,
248248
});
249249
self

src/cpu.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct Cpu {
4545

4646
/// The current state of the control group and its processes.
4747
#[derive(Debug)]
48-
struct CFSQuotaAndPeriod {
48+
struct CfsQuotaAndPeriod {
4949
quota: MaxValue,
5050
period: u64,
5151
}
@@ -284,7 +284,7 @@ impl CpuController {
284284

285285
impl CustomizedAttribute for CpuController {}
286286

287-
fn parse_cfs_quota_and_period(mut file: File) -> Result<CFSQuotaAndPeriod> {
287+
fn parse_cfs_quota_and_period(mut file: File) -> Result<CfsQuotaAndPeriod> {
288288
let mut content = String::new();
289289
file.read_to_string(&mut content)
290290
.map_err(|e| Error::with_cause(ReadFailed, e))?;
@@ -299,5 +299,5 @@ fn parse_cfs_quota_and_period(mut file: File) -> Result<CFSQuotaAndPeriod> {
299299
.parse::<u64>()
300300
.map_err(|e| Error::with_cause(ParseError, e))?;
301301

302-
Ok(CFSQuotaAndPeriod { quota, period })
302+
Ok(CfsQuotaAndPeriod { quota, period })
303303
}

src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl fmt::Display for Error {
7676

7777
impl StdError for Error {
7878
fn cause(&self) -> Option<&dyn StdError> {
79+
#[allow(clippy::manual_map)]
7980
match self.cause {
8081
Some(ref x) => Some(&**x),
8182
None => None,

src/events.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use nix::sys::eventfd;
88
use std::fs::{self, File};
99
use std::io::Read;
1010
use std::os::unix::io::{AsRawFd, FromRawFd};
11-
use std::path::{Path, PathBuf};
11+
use std::path::Path;
1212
use std::sync::mpsc::{self, Receiver};
1313
use std::thread;
1414

@@ -17,18 +17,18 @@ use crate::error::*;
1717

1818
// notify_on_oom returns channel on which you can expect event about OOM,
1919
// if process died without OOM this channel will be closed.
20-
pub fn notify_on_oom_v2(key: &str, dir: &PathBuf) -> Result<Receiver<String>> {
20+
pub fn notify_on_oom_v2(key: &str, dir: &Path) -> Result<Receiver<String>> {
2121
register_memory_event(key, dir, "memory.oom_control", "")
2222
}
2323

2424
// notify_on_oom returns channel on which you can expect event about OOM,
2525
// if process died without OOM this channel will be closed.
26-
pub fn notify_on_oom_v1(key: &str, dir: &PathBuf) -> Result<Receiver<String>> {
26+
pub fn notify_on_oom_v1(key: &str, dir: &Path) -> Result<Receiver<String>> {
2727
register_memory_event(key, dir, "memory.oom_control", "")
2828
}
2929

3030
// level is one of "low", "medium", or "critical"
31-
pub fn notify_memory_pressure(key: &str, dir: &PathBuf, level: &str) -> Result<Receiver<String>> {
31+
pub fn notify_memory_pressure(key: &str, dir: &Path, level: &str) -> Result<Receiver<String>> {
3232
if level != "low" && level != "medium" && level != "critical" {
3333
return Err(Error::from_string(format!(
3434
"invalid pressure level {}",
@@ -41,7 +41,7 @@ pub fn notify_memory_pressure(key: &str, dir: &PathBuf, level: &str) -> Result<R
4141

4242
fn register_memory_event(
4343
key: &str,
44-
cg_dir: &PathBuf,
44+
cg_dir: &Path,
4545
event_name: &str,
4646
arg: &str,
4747
) -> Result<Receiver<String>> {

src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,9 @@ where
365365
.map(|file| {
366366
let bf = BufReader::new(file);
367367
let mut v = Vec::new();
368-
for line in bf.lines() {
369-
if let Ok(line) = line {
370-
let n = line.trim().parse().unwrap_or(0u64);
371-
v.push(n);
372-
}
368+
for line in bf.lines().flatten() {
369+
let n = line.trim().parse().unwrap_or(0u64);
370+
v.push(n);
373371
}
374372
v.into_iter().map(CgroupPid::from).collect()
375373
})
@@ -383,7 +381,7 @@ where
383381

384382
// remove_dir aims to remove cgroup path. It does so recursively,
385383
// by removing any subdirectories (sub-cgroups) first.
386-
fn remove_dir(dir: &PathBuf) -> Result<()> {
384+
fn remove_dir(dir: &Path) -> Result<()> {
387385
// try the fast path first.
388386
if fs::remove_dir(dir).is_ok() {
389387
return Ok(());

0 commit comments

Comments
 (0)