Skip to content

Commit cd51523

Browse files
committed
tidy: Use chars for single-character patterns
Fixes the clippy "single_char_pattern" lint, and (marginally) improves performance.
1 parent 571a624 commit cd51523

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/tools/tidy/src/cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) {
6767
};
6868
let mut lines = deps.lines().peekable();
6969
while let Some(line) = lines.next() {
70-
if line.starts_with("[") {
70+
if line.starts_with('[') {
7171
break
7272
}
7373

src/tools/tidy/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn check(path: &Path, bad: &mut bool) {
5050
}
5151

5252
let mut search = line;
53-
while let Some(i) = search.find("E") {
53+
while let Some(i) = search.find('E') {
5454
search = &search[i + 1..];
5555
let code = if search.len() > 4 {
5656
search[..4].parse::<u32>()

src/tools/tidy/src/extdeps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn check(path: &Path, bad: &mut bool) {
3838
}
3939

4040
// extract source value
41-
let parts: Vec<&str> = line.splitn(2, "=").collect();
41+
let parts: Vec<&str> = line.splitn(2, '=').collect();
4242
let source = parts[1].trim();
4343

4444
// ensure source is whitelisted

src/tools/tidy/src/features.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn check(path: &Path, bad: &mut bool, quiet: bool) {
7575
return;
7676
}
7777

78-
let filen_underscore = filename.replace("-","_").replace(".rs","");
78+
let filen_underscore = filename.replace('-',"_").replace(".rs","");
7979
let filename_is_gate_test = test_filen_gate(&filen_underscore, &mut features);
8080

8181
contents.truncate(0);
@@ -332,11 +332,11 @@ fn map_lib_features(base_src_path: &Path,
332332
f.tracking_issue = find_attr_val(line, "issue")
333333
.map(|s| s.parse().unwrap());
334334
}
335-
if line.ends_with("]") {
335+
if line.ends_with(']') {
336336
mf(Ok((name, f.clone())), file, i + 1);
337-
} else if !line.ends_with(",") && !line.ends_with("\\") {
337+
} else if !line.ends_with(',') && !line.ends_with('\\') {
338338
// We need to bail here because we might have missed the
339-
// end of a stability attribute above because the "]"
339+
// end of a stability attribute above because the ']'
340340
// might not have been at the end of the line.
341341
// We could then get into the very unfortunate situation that
342342
// we continue parsing the file assuming the current stability
@@ -394,7 +394,7 @@ fn map_lib_features(base_src_path: &Path,
394394
has_gate_test: false,
395395
tracking_issue,
396396
};
397-
if line.contains("]") {
397+
if line.contains(']') {
398398
mf(Ok((feature_name, feature)), file, i + 1);
399399
} else {
400400
becoming_feature = Some((feature_name.to_owned(), feature));

src/tools/tidy/src/style.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn line_is_url(line: &str) -> bool {
6969
(EXP_COMMENT_START, "//!") => state = EXP_LINK_LABEL_OR_URL,
7070

7171
(EXP_LINK_LABEL_OR_URL, w)
72-
if w.len() >= 4 && w.starts_with("[") && w.ends_with("]:")
72+
if w.len() >= 4 && w.starts_with('[') && w.ends_with("]:")
7373
=> state = EXP_URL,
7474

7575
(EXP_LINK_LABEL_OR_URL, w)
@@ -128,13 +128,13 @@ pub fn check(path: &Path, bad: &mut bool) {
128128
&& !long_line_is_ok(line) {
129129
err(&format!("line longer than {} chars", COLS));
130130
}
131-
if line.contains("\t") && !skip_tab {
131+
if line.contains('\t') && !skip_tab {
132132
err("tab character");
133133
}
134-
if !skip_end_whitespace && (line.ends_with(" ") || line.ends_with("\t")) {
134+
if !skip_end_whitespace && (line.ends_with(' ') || line.ends_with('\t')) {
135135
err("trailing whitespace");
136136
}
137-
if line.contains("\r") && !skip_cr {
137+
if line.contains('\r') && !skip_cr {
138138
err("CR character");
139139
}
140140
if filename != "style.rs" {

0 commit comments

Comments
 (0)