Rollup merge of #75856 - matthiaskrgr:more_clippy, r=Dylan-DPC

more tool clippy fixes

r? @Dylan-DPC
This commit is contained in:
Yuki Okushi 2020-08-24 11:48:53 +09:00 committed by GitHub
commit 7209b9cc49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 27 deletions

View File

@ -48,8 +48,8 @@ impl App {
// Parse CLI arguments
let args = std::env::args().skip(1).collect::<Vec<_>>();
let (mode, base) = match args.iter().map(|s| s.as_str()).collect::<Vec<_>>().as_slice() {
&["generate", ref base] => (Mode::Generate, PathBuf::from(base)),
&["check", ref base] => (Mode::Check, PathBuf::from(base)),
["generate", ref base] => (Mode::Generate, PathBuf::from(base)),
["check", ref base] => (Mode::Check, PathBuf::from(base)),
_ => {
eprintln!("usage: expand-yaml-anchors <source-dir> <dest-dir>");
std::process::exit(1);
@ -138,9 +138,7 @@ fn filter_document(document: Yaml) -> Yaml {
.map(|(key, value)| (filter_document(key), filter_document(value)))
.collect(),
),
Yaml::Array(vec) => {
Yaml::Array(vec.into_iter().map(|item| filter_document(item)).collect())
}
Yaml::Array(vec) => Yaml::Array(vec.into_iter().map(filter_document).collect()),
other => other,
}
}

View File

@ -172,10 +172,10 @@ fn check(cache: &mut Cache, root: &Path, file: &Path, errors: &mut bool) -> Opti
{
return;
}
let mut parts = url.splitn(2, "#");
let mut parts = url.splitn(2, '#');
let url = parts.next().unwrap();
let fragment = parts.next();
let mut parts = url.splitn(2, "?");
let mut parts = url.splitn(2, '?');
let url = parts.next().unwrap();
// Once we've plucked out the URL, parse it using our base url and
@ -258,7 +258,7 @@ fn check(cache: &mut Cache, root: &Path, file: &Path, errors: &mut bool) -> Opti
}
// These appear to be broken in mdbook right now?
if fragment.starts_with("-") {
if fragment.starts_with('-') {
return;
}
@ -324,7 +324,7 @@ fn load_file(
}
fn maybe_redirect(source: &str) -> Option<String> {
const REDIRECT: &'static str = "<p>Redirecting to <a href=";
const REDIRECT: &str = "<p>Redirecting to <a href=";
let mut lines = source.lines();
let redirect_line = lines.nth(6)?;
@ -345,11 +345,11 @@ fn with_attrs_in_source<F: FnMut(&str, usize, &str)>(contents: &str, attr: &str,
// we can get away with using one pass.
let is_base = line[..j].ends_with("<base");
line = rest;
let pos_equals = match rest.find("=") {
let pos_equals = match rest.find('=') {
Some(i) => i,
None => continue,
};
if rest[..pos_equals].trim_start_matches(" ") != "" {
if rest[..pos_equals].trim_start_matches(' ') != "" {
continue;
}
@ -361,7 +361,7 @@ fn with_attrs_in_source<F: FnMut(&str, usize, &str)>(contents: &str, attr: &str,
};
let quote_delim = rest.as_bytes()[pos_quote] as char;
if rest[..pos_quote].trim_start_matches(" ") != "" {
if rest[..pos_quote].trim_start_matches(' ') != "" {
continue;
}
let rest = &rest[pos_quote + 1..];

View File

@ -47,9 +47,7 @@ fn check_error_code_explanation(
invalid_compile_fail_format
}
fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &String) -> bool {
let mut can_be_ignored = false;
fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &str) -> bool {
for line in f.lines() {
let s = line.trim();
if s.starts_with("#### Note: this error code is no longer emitted by the compiler") {
@ -58,13 +56,13 @@ fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &String) -> boo
if s.starts_with("```") {
if s.contains("compile_fail") && s.contains(err_code) {
return true;
} else if s.contains("(") {
} else if s.contains('(') {
// It's very likely that we can't actually make it fail compilation...
can_be_ignored = true;
return true;
}
}
}
can_be_ignored
false
}
macro_rules! some_or_continue {

View File

@ -315,7 +315,7 @@ fn version() -> String {
fn fmt_list<V: std::fmt::Debug>(values: impl IntoIterator<Item = V>) -> String {
let pieces = values.into_iter().map(|b| format!("{:?}, ", b)).collect::<Vec<_>>();
let mut out = String::new();
let mut line = format!("\n ");
let mut line = String::from("\n ");
for piece in pieces {
if line.len() + piece.len() < 98 {
line.push_str(&piece);

View File

@ -20,7 +20,7 @@ impl RawEmitter {
if self.file.is_empty() || self.file.ends_with("\n\n") {
return;
}
writeln!(&mut self.file, "").unwrap();
writeln!(&mut self.file).unwrap();
}
fn emit_bitset(&mut self, ranges: &[Range<u32>]) {
@ -161,10 +161,10 @@ pub fn emit_codepoints(emitter: &mut RawEmitter, ranges: &[Range<u32>]) {
if bitset.bytes_used <= skiplist.bytes_used {
*emitter = bitset;
emitter.desc = format!("bitset");
emitter.desc = String::from("bitset");
} else {
*emitter = skiplist;
emitter.desc = format!("skiplist");
emitter.desc = String::from("skiplist");
}
}
@ -289,7 +289,7 @@ impl Canonicalized {
// Remove the now-canonicalized word from other mappings,
// to ensure that we deprioritize them in the next iteration of
// the while loop.
for (_, mapped) in &mut mappings {
for mapped in mappings.values_mut() {
let mut i = 0;
while i != mapped.len() {
if mapped[i].0 == *from {
@ -309,7 +309,7 @@ impl Canonicalized {
// Remove the now-canonical word from other mappings, to ensure that
// we deprioritize them in the next iteration of the while loop.
for (_, mapped) in &mut mappings {
for mapped in mappings.values_mut() {
let mut i = 0;
while i != mapped.len() {
if mapped[i].0 == to {

View File

@ -94,9 +94,9 @@ fn copy_recursive(from: &Path, to: &Path) {
}
fn main() {
let library_path_str = env::args_os().skip(1).next().expect("library path required");
let src_path_str = env::args_os().skip(2).next().expect("source path required");
let dest_path_str = env::args_os().skip(3).next().expect("destination path required");
let library_path_str = env::args_os().nth(1).expect("library path required");
let src_path_str = env::args_os().nth(2).expect("source path required");
let dest_path_str = env::args_os().nth(3).expect("destination path required");
let library_path = Path::new(&library_path_str);
let src_path = Path::new(&src_path_str);
let dest_path = Path::new(&dest_path_str);