From cd51523715a77a30660dfb46898eb407937ec9d7 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Fri, 31 Aug 2018 20:57:46 -0700 Subject: [PATCH] tidy: Use chars for single-character patterns Fixes the clippy "single_char_pattern" lint, and (marginally) improves performance. --- src/tools/tidy/src/cargo.rs | 2 +- src/tools/tidy/src/errors.rs | 2 +- src/tools/tidy/src/extdeps.rs | 2 +- src/tools/tidy/src/features.rs | 10 +++++----- src/tools/tidy/src/style.rs | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/tools/tidy/src/cargo.rs b/src/tools/tidy/src/cargo.rs index f40fea60f40a..1f0379f1ea80 100644 --- a/src/tools/tidy/src/cargo.rs +++ b/src/tools/tidy/src/cargo.rs @@ -67,7 +67,7 @@ fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) { }; let mut lines = deps.lines().peekable(); while let Some(line) = lines.next() { - if line.starts_with("[") { + if line.starts_with('[') { break } diff --git a/src/tools/tidy/src/errors.rs b/src/tools/tidy/src/errors.rs index 3dccffddf938..9f55d6f9ad63 100644 --- a/src/tools/tidy/src/errors.rs +++ b/src/tools/tidy/src/errors.rs @@ -50,7 +50,7 @@ pub fn check(path: &Path, bad: &mut bool) { } let mut search = line; - while let Some(i) = search.find("E") { + while let Some(i) = search.find('E') { search = &search[i + 1..]; let code = if search.len() > 4 { search[..4].parse::() diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 761803a45b8b..74f3a41047a3 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -38,7 +38,7 @@ pub fn check(path: &Path, bad: &mut bool) { } // extract source value - let parts: Vec<&str> = line.splitn(2, "=").collect(); + let parts: Vec<&str> = line.splitn(2, '=').collect(); let source = parts[1].trim(); // ensure source is whitelisted diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index 74f66c0a0516..c95f1c7b32a9 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -75,7 +75,7 @@ pub fn check(path: &Path, bad: &mut bool, quiet: bool) { return; } - let filen_underscore = filename.replace("-","_").replace(".rs",""); + let filen_underscore = filename.replace('-',"_").replace(".rs",""); let filename_is_gate_test = test_filen_gate(&filen_underscore, &mut features); contents.truncate(0); @@ -332,11 +332,11 @@ fn map_lib_features(base_src_path: &Path, f.tracking_issue = find_attr_val(line, "issue") .map(|s| s.parse().unwrap()); } - if line.ends_with("]") { + if line.ends_with(']') { mf(Ok((name, f.clone())), file, i + 1); - } else if !line.ends_with(",") && !line.ends_with("\\") { + } else if !line.ends_with(',') && !line.ends_with('\\') { // We need to bail here because we might have missed the - // end of a stability attribute above because the "]" + // end of a stability attribute above because the ']' // might not have been at the end of the line. // We could then get into the very unfortunate situation that // we continue parsing the file assuming the current stability @@ -394,7 +394,7 @@ fn map_lib_features(base_src_path: &Path, has_gate_test: false, tracking_issue, }; - if line.contains("]") { + if line.contains(']') { mf(Ok((feature_name, feature)), file, i + 1); } else { becoming_feature = Some((feature_name.to_owned(), feature)); diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index 6b431ccda088..33cd8b5dcd9a 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -69,7 +69,7 @@ fn line_is_url(line: &str) -> bool { (EXP_COMMENT_START, "//!") => state = EXP_LINK_LABEL_OR_URL, (EXP_LINK_LABEL_OR_URL, w) - if w.len() >= 4 && w.starts_with("[") && w.ends_with("]:") + if w.len() >= 4 && w.starts_with('[') && w.ends_with("]:") => state = EXP_URL, (EXP_LINK_LABEL_OR_URL, w) @@ -128,13 +128,13 @@ pub fn check(path: &Path, bad: &mut bool) { && !long_line_is_ok(line) { err(&format!("line longer than {} chars", COLS)); } - if line.contains("\t") && !skip_tab { + if line.contains('\t') && !skip_tab { err("tab character"); } - if !skip_end_whitespace && (line.ends_with(" ") || line.ends_with("\t")) { + if !skip_end_whitespace && (line.ends_with(' ') || line.ends_with('\t')) { err("trailing whitespace"); } - if line.contains("\r") && !skip_cr { + if line.contains('\r') && !skip_cr { err("CR character"); } if filename != "style.rs" {