Skip to content

Commit 55053cc

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 f0eac78 commit 55053cc

20 files changed

+50
-36
lines changed

.travis.yml

+1-1
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

+2-1
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

+3-3
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

+2-3
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

+2-1
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

+2-1
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

+2-5
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

+2-1
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

+2-2
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

+2-2
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(_) => {}

src/freezer.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ impl<'a> From<&'a Subsystem> for &'a FreezerController {
7373
Subsystem::Freezer(c) => c,
7474
_ => {
7575
assert_eq!(1, 0);
76-
::std::mem::uninitialized()
76+
let v = std::mem::MaybeUninit::uninit();
77+
v.assume_init()
7778
}
7879
}
7980
}

src/hierarchies.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Hierarchy for V1 {
107107
}
108108

109109
fn root_control_group(&self) -> Cgroup {
110-
let b: &Hierarchy = self as &Hierarchy;
110+
let b: &dyn Hierarchy = self as &dyn Hierarchy;
111111
Cgroup::load(Box::new(&*b), "".to_string())
112112
}
113113

@@ -182,7 +182,7 @@ impl Hierarchy for V2 {
182182
}
183183

184184
fn root_control_group(&self) -> Cgroup {
185-
let b: &Hierarchy = self as &Hierarchy;
185+
let b: &dyn Hierarchy = self as &dyn Hierarchy;
186186
Cgroup::load(Box::new(&*b), "".to_string())
187187
}
188188

src/hugetlb.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ impl<'a> From<&'a Subsystem> for &'a HugeTlbController {
7979
Subsystem::HugeTlb(c) => c,
8080
_ => {
8181
assert_eq!(1, 0);
82-
::std::mem::uninitialized()
82+
let v = std::mem::MaybeUninit::uninit();
83+
v.assume_init()
8384
}
8485
}
8586
}
@@ -225,10 +226,15 @@ pub const GB: u128 = 1000 * MB;
225226
pub const TB: u128 = 1000 * GB;
226227
pub const PB: u128 = 1000 * TB;
227228

229+
#[allow(non_upper_case_globals)]
228230
pub const KiB: u128 = 1024;
231+
#[allow(non_upper_case_globals)]
229232
pub const MiB: u128 = 1024 * KiB;
233+
#[allow(non_upper_case_globals)]
230234
pub const GiB: u128 = 1024 * MiB;
235+
#[allow(non_upper_case_globals)]
231236
pub const TiB: u128 = 1024 * GiB;
237+
#[allow(non_upper_case_globals)]
232238
pub const PiB: u128 = 1024 * TiB;
233239

234240
pub fn get_binary_size_map() -> HashMap<String, u128> {

src/memory.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,11 @@ impl MemController {
505505
// for v2
506506
pub fn get_mem(&self) -> Result<SetMemory> {
507507
let mut m: SetMemory = Default::default();
508-
self.get_max_value("memory.high").map(|x| m.high = Some(x));
509-
self.get_max_value("memory.low").map(|x| m.low = Some(x));
510-
self.get_max_value("memory.max").map(|x| m.max = Some(x));
511-
self.get_max_value("memory.min").map(|x| m.min = Some(x));
508+
self.get_max_value("memory.high")
509+
.map(|x| m.high = Some(x))?;
510+
self.get_max_value("memory.low").map(|x| m.low = Some(x))?;
511+
self.get_max_value("memory.max").map(|x| m.max = Some(x))?;
512+
self.get_max_value("memory.min").map(|x| m.min = Some(x))?;
512513

513514
Ok(m)
514515
}
@@ -831,7 +832,8 @@ impl<'a> From<&'a Subsystem> for &'a MemController {
831832
Subsystem::Mem(c) => c,
832833
_ => {
833834
assert_eq!(1, 0);
834-
::std::mem::uninitialized()
835+
let v = std::mem::MaybeUninit::uninit();
836+
v.assume_init()
835837
}
836838
}
837839
}

src/net_cls.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ impl<'a> From<&'a Subsystem> for &'a NetClsController {
7070
Subsystem::NetCls(c) => c,
7171
_ => {
7272
assert_eq!(1, 0);
73-
::std::mem::uninitialized()
73+
let v = std::mem::MaybeUninit::uninit();
74+
v.assume_init()
7475
}
7576
}
7677
}

src/net_prio.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ impl<'a> From<&'a Subsystem> for &'a NetPrioController {
7171
Subsystem::NetPrio(c) => c,
7272
_ => {
7373
assert_eq!(1, 0);
74-
::std::mem::uninitialized()
74+
let v = std::mem::MaybeUninit::uninit();
75+
v.assume_init()
7576
}
7677
}
7778
}

src/perf_event.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ impl<'a> From<&'a Subsystem> for &'a PerfEventController {
5555
Subsystem::PerfEvent(c) => c,
5656
_ => {
5757
assert_eq!(1, 0);
58-
::std::mem::uninitialized()
58+
let v = std::mem::MaybeUninit::uninit();
59+
v.assume_init()
5960
}
6061
}
6162
}

src/pid.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ impl<'a> From<&'a Subsystem> for &'a PidController {
8585
Subsystem::Pid(c) => c,
8686
_ => {
8787
assert_eq!(1, 0);
88-
::std::mem::uninitialized()
88+
let v = std::mem::MaybeUninit::uninit();
89+
v.assume_init()
8990
}
9091
}
9192
}

src/rdma.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ impl<'a> From<&'a Subsystem> for &'a RdmaController {
5858
Subsystem::Rdma(c) => c,
5959
_ => {
6060
assert_eq!(1, 0);
61-
::std::mem::uninitialized()
61+
let v = std::mem::MaybeUninit::uninit();
62+
v.assume_init()
6263
}
6364
}
6465
}

src/systemd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//!
88
use std::path::PathBuf;
99

10-
use crate::error::ErrorKind::*;
1110
use crate::error::*;
1211

1312
use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subsystem};
@@ -53,7 +52,8 @@ impl<'a> From<&'a Subsystem> for &'a SystemdController {
5352
Subsystem::Systemd(c) => c,
5453
_ => {
5554
assert_eq!(1, 0);
56-
::std::mem::uninitialized()
55+
let v = std::mem::MaybeUninit::uninit();
56+
v.assume_init()
5757
}
5858
}
5959
}

0 commit comments

Comments
 (0)