Skip to content

Commit 97e844a

Browse files
committed
fix clippy::single_char_pattern perf findings
1 parent 1796de7 commit 97e844a

File tree

19 files changed

+36
-36
lines changed

19 files changed

+36
-36
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2226,8 +2226,8 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
22262226
continue;
22272227
}
22282228

2229-
let canonical = f.replace("-", "_");
2230-
let canonical_name = name.replace("-", "_");
2229+
let canonical = f.replace('-', "_");
2230+
let canonical_name = name.replace('-', "_");
22312231

22322232
let is_rust_object =
22332233
canonical.starts_with(&canonical_name) && looks_like_rust_object_file(&f);

compiler/rustc_driver/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ Available lint options:
872872

873873
let print_lints = |lints: Vec<&Lint>| {
874874
for lint in lints {
875-
let name = lint.name_lower().replace("_", "-");
875+
let name = lint.name_lower().replace('_', "-");
876876
println!(
877877
" {} {:7.7} {}",
878878
padded(&name),
@@ -908,10 +908,10 @@ Available lint options:
908908

909909
let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>| {
910910
for (name, to) in lints {
911-
let name = name.to_lowercase().replace("_", "-");
911+
let name = name.to_lowercase().replace('_', "-");
912912
let desc = to
913913
.into_iter()
914-
.map(|x| x.to_string().replace("_", "-"))
914+
.map(|x| x.to_string().replace('_', "-"))
915915
.collect::<Vec<String>>()
916916
.join(", ");
917917
println!(" {} {}", padded(&name), desc);
@@ -960,7 +960,7 @@ fn print_flag_list<T>(
960960
println!(
961961
" {} {:>width$}=val -- {}",
962962
cmdline_opt,
963-
name.replace("_", "-"),
963+
name.replace('_', "-"),
964964
desc,
965965
width = max_len
966966
);
@@ -1015,7 +1015,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
10151015
.iter()
10161016
.map(|&(name, ..)| ('C', name))
10171017
.chain(DB_OPTIONS.iter().map(|&(name, ..)| ('Z', name)))
1018-
.find(|&(_, name)| *opt == name.replace("_", "-"))
1018+
.find(|&(_, name)| *opt == name.replace('_', "-"))
10191019
.map(|(flag, _)| format!("{}. Did you mean `-{} {}`?", e, flag, opt)),
10201020
_ => None,
10211021
};

compiler/rustc_graphviz/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ pub trait Labeller<'a> {
472472
/// Escape tags in such a way that it is suitable for inclusion in a
473473
/// Graphviz HTML label.
474474
pub fn escape_html(s: &str) -> String {
475-
s.replace("&", "&amp;").replace("\"", "&quot;").replace("<", "&lt;").replace(">", "&gt;")
475+
s.replace('&', "&amp;").replace('\"', "&quot;").replace('<', "&lt;").replace('>', "&gt;")
476476
}
477477

478478
impl<'a> LabelText<'a> {

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option<PathBuf> {
584584
fn escape_dep_filename(filename: &str) -> String {
585585
// Apparently clang and gcc *only* escape spaces:
586586
// https://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
587-
filename.replace(" ", "\\ ")
587+
filename.replace(' ', "\\ ")
588588
}
589589

590590
// Makefile comments only need escaping newlines and `\`.

compiler/rustc_middle/src/lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub fn struct_lint_level<'s, 'd>(
295295
Level::Allow => "-A",
296296
Level::ForceWarn => "--force-warn",
297297
};
298-
let hyphen_case_lint_name = name.replace("_", "-");
298+
let hyphen_case_lint_name = name.replace('_', "-");
299299
if lint_flag_val.as_str() == name {
300300
sess.diag_note_once(
301301
&mut err,
@@ -306,7 +306,7 @@ pub fn struct_lint_level<'s, 'd>(
306306
),
307307
);
308308
} else {
309-
let hyphen_case_flag_val = lint_flag_val.as_str().replace("_", "-");
309+
let hyphen_case_flag_val = lint_flag_val.as_str().replace('_', "-");
310310
sess.diag_note_once(
311311
&mut err,
312312
DiagnosticMessageId::from(lint),

compiler/rustc_middle/src/mir/generic_graphviz.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<
126126
write!(
127127
w,
128128
r#"<tr><td align="left" balign="left">{}</td></tr>"#,
129-
dot::escape_html(&section).replace("\n", "<br/>")
129+
dot::escape_html(&section).replace('\n', "<br/>")
130130
)?;
131131
}
132132

@@ -147,7 +147,7 @@ impl<
147147
let src = self.node(source);
148148
let trg = self.node(target);
149149
let escaped_edge_label = if let Some(edge_label) = edge_labels.get(index) {
150-
dot::escape_html(edge_label).replace("\n", r#"<br align="left"/>"#)
150+
dot::escape_html(edge_label).replace('\n', r#"<br align="left"/>"#)
151151
} else {
152152
"".to_owned()
153153
};

compiler/rustc_middle/src/mir/spanview.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -681,13 +681,13 @@ fn hir_body<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<&'tcx rustc_hir::B
681681
}
682682

683683
fn escape_html(s: &str) -> String {
684-
s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
684+
s.replace('&', "&amp;").replace('<', "&lt;").replace('>', "&gt;")
685685
}
686686

687687
fn escape_attr(s: &str) -> String {
688-
s.replace("&", "&amp;")
689-
.replace("\"", "&quot;")
690-
.replace("'", "&#39;")
691-
.replace("<", "&lt;")
692-
.replace(">", "&gt;")
688+
s.replace('&', "&amp;")
689+
.replace('\"', "&quot;")
690+
.replace('\'', "&#39;")
691+
.replace('<', "&lt;")
692+
.replace('>', "&gt;")
693693
}

compiler/rustc_mir_transform/src/coverage/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl DebugOptions {
148148
let mut counter_format = ExpressionFormat::default();
149149

150150
if let Ok(env_debug_options) = std::env::var(RUSTC_COVERAGE_DEBUG_OPTIONS) {
151-
for setting_str in env_debug_options.replace(" ", "").replace("-", "_").split(',') {
151+
for setting_str in env_debug_options.replace(' ', "").replace('-', "_").split(',') {
152152
let (option, value) = match setting_str.split_once('=') {
153153
None => (setting_str, None),
154154
Some((k, v)) => (k, Some(v)),

compiler/rustc_mir_transform/src/coverage/spans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl CoverageSpan {
155155
format!(
156156
"{}\n {}",
157157
source_range_no_file(tcx, &self.span),
158-
self.format_coverage_statements(tcx, mir_body).replace("\n", "\n "),
158+
self.format_coverage_statements(tcx, mir_body).replace('\n', "\n "),
159159
)
160160
}
161161

compiler/rustc_parse/src/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ impl<'a> Parser<'a> {
22362236
err.span_suggestion(
22372237
seq_span,
22382238
"...or a vertical bar to match on multiple alternatives",
2239-
seq_snippet.replace(",", " |"),
2239+
seq_snippet.replace(',', " |"),
22402240
Applicability::MachineApplicable,
22412241
);
22422242
}

compiler/rustc_save_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ fn find_config(supplied: Option<Config>) -> Config {
10361036

10371037
// Helper function to escape quotes in a string
10381038
fn escape(s: String) -> String {
1039-
s.replace("\"", "\"\"")
1039+
s.replace('\"', "\"\"")
10401040
}
10411041

10421042
// Helper function to determine if a span came from a

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ pub fn get_cmd_lint_options(
12131213
if lint_name == "help" {
12141214
describe_lints = true;
12151215
} else {
1216-
lint_opts_with_position.push((arg_pos, lint_name.replace("-", "_"), level));
1216+
lint_opts_with_position.push((arg_pos, lint_name.replace('-', "_"), level));
12171217
}
12181218
}
12191219
}

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn build_options<O: Default>(
335335
Some((k, v)) => (k.to_string(), Some(v)),
336336
};
337337

338-
let option_to_lookup = key.replace("-", "_");
338+
let option_to_lookup = key.replace('-', "_");
339339
match descrs.iter().find(|(name, ..)| *name == option_to_lookup) {
340340
Some((_, setter, type_desc, _)) => {
341341
if !setter(&mut op, value) {

compiler/rustc_session/src/output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute], input: &Input)
8585
);
8686
sess.err(&msg);
8787
} else {
88-
return validate(s.replace("-", "_"), None);
88+
return validate(s.replace('-', "_"), None);
8989
}
9090
}
9191
}

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
741741

742742
let msg = format!(
743743
"the trait bound `{}: {}` is not satisfied",
744-
orig_ty.to_string(),
744+
orig_ty,
745745
old_ref.print_only_trait_path(),
746746
);
747747
if has_custom_message {

src/librustdoc/html/render/cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
184184
})
185185
.expect("failed serde conversion")
186186
// All these `replace` calls are because we have to go through JS string for JSON content.
187-
.replace(r"\", r"\\")
188-
.replace("'", r"\'")
187+
.replace(r#"\"#, r"\\")
188+
.replace(r#"'"#, r"\'")
189189
// We need to escape double quotes for the JSON.
190190
.replace("\\\"", "\\\\\"")
191191
)

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ fn attributes(it: &clean::Item) -> Vec<String> {
989989
.iter()
990990
.filter_map(|attr| {
991991
if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
992-
Some(pprust::attribute_to_string(attr).replace("\n", "").replace(" ", " "))
992+
Some(pprust::attribute_to_string(attr).replace('\n', "").replace(" ", " "))
993993
} else {
994994
None
995995
}

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ fn preprocess_link<'a>(
963963
return None;
964964
}
965965

966-
let stripped = ori_link.link.replace("`", "");
966+
let stripped = ori_link.link.replace('`', "");
967967
let mut parts = stripped.split('#');
968968

969969
let link = parts.next().unwrap();

src/librustdoc/theme.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ fn build_rule(v: &[u8], positions: &[usize]) -> String {
173173
.map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or(""))
174174
.collect::<String>()
175175
.trim()
176-
.replace("\n", " ")
177-
.replace("/", "")
178-
.replace("\t", " ")
179-
.replace("{", "")
180-
.replace("}", "")
176+
.replace('\n', " ")
177+
.replace('/', "")
178+
.replace('\t', " ")
179+
.replace('{', "")
180+
.replace('}', "")
181181
.split(' ')
182182
.filter(|s| !s.is_empty())
183183
.collect::<Vec<&str>>()

0 commit comments

Comments
 (0)