From 12db2225b6e82b861597d1a98c018d56100a741c Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Mon, 7 Dec 2020 11:59:24 -0700 Subject: Dogfood 'str_split_once() with `compiler/` --- compiler/rustc_mir/src/transform/coverage/debug.rs | 48 +++++++++++----------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'compiler/rustc_mir/src/transform/coverage/debug.rs') diff --git a/compiler/rustc_mir/src/transform/coverage/debug.rs b/compiler/rustc_mir/src/transform/coverage/debug.rs index e9528557b33..1347656c23e 100644 --- a/compiler/rustc_mir/src/transform/coverage/debug.rs +++ b/compiler/rustc_mir/src/transform/coverage/debug.rs @@ -148,23 +148,19 @@ impl DebugOptions { if let Ok(env_debug_options) = std::env::var(RUSTC_COVERAGE_DEBUG_OPTIONS) { for setting_str in env_debug_options.replace(" ", "").replace("-", "_").split(',') { - let mut setting = setting_str.splitn(2, '='); - match setting.next() { - Some(option) if option == "allow_unused_expressions" => { - allow_unused_expressions = bool_option_val(option, setting.next()); - debug!( - "{} env option `allow_unused_expressions` is set to {}", - RUSTC_COVERAGE_DEBUG_OPTIONS, allow_unused_expressions - ); - } - Some(option) if option == "counter_format" => { - if let Some(strval) = setting.next() { - counter_format = counter_format_option_val(strval); - debug!( - "{} env option `counter_format` is set to {:?}", - RUSTC_COVERAGE_DEBUG_OPTIONS, counter_format - ); - } else { + let (option, value) = match setting_str.split_once('=') { + None => (setting_str, None), + Some((k, v)) => (k, Some(v)), + }; + if option == "allow_unused_expressions" { + allow_unused_expressions = bool_option_val(option, value); + debug!( + "{} env option `allow_unused_expressions` is set to {}", + RUSTC_COVERAGE_DEBUG_OPTIONS, allow_unused_expressions + ); + } else if option == "counter_format" { + match value { + None => { bug!( "`{}` option in environment variable {} requires one or more \ plus-separated choices (a non-empty subset of \ @@ -173,14 +169,20 @@ impl DebugOptions { RUSTC_COVERAGE_DEBUG_OPTIONS ); } - } - Some("") => {} - Some(invalid) => bug!( + Some(val) => { + counter_format = counter_format_option_val(val); + debug!( + "{} env option `counter_format` is set to {:?}", + RUSTC_COVERAGE_DEBUG_OPTIONS, counter_format + ); + } + }; + } else { + bug!( "Unsupported setting `{}` in environment variable {}", - invalid, + option, RUSTC_COVERAGE_DEBUG_OPTIONS - ), - None => {} + ) } } } -- cgit 1.4.1-3-g733a5 From 989edf4a5ffb0944e173ec23cb5614c252e8082e Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Tue, 8 Dec 2020 12:50:52 -0700 Subject: Review feedback * Use a match statement. * Clarify why we can't use `file_stem()`. * Error if the `:` is missing for Tidy error codes, rather than no-oping. --- compiler/rustc_mir/src/transform/coverage/debug.rs | 68 ++++++++++++---------- src/tools/tidy/src/error_codes_check.rs | 14 +++-- src/tools/tidy/src/ui_tests.rs | 3 + 3 files changed, 49 insertions(+), 36 deletions(-) (limited to 'compiler/rustc_mir/src/transform/coverage/debug.rs') diff --git a/compiler/rustc_mir/src/transform/coverage/debug.rs b/compiler/rustc_mir/src/transform/coverage/debug.rs index 1347656c23e..af81d9af0e2 100644 --- a/compiler/rustc_mir/src/transform/coverage/debug.rs +++ b/compiler/rustc_mir/src/transform/coverage/debug.rs @@ -152,38 +152,42 @@ impl DebugOptions { None => (setting_str, None), Some((k, v)) => (k, Some(v)), }; - if option == "allow_unused_expressions" { - allow_unused_expressions = bool_option_val(option, value); - debug!( - "{} env option `allow_unused_expressions` is set to {}", - RUSTC_COVERAGE_DEBUG_OPTIONS, allow_unused_expressions - ); - } else if option == "counter_format" { - match value { - None => { - bug!( - "`{}` option in environment variable {} requires one or more \ - plus-separated choices (a non-empty subset of \ - `id+block+operation`)", - option, - RUSTC_COVERAGE_DEBUG_OPTIONS - ); - } - Some(val) => { - counter_format = counter_format_option_val(val); - debug!( - "{} env option `counter_format` is set to {:?}", - RUSTC_COVERAGE_DEBUG_OPTIONS, counter_format - ); - } - }; - } else { - bug!( - "Unsupported setting `{}` in environment variable {}", - option, - RUSTC_COVERAGE_DEBUG_OPTIONS - ) - } + match option { + "allow_unused_expressions" => { + allow_unused_expressions = bool_option_val(option, value); + debug!( + "{} env option `allow_unused_expressions` is set to {}", + RUSTC_COVERAGE_DEBUG_OPTIONS, allow_unused_expressions + ); + } + "counter_format" => { + match value { + None => { + bug!( + "`{}` option in environment variable {} requires one or more \ + plus-separated choices (a non-empty subset of \ + `id+block+operation`)", + option, + RUSTC_COVERAGE_DEBUG_OPTIONS + ); + } + Some(val) => { + counter_format = counter_format_option_val(val); + debug!( + "{} env option `counter_format` is set to {:?}", + RUSTC_COVERAGE_DEBUG_OPTIONS, counter_format + ); + } + }; + } + _ => { + bug!( + "Unsupported setting `{}` in environment variable {}", + option, + RUSTC_COVERAGE_DEBUG_OPTIONS + ) + } + }; } } diff --git a/src/tools/tidy/src/error_codes_check.rs b/src/tools/tidy/src/error_codes_check.rs index 1c175901be8..a7199fdfce6 100644 --- a/src/tools/tidy/src/error_codes_check.rs +++ b/src/tools/tidy/src/error_codes_check.rs @@ -85,10 +85,16 @@ fn extract_error_codes( for line in f.lines() { let s = line.trim(); if !reached_no_explanation && s.starts_with('E') && s.contains("include_str!(\"") { - let err_code = match s.split_once(':') { - None => continue, - Some((err_code, _)) => err_code.to_owned(), - }; + let err_code = s + .split_once(':') + .expect( + format!( + "Expected a line with the format `E0xxx: include_str!(\"..\")`, but got {} without a `:` delimiter", + s, + ).as_str() + ) + .0 + .to_owned(); if !error_codes.contains_key(&err_code) { error_codes.insert(err_code.clone(), false); } diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 4c8c1d58ed7..03f4efea983 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -19,6 +19,9 @@ pub fn check(path: &Path, bad: &mut bool) { // // For now, just make sure that there is a corresponding // `$testname.rs` file. + // + // NB: We do not use file_stem() as some file names have multiple `.`s and we + // must strip all of them. let testname = file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0; if !file_path.with_file_name(testname).with_extension("rs").exists() { -- cgit 1.4.1-3-g733a5 From 82fe5c16622051a71a37c9c4909dd1f4e0857584 Mon Sep 17 00:00:00 2001 From: Matthias Krüger Date: Fri, 11 Dec 2020 17:40:59 +0100 Subject: don't convert types into identical types with .into() (clippy::useless_conversion) --- compiler/rustc_mir/src/transform/coverage/debug.rs | 4 ++-- src/librustdoc/passes/collect_intra_doc_links.rs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_mir/src/transform/coverage/debug.rs') diff --git a/compiler/rustc_mir/src/transform/coverage/debug.rs b/compiler/rustc_mir/src/transform/coverage/debug.rs index af81d9af0e2..b66e37436a6 100644 --- a/compiler/rustc_mir/src/transform/coverage/debug.rs +++ b/compiler/rustc_mir/src/transform/coverage/debug.rs @@ -285,7 +285,7 @@ impl DebugCounters { ), }; counters - .insert(id.into(), DebugCounter::new(counter_kind.clone(), some_block_label)) + .insert(id, DebugCounter::new(counter_kind.clone(), some_block_label)) .expect_none( "attempt to add the same counter_kind to DebugCounters more than once", ); @@ -340,7 +340,7 @@ impl DebugCounters { if self.some_counters.is_some() && (counter_format.block || !counter_format.id) { let counters = self.some_counters.as_ref().unwrap(); if let Some(DebugCounter { some_block_label: Some(block_label), .. }) = - counters.get(&id.into()) + counters.get(&id) { return if counter_format.id { format!("{}#{}", block_label, id.index()) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 5ce64c4cd83..d8d6f862921 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1012,7 +1012,6 @@ impl LinkCollector<'_, '_> { } else { // This is a bug. debug!("attempting to resolve item without parent module: {}", path_str); - let err_kind = ResolutionFailure::NoParentItem.into(); resolution_failure( self, &item, @@ -1020,7 +1019,7 @@ impl LinkCollector<'_, '_> { disambiguator, dox, link_range, - smallvec![err_kind], + smallvec![ResolutionFailure::NoParentItem], ); return None; }; -- cgit 1.4.1-3-g733a5