From 97e844a032c47d4b3e70d2043f809767e437ac24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Mon, 13 Dec 2021 22:58:58 +0100 Subject: [PATCH] fix clippy::single_char_pattern perf findings --- compiler/rustc_codegen_ssa/src/back/link.rs | 4 ++-- compiler/rustc_driver/src/lib.rs | 10 +++++----- compiler/rustc_graphviz/src/lib.rs | 2 +- compiler/rustc_interface/src/passes.rs | 2 +- compiler/rustc_middle/src/lint.rs | 4 ++-- compiler/rustc_middle/src/mir/generic_graphviz.rs | 4 ++-- compiler/rustc_middle/src/mir/spanview.rs | 12 ++++++------ compiler/rustc_mir_transform/src/coverage/debug.rs | 2 +- compiler/rustc_mir_transform/src/coverage/spans.rs | 2 +- compiler/rustc_parse/src/parser/diagnostics.rs | 2 +- compiler/rustc_save_analysis/src/lib.rs | 2 +- compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_session/src/options.rs | 2 +- compiler/rustc_session/src/output.rs | 2 +- .../src/traits/error_reporting/suggestions.rs | 2 +- src/librustdoc/html/render/cache.rs | 4 ++-- src/librustdoc/html/render/mod.rs | 2 +- src/librustdoc/passes/collect_intra_doc_links.rs | 2 +- src/librustdoc/theme.rs | 10 +++++----- 19 files changed, 36 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index bf45810de7708..e29c109f12d59 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2226,8 +2226,8 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( continue; } - let canonical = f.replace("-", "_"); - let canonical_name = name.replace("-", "_"); + let canonical = f.replace('-', "_"); + let canonical_name = name.replace('-', "_"); let is_rust_object = canonical.starts_with(&canonical_name) && looks_like_rust_object_file(&f); diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 6ff94341142fd..12e0b7a4977e1 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -872,7 +872,7 @@ Available lint options: let print_lints = |lints: Vec<&Lint>| { for lint in lints { - let name = lint.name_lower().replace("_", "-"); + let name = lint.name_lower().replace('_', "-"); println!( " {} {:7.7} {}", padded(&name), @@ -908,10 +908,10 @@ Available lint options: let print_lint_groups = |lints: Vec<(&'static str, Vec)>| { for (name, to) in lints { - let name = name.to_lowercase().replace("_", "-"); + let name = name.to_lowercase().replace('_', "-"); let desc = to .into_iter() - .map(|x| x.to_string().replace("_", "-")) + .map(|x| x.to_string().replace('_', "-")) .collect::>() .join(", "); println!(" {} {}", padded(&name), desc); @@ -960,7 +960,7 @@ fn print_flag_list( println!( " {} {:>width$}=val -- {}", cmdline_opt, - name.replace("_", "-"), + name.replace('_', "-"), desc, width = max_len ); @@ -1015,7 +1015,7 @@ pub fn handle_options(args: &[String]) -> Option { .iter() .map(|&(name, ..)| ('C', name)) .chain(DB_OPTIONS.iter().map(|&(name, ..)| ('Z', name))) - .find(|&(_, name)| *opt == name.replace("_", "-")) + .find(|&(_, name)| *opt == name.replace('_', "-")) .map(|(flag, _)| format!("{}. Did you mean `-{} {}`?", e, flag, opt)), _ => None, }; diff --git a/compiler/rustc_graphviz/src/lib.rs b/compiler/rustc_graphviz/src/lib.rs index edb8bd503e1d0..e318090ebe15a 100644 --- a/compiler/rustc_graphviz/src/lib.rs +++ b/compiler/rustc_graphviz/src/lib.rs @@ -472,7 +472,7 @@ pub trait Labeller<'a> { /// Escape tags in such a way that it is suitable for inclusion in a /// Graphviz HTML label. pub fn escape_html(s: &str) -> String { - s.replace("&", "&").replace("\"", """).replace("<", "<").replace(">", ">") + s.replace('&', "&").replace('\"', """).replace('<', "<").replace('>', ">") } impl<'a> LabelText<'a> { diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index da76f221269fe..34865900495c7 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -584,7 +584,7 @@ fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option { fn escape_dep_filename(filename: &str) -> String { // Apparently clang and gcc *only* escape spaces: // https://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4 - filename.replace(" ", "\\ ") + filename.replace(' ', "\\ ") } // Makefile comments only need escaping newlines and `\`. diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 881b14278e99e..a6432b301743a 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -295,7 +295,7 @@ pub fn struct_lint_level<'s, 'd>( Level::Allow => "-A", Level::ForceWarn => "--force-warn", }; - let hyphen_case_lint_name = name.replace("_", "-"); + let hyphen_case_lint_name = name.replace('_', "-"); if lint_flag_val.as_str() == name { sess.diag_note_once( &mut err, @@ -306,7 +306,7 @@ pub fn struct_lint_level<'s, 'd>( ), ); } else { - let hyphen_case_flag_val = lint_flag_val.as_str().replace("_", "-"); + let hyphen_case_flag_val = lint_flag_val.as_str().replace('_', "-"); sess.diag_note_once( &mut err, DiagnosticMessageId::from(lint), diff --git a/compiler/rustc_middle/src/mir/generic_graphviz.rs b/compiler/rustc_middle/src/mir/generic_graphviz.rs index 21c18b28e258b..c907680bda14a 100644 --- a/compiler/rustc_middle/src/mir/generic_graphviz.rs +++ b/compiler/rustc_middle/src/mir/generic_graphviz.rs @@ -126,7 +126,7 @@ impl< write!( w, r#"{}"#, - dot::escape_html(§ion).replace("\n", "
") + dot::escape_html(§ion).replace('\n', "
") )?; } @@ -147,7 +147,7 @@ impl< let src = self.node(source); let trg = self.node(target); let escaped_edge_label = if let Some(edge_label) = edge_labels.get(index) { - dot::escape_html(edge_label).replace("\n", r#"
"#) + dot::escape_html(edge_label).replace('\n', r#"
"#) } else { "".to_owned() }; diff --git a/compiler/rustc_middle/src/mir/spanview.rs b/compiler/rustc_middle/src/mir/spanview.rs index 1260c691e7844..507f9971981b0 100644 --- a/compiler/rustc_middle/src/mir/spanview.rs +++ b/compiler/rustc_middle/src/mir/spanview.rs @@ -681,13 +681,13 @@ fn hir_body<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<&'tcx rustc_hir::B } fn escape_html(s: &str) -> String { - s.replace("&", "&").replace("<", "<").replace(">", ">") + s.replace('&', "&").replace('<', "<").replace('>', ">") } fn escape_attr(s: &str) -> String { - s.replace("&", "&") - .replace("\"", """) - .replace("'", "'") - .replace("<", "<") - .replace(">", ">") + s.replace('&', "&") + .replace('\"', """) + .replace('\'', "'") + .replace('<', "<") + .replace('>', ">") } diff --git a/compiler/rustc_mir_transform/src/coverage/debug.rs b/compiler/rustc_mir_transform/src/coverage/debug.rs index 588103ca43dd0..c61ee6f7e6cb7 100644 --- a/compiler/rustc_mir_transform/src/coverage/debug.rs +++ b/compiler/rustc_mir_transform/src/coverage/debug.rs @@ -148,7 +148,7 @@ impl DebugOptions { let mut counter_format = ExpressionFormat::default(); if let Ok(env_debug_options) = std::env::var(RUSTC_COVERAGE_DEBUG_OPTIONS) { - for setting_str in env_debug_options.replace(" ", "").replace("-", "_").split(',') { + for setting_str in env_debug_options.replace(' ', "").replace('-', "_").split(',') { let (option, value) = match setting_str.split_once('=') { None => (setting_str, None), Some((k, v)) => (k, Some(v)), diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index 01e72a6c1588d..b5356a817f7ac 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -155,7 +155,7 @@ impl CoverageSpan { format!( "{}\n {}", source_range_no_file(tcx, &self.span), - self.format_coverage_statements(tcx, mir_body).replace("\n", "\n "), + self.format_coverage_statements(tcx, mir_body).replace('\n', "\n "), ) } diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 25beed1ecf9c7..9677e7642b88c 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -2236,7 +2236,7 @@ impl<'a> Parser<'a> { err.span_suggestion( seq_span, "...or a vertical bar to match on multiple alternatives", - seq_snippet.replace(",", " |"), + seq_snippet.replace(',', " |"), Applicability::MachineApplicable, ); } diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index c7f8fe3a88a64..6f86bafbe4581 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -1036,7 +1036,7 @@ fn find_config(supplied: Option) -> Config { // Helper function to escape quotes in a string fn escape(s: String) -> String { - s.replace("\"", "\"\"") + s.replace('\"', "\"\"") } // Helper function to determine if a span came from a diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 5df8a4103b74f..50a8f0336728e 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1213,7 +1213,7 @@ pub fn get_cmd_lint_options( if lint_name == "help" { describe_lints = true; } else { - lint_opts_with_position.push((arg_pos, lint_name.replace("-", "_"), level)); + lint_opts_with_position.push((arg_pos, lint_name.replace('-', "_"), level)); } } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index bd7b1639613eb..dc5f4ee0ece0c 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -335,7 +335,7 @@ fn build_options( Some((k, v)) => (k.to_string(), Some(v)), }; - let option_to_lookup = key.replace("-", "_"); + let option_to_lookup = key.replace('-', "_"); match descrs.iter().find(|(name, ..)| *name == option_to_lookup) { Some((_, setter, type_desc, _)) => { if !setter(&mut op, value) { diff --git a/compiler/rustc_session/src/output.rs b/compiler/rustc_session/src/output.rs index cc1e4bb198a3b..5689b723ad610 100644 --- a/compiler/rustc_session/src/output.rs +++ b/compiler/rustc_session/src/output.rs @@ -85,7 +85,7 @@ pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute], input: &Input) ); sess.err(&msg); } else { - return validate(s.replace("-", "_"), None); + return validate(s.replace('-', "_"), None); } } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 286c9c9900b95..1396d1e606af4 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -741,7 +741,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let msg = format!( "the trait bound `{}: {}` is not satisfied", - orig_ty.to_string(), + orig_ty, old_ref.print_only_trait_path(), ); if has_custom_message { diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index 2f7214e958ea7..631eacc961828 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -184,8 +184,8 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt< }) .expect("failed serde conversion") // All these `replace` calls are because we have to go through JS string for JSON content. - .replace(r"\", r"\\") - .replace("'", r"\'") + .replace(r#"\"#, r"\\") + .replace(r#"'"#, r"\'") // We need to escape double quotes for the JSON. .replace("\\\"", "\\\\\"") ) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 166e084012724..c67fe1fef40cd 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -989,7 +989,7 @@ fn attributes(it: &clean::Item) -> Vec { .iter() .filter_map(|attr| { if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) { - Some(pprust::attribute_to_string(attr).replace("\n", "").replace(" ", " ")) + Some(pprust::attribute_to_string(attr).replace('\n', "").replace(" ", " ")) } else { None } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 4e5812d7f8429..2faf7781807d4 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -963,7 +963,7 @@ fn preprocess_link<'a>( return None; } - let stripped = ori_link.link.replace("`", ""); + let stripped = ori_link.link.replace('`', ""); let mut parts = stripped.split('#'); let link = parts.next().unwrap(); diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index b8b3f9634e582..1e9a65e1d2fc4 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -173,11 +173,11 @@ fn build_rule(v: &[u8], positions: &[usize]) -> String { .map(|x| ::std::str::from_utf8(&v[x[0]..x[1]]).unwrap_or("")) .collect::() .trim() - .replace("\n", " ") - .replace("/", "") - .replace("\t", " ") - .replace("{", "") - .replace("}", "") + .replace('\n', " ") + .replace('/', "") + .replace('\t', " ") + .replace('{', "") + .replace('}', "") .split(' ') .filter(|s| !s.is_empty()) .collect::>()