Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more clippy fixes #70613

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/i686_apple_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/spec/x86_64_apple_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
7 changes: 2 additions & 5 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
32 changes: 12 additions & 20 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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_,
),
Expand Down
31 changes: 14 additions & 17 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}
}
}
}
_ => {}
}
}
}
Expand Down
123 changes: 59 additions & 64 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Centril marked this conversation as resolved.
Show resolved Hide resolved
let mut is_start = true;
let is_allowed_tag = match event {
Event::Start(Tag::CodeBlock(_)) | Event::End(Tag::CodeBlock(_)) => {
Expand Down Expand Up @@ -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,
});
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ themePicker.onblur = handleThemeButtonsBlur;
.split('"')
.next()
.map(|s| s.to_owned())
.unwrap_or_else(|| String::new()),
.unwrap_or_else(String::new),
);
}
}
Expand Down Expand Up @@ -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()]
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -664,7 +664,7 @@ pub fn stderr() -> Stderr {
*INSTANCE.lock().borrow_mut() = Maybe::Real(stderr);
}
});
return Stderr { inner: &INSTANCE };
Stderr { inner: &INSTANCE }
}

impl Stderr {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down