Skip to content

Commit b2b6c6b

Browse files
committed
Auto merge of #28287 - llogiq:clippy, r=Manishearth
It's a large number of small improvements to the code, mostly readability-related, but removing closures and replacing `str::to_string()` with `.to_owned()` should also positively affect performance. r? @Manishearth (once it compiles, of course 😄)
2 parents a7d63fd + d956e63 commit b2b6c6b

File tree

33 files changed

+252
-272
lines changed

33 files changed

+252
-272
lines changed

src/libarena/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {
220220
*self.copy_head.borrow_mut() =
221221
chunk((new_min_chunk_size + 1).next_power_of_two(), true);
222222

223-
return self.alloc_copy_inner(n_bytes, align);
223+
self.alloc_copy_inner(n_bytes, align)
224224
}
225225

226226
#[inline]
@@ -247,7 +247,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {
247247
mem::align_of::<T>());
248248
let ptr = ptr as *mut T;
249249
ptr::write(&mut (*ptr), op());
250-
return &mut *ptr;
250+
&mut *ptr
251251
}
252252
}
253253

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

264-
return self.alloc_noncopy_inner(n_bytes, align);
264+
self.alloc_noncopy_inner(n_bytes, align)
265265
}
266266

267267
#[inline]
@@ -290,7 +290,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {
290290

291291
unsafe {
292292
let buf = head.as_ptr();
293-
return (buf.offset(tydesc_start as isize), buf.offset(start as isize));
293+
(buf.offset(tydesc_start as isize), buf.offset(start as isize))
294294
}
295295
}
296296

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

315-
return &mut *ptr;
315+
&mut *ptr
316316
}
317317
}
318318

@@ -486,14 +486,12 @@ impl<T> TypedArena<T> {
486486
self.grow()
487487
}
488488

489-
let ptr: &mut T = unsafe {
489+
unsafe {
490490
let ptr: &mut T = &mut *(self.ptr.get() as *mut T);
491491
ptr::write(ptr, object);
492492
self.ptr.set(self.ptr.get().offset(1));
493493
ptr
494-
};
495-
496-
ptr
494+
}
497495
}
498496

499497
/// Grows the arena.

src/libcore/str/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,10 +1558,10 @@ impl StrExt for str {
15581558
if w > 2 { val = utf8_acc_cont_byte(val, s.as_bytes()[i + 2]); }
15591559
if w > 3 { val = utf8_acc_cont_byte(val, s.as_bytes()[i + 3]); }
15601560

1561-
return CharRange {ch: unsafe { char::from_u32_unchecked(val) }, next: i};
1561+
CharRange {ch: unsafe { char::from_u32_unchecked(val) }, next: i}
15621562
}
15631563

1564-
return multibyte_char_range_at_reverse(self, prev);
1564+
multibyte_char_range_at_reverse(self, prev)
15651565
}
15661566

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

1686-
return (val, i + w as usize);
1686+
(val, i + w as usize)
16871687
}
16881688

16891689
multibyte_char_range_at(bytes, i)

src/libgetopts/lib.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ impl Name {
229229
if nm.len() == 1 {
230230
Short(nm.char_at(0))
231231
} else {
232-
Long(nm.to_string())
232+
Long(nm.to_owned())
233233
}
234234
}
235235

