diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 332e5abdefb0a..f48443e52b3e9 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -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] @@ -247,7 +247,7 @@ impl<'longer_than_self> Arena<'longer_than_self> { mem::align_of::()); let ptr = ptr as *mut T; ptr::write(&mut (*ptr), op()); - return &mut *ptr; + &mut *ptr } } @@ -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] @@ -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)) } } @@ -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 } } @@ -486,14 +486,12 @@ impl TypedArena { 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. diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 79718ad6d775d..694d93b75ca41 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -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] @@ -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) diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index ef63f85bb1337..ab34f2e48ca4a 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -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() } } } @@ -375,7 +375,7 @@ impl Matches { } else { match vals[0] { Val(ref s) => Some((*s).clone()), - _ => Some(def.to_string()) + _ => Some(def.to_owned()) } } } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -574,7 +574,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result { let opts: Vec = optgrps.iter().map(|x| x.long_to_short()).collect(); let n_opts = opts.len(); - fn f(_x: usize) -> Vec { return Vec::new(); } + fn f(_x: usize) -> Vec { Vec::new() } let mut vals: Vec<_> = (0..n_opts).map(f).collect(); let mut free: Vec = Vec::new(); @@ -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; @@ -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; } @@ -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 }); @@ -936,7 +936,7 @@ fn each_split_within(ss: &str, lim: usize, mut it: F) -> bool where machine(&mut cont, (fake_i, ' ')); fake_i += 1; } - return cont; + cont } #[test] diff --git a/src/liblog/directive.rs b/src/liblog/directive.rs index 5d38a381e6b7e..362303869d78d 100644 --- a/src/liblog/directive.rs +++ b/src/liblog/directive.rs @@ -74,12 +74,12 @@ pub fn parse_logging_spec(spec: &str) -> (Vec, Option) { } }; 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)] @@ -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()); } @@ -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()); } @@ -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()); } @@ -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()); } @@ -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()); } @@ -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()); } @@ -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"); } } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 09f98978653e3..4bcaa4b5dbc75 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1039,8 +1039,8 @@ impl Json { /// If the Json value is an Object, returns the value associated with the provided key. /// Otherwise, returns None. pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{ - match self { - &Json::Object(ref map) => map.get(key), + match *self { + Json::Object(ref map) => map.get(key), _ => None } } @@ -1083,41 +1083,41 @@ impl Json { } /// Returns true if the Json value is an Object. Returns false otherwise. - pub fn is_object<'a>(&'a self) -> bool { + pub fn is_object(&self) -> bool { self.as_object().is_some() } /// If the Json value is an Object, returns the associated BTreeMap. /// Returns None otherwise. - pub fn as_object<'a>(&'a self) -> Option<&'a Object> { - match self { - &Json::Object(ref map) => Some(map), + pub fn as_object(&self) -> Option<&Object> { + match *self { + Json::Object(ref map) => Some(map), _ => None } } /// Returns true if the Json value is an Array. Returns false otherwise. - pub fn is_array<'a>(&'a self) -> bool { + pub fn is_array(&self) -> bool { self.as_array().is_some() } /// If the Json value is an Array, returns the associated vector. /// Returns None otherwise. - pub fn as_array<'a>(&'a self) -> Option<&'a Array> { - match self { - &Json::Array(ref array) => Some(&*array), + pub fn as_array(&self) -> Option<&Array> { + match *self { + Json::Array(ref array) => Some(&*array), _ => None } } /// Returns true if the Json value is a String. Returns false otherwise. - pub fn is_string<'a>(&'a self) -> bool { + pub fn is_string(&self) -> bool { self.as_string().is_some() } /// If the Json value is a String, returns the associated str. /// Returns None otherwise. - pub fn as_string<'a>(&'a self) -> Option<&'a str> { + pub fn as_string(&self) -> Option<&str> { match *self { Json::String(ref s) => Some(&s[..]), _ => None @@ -1195,8 +1195,8 @@ impl Json { /// If the Json value is a Boolean, returns the associated bool. /// Returns None otherwise. pub fn as_boolean(&self) -> Option { - match self { - &Json::Boolean(b) => Some(b), + match *self { + Json::Boolean(b) => Some(b), _ => None } } @@ -1209,8 +1209,8 @@ impl Json { /// If the Json value is a Null, returns (). /// Returns None otherwise. pub fn as_null(&self) -> Option<()> { - match self { - &Json::Null => Some(()), + match *self { + Json::Null => Some(()), _ => None } } @@ -1228,8 +1228,8 @@ impl Index for Json { type Output = Json; fn index<'a>(&'a self, idx: usize) -> &'a Json { - match self { - &Json::Array(ref v) => &v[idx], + match *self { + Json::Array(ref v) => &v[idx], _ => panic!("can only index Json with usize if it is an array") } } @@ -1323,20 +1323,20 @@ impl Stack { /// Compares this stack with an array of StackElements. pub fn is_equal_to(&self, rhs: &[StackElement]) -> bool { if self.stack.len() != rhs.len() { return false; } - for i in 0..rhs.len() { - if self.get(i) != rhs[i] { return false; } + for (i, r) in rhs.iter().enumerate() { + if self.get(i) != *r { return false; } } - return true; + true } /// Returns true if the bottom-most elements of this stack are the same as /// the ones passed as parameter. pub fn starts_with(&self, rhs: &[StackElement]) -> bool { if self.stack.len() < rhs.len() { return false; } - for i in 0..rhs.len() { - if self.get(i) != rhs[i] { return false; } + for (i, r) in rhs.iter().enumerate() { + if self.get(i) != *r { return false; } } - return true; + true } /// Returns true if the top-most elements of this stack are the same as @@ -1344,15 +1344,15 @@ impl Stack { pub fn ends_with(&self, rhs: &[StackElement]) -> bool { if self.stack.len() < rhs.len() { return false; } let offset = self.stack.len() - rhs.len(); - for i in 0..rhs.len() { - if self.get(i + offset) != rhs[i] { return false; } + for (i, r) in rhs.iter().enumerate() { + if self.get(i + offset) != *r { return false; } } - return true; + true } /// Returns the top-most element (if any). pub fn top<'l>(&'l self) -> Option> { - return match self.stack.last() { + match self.stack.last() { None => None, Some(&InternalIndex(i)) => Some(StackElement::Index(i)), Some(&InternalKey(start, size)) => { @@ -1442,7 +1442,7 @@ impl> Iterator for Parser { } } - return Some(self.parse()); + Some(self.parse()) } } @@ -1458,13 +1458,13 @@ impl> Parser { state: ParseStart, }; p.bump(); - return p; + p } /// Provides access to the current position in the logical structure of the /// JSON stream. pub fn stack<'l>(&'l self) -> &'l Stack { - return &self.stack; + &self.stack } fn eof(&self) -> bool { self.ch.is_none() } @@ -1559,9 +1559,8 @@ impl> Parser { self.bump(); // A leading '0' must be the only digit before the decimal point. - match self.ch_or_null() { - '0' ... '9' => return self.error(InvalidNumber), - _ => () + if let '0' ... '9' = self.ch_or_null() { + return self.error(InvalidNumber) } }, '1' ... '9' => { @@ -1798,7 +1797,7 @@ impl> Parser { ObjectStart => ParseObject(true), _ => ParseBeforeFinish, }; - return val; + val } fn parse_array(&mut self, first: bool) -> JsonEvent { @@ -1905,7 +1904,7 @@ impl> Parser { ObjectStart => ParseObject(true), _ => ParseObjectComma, }; - return val; + val } fn parse_object_end(&mut self) -> JsonEvent { @@ -1994,7 +1993,7 @@ impl> Builder { } fn build_value(&mut self) -> Result { - return match self.token { + match self.token { Some(NullValue) => Ok(Json::Null), Some(I64Value(n)) => Ok(Json::I64(n)), Some(U64Value(n)) => Ok(Json::U64(n)), @@ -2043,7 +2042,7 @@ impl> Builder { _ => {} } let key = match self.parser.stack().top() { - Some(StackElement::Key(k)) => { k.to_string() } + Some(StackElement::Key(k)) => { k.to_owned() } _ => { panic!("invalid state"); } }; match self.build_value() { @@ -2052,7 +2051,7 @@ impl> Builder { } self.bump(); } - return self.parser.error(EOFWhileParsingObject); + self.parser.error(EOFWhileParsingObject) } } @@ -2099,7 +2098,7 @@ macro_rules! expect { ($e:expr, Null) => ({ match $e { Json::Null => Ok(()), - other => Err(ExpectedError("Null".to_string(), + other => Err(ExpectedError("Null".to_owned(), format!("{}", other))) } }); @@ -2107,7 +2106,7 @@ macro_rules! expect { match $e { Json::$t(v) => Ok(v), other => { - Err(ExpectedError(stringify!($t).to_string(), + Err(ExpectedError(stringify!($t).to_owned(), format!("{}", other))) } } @@ -2120,14 +2119,14 @@ macro_rules! read_primitive { match self.pop() { Json::I64(f) => Ok(f as $ty), Json::U64(f) => Ok(f as $ty), - Json::F64(f) => Err(ExpectedError("Integer".to_string(), format!("{}", f))), + Json::F64(f) => Err(ExpectedError("Integer".to_owned(), format!("{}", f))), // re: #12967.. a type w/ numeric keys (ie HashMap etc) // is going to have a string here, as per JSON spec. Json::String(s) => match s.parse().ok() { Some(f) => Ok(f), - None => Err(ExpectedError("Number".to_string(), s)), + None => Err(ExpectedError("Number".to_owned(), s)), }, - value => Err(ExpectedError("Number".to_string(), format!("{}", value))), + value => Err(ExpectedError("Number".to_owned(), format!("{}", value))), } } } @@ -2163,11 +2162,11 @@ impl ::Decoder for Decoder { // is going to have a string here, as per JSON spec. match s.parse().ok() { Some(f) => Ok(f), - None => Err(ExpectedError("Number".to_string(), s)), + None => Err(ExpectedError("Number".to_owned(), s)), } }, Json::Null => Ok(f64::NAN), - value => Err(ExpectedError("Number".to_string(), format!("{}", value))) + value => Err(ExpectedError("Number".to_owned(), format!("{}", value))) } } @@ -2185,7 +2184,7 @@ impl ::Decoder for Decoder { _ => () } } - Err(ExpectedError("single character string".to_string(), format!("{}", s))) + Err(ExpectedError("single character string".to_owned(), format!("{}", s))) } fn read_str(&mut self) -> DecodeResult { @@ -2205,13 +2204,13 @@ impl ::Decoder for Decoder { let name = match self.pop() { Json::String(s) => s, Json::Object(mut o) => { - let n = match o.remove(&"variant".to_string()) { + let n = match o.remove(&"variant".to_owned()) { Some(Json::String(s)) => s, Some(val) => { - return Err(ExpectedError("String".to_string(), format!("{}", val))) + return Err(ExpectedError("String".to_owned(), format!("{}", val))) } None => { - return Err(MissingFieldError("variant".to_string())) + return Err(MissingFieldError("variant".to_owned())) } }; match o.remove(&"fields".to_string()) { @@ -2221,16 +2220,16 @@ impl ::Decoder for Decoder { } }, Some(val) => { - return Err(ExpectedError("Array".to_string(), format!("{}", val))) + return Err(ExpectedError("Array".to_owned(), format!("{}", val))) } None => { - return Err(MissingFieldError("fields".to_string())) + return Err(MissingFieldError("fields".to_owned())) } } n } json => { - return Err(ExpectedError("String or Object".to_string(), format!("{}", json))) + return Err(ExpectedError("String or Object".to_owned(), format!("{}", json))) } }; let idx = match names.iter().position(|n| *n == &name[..]) { diff --git a/src/libserialize/serialize.rs b/src/libserialize/serialize.rs index 5e96ec6ab0df3..23888bed25973 100644 --- a/src/libserialize/serialize.rs +++ b/src/libserialize/serialize.rs @@ -515,7 +515,7 @@ macro_rules! tuple { |d| -> Result<$name,D::Error> { Decodable::decode(d) })),)*); - return Ok(ret); + Ok(ret) }) } } diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 43bfce9b9e9e4..7801662ff25f9 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -231,7 +231,7 @@ mod dl { Ok(result) } else { let s = CStr::from_ptr(last_error).to_bytes(); - Err(str::from_utf8(s).unwrap().to_string()) + Err(str::from_utf8(s).unwrap().to_owned()) }; ret diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index d161b6250687b..576d9b92156b8 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -277,11 +277,11 @@ impl Error { impl fmt::Debug for Repr { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - match self { - &Repr::Os(ref code) => + match *self { + Repr::Os(ref code) => fmt.debug_struct("Os").field("code", code) .field("message", &sys::os::error_string(*code)).finish(), - &Repr::Custom(ref c) => fmt.debug_tuple("Custom").field(c).finish(), + Repr::Custom(ref c) => fmt.debug_tuple("Custom").field(c).finish(), } } } diff --git a/src/libstd/io/lazy.rs b/src/libstd/io/lazy.rs index ad17a650336c5..5424fec81104b 100644 --- a/src/libstd/io/lazy.rs +++ b/src/libstd/io/lazy.rs @@ -62,6 +62,6 @@ impl Lazy { if registered.is_ok() { self.ptr.set(Box::into_raw(Box::new(ret.clone()))); } - return ret + ret } } diff --git a/src/libstd/net/parser.rs b/src/libstd/net/parser.rs index 480fd63c36a85..f0b35bbc38811 100644 --- a/src/libstd/net/parser.rs +++ b/src/libstd/net/parser.rs @@ -262,8 +262,8 @@ impl<'a> Parser<'a> { } fn read_ip_addr(&mut self) -> Option { - let ipv4_addr = |p: &mut Parser| p.read_ipv4_addr().map(|v4| IpAddr::V4(v4)); - let ipv6_addr = |p: &mut Parser| p.read_ipv6_addr().map(|v6| IpAddr::V6(v6)); + let ipv4_addr = |p: &mut Parser| p.read_ipv4_addr().map(IpAddr::V4); + let ipv6_addr = |p: &mut Parser| p.read_ipv6_addr().map(IpAddr::V6); self.read_or(&mut [Box::new(ipv4_addr), Box::new(ipv6_addr)]) } diff --git a/src/libstd/rt/at_exit_imp.rs b/src/libstd/rt/at_exit_imp.rs index 379c86eb2a0fb..7a1215bf382b2 100644 --- a/src/libstd/rt/at_exit_imp.rs +++ b/src/libstd/rt/at_exit_imp.rs @@ -42,7 +42,7 @@ unsafe fn init() -> bool { return false } - return true + true } pub fn cleanup() { @@ -78,5 +78,5 @@ pub fn push(f: Box) -> bool { } LOCK.unlock(); } - return ret + ret } diff --git a/src/libstd/rt/dwarf/eh.rs b/src/libstd/rt/dwarf/eh.rs index 990501b28dba1..f4799703d996d 100644 --- a/src/libstd/rt/dwarf/eh.rs +++ b/src/libstd/rt/dwarf/eh.rs @@ -104,7 +104,7 @@ pub unsafe fn find_landing_pad(lsda: *const u8, context: &EHContext) // IP range not found: gcc's C++ personality calls terminate() here, // however the rest of the languages treat this the same as cs_lpad == 0. // We follow this suit. - return None; + None } #[inline] diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index f2bf8757a51dc..95cba13220133 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -73,7 +73,7 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { // created. Note that this isn't necessary in general for new threads, // but we just do this to name the main thread and to give it correct // info about the stack bounds. - let thread: Thread = NewThread::new(Some("
".to_string())); + let thread: Thread = NewThread::new(Some("
".to_owned())); thread_info::set(main_guard, thread); // By default, some platforms will send a *signal* when a EPIPE error diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 0fe8d873a75c6..23a3c3e38c467 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -27,7 +27,7 @@ pub fn min_stack() -> usize { // 0 is our sentinel value, so ensure that we'll never see 0 after // initialization has run MIN.store(amt + 1, Ordering::SeqCst); - return amt; + amt } // Indicates whether we should perform expensive sanity checks, including rtassert! diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index c37c0405bbb38..8c5cec969a6aa 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -397,7 +397,7 @@ enum Flavor { #[doc(hidden)] trait UnsafeFlavor { - fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell>; + fn inner_unsafe(&self) -> &UnsafeCell>; unsafe fn inner_mut<'a>(&'a self) -> &'a mut Flavor { &mut *self.inner_unsafe().get() } @@ -406,12 +406,12 @@ trait UnsafeFlavor { } } impl UnsafeFlavor for Sender { - fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell> { + fn inner_unsafe(&self) -> &UnsafeCell> { &self.inner } } impl UnsafeFlavor for Receiver { - fn inner_unsafe<'a>(&'a self) -> &'a UnsafeCell> { + fn inner_unsafe(&self) -> &UnsafeCell> { &self.inner } } @@ -677,7 +677,7 @@ impl SyncSender { impl Clone for SyncSender { fn clone(&self) -> SyncSender { unsafe { (*self.inner.get()).clone_chan(); } - return SyncSender::new(self.inner.clone()); + SyncSender::new(self.inner.clone()) } } diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index 819f75c006b31..ffd33f8518f68 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -196,7 +196,7 @@ impl Queue { let _: Box> = Box::from_raw(tail); } } - return ret; + ret } } @@ -207,14 +207,13 @@ impl Queue { /// The reference returned is invalid if it is not used before the consumer /// pops the value off the queue. If the producer then pushes another value /// onto the queue, it will overwrite the value pointed to by the reference. - pub fn peek<'a>(&'a self) -> Option<&'a mut T> { + pub fn peek(&self) -> Option<&mut T> { // This is essentially the same as above with all the popping bits // stripped out. unsafe { let tail = *self.tail.get(); let next = (*tail).next.load(Ordering::Acquire); - if next.is_null() { return None } - return (*next).value.as_mut(); + if next.is_null() { None } else { (*next).value.as_mut() } } } } diff --git a/src/libstd/sync/mpsc/stream.rs b/src/libstd/sync/mpsc/stream.rs index a9da1b12f7d92..e8012ca470b02 100644 --- a/src/libstd/sync/mpsc/stream.rs +++ b/src/libstd/sync/mpsc/stream.rs @@ -307,12 +307,7 @@ impl Packet { steals, DISCONNECTED, Ordering::SeqCst); cnt != DISCONNECTED && cnt != steals } { - loop { - match self.queue.pop() { - Some(..) => { steals += 1; } - None => break - } - } + while let Some(_) = self.queue.pop() { steals += 1; } } // At this point in time, we have gated all future senders from sending, @@ -378,7 +373,7 @@ impl Packet { // previous value is positive because we're not going to sleep let prev = self.bump(1); assert!(prev == DISCONNECTED || prev >= 0); - return ret; + ret } } } diff --git a/src/libstd/sync/mpsc/sync.rs b/src/libstd/sync/mpsc/sync.rs index 84d758cf9b3b6..b98fc2859afcc 100644 --- a/src/libstd/sync/mpsc/sync.rs +++ b/src/libstd/sync/mpsc/sync.rs @@ -254,7 +254,7 @@ impl Packet { assert!(guard.buf.size() > 0); let ret = guard.buf.dequeue(); self.wakeup_senders(waited, guard); - return Ok(ret); + Ok(ret) } pub fn try_recv(&self) -> Result { @@ -267,8 +267,7 @@ impl Packet { // Be sure to wake up neighbors let ret = Ok(guard.buf.dequeue()); self.wakeup_senders(false, guard); - - return ret; + ret } // Wake up pending senders after some data has been received @@ -356,12 +355,7 @@ impl Packet { }; mem::drop(guard); - loop { - match queue.dequeue() { - Some(token) => { token.signal(); } - None => break, - } - } + while let Some(token) = queue.dequeue() { token.signal(); } waiter.map(|t| t.signal()); } diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index e56e5a72c13b9..846a97b547dc6 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -334,13 +334,14 @@ impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> { impl<'mutex, T: ?Sized> Deref for MutexGuard<'mutex, T> { type Target = T; - fn deref<'a>(&'a self) -> &'a T { + fn deref(&self) -> &T { unsafe { &*self.__data.get() } } } + #[stable(feature = "rust1", since = "1.0.0")] impl<'mutex, T: ?Sized> DerefMut for MutexGuard<'mutex, T> { - fn deref_mut<'a>(&'a mut self) -> &'a mut T { + fn deref_mut(&mut self) -> &mut T { unsafe { &mut *self.__data.get() } } } diff --git a/src/libstd/sys/common/gnu/libbacktrace.rs b/src/libstd/sys/common/gnu/libbacktrace.rs index 7a2ca0a9f097d..3b846fd462ed3 100644 --- a/src/libstd/sys/common/gnu/libbacktrace.rs +++ b/src/libstd/sys/common/gnu/libbacktrace.rs @@ -151,7 +151,7 @@ pub fn print(w: &mut Write, idx: isize, addr: *mut libc::c_void, }; STATE = backtrace_create_state(filename, 0, error_cb, ptr::null_mut()); - return STATE + STATE } //////////////////////////////////////////////////////////////////////// diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 4fb3134eac99c..37379596251de 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -161,7 +161,7 @@ pub fn lookup_addr(addr: &IpAddr) -> io::Result { }; match from_utf8(data.to_bytes()) { - Ok(name) => Ok(name.to_string()), + Ok(name) => Ok(name.to_owned()), Err(_) => Err(io::Error::new(io::ErrorKind::Other, "failed to lookup address information")) } diff --git a/src/libstd/sys/common/remutex.rs b/src/libstd/sys/common/remutex.rs index 4df3441f87b21..f3f21e47a1406 100644 --- a/src/libstd/sys/common/remutex.rs +++ b/src/libstd/sys/common/remutex.rs @@ -67,7 +67,7 @@ impl ReentrantMutex { data: t, }; mutex.inner.init(); - return mutex + mutex } } @@ -145,7 +145,7 @@ impl<'mutex, T> ReentrantMutexGuard<'mutex, T> { impl<'mutex, T> Deref for ReentrantMutexGuard<'mutex, T> { type Target = T; - fn deref<'a>(&'a self) -> &'a T { + fn deref(&self) -> &T { &self.__lock.data } } diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index eb313d275a191..633e7d78a9aeb 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -282,19 +282,13 @@ impl Wtf8Buf { /// like concatenating ill-formed UTF-16 strings effectively would. #[inline] pub fn push(&mut self, code_point: CodePoint) { - match code_point.to_u32() { - trail @ 0xDC00...0xDFFF => { - match (&*self).final_lead_surrogate() { - Some(lead) => { - let len_without_lead_surrogate = self.len() - 3; - self.bytes.truncate(len_without_lead_surrogate); - self.push_char(decode_surrogate_pair(lead, trail as u16)); - return - } - _ => {} - } + if let trail @ 0xDC00...0xDFFF = code_point.to_u32() { + if let Some(lead) = (&*self).final_lead_surrogate() { + let len_without_lead_surrogate = self.len() - 3; + self.bytes.truncate(len_without_lead_surrogate); + self.push_char(decode_surrogate_pair(lead, trail as u16)); + return } - _ => {} } // No newly paired surrogates at the boundary. diff --git a/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs b/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs index cdaf69c488253..8b32b5ec04002 100644 --- a/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs +++ b/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs @@ -99,7 +99,7 @@ pub fn write(w: &mut Write) -> io::Result<()> { } // keep going - return uw::_URC_NO_REASON + uw::_URC_NO_REASON } } diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index f1a9518d08de5..6d65cb838f67a 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -35,7 +35,7 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> { let detail = unsafe { str::from_utf8(CStr::from_ptr(c::gai_strerror(err)).to_bytes()).unwrap() - .to_string() + .to_owned() }; Err(io::Error::new(io::ErrorKind::Other, &format!("failed to lookup address information: {}", diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 70be04b631ad5..af0d8da05f49a 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -88,7 +88,7 @@ pub fn error_string(errno: i32) -> String { } let p = p as *const _; - str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap().to_string() + str::from_utf8(CStr::from_ptr(p).to_bytes()).unwrap().to_owned() } } @@ -134,7 +134,7 @@ pub struct SplitPaths<'a> { fn(&'a [u8]) -> PathBuf>, } -pub fn split_paths<'a>(unparsed: &'a OsStr) -> SplitPaths<'a> { +pub fn split_paths(unparsed: &OsStr) -> SplitPaths { fn bytes_to_path(b: &[u8]) -> PathBuf { PathBuf::from(::from_bytes(b)) } @@ -142,7 +142,7 @@ pub fn split_paths<'a>(unparsed: &'a OsStr) -> SplitPaths<'a> { let unparsed = unparsed.as_bytes(); SplitPaths { iter: unparsed.split(is_colon as fn(&u8) -> bool) - .map(bytes_to_path as fn(&'a [u8]) -> PathBuf) + .map(bytes_to_path as fn(&[u8]) -> PathBuf) } } diff --git a/src/libstd/sys/unix/stdio.rs b/src/libstd/sys/unix/stdio.rs index c87800a1498f0..ccbb14677c7e4 100644 --- a/src/libstd/sys/unix/stdio.rs +++ b/src/libstd/sys/unix/stdio.rs @@ -23,7 +23,7 @@ impl Stdin { let fd = FileDesc::new(libc::STDIN_FILENO); let ret = fd.read(data); fd.into_raw(); - return ret; + ret } } @@ -34,7 +34,7 @@ impl Stdout { let fd = FileDesc::new(libc::STDOUT_FILENO); let ret = fd.write(data); fd.into_raw(); - return ret; + ret } } @@ -45,7 +45,7 @@ impl Stderr { let fd = FileDesc::new(libc::STDERR_FILENO); let ret = fd.write(data); fd.into_raw(); - return ret; + ret } } diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 5a551e2b3f33f..268ec7fe35687 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -310,7 +310,7 @@ pub mod guard { ret = Some(stackaddr as usize + guardsize as usize); } assert_eq!(pthread_attr_destroy(&mut attr), 0); - return ret + ret } #[cfg(any(target_os = "linux", target_os = "android"))] diff --git a/src/libstd/sys/unix/thread_local.rs b/src/libstd/sys/unix/thread_local.rs index c375788fdc169..e697417675d77 100644 --- a/src/libstd/sys/unix/thread_local.rs +++ b/src/libstd/sys/unix/thread_local.rs @@ -18,7 +18,7 @@ pub type Key = pthread_key_t; pub unsafe fn create(dtor: Option) -> Key { let mut key = 0; assert_eq!(pthread_key_create(&mut key, dtor), 0); - return key; + key } #[inline] diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index 4840cd1fddadf..ffe896b93a718 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -151,7 +151,7 @@ impl Terminal for TerminfoTerminal { cap = self.ti.strings.get("op"); } } - let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_string()), |op| { + let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_owned()), |op| { expand(op, &[], &mut Variables::new()) }); if s.is_ok() { @@ -211,9 +211,9 @@ impl TerminfoTerminal { inf.numbers.get("colors").map_or(0, |&n| n) } else { 0 }; - return Some(box TerminfoTerminal {out: out, - ti: inf, - num_colors: nc}); + Some(box TerminfoTerminal {out: out, + ti: inf, + num_colors: nc}) } fn dim_if_necessary(&self, color: color::Color) -> color::Color { diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index 14a9d2677e2b9..9110be33907b0 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -133,9 +133,9 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) c as u8 }) } - _ => return Err("a non-char was used with %c".to_string()) + _ => return Err("a non-char was used with %c".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, 'p' => state = PushParam, 'P' => state = SetVar, 'g' => state = GetVar, @@ -144,112 +144,112 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) 'l' => if !stack.is_empty() { match stack.pop().unwrap() { Words(s) => stack.push(Number(s.len() as isize)), - _ => return Err("a non-str was used with %l".to_string()) + _ => return Err("a non-str was used with %l".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '+' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x + y)), - _ => return Err("non-numbers on stack with +".to_string()) + _ => return Err("non-numbers on stack with +".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '-' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x - y)), - _ => return Err("non-numbers on stack with -".to_string()) + _ => return Err("non-numbers on stack with -".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '*' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x * y)), - _ => return Err("non-numbers on stack with *".to_string()) + _ => return Err("non-numbers on stack with *".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '/' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x / y)), - _ => return Err("non-numbers on stack with /".to_string()) + _ => return Err("non-numbers on stack with /".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, 'm' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x % y)), - _ => return Err("non-numbers on stack with %".to_string()) + _ => return Err("non-numbers on stack with %".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '&' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x & y)), - _ => return Err("non-numbers on stack with &".to_string()) + _ => return Err("non-numbers on stack with &".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '|' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x | y)), - _ => return Err("non-numbers on stack with |".to_string()) + _ => return Err("non-numbers on stack with |".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '^' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x ^ y)), - _ => return Err("non-numbers on stack with ^".to_string()) + _ => return Err("non-numbers on stack with ^".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '=' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x == y { 1 } else { 0 })), - _ => return Err("non-numbers on stack with =".to_string()) + _ => return Err("non-numbers on stack with =".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '>' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x > y { 1 } else { 0 })), - _ => return Err("non-numbers on stack with >".to_string()) + _ => return Err("non-numbers on stack with >".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '<' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x < y { 1 } else { 0 })), - _ => return Err("non-numbers on stack with <".to_string()) + _ => return Err("non-numbers on stack with <".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, 'A' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(0), Number(_)) => stack.push(Number(0)), (Number(_), Number(0)) => stack.push(Number(0)), (Number(_), Number(_)) => stack.push(Number(1)), - _ => return Err("non-numbers on stack with logical and".to_string()) + _ => return Err("non-numbers on stack with logical and".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, 'O' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(0), Number(0)) => stack.push(Number(0)), (Number(_), Number(_)) => stack.push(Number(1)), - _ => return Err("non-numbers on stack with logical or".to_string()) + _ => return Err("non-numbers on stack with logical or".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '!' => if !stack.is_empty() { match stack.pop().unwrap() { Number(0) => stack.push(Number(1)), Number(_) => stack.push(Number(0)), - _ => return Err("non-number on stack with logical not".to_string()) + _ => return Err("non-number on stack with logical not".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, '~' => if !stack.is_empty() { match stack.pop().unwrap() { Number(x) => stack.push(Number(!x)), - _ => return Err("non-number on stack with %~".to_string()) + _ => return Err("non-number on stack with %~".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, 'i' => match (mparams[0].clone(), mparams[1].clone()) { (Number(x), Number(y)) => { mparams[0] = Number(x+1); mparams[1] = Number(y+1); }, - (_, _) => return Err("first two params not numbers with %i".to_string()) + (_, _) => return Err("first two params not numbers with %i".to_owned()) }, // printf-style support for %doxXs @@ -258,7 +258,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) let res = format(stack.pop().unwrap(), FormatOp::from_char(cur), flags); if res.is_err() { return res } output.push_all(&res.unwrap()) - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, ':'|'#'|' '|'.'|'0'...'9' => { let mut flags = Flags::new(); let mut fstate = FormatStateFlags; @@ -283,9 +283,9 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) Number(0) => state = SeekIfElse(0), Number(_) => (), _ => return Err("non-number on stack \ - with conditional".to_string()) + with conditional".to_owned()) } - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, 'e' => state = SeekIfEnd(0), ';' => (), @@ -298,7 +298,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) // params are 1-indexed stack.push(mparams[match cur.to_digit(10) { Some(d) => d as usize - 1, - None => return Err("bad param number".to_string()) + None => return Err("bad param number".to_owned()) }].clone()); }, SetVar => { @@ -306,14 +306,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) if !stack.is_empty() { let idx = (cur as u8) - b'A'; vars.sta[idx as usize] = stack.pop().unwrap(); - } else { return Err("stack is empty".to_string()) } + } else { return Err("stack is empty".to_owned()) } } else if cur >= 'a' && cur <= 'z' { if !stack.is_empty() { let idx = (cur as u8) - b'a'; vars.dyn[idx as usize] = stack.pop().unwrap(); - } else { return Err("stack is empty".to_string()) } + } else { return Err("stack is empty".to_owned()) } } else { - return Err("bad variable name in %P".to_string()); + return Err("bad variable name in %P".to_owned()); } }, GetVar => { @@ -324,7 +324,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) let idx = (cur as u8) - b'a'; stack.push(vars.dyn[idx as usize].clone()); } else { - return Err("bad variable name in %g".to_string()); + return Err("bad variable name in %g".to_owned()); } }, CharConstant => { @@ -333,7 +333,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) }, CharClose => { if cur != '\'' { - return Err("malformed character constant".to_string()); + return Err("malformed character constant".to_owned()); } }, IntConstant(i) => { @@ -346,7 +346,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) state = IntConstant(i*10 + (cur as isize - '0' as isize)); old_state = Nothing; } - _ => return Err("bad isize constant".to_string()) + _ => return Err("bad isize constant".to_owned()) } } FormatPattern(ref mut flags, ref mut fstate) => { @@ -358,7 +358,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) output.push_all(&res.unwrap()); // will cause state to go to Nothing old_state = FormatPattern(*flags, *fstate); - } else { return Err("stack is empty".to_string()) }, + } else { return Err("stack is empty".to_owned()) }, (FormatStateFlags,'#') => { flags.alternate = true; } @@ -381,7 +381,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) (FormatStateWidth,'0'...'9') => { let old = flags.width; flags.width = flags.width * 10 + (cur as usize - '0' as usize); - if flags.width < old { return Err("format width overflow".to_string()) } + if flags.width < old { return Err("format width overflow".to_owned()) } } (FormatStateWidth,'.') => { *fstate = FormatStatePrecision; @@ -390,10 +390,10 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) let old = flags.precision; flags.precision = flags.precision * 10 + (cur as usize - '0' as usize); if flags.precision < old { - return Err("format precision overflow".to_string()) + return Err("format precision overflow".to_owned()) } } - _ => return Err("invalid format specifier".to_string()) + _ => return Err("invalid format specifier".to_owned()) } } SeekIfElse(level) => { @@ -502,7 +502,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,String> { (FormatHex, _) => format!("{:x}", d).into_bytes(), (FormatHEX, _) => format!("{:X}", d).into_bytes(), (FormatString, _) => { - return Err("non-number on stack with %s".to_string()) + return Err("non-number on stack with %s".to_owned()) } }; let mut s: Vec = s.into_iter().collect(); @@ -692,7 +692,7 @@ mod tests { Words("f".to_string()), Words("foo".to_string())], vars), Ok("foofoo ffo".bytes().collect::>())); - assert_eq!(expand(b"%p1%:-4.2s", &[Words("foo".to_string())], vars), + assert_eq!(expand(b"%p1%:-4.2s", &[Words("foo".to_owned())], vars), Ok("fo ".bytes().collect::>())); assert_eq!(expand(b"%p1%d%p1%.3d%p1%5d%p1%:+d", &[Number(1)], vars), diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index f71f7f7aac5fa..d29042ae5e762 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -205,28 +205,28 @@ pub fn parse(file: &mut Read, longnames: bool) if (bools_bytes as usize) > boolnames.len() { return Err("incompatible file: more booleans than \ - expected".to_string()); + expected".to_owned()); } if (numbers_count as usize) > numnames.len() { return Err("incompatible file: more numbers than \ - expected".to_string()); + expected".to_owned()); } if (string_offsets_count as usize) > stringnames.len() { return Err("incompatible file: more string offsets than \ - expected".to_string()); + expected".to_owned()); } // don't read NUL let bytes = try!(read_exact(file, names_bytes as usize - 1)); let names_str = match String::from_utf8(bytes) { Ok(s) => s, - Err(_) => return Err("input not utf-8".to_string()), + Err(_) => return Err("input not utf-8".to_owned()), }; let term_names: Vec = names_str.split('|') - .map(|s| s.to_string()) + .map(str::to_owned) .collect(); try!(read_byte(file)); // consume NUL @@ -236,7 +236,7 @@ pub fn parse(file: &mut Read, longnames: bool) for i in 0..bools_bytes { let b = try!(read_byte(file)); if b == 1 { - bools_map.insert(bnames[i as usize].to_string(), true); + bools_map.insert(bnames[i as usize].to_owned(), true); } } } @@ -250,7 +250,7 @@ pub fn parse(file: &mut Read, longnames: bool) for i in 0..numbers_count { let n = try!(read_le_u16(file)); if n != 0xFFFF { - numbers_map.insert(nnames[i as usize].to_string(), n); + numbers_map.insert(nnames[i as usize].to_owned(), n); } } } @@ -267,7 +267,7 @@ pub fn parse(file: &mut Read, longnames: bool) if string_table.len() != string_table_bytes as usize { return Err("error: hit EOF before end of string \ - table".to_string()); + table".to_owned()); } for (i, v) in string_offsets.iter().enumerate() { @@ -285,7 +285,7 @@ pub fn parse(file: &mut Read, longnames: bool) if offset == 0xFFFE { // undocumented: FFFE indicates cap@, which means the capability is not present // unsure if the handling for this is correct - string_map.insert(name.to_string(), Vec::new()); + string_map.insert(name.to_owned(), Vec::new()); continue; } @@ -301,7 +301,7 @@ pub fn parse(file: &mut Read, longnames: bool) }, None => { return Err("invalid file: missing NUL in \ - string_table".to_string()); + string_table".to_owned()); } }; } @@ -338,12 +338,12 @@ fn read_exact(r: &mut R, sz: usize) -> io::Result> { /// Create a dummy TermInfo struct for msys terminals pub fn msys_terminfo() -> Box { let mut strings = HashMap::new(); - strings.insert("sgr0".to_string(), b"\x1B[0m".to_vec()); - strings.insert("bold".to_string(), b"\x1B[1m".to_vec()); - strings.insert("setaf".to_string(), b"\x1B[3%p1%dm".to_vec()); - strings.insert("setab".to_string(), b"\x1B[4%p1%dm".to_vec()); + strings.insert("sgr0".to_owned(), b"\x1B[0m".to_vec()); + strings.insert("bold".to_owned(), b"\x1B[1m".to_vec()); + strings.insert("setaf".to_owned(), b"\x1B[3%p1%dm".to_vec()); + strings.insert("setab".to_owned(), b"\x1B[4%p1%dm".to_vec()); box TermInfo { - names: vec!("cygwin".to_string()), // msys is a fork of an older cygwin version + names: vec!("cygwin".to_owned()), // msys is a fork of an older cygwin version bools: HashMap::new(), numbers: HashMap::new(), strings: strings diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 4de7e7c586606..ad00bb6673308 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -103,7 +103,7 @@ pub enum TestName { DynTestName(String) } impl TestName { - fn as_slice<'a>(&'a self) -> &'a str { + fn as_slice(&self) -> &str { match *self { StaticTestName(s) => s, DynTestName(ref s) => s @@ -157,13 +157,13 @@ pub enum TestFn { impl TestFn { fn padding(&self) -> NamePadding { - match self { - &StaticTestFn(..) => PadNone, - &StaticBenchFn(..) => PadOnRight, - &StaticMetricFn(..) => PadOnRight, - &DynTestFn(..) => PadNone, - &DynMetricFn(..) => PadOnRight, - &DynBenchFn(..) => PadOnRight, + match *self { + StaticTestFn(..) => PadNone, + StaticBenchFn(..) => PadOnRight, + StaticMetricFn(..) => PadOnRight, + DynTestFn(..) => PadNone, + DynMetricFn(..) => PadOnRight, + DynBenchFn(..) => PadOnRight, } } } @@ -564,9 +564,9 @@ impl ConsoleTestState { None => Ok(()), Some(ref mut o) => { let s = format!("{} {}\n", match *result { - TrOk => "ok".to_string(), - TrFailed => "failed".to_string(), - TrIgnored => "ignored".to_string(), + TrOk => "ok".to_owned(), + TrFailed => "failed".to_owned(), + TrIgnored => "ignored".to_owned(), TrMetrics(ref mm) => mm.fmt_metrics(), TrBench(ref bs) => fmt_bench_samples(bs) }, test.name); @@ -925,7 +925,7 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec) -> Vec name.clone().to_string(), - StaticTestName(name) => name.to_string(), + DynTestName(ref name) => name.clone(), + StaticTestName(name) => name.to_owned(), }); let result_guard = cfg.spawn(move || { @@ -1020,7 +1020,7 @@ pub fn run_test(opts: &TestOpts, } DynTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, f), StaticTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, - Box::new(move|| f())) + Box::new(f)) } } @@ -1063,7 +1063,7 @@ impl MetricMap { noise: noise }; let MetricMap(ref mut map) = *self; - map.insert(name.to_string(), m); + map.insert(name.to_owned(), m); } pub fn fmt_metrics(&self) -> String {