Skip to content

Commit 152af17

Browse files
committed
fix build warnings
And in Travis CI, treat warnings as error to keep from merging codes with warning. Fixes: levex#13 Signed-off-by: bin liu <[email protected]>
1 parent d18b3ba commit 152af17

20 files changed

+50
-36
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ install:
1717
- rustup component add rustfmt
1818

1919
script:
20-
- cargo build
20+
- RUSTFLAGS="--deny warnings" cargo build
2121
- if [ "$TRAVIS_CPU_ARCH" == "amd64" ]; then cargo test -- --color always --nocapture ; fi
2222
- cargo fmt -- --check
2323

src/blkio.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ impl<'a> From<&'a Subsystem> for &'a BlkIoController {
396396
Subsystem::BlkIo(c) => c,
397397
_ => {
398398
assert_eq!(1, 0);
399-
::std::mem::uninitialized()
399+
let v = std::mem::MaybeUninit::uninit();
400+
v.assume_init()
400401
}
401402
}
402403
}

src/cgroup.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'b> Cgroup<'b> {
4343
/// Create this control group.
4444
fn create(&self) {
4545
if self.hier.v2() {
46-
create_v2_cgroup(self.hier.root().clone(), &self.path);
46+
let _ret = create_v2_cgroup(self.hier.root().clone(), &self.path);
4747
} else {
4848
for subsystem in &self.subsystems {
4949
subsystem.to_controller().create();
@@ -272,7 +272,7 @@ fn enable_controllers(controllers: &Vec<String>, path: &PathBuf) {
272272
}
273273
}
274274

275-
fn supported_controllers(p: &PathBuf) -> Vec<String> {
275+
fn supported_controllers() -> Vec<String> {
276276
let p = format!("{}/{}", UNIFIED_MOUNTPOINT, "cgroup.controllers");
277277
let ret = fs::read_to_string(p.as_str());
278278
ret.unwrap_or(String::new())
@@ -283,7 +283,7 @@ fn supported_controllers(p: &PathBuf) -> Vec<String> {
283283

284284
fn create_v2_cgroup(root: PathBuf, path: &str) -> Result<()> {
285285
// controler list ["memory", "cpu"]
286-
let controllers = supported_controllers(&root);
286+
let controllers = supported_controllers();
287287
let mut fp = root;
288288

289289
// enable for root

src/cgroup_builder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@
6060
//! .done()
6161
//! .build();
6262
//! ```
63-
use crate::error::*;
6463
6564
use crate::{
66-
pid, BlkIoDeviceResource, BlkIoDeviceThrottleResource, Cgroup, DeviceResource, Hierarchy,
65+
BlkIoDeviceResource, BlkIoDeviceThrottleResource, Cgroup, DeviceResource, Hierarchy,
6766
HugePageResource, MaxValue, NetworkPriority, Resources,
6867
};
6968

@@ -141,7 +140,7 @@ impl<'a> CgroupBuilder<'a> {
141140
/// Finalize the control group, consuming the builder and creating the control group.
142141
pub fn build(self) -> Cgroup<'a> {
143142
let cg = Cgroup::new(self.hierarchy, self.name);
144-
cg.apply(&self.resources);
143+
let _ret = cg.apply(&self.resources);
145144
cg
146145
}
147146
}

src/cpu.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ impl<'a> From<&'a Subsystem> for &'a CpuController {
111111
Subsystem::Cpu(c) => c,
112112
_ => {
113113
assert_eq!(1, 0);
114-
::std::mem::uninitialized()
114+
let v = std::mem::MaybeUninit::uninit();
115+
v.assume_init()
115116
}
116117
}
117118
}

src/cpuacct.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ impl<'a> From<&'a Subsystem> for &'a CpuAcctController {
8989
Subsystem::CpuAcct(c) => c,
9090
_ => {
9191
assert_eq!(1, 0);
92-
::std::mem::uninitialized()
92+
let v = std::mem::MaybeUninit::uninit();
93+
v.assume_init()
9394
}
9495
}
9596
}

src/cpuset.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ impl ControllerInternal for CpuSetController {
125125
return;
126126
}
127127
let current = self.get_path();
128-
let parent = match current.parent() {
129-
Some(p) => p,
130-
None => return,
131-
};
132128

133129
if current != self.get_base() {
134130
match copy_from_parent(current.to_str().unwrap(), "cpuset.cpus") {
@@ -204,7 +200,8 @@ impl<'a> From<&'a Subsystem> for &'a CpuSetController {
204200
Subsystem::CpuSet(c) => c,
205201
_ => {
206202
assert_eq!(1, 0);
207-
::std::mem::uninitialized()
203+
let v = std::mem::MaybeUninit::uninit();
204+
v.assume_init()
208205
}
209206
}
210207
}

src/devices.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ impl<'a> From<&'a Subsystem> for &'a DevicesController {
182182
Subsystem::Devices(c) => c,
183183
_ => {
184184
assert_eq!(1, 0);
185-
::std::mem::uninitialized()
185+
let v = std::mem::MaybeUninit::uninit();
186+
v.assume_init()
186187
}
187188
}
188189
}

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub enum ErrorKind {
4545
#[derive(Debug)]
4646
pub struct Error {
4747
kind: ErrorKind,
48-
cause: Option<Box<StdError + Send + Sync>>,
48+
cause: Option<Box<dyn StdError + Send + Sync>>,
4949
}
5050

5151
impl fmt::Display for Error {
@@ -67,7 +67,7 @@ impl fmt::Display for Error {
6767
}
6868

6969
impl StdError for Error {
70-
fn cause(&self) -> Option<&StdError> {
70+
fn cause(&self) -> Option<&dyn StdError> {
7171
match self.cause {
7272
Some(ref x) => Some(&**x),
7373
None => None,

src/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn register_memory_event(
6060
}
6161

6262
// write to file and set mode to 0700(FIXME)
63-
fs::write(&event_control_path, data).map_err(|e| Error::with_cause(WriteFailed, e));
63+
fs::write(&event_control_path, data).map_err(|e| Error::with_cause(WriteFailed, e))?;
6464

6565
let mut eventfd_file = unsafe { File::from_raw_fd(eventfd) };
6666

@@ -71,7 +71,7 @@ fn register_memory_event(
7171
loop {
7272
let mut buf = [0; 8];
7373
match eventfd_file.read(&mut buf) {
74-
Err(err) => {
74+
Err(_err) => {
7575
return;
7676
}
7777
Ok(_) => {}

0 commit comments

Comments
 (0)