Skip to content

some more clippy-based improvements #28287

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 5 commits into from
Sep 8, 2015
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
16 changes: 7 additions & 9 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {
*self.copy_head.borrow_mut() =
chunk((new_min_chunk_size + 1).next_power_of_two(), true);

return self.alloc_copy_inner(n_bytes, align);
self.alloc_copy_inner(n_bytes, align)
}

#[inline]
Expand All @@ -247,7 +247,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {
mem::align_of::<T>());
let ptr = ptr as *mut T;
ptr::write(&mut (*ptr), op());
return &mut *ptr;
&mut *ptr
}
}

Expand All @@ -261,7 +261,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {
*self.head.borrow_mut() =
chunk((new_min_chunk_size + 1).next_power_of_two(), false);

return self.alloc_noncopy_inner(n_bytes, align);
self.alloc_noncopy_inner(n_bytes, align)
}

#[inline]
Expand Down Expand Up @@ -290,7 +290,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {

unsafe {
let buf = head.as_ptr();
return (buf.offset(tydesc_start as isize), buf.offset(start as isize));
(buf.offset(tydesc_start as isize), buf.offset(start as isize))
}
}

Expand All @@ -312,7 +312,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {
// the object is there.
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);

return &mut *ptr;
&mut *ptr
}
}

Expand Down Expand Up @@ -486,14 +486,12 @@ impl<T> TypedArena<T> {
self.grow()
}

let ptr: &mut T = unsafe {
unsafe {
let ptr: &mut T = &mut *(self.ptr.get() as *mut T);
ptr::write(ptr, object);
self.ptr.set(self.ptr.get().offset(1));
ptr
};

ptr
}
}

/// Grows the arena.
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,10 +1558,10 @@ impl StrExt for str {
if w > 2 { val = utf8_acc_cont_byte(val, s.as_bytes()[i + 2]); }
if w > 3 { val = utf8_acc_cont_byte(val, s.as_bytes()[i + 3]); }

return CharRange {ch: unsafe { char::from_u32_unchecked(val) }, next: i};
CharRange {ch: unsafe { char::from_u32_unchecked(val) }, next: i}
}

return multibyte_char_range_at_reverse(self, prev);
multibyte_char_range_at_reverse(self, prev)
}

#[inline]
Expand Down Expand Up @@ -1683,7 +1683,7 @@ fn char_range_at_raw(bytes: &[u8], i: usize) -> (u32, usize) {
if w > 2 { val = utf8_acc_cont_byte(val, bytes[i + 2]); }
if w > 3 { val = utf8_acc_cont_byte(val, bytes[i + 3]); }

return (val, i + w as usize);
(val, i + w as usize)
}

multibyte_char_range_at(bytes, i)
Expand Down
76 changes: 38 additions & 38 deletions src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ impl Name {
if nm.len() == 1 {
Short(nm.char_at(0))
} else {
Long(nm.to_string())
Long(nm.to_owned())
}
}

