Skip to content

Commit 08f2904

Browse files
committed
more clippy fixes
use is_empty() instead of len comparison (clippy::len_zero) use if let instead of while let loop that never loops (clippy::never_loop) remove redundant returns (clippy::needless_return) remove redundant closures (clippy::redundant_closure) use if let instead of match and wildcard pattern (clippy::single_match) don't repeat field names redundantly (clippy::redundant_field_names)
1 parent 2113659 commit 08f2904

File tree

14 files changed

+102
-124
lines changed

14 files changed

+102
-124
lines changed

src/librustc_interface/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ impl<'tcx> QueryContext<'tcx> {
711711
}
712712

713713
pub fn print_stats(&mut self) {
714-
self.enter(|tcx| ty::query::print_stats(tcx))
714+
self.enter(ty::query::print_stats)
715715
}
716716
}
717717

src/librustc_mir/interpret/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3030
trace!("SwitchInt({:?})", *discr);
3131

3232
// Branch to the `otherwise` case by default, if no match is found.
33-
assert!(targets.len() > 0);
33+
assert!(!targets.is_empty());
3434
let mut target_block = targets[targets.len() - 1];
3535

3636
for (index, &const_int) in values.iter().enumerate() {

src/librustc_save_analysis/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
591591
Some(Data::RefData(Ref {
592592
kind: RefKind::Function,
593593
span,
594-
ref_id: def_id.or(decl_id).map(id_from_def_id).unwrap_or_else(|| null_id()),
594+
ref_id: def_id.or(decl_id).map(id_from_def_id).unwrap_or_else(null_id),
595595
}))
596596
}
597597
ast::ExprKind::Path(_, ref path) => {

src/librustc_session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
16501650

16511651
check_thread_count(&debugging_opts, error_format);
16521652

1653-
let incremental = cg.incremental.as_ref().map(|m| PathBuf::from(m));
1653+
let incremental = cg.incremental.as_ref().map(PathBuf::from);
16541654

16551655
if debugging_opts.profile && incremental.is_some() {
16561656
early_error(

src/librustc_target/spec/i686_apple_darwin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn target() -> TargetResult {
1616
let llvm_target = super::apple_base::macos_llvm_target(&arch);
1717

1818
Ok(Target {
19-
llvm_target: llvm_target,
19+
llvm_target,
2020
target_endian: "little".to_string(),
2121
target_pointer_width: "32".to_string(),
2222
target_c_int_width: "32".to_string(),

src/librustc_target/spec/x86_64_apple_darwin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn target() -> TargetResult {
1616
let llvm_target = super::apple_base::macos_llvm_target(&arch);
1717

1818
Ok(Target {
19-
llvm_target: llvm_target,
19+
llvm_target,
2020
target_endian: "little".to_string(),
2121
target_pointer_width: "64".to_string(),
2222
target_c_int_width: "32".to_string(),

src/librustdoc/clean/auto_trait.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
497497
// of the type.
498498
// Therefore, we make sure that we never add a ?Sized
499499
// bound for projections
500-
match &ty {
501-
&Type::QPath { .. } => {
502-
has_sized.insert(ty.clone());
503-
}
504-
_ => {}
500+
if let Type::QPath { .. } = ty {
501+
has_sized.insert(ty.clone());
505502
}
506503

507504
if bounds.is_empty() {

src/librustdoc/clean/mod.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,8 @@ impl<'tcx> Clean<Option<WherePredicate>>
521521
fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> {
522522
let ty::OutlivesPredicate(ref a, ref b) = *self;
523523

524-
match (a, b) {
525-
(ty::ReEmpty(_), ty::ReEmpty(_)) => {
526-
return None;
527-
}
528-
_ => {}
524+
if let (ty::ReEmpty(_), ty::ReEmpty(_)) = (a, b) {
525+
return None;
529526
}
530527

531528
Some(WherePredicate::RegionPredicate {
@@ -539,9 +536,8 @@ impl<'tcx> Clean<Option<WherePredicate>> for ty::OutlivesPredicate<Ty<'tcx>, ty:
539536
fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> {
540537
let ty::OutlivesPredicate(ref ty, ref lt) = *self;
541538

542-
match lt {
543-
ty::ReEmpty(_) => return None,
544-
_ => {}
539+
if let ty::ReEmpty(_) = lt {
540+
return None;
545541
}
546542

547543
Some(WherePredicate::BoundPredicate {
@@ -2239,15 +2235,12 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
22392235
} else {
22402236
let name = self.name;
22412237
if !please_inline {
2242-
match path.res {
2243-
Res::Def(DefKind::Mod, did) => {
2244-
if !did.is_local() && did.index == CRATE_DEF_INDEX {
2245-
// if we're `pub use`ing an extern crate root, don't inline it unless we
2246-
// were specifically asked for it
2247-
denied = true;
2248-
}
2238+
if let Res::Def(DefKind::Mod, did) = path.res {
2239+
if !did.is_local() && did.index == CRATE_DEF_INDEX {
2240+
// if we're `pub use`ing an extern crate root, don't inline it unless we
2241+
// were specifically asked for it
2242+
denied = true;
22492243
}
2250-
_ => {}
22512244
}
22522245
}
22532246
if !denied {
@@ -2426,10 +2419,9 @@ impl From<GenericBound> for SimpleBound {
24262419
GenericBound::TraitBound(t, mod_) => match t.trait_ {
24272420
Type::ResolvedPath { path, param_names, .. } => SimpleBound::TraitBound(
24282421
path.segments,
2429-
param_names.map_or_else(
2430-
|| Vec::new(),
2431-
|v| v.iter().map(|p| SimpleBound::from(p.clone())).collect(),
2432-
),
2422+
param_names.map_or_else(Vec::new, |v| {
2423+
v.iter().map(|p| SimpleBound::from(p.clone())).collect()
2424+
}),
24332425
t.generic_params,
24342426
mod_,
24352427
),

src/librustdoc/clean/utils.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn external_generic_args(
121121
let args: Vec<_> = substs
122122
.iter()
123123
.filter_map(|kind| match kind.unpack() {
124-
GenericArgKind::Lifetime(lt) => lt.clean(cx).map(|lt| GenericArg::Lifetime(lt)),
124+
GenericArgKind::Lifetime(lt) => lt.clean(cx).map(GenericArg::Lifetime),
125125
GenericArgKind::Type(_) if skip_self => {
126126
skip_self = false;
127127
None
@@ -198,27 +198,24 @@ pub fn get_real_types(
198198
}) {
199199
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
200200
for bound in bounds.iter() {
201-
match *bound {
202-
GenericBound::TraitBound(ref poly_trait, _) => {
203-
for x in poly_trait.generic_params.iter() {
204-
if !x.is_type() {
205-
continue;
206-
}
207-
if let Some(ty) = x.get_type() {
208-
let adds = get_real_types(generics, &ty, cx, recurse + 1);
209-
if !adds.is_empty() {
210-
res.extend(adds);
211-
} else if !ty.is_full_generic() {
212-
if let Some(did) = ty.def_id() {
213-
if let Some(kind) = cx.tcx.def_kind(did).clean(cx) {
214-
res.insert((ty, kind));
215-
}
201+
if let GenericBound::TraitBound(ref poly_trait, _) = *bound {
202+
for x in poly_trait.generic_params.iter() {
203+
if !x.is_type() {
204+
continue;
205+
}
206+
if let Some(ty) = x.get_type() {
207+
let adds = get_real_types(generics, &ty, cx, recurse + 1);
208+
if !adds.is_empty() {
209+
res.extend(adds);
210+
} else if !ty.is_full_generic() {
211+
if let Some(did) = ty.def_id() {
212+
if let Some(kind) = cx.tcx.def_kind(did).clean(cx) {
213+
res.insert((ty, kind));
216214
}
217215
}
218216
}
219217
}
220218
}
221-
_ => {}
222219
}
223220
}
224221
}

src/librustdoc/html/markdown.rs

+59-64
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
448448
if !self.started {
449449
self.started = true;
450450
}
451-
while let Some(event) = self.inner.next() {
451+
if let Some(event) = self.inner.next() {
452452
let mut is_start = true;
453453
let is_allowed_tag = match event {
454454
Event::Start(Tag::CodeBlock(_)) | Event::End(Tag::CodeBlock(_)) => {
@@ -944,75 +944,70 @@ crate fn rust_code_blocks(md: &str) -> Vec<RustCodeBlock> {
944944
let mut p = Parser::new_ext(md, opts()).into_offset_iter();
945945

946946
while let Some((event, offset)) = p.next() {
947-
match event {
948-
Event::Start(Tag::CodeBlock(syntax)) => {
949-
let (syntax, code_start, code_end, range, is_fenced) = match syntax {
950-
CodeBlockKind::Fenced(syntax) => {
951-
let syntax = syntax.as_ref();
952-
let lang_string = if syntax.is_empty() {
953-
LangString::all_false()
954-
} else {
955-
LangString::parse(&*syntax, ErrorCodes::Yes, false)
956-
};
957-
if !lang_string.rust {
947+
if let Event::Start(Tag::CodeBlock(syntax)) = event {
948+
let (syntax, code_start, code_end, range, is_fenced) = match syntax {
949+
CodeBlockKind::Fenced(syntax) => {
950+
let syntax = syntax.as_ref();
951+
let lang_string = if syntax.is_empty() {
952+
LangString::all_false()
953+
} else {
954+
LangString::parse(&*syntax, ErrorCodes::Yes, false)
955+
};
956+
if !lang_string.rust {
957+
continue;
958+
}
959+
let syntax = if syntax.is_empty() { None } else { Some(syntax.to_owned()) };
960+
let (code_start, mut code_end) = match p.next() {
961+
Some((Event::Text(_), offset)) => (offset.start, offset.end),
962+
Some((_, sub_offset)) => {
963+
let code = Range { start: sub_offset.start, end: sub_offset.start };
964+
code_blocks.push(RustCodeBlock {
965+
is_fenced: true,
966+
range: offset,
967+
code,
968+
syntax,
969+
});
958970
continue;
959971
}
960-
let syntax = if syntax.is_empty() { None } else { Some(syntax.to_owned()) };
961-
let (code_start, mut code_end) = match p.next() {
962-
Some((Event::Text(_), offset)) => (offset.start, offset.end),
963-
Some((_, sub_offset)) => {
964-
let code = Range { start: sub_offset.start, end: sub_offset.start };
965-
code_blocks.push(RustCodeBlock {
966-
is_fenced: true,
967-
range: offset,
968-
code,
969-
syntax,
970-
});
971-
continue;
972-
}
973-
None => {
974-
let code = Range { start: offset.end, end: offset.end };
975-
code_blocks.push(RustCodeBlock {
976-
is_fenced: true,
977-
range: offset,
978-
code,
979-
syntax,
980-
});
981-
continue;
982-
}
983-
};
984-
while let Some((Event::Text(_), offset)) = p.next() {
985-
code_end = offset.end;
972+
None => {
973+
let code = Range { start: offset.end, end: offset.end };
974+
code_blocks.push(RustCodeBlock {
975+
is_fenced: true,
976+
range: offset,
977+
code,
978+
syntax,
979+
});
980+
continue;
986981
}
987-
(syntax, code_start, code_end, offset, true)
982+
};
983+
while let Some((Event::Text(_), offset)) = p.next() {
984+
code_end = offset.end;
988985
}
989-
CodeBlockKind::Indented => {
990-
// The ending of the offset goes too far sometime so we reduce it by one in
991-
// these cases.
992-
if offset.end > offset.start
993-
&& md.get(offset.end..=offset.end) == Some(&"\n")
994-
{
995-
(
996-
None,
997-
offset.start,
998-
offset.end,
999-
Range { start: offset.start, end: offset.end - 1 },
1000-
false,
1001-
)
1002-
} else {
1003-
(None, offset.start, offset.end, offset, false)
1004-
}
986+
(syntax, code_start, code_end, offset, true)
987+
}
988+
CodeBlockKind::Indented => {
989+
// The ending of the offset goes too far sometime so we reduce it by one in
990+
// these cases.
991+
if offset.end > offset.start && md.get(offset.end..=offset.end) == Some(&"\n") {
992+
(
993+
None,
994+
offset.start,
995+
offset.end,
996+
Range { start: offset.start, end: offset.end - 1 },
997+
false,
998+
)
999+
} else {
1000+
(None, offset.start, offset.end, offset, false)
10051001
}
1006-
};
1002+
}
1003+
};
10071004

1008-
code_blocks.push(RustCodeBlock {
1009-
is_fenced,
1010-
range,
1011-
code: Range { start: code_start, end: code_end },
1012-
syntax,
1013-
});
1014-
}
1015-
_ => (),
1005+
code_blocks.push(RustCodeBlock {
1006+
is_fenced,
1007+
range,
1008+
code: Range { start: code_start, end: code_end },
1009+
syntax,
1010+
});
10161011
}
10171012
}
10181013

src/librustdoc/html/render.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ themePicker.onblur = handleThemeButtonsBlur;
782782
.split('"')
783783
.next()
784784
.map(|s| s.to_owned())
785-
.unwrap_or_else(|| String::new()),
785+
.unwrap_or_else(String::new),
786786
);
787787
}
788788
}
@@ -2158,7 +2158,7 @@ fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean:
21582158
docs = MarkdownSummaryLine(doc_value, &myitem.links()).to_string(),
21592159
class = myitem.type_(),
21602160
add = add,
2161-
stab = stab.unwrap_or_else(|| String::new()),
2161+
stab = stab.unwrap_or_else(String::new),
21622162
unsafety_flag = unsafety_flag,
21632163
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
21642164
title = [full_path(cx, myitem), myitem.type_().to_string()]
@@ -4593,12 +4593,9 @@ fn collect_paths_for_type(first_ty: clean::Type) -> Vec<String> {
45934593
let get_extern = || cache.external_paths.get(&did).map(|s| s.0.clone());
45944594
let fqp = cache.exact_paths.get(&did).cloned().or_else(get_extern);
45954595

4596-
match fqp {
4597-
Some(path) => {
4598-
out.push(path.join("::"));
4599-
}
4600-
_ => {}
4601-
};
4596+
if let Some(path) = fqp {
4597+
out.push(path.join("::"));
4598+
}
46024599
}
46034600
clean::Type::Tuple(tys) => {
46044601
work.extend(tys.into_iter());

src/librustdoc/html/render/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
590590
for item in search_index {
591591
item.parent_idx = item.parent.and_then(|defid| {
592592
if defid_to_pathid.contains_key(&defid) {
593-
defid_to_pathid.get(&defid).map(|x| *x)
593+
defid_to_pathid.get(&defid).copied()
594594
} else {
595595
let pathid = lastpathid;
596596
defid_to_pathid.insert(defid, pathid);

src/libstd/io/stdio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pub fn stdout() -> Stdout {
496496
unsafe {
497497
let ret = Arc::new(ReentrantMutex::new(RefCell::new(LineWriter::new(stdout))));
498498
ret.init();
499-
return ret;
499+
ret
500500
}
501501
}
502502
}
@@ -664,7 +664,7 @@ pub fn stderr() -> Stderr {
664664
*INSTANCE.lock().borrow_mut() = Maybe::Real(stderr);
665665
}
666666
});
667-
return Stderr { inner: &INSTANCE };
667+
Stderr { inner: &INSTANCE }
668668
}
669669

670670
impl Stderr {

src/libstd/sys/unix/process/process_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Command {
7272
}
7373
};
7474

75-
let mut p = Process { pid: pid, status: None };
75+
let mut p = Process { pid, status: None };
7676
drop(output);
7777
let mut bytes = [0; 8];
7878

0 commit comments

Comments
 (0)