236236
fn to_string(&self) -> String {
237237
match *self {
238238
Short(ch) => ch.to_string(),
239-
Long(ref s) => s.to_string()
239+
Long(ref s) => s.to_owned()
240240
}
241241
}
242242
}
@@ -375,7 +375,7 @@ impl Matches {
375375
} else {
376376
match vals[0] {
377377
Val(ref s) => Some((*s).clone()),
378-
_ => Some(def.to_string())
378+
_ => Some(def.to_owned())
379379
}
380380
}
381381
}
@@ -414,10 +414,10 @@ pub fn reqopt(short_name: &str, long_name: &str, desc: &str, hint: &str) -> OptG
414414
let len = short_name.len();
415415
assert!(len == 1 || len == 0);
416416
OptGroup {
417-
short_name: short_name.to_string(),
418-
long_name: long_name.to_string(),
419-
hint: hint.to_string(),
420-
desc: desc.to_string(),
417+
short_name: short_name.to_owned(),
418+
long_name: long_name.to_owned(),
419+
hint: hint.to_owned(),
420+
desc: desc.to_owned(),
421421
hasarg: Yes,
422422
occur: Req
423423
}
@@ -434,10 +434,10 @@ pub fn optopt(short_name: &str, long_name: &str, desc: &str, hint: &str) -> OptG
434434
let len = short_name.len();
435435
assert!(len == 1 || len == 0);
436436
OptGroup {
437-
short_name: short_name.to_string(),
438-
long_name: long_name.to_string(),
439-
hint: hint.to_string(),
440-
desc: desc.to_string(),
437+
short_name: short_name.to_owned(),
438+
long_name: long_name.to_owned(),
439+
hint: hint.to_owned(),
440+
desc: desc.to_owned(),
441441
hasarg: Yes,
442442
occur: Optional
443443
}
@@ -452,10 +452,10 @@ pub fn optflag(short_name: &str, long_name: &str, desc: &str) -> OptGroup {
452452
let len = short_name.len();
453453
assert!(len == 1 || len == 0);
454454
OptGroup {
455-
short_name: short_name.to_string(),
456-
long_name: long_name.to_string(),
457-
hint: "".to_string(),
458-
desc: desc.to_string(),
455+
short_name: short_name.to_owned(),
456+
long_name: long_name.to_owned(),
457+
hint: "".to_owned(),
458+
desc: desc.to_owned(),
459459
hasarg: No,
460460
occur: Optional
461461
}
@@ -471,10 +471,10 @@ pub fn optflagmulti(short_name: &str, long_name: &str, desc: &str) -> OptGroup {
471471
let len = short_name.len();
472472
assert!(len == 1 || len == 0);
473473
OptGroup {
474-
short_name: short_name.to_string(),
475-
long_name: long_name.to_string(),
476-
hint: "".to_string(),
477-
desc: desc.to_string(),
474+
short_name: short_name.to_owned(),
475+
long_name: long_name.to_owned(),
476+
hint: "".to_owned(),
477+
desc: desc.to_owned(),
478478
hasarg: No,
479479
occur: Multi
480480
}
@@ -491,10 +491,10 @@ pub fn optflagopt(short_name: &str, long_name: &str, desc: &str, hint: &str) ->
491491
let len = short_name.len();
492492
assert!(len == 1 || len == 0);
493493
OptGroup {
494-
short_name: short_name.to_string(),
495-
long_name: long_name.to_string(),
496-
hint: hint.to_string(),
497-
desc: desc.to_string(),
494+
short_name: short_name.to_owned(),
495+
long_name: long_name.to_owned(),
496+
hint: hint.to_owned(),
497+
desc: desc.to_owned(),
498498
hasarg: Maybe,
499499
occur: Optional
500500
}
@@ -512,10 +512,10 @@ pub fn optmulti(short_name: &str, long_name: &str, desc: &str, hint: &str) -> Op
512512
let len = short_name.len();
513513
assert!(len == 1 || len == 0);
514514
OptGroup {
515-
short_name: short_name.to_string(),
516-
long_name: long_name.to_string(),
517-
hint: hint.to_string(),
518-
desc: desc.to_string(),
515+
short_name: short_name.to_owned(),
516+
long_name: long_name.to_owned(),
517+
hint: hint.to_owned(),
518+
desc: desc.to_owned(),
519519
hasarg: Yes,
520520
occur: Multi
521521
}
@@ -531,10 +531,10 @@ pub fn opt(short_name: &str,
531531
let len = short_name.len();
532532
assert!(len == 1 || len == 0);
533533
OptGroup {
534-
short_name: short_name.to_string(),
535-
long_name: long_name.to_string(),
536-
hint: hint.to_string(),
537-
desc: desc.to_string(),
534+
short_name: short_name.to_owned(),
535+
long_name: long_name.to_owned(),
536+
hint: hint.to_owned(),
537+
desc: desc.to_owned(),
538538
hasarg: hasarg,
539539
occur: occur
540540
}
@@ -574,7 +574,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
574574
let opts: Vec<Opt> = optgrps.iter().map(|x| x.long_to_short()).collect();
575575
let n_opts = opts.len();
576576

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

579579
let mut vals: Vec<_> = (0..n_opts).map(f).collect();
580580
let mut free: Vec<String> = Vec::new();
@@ -596,11 +596,11 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
596596
let tail = &cur[2..curlen];
597597
let tail_eq: Vec<&str> = tail.split('=').collect();
598598
if tail_eq.len() <= 1 {
599-
names = vec!(Long(tail.to_string()));
599+
names = vec!(Long(tail.to_owned()));
600600
} else {
601601
names =
602-
vec!(Long(tail_eq[0].to_string()));
603-
i_arg = Some(tail_eq[1].to_string());
602+
vec!(Long(tail_eq[0].to_owned()));
603+
i_arg = Some(tail_eq[1].to_owned());
604604
}
605605
} else {
606606
let mut j = 1;
@@ -630,7 +630,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
630630

631631
let next = j + ch.len_utf8();
632632
if arg_follows && next < curlen {
633-
i_arg = Some((&cur[next..curlen]).to_string());
633+
i_arg = Some((&cur[next..curlen]).to_owned());
634634
break;
635635
}
636636

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

@@ -936,7 +936,7 @@ fn each_split_within<F>(ss: &str, lim: usize, mut it: F) -> bool where
936936
machine(&mut cont, (fake_i, ' '));
937937
fake_i += 1;
938938
}
939-
return cont;
939+
cont
940940
}
941941

942942
#[test]

src/liblog/directive.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<String>) {
7474
}
7575
};
7676
dirs.push(LogDirective {
77-
name: name.map(|s| s.to_string()),
77+
name: name.map(str::to_owned),
7878
level: log_level,
7979
});
8080
}});
8181