fn to_string(&self) -> String {
match *self {
Short(ch) => ch.to_string(),
Long(ref s) => s.to_string()
Long(ref s) => s.to_owned()
}
}
}
Expand Down Expand Up @@ -375,7 +375,7 @@ impl Matches {
} else {
match vals[0] {
Val(ref s) => Some((*s).clone()),
_ => Some(def.to_string())
_ => Some(def.to_owned())
}
}
}
Expand Down Expand Up @@ -414,10 +414,10 @@ pub fn reqopt(short_name: &str, long_name: &str, desc: &str, hint: &str) -> OptG
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_string(),
long_name: long_name.to_string(),
hint: hint.to_string(),
desc: desc.to_string(),
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
hasarg: Yes,
occur: Req
}
Expand All @@ -434,10 +434,10 @@ pub fn optopt(short_name: &str, long_name: &str, desc: &str, hint: &str) -> OptG
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_string(),
long_name: long_name.to_string(),
hint: hint.to_string(),
desc: desc.to_string(),
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
hasarg: Yes,
occur: Optional
}
Expand All @@ -452,10 +452,10 @@ pub fn optflag(short_name: &str, long_name: &str, desc: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_string(),
long_name: long_name.to_string(),
hint: "".to_string(),
desc: desc.to_string(),
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: "".to_owned(),
desc: desc.to_owned(),
hasarg: No,
occur: Optional
}
Expand All @@ -471,10 +471,10 @@ pub fn optflagmulti(short_name: &str, long_name: &str, desc: &str) -> OptGroup {
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_string(),
long_name: long_name.to_string(),
hint: "".to_string(),
desc: desc.to_string(),
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: "".to_owned(),
desc: desc.to_owned(),
hasarg: No,
occur: Multi
}
Expand All @@ -491,10 +491,10 @@ pub fn optflagopt(short_name: &str, long_name: &str, desc: &str, hint: &str) ->
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_string(),
long_name: long_name.to_string(),
hint: hint.to_string(),
desc: desc.to_string(),
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
hasarg: Maybe,
occur: Optional
}
Expand All @@ -512,10 +512,10 @@ pub fn optmulti(short_name: &str, long_name: &str, desc: &str, hint: &str) -> Op
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_string(),
long_name: long_name.to_string(),
hint: hint.to_string(),
desc: desc.to_string(),
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
hasarg: Yes,
occur: Multi
}
Expand All @@ -531,10 +531,10 @@ pub fn opt(short_name: &str,
let len = short_name.len();
assert!(len == 1 || len == 0);
OptGroup {
short_name: short_name.to_string(),
long_name: long_name.to_string(),
hint: hint.to_string(),
desc: desc.to_string(),
short_name: short_name.to_owned(),
long_name: long_name.to_owned(),
hint: hint.to_owned(),
desc: desc.to_owned(),
hasarg: hasarg,
occur: occur
}
Expand Down Expand Up @@ -574,7 +574,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
let opts: Vec<Opt> = optgrps.iter().map(|x| x.long_to_short()).collect();
let n_opts = opts.len();

fn f(_x: usize) -> Vec<Optval> { return Vec::new(); }
fn f(_x: usize) -> Vec<Optval> { Vec::new() }

let mut vals: Vec<_> = (0..n_opts).map(f).collect();
let mut free: Vec<String> = Vec::new();
Expand All @@ -596,11 +596,11 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
let tail = &cur[2..curlen];
let tail_eq: Vec<&str> = tail.split('=').collect();
if tail_eq.len() <= 1 {
names = vec!(Long(tail.to_string()));
names = vec!(Long(tail.to_owned()));
} else {
names =
vec!(Long(tail_eq[0].to_string()));
i_arg = Some(tail_eq[1].to_string());
vec!(Long(tail_eq[0].to_owned()));
i_arg = Some(tail_eq[1].to_owned());
}
} else {
let mut j = 1;
Expand Down Expand Up @@ -630,7 +630,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {

let next = j + ch.len_utf8();
if arg_follows && next < curlen {
i_arg = Some((&cur[next..curlen]).to_string());
i_arg = Some((&cur[next..curlen]).to_owned());
break;
}

Expand Down Expand Up @@ -769,7 +769,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> String {
// FIXME: #5516 should be graphemes not codepoints
let mut desc_rows = Vec::new();
each_split_within(&desc_normalized_whitespace[..], 54, |substr| {
desc_rows.push(substr.to_string());
desc_rows.push(substr.to_owned());
true
});

Expand Down Expand Up @@ -936,7 +936,7 @@ fn each_split_within<F>(ss: &str, lim: usize, mut it: F) -> bool where
machine(&mut cont, (fake_i, ' '));
fake_i += 1;
}
return cont;
cont
}

#[test]
Expand Down
36 changes: 18 additions & 18 deletions src/liblog/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<String>) {
}
};
dirs.push(LogDirective {
name: name.map(|s| s.to_string()),
name: name.map(str::to_owned),
level: log_level,
});
}});

(dirs, filter.map(|s| s.to_string()))
(dirs, filter.map(str::to_owned))
}

