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)
This commit is contained in:
Matthias Krüger 2020-03-29 20:19:14 +02:00
parent 2113659479
commit 08f2904dfa
14 changed files with 102 additions and 124 deletions

View File

@ -711,7 +711,7 @@ impl<'tcx> QueryContext<'tcx> {
}
pub fn print_stats(&mut self) {
self.enter(|tcx| ty::query::print_stats(tcx))
self.enter(ty::query::print_stats)
}
}

View File

@ -30,7 +30,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
trace!("SwitchInt({:?})", *discr);
// Branch to the `otherwise` case by default, if no match is found.
assert!(targets.len() > 0);
assert!(!targets.is_empty());
let mut target_block = targets[targets.len() - 1];
for (index, &const_int) in values.iter().enumerate() {

View File

@ -591,7 +591,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
Some(Data::RefData(Ref {
kind: RefKind::Function,
span,
ref_id: def_id.or(decl_id).map(id_from_def_id).unwrap_or_else(|| null_id()),
ref_id: def_id.or(decl_id).map(id_from_def_id).unwrap_or_else(null_id),
}))
}
ast::ExprKind::Path(_, ref path) => {

View File

@ -1650,7 +1650,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
check_thread_count(&debugging_opts, error_format);
let incremental = cg.incremental.as_ref().map(|m| PathBuf::from(m));
let incremental = cg.incremental.as_ref().map(PathBuf::from);
if debugging_opts.profile && incremental.is_some() {
early_error(

View File

@ -16,7 +16,7 @@ pub fn target() -> TargetResult {
let llvm_target = super::apple_base::macos_llvm_target(&arch);
Ok(Target {
llvm_target: llvm_target,
llvm_target,
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
target_c_int_width: "32".to_string(),

View File

@ -16,7 +16,7 @@ pub fn target() -> TargetResult {
let llvm_target = super::apple_base::macos_llvm_target(&arch);
Ok(Target {
llvm_target: llvm_target,
llvm_target,
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
target_c_int_width: "32".to_string(),

View File

@ -497,11 +497,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
// of the type.
// Therefore, we make sure that we never add a ?Sized
// bound for projections
match &ty {
&Type::QPath { .. } => {
has_sized.insert(ty.clone());
}
_ => {}
if let Type::QPath { .. } = ty {
has_sized.insert(ty.clone());
}
if bounds.is_empty() {

View File

@ -521,11 +521,8 @@ impl<'tcx> Clean<Option<WherePredicate>>
fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> {
let ty::OutlivesPredicate(ref a, ref b) = *self;
match (a, b) {
(ty::ReEmpty(_), ty::ReEmpty(_)) => {
return None;
}
_ => {}
if let (ty::ReEmpty(_), ty::ReEmpty(_)) = (a, b) {
return None;
}
Some(WherePredicate::RegionPredicate {
@ -539,9 +536,8 @@ impl<'tcx> Clean<Option<WherePredicate>> for ty::OutlivesPredicate<Ty<'tcx>, ty:
fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> {
let ty::OutlivesPredicate(ref ty, ref lt) = *self;
match lt {
ty::ReEmpty(_) => return None,
_ => {}
if let ty::ReEmpty(_) = lt {
return None;
}
Some(WherePredicate::BoundPredicate {
@ -2239,15 +2235,12 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
} else {
let name = self.name;
if !please_inline {
match path.res {
Res::Def(DefKind::Mod, did) => {
if !did.is_local() && did.index == CRATE_DEF_INDEX {
// if we're `pub use`ing an extern crate root, don't inline it unless we
// were specifically asked for it
denied = true;
}
if let Res::Def(DefKind::Mod, did) = path.res {
if !did.is_local() && did.index == CRATE_DEF_INDEX {
// if we're `pub use`ing an extern crate root, don't inline it unless we
// were specifically asked for it
denied = true;
}
_ => {}
}
}
if !denied {
@ -2426,10 +2419,9 @@ impl From<GenericBound> for SimpleBound {
GenericBound::TraitBound(t, mod_) => match t.trait_ {
Type::ResolvedPath { path, param_names, .. } => SimpleBound::TraitBound(
path.segments,
param_names.map_or_else(
|| Vec::new(),
|v| v.iter().map(|p| SimpleBound::from(p.clone())).collect(),
),
param_names.map_or_else(Vec::new, |v| {
v.iter().map(|p| SimpleBound::from(p.clone())).collect()
}),
t.generic_params,
mod_,
),

View File

@ -121,7 +121,7 @@ pub fn external_generic_args(
let args: Vec<_> = substs
.iter()
.filter_map(|kind| match kind.unpack() {
GenericArgKind::Lifetime(lt) => lt.clean(cx).map(|lt| GenericArg::Lifetime(lt)),
GenericArgKind::Lifetime(lt) => lt.clean(cx).map(GenericArg::Lifetime),
GenericArgKind::Type(_) if skip_self => {
skip_self = false;
None
@ -198,27 +198,24 @@ pub fn get_real_types(
}) {
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
for bound in bounds.iter() {
match *bound {
GenericBound::TraitBound(ref poly_trait, _) => {
for x in poly_trait.generic_params.iter() {
if !x.is_type() {
continue;
}
if let Some(ty) = x.get_type() {
let adds = get_real_types(generics, &ty, cx, recurse + 1);
if !adds.is_empty() {
res.extend(adds);
} else if !ty.is_full_generic() {
if let Some(did) = ty.def_id() {
if let Some(kind) = cx.tcx.def_kind(did).clean(cx) {
res.insert((ty, kind));
}
if let GenericBound::TraitBound(ref poly_trait, _) = *bound {
for x in poly_trait.generic_params.iter() {
if !x.is_type() {
continue;
}
if let Some(ty) = x.get_type() {
let adds = get_real_types(generics, &ty, cx, recurse + 1);
if !adds.is_empty() {
res.extend(adds);
} else if !ty.is_full_generic() {
if let Some(did) = ty.def_id() {
if let Some(kind) = cx.tcx.def_kind(did).clean(cx) {
res.insert((ty, kind));
}
}
}
}
}
_ => {}
}
}
}

View File

@ -448,7 +448,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
if !self.started {
self.started = true;
}
while let Some(event) = self.inner.next() {
if let Some(event) = self.inner.next() {
let mut is_start = true;
let is_allowed_tag = match event {
Event::Start(Tag::CodeBlock(_)) | Event::End(Tag::CodeBlock(_)) => {
@ -944,75 +944,70 @@ crate fn rust_code_blocks(md: &str) -> Vec<RustCodeBlock> {
let mut p = Parser::new_ext(md, opts()).into_offset_iter();
while let Some((event, offset)) = p.next() {
match event {
Event::Start(Tag::CodeBlock(syntax)) => {
let (syntax, code_start, code_end, range, is_fenced) = match syntax {
CodeBlockKind::Fenced(syntax) => {
let syntax = syntax.as_ref();
let lang_string = if syntax.is_empty() {
LangString::all_false()
} else {
LangString::parse(&*syntax, ErrorCodes::Yes, false)
};
if !lang_string.rust {
if let Event::Start(Tag::CodeBlock(syntax)) = event {
let (syntax, code_start, code_end, range, is_fenced) = match syntax {
CodeBlockKind::Fenced(syntax) => {
let syntax = syntax.as_ref();
let lang_string = if syntax.is_empty() {
LangString::all_false()
} else {
LangString::parse(&*syntax, ErrorCodes::Yes, false)
};
if !lang_string.rust {
continue;
}
let syntax = if syntax.is_empty() { None } else { Some(syntax.to_owned()) };
let (code_start, mut code_end) = match p.next() {
Some((Event::Text(_), offset)) => (offset.start, offset.end),
Some((_, sub_offset)) => {
let code = Range { start: sub_offset.start, end: sub_offset.start };
code_blocks.push(RustCodeBlock {
is_fenced: true,
range: offset,
code,
syntax,
});
continue;
}
let syntax = if syntax.is_empty() { None } else { Some(syntax.to_owned()) };
let (code_start, mut code_end) = match p.next() {
Some((Event::Text(_), offset)) => (offset.start, offset.end),
Some((_, sub_offset)) => {
let code = Range { start: sub_offset.start, end: sub_offset.start };
code_blocks.push(RustCodeBlock {
is_fenced: true,
range: offset,
code,
syntax,
});
continue;
}
None => {
let code = Range { start: offset.end, end: offset.end };
code_blocks.push(RustCodeBlock {
is_fenced: true,
range: offset,
code,
syntax,
});
continue;
}
};
while let Some((Event::Text(_), offset)) = p.next() {
code_end = offset.end;
None => {
let code = Range { start: offset.end, end: offset.end };
code_blocks.push(RustCodeBlock {
is_fenced: true,
range: offset,
code,
syntax,
});
continue;
}
(syntax, code_start, code_end, offset, true)
};
while let Some((Event::Text(_), offset)) = p.next() {
code_end = offset.end;
}
CodeBlockKind::Indented => {
// The ending of the offset goes too far sometime so we reduce it by one in
// these cases.
if offset.end > offset.start
&& md.get(offset.end..=offset.end) == Some(&"\n")
{
(
None,
offset.start,
offset.end,
Range { start: offset.start, end: offset.end - 1 },
false,
)
} else {
(None, offset.start, offset.end, offset, false)
}
(syntax, code_start, code_end, offset, true)
}
CodeBlockKind::Indented => {
// The ending of the offset goes too far sometime so we reduce it by one in
// these cases.
if offset.end > offset.start && md.get(offset.end..=offset.end) == Some(&"\n") {
(
None,
offset.start,
offset.end,
Range { start: offset.start, end: offset.end - 1 },
false,
)
} else {
(None, offset.start, offset.end, offset, false)
}
};
}
};
code_blocks.push(RustCodeBlock {
is_fenced,
range,
code: Range { start: code_start, end: code_end },
syntax,
});
}
_ => (),
code_blocks.push(RustCodeBlock {
is_fenced,
range,
code: Range { start: code_start, end: code_end },
syntax,
});
}
}

View File

@ -782,7 +782,7 @@ themePicker.onblur = handleThemeButtonsBlur;
.split('"')
.next()
.map(|s| s.to_owned())
.unwrap_or_else(|| String::new()),
.unwrap_or_else(String::new),
);
}
}
@ -2158,7 +2158,7 @@ fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean:
docs = MarkdownSummaryLine(doc_value, &myitem.links()).to_string(),
class = myitem.type_(),
add = add,
stab = stab.unwrap_or_else(|| String::new()),
stab = stab.unwrap_or_else(String::new),
unsafety_flag = unsafety_flag,
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
title = [full_path(cx, myitem), myitem.type_().to_string()]
@ -4593,12 +4593,9 @@ fn collect_paths_for_type(first_ty: clean::Type) -> Vec<String> {
let get_extern = || cache.external_paths.get(&did).map(|s| s.0.clone());
let fqp = cache.exact_paths.get(&did).cloned().or_else(get_extern);
match fqp {
Some(path) => {
out.push(path.join("::"));
}
_ => {}
};
if let Some(path) = fqp {
out.push(path.join("::"));
}
}
clean::Type::Tuple(tys) => {
work.extend(tys.into_iter());

View File

@ -590,7 +590,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
for item in search_index {
item.parent_idx = item.parent.and_then(|defid| {
if defid_to_pathid.contains_key(&defid) {
defid_to_pathid.get(&defid).map(|x| *x)
defid_to_pathid.get(&defid).copied()
} else {
let pathid = lastpathid;
defid_to_pathid.insert(defid, pathid);

View File

@ -496,7 +496,7 @@ pub fn stdout() -> Stdout {
unsafe {
let ret = Arc::new(ReentrantMutex::new(RefCell::new(LineWriter::new(stdout))));
ret.init();
return ret;
ret
}
}
}
@ -664,7 +664,7 @@ pub fn stderr() -> Stderr {
*INSTANCE.lock().borrow_mut() = Maybe::Real(stderr);
}
});
return Stderr { inner: &INSTANCE };
Stderr { inner: &INSTANCE }
}
impl Stderr {

View File

@ -72,7 +72,7 @@ impl Command {
}
};
let mut p = Process { pid: pid, status: None };
let mut p = Process { pid, status: None };
drop(output);
let mut bytes = [0; 8];