82-
(dirs, filter.map(|s| s.to_string()))
82+
(dirs, filter.map(str::to_owned))
8383
}
8484

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

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

99-
assert_eq!(dirs[2].name, Some("crate2".to_string()));
99+
assert_eq!(dirs[2].name, Some("crate2".to_owned()));
100100
assert_eq!(dirs[2].level, 4);
101101
assert!(filter.is_none());
102102
}
@@ -106,7 +106,7 @@ mod tests {
106106
// test parse_logging_spec with multiple = in specification
107107
let (dirs, filter) = parse_logging_spec("crate1::mod1=1=2,crate2=4");
108108
assert_eq!(dirs.len(), 1);
109-
assert_eq!(dirs[0].name, Some("crate2".to_string()));
109+
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
110110
assert_eq!(dirs[0].level, 4);
111111
assert!(filter.is_none());
112112
}
@@ -116,7 +116,7 @@ mod tests {
116116
// test parse_logging_spec with 'noNumber' as log level
117117
let (dirs, filter) = parse_logging_spec("crate1::mod1=noNumber,crate2=4");
118118
assert_eq!(dirs.len(), 1);
119-
assert_eq!(dirs[0].name, Some("crate2".to_string()));
119+
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
120120
assert_eq!(dirs[0].level, 4);
121121
assert!(filter.is_none());
122122
}
@@ -126,7 +126,7 @@ mod tests {
126126
// test parse_logging_spec with 'warn' as log level
127127
let (dirs, filter) = parse_logging_spec("crate1::mod1=wrong,crate2=warn");
128128
assert_eq!(dirs.len(), 1);
129-
assert_eq!(dirs[0].name, Some("crate2".to_string()));
129+
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
130130
assert_eq!(dirs[0].level, ::WARN);
131131
assert!(filter.is_none());
132132
}
@@ -136,7 +136,7 @@ mod tests {
136136
// test parse_logging_spec with '' as log level
137137
let (dirs, filter) = parse_logging_spec("crate1::mod1=wrong,crate2=");
138138
assert_eq!(dirs.len(), 1);
139-
assert_eq!(dirs[0].name, Some("crate2".to_string()));
139+
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
140140
assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL);
141141
assert!(filter.is_none());
142142
}
@@ -148,7 +148,7 @@ mod tests {
148148
assert_eq!(dirs.len(), 2);
149149
assert_eq!(dirs[0].name, None);
150150
assert_eq!(dirs[0].level, 2);
151-
assert_eq!(dirs[1].name, Some("crate2".to_string()));
151+
assert_eq!(dirs[1].name, Some("crate2".to_owned()));
152152
assert_eq!(dirs[1].level, 4);
153153
assert!(filter.is_none());
154154
}
@@ -157,32 +157,32 @@ mod tests {
157157
fn parse_logging_spec_valid_filter() {
158158
let (dirs, filter) = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4/abc");
159159
assert_eq!(dirs.len(), 3);
160-
assert_eq!(dirs[0].name, Some("crate1::mod1".to_string()));
160+
assert_eq!(dirs[0].name, Some("crate1::mod1".to_owned()));
161161
assert_eq!(dirs[0].level, 1);
162162

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

166-
assert_eq!(dirs[2].name, Some("crate2".to_string()));
166+
assert_eq!(dirs[2].name, Some("crate2".to_owned()));
167167
assert_eq!(dirs[2].level, 4);
168-
assert!(filter.is_some() && filter.unwrap().to_string() == "abc");
168+
assert!(filter.is_some() && filter.unwrap().to_owned() == "abc");
169169
}
170170

171171
#[test]
172172
fn parse_logging_spec_invalid_crate_filter() {
173173
let (dirs, filter) = parse_logging_spec("crate1::mod1=1=2,crate2=4/a.c");
174174
assert_eq!(dirs.len(), 1);
175-
assert_eq!(dirs[0].name, Some("crate2".to_string()));
175+
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
176176
assert_eq!(dirs[0].level, 4);
177-
assert!(filter.is_some() && filter.unwrap().to_string() == "a.c");
177+
assert!(filter.is_some() && filter.unwrap().to_owned() == "a.c");
178178
}
179179

180180
#[test]
181181
fn parse_logging_spec_empty_with_filter() {
182182
let (dirs, filter) = parse_logging_spec("crate1/a*c");
183183
assert_eq!(dirs.len(), 1);
184-
assert_eq!(dirs[0].name, Some("crate1".to_string()));
184+
assert_eq!(dirs[0].name, Some("crate1".to_owned()));
185185
assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL);
186-
assert!(filter.is_some() && filter.unwrap().to_string() == "a*c");
186+
assert!(filter.is_some() && filter.unwrap().to_owned() == "a*c");
187187
}
188188
}

0 commit comments

Comments
 (0)