#[cfg(test)]
Expand All @@ -90,13 +90,13 @@ mod tests {
fn parse_logging_spec_valid() {
let (dirs, filter) = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4");
assert_eq!(dirs.len(), 3);
assert_eq!(dirs[0].name, Some("crate1::mod1".to_string()));
assert_eq!(dirs[0].name, Some("crate1::mod1".to_owned()));
assert_eq!(dirs[0].level, 1);

assert_eq!(dirs[1].name, Some("crate1::mod2".to_string()));
assert_eq!(dirs[1].name, Some("crate1::mod2".to_owned()));
assert_eq!(dirs[1].level, ::MAX_LOG_LEVEL);

assert_eq!(dirs[2].name, Some("crate2".to_string()));
assert_eq!(dirs[2].name, Some("crate2".to_owned()));
assert_eq!(dirs[2].level, 4);
assert!(filter.is_none());
}
Expand All @@ -106,7 +106,7 @@ mod tests {
// test parse_logging_spec with multiple = in specification
let (dirs, filter) = parse_logging_spec("crate1::mod1=1=2,crate2=4");
assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
assert_eq!(dirs[0].level, 4);
assert!(filter.is_none());
}
Expand All @@ -116,7 +116,7 @@ mod tests {
// test parse_logging_spec with 'noNumber' as log level
let (dirs, filter) = parse_logging_spec("crate1::mod1=noNumber,crate2=4");
assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
assert_eq!(dirs[0].level, 4);
assert!(filter.is_none());
}
Expand All @@ -126,7 +126,7 @@ mod tests {
// test parse_logging_spec with 'warn' as log level
let (dirs, filter) = parse_logging_spec("crate1::mod1=wrong,crate2=warn");
assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
assert_eq!(dirs[0].level, ::WARN);
assert!(filter.is_none());
}
Expand All @@ -136,7 +136,7 @@ mod tests {
// test parse_logging_spec with '' as log level
let (dirs, filter) = parse_logging_spec("crate1::mod1=wrong,crate2=");
assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL);
assert!(filter.is_none());
}
Expand All @@ -148,7 +148,7 @@ mod tests {
assert_eq!(dirs.len(), 2);
assert_eq!(dirs[0].name, None);
assert_eq!(dirs[0].level, 2);
assert_eq!(dirs[1].name, Some("crate2".to_string()));
assert_eq!(dirs[1].name, Some("crate2".to_owned()));
assert_eq!(dirs[1].level, 4);
assert!(filter.is_none());
}
Expand All @@ -157,32 +157,32 @@ mod tests {
fn parse_logging_spec_valid_filter() {
let (dirs, filter) = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4/abc");
assert_eq!(dirs.len(), 3);
assert_eq!(dirs[0].name, Some("crate1::mod1".to_string()));
assert_eq!(dirs[0].name, Some("crate1::mod1".to_owned()));
assert_eq!(dirs[0].level, 1);

assert_eq!(dirs[1].name, Some("crate1::mod2".to_string()));
assert_eq!(dirs[1].name, Some("crate1::mod2".to_owned()));
assert_eq!(dirs[1].level, ::MAX_LOG_LEVEL);

assert_eq!(dirs[2].name, Some("crate2".to_string()));
assert_eq!(dirs[2].name, Some("crate2".to_owned()));
assert_eq!(dirs[2].level, 4);
assert!(filter.is_some() && filter.unwrap().to_string() == "abc");
assert!(filter.is_some() && filter.unwrap().to_owned() == "abc");
}

#[test]
fn parse_logging_spec_invalid_crate_filter() {
let (dirs, filter) = parse_logging_spec("crate1::mod1=1=2,crate2=4/a.c");
assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
assert_eq!(dirs[0].level, 4);
assert!(filter.is_some() && filter.unwrap().to_string() == "a.c");
assert!(filter.is_some() && filter.unwrap().to_owned() == "a.c");
}

#[test]
fn parse_logging_spec_empty_with_filter() {
let (dirs, filter) = parse_logging_spec("crate1/a*c");
assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate1".to_string()));
assert_eq!(dirs[0].name, Some("crate1".to_owned()));
assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL);
assert!(filter.is_some() && filter.unwrap().to_string() == "a*c");
assert!(filter.is_some() && filter.unwrap().to_owned() == "a*c");
}
}
Loading