From 5b153b52a25dfe4c9592dd6c9f47582018b4fa61 Mon Sep 17 00:00:00 2001 From: klensy Date: Sat, 30 Dec 2023 18:11:41 +0300 Subject: [PATCH 01/26] annotate-snippets: update to 0.10 --- Cargo.lock | 22 ++++++++++++++----- compiler/rustc_errors/Cargo.toml | 2 +- .../src/annotate_snippet_emitter_writer.rs | 11 +++------- compiler/rustc_fluent_macro/Cargo.toml | 2 +- compiler/rustc_fluent_macro/src/fluent.rs | 10 +++------ 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8192e333fe..6ceadaa09a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,6 +119,16 @@ dependencies = [ "yansi-term", ] +[[package]] +name = "annotate-snippets" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a433302f833baa830c0092100c481c7ea768c5981a3c36f549517a502f246dd" +dependencies = [ + "anstyle", + "unicode-width", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -3770,7 +3780,7 @@ dependencies = [ name = "rustc_errors" version = "0.0.0" dependencies = [ - "annotate-snippets", + "annotate-snippets 0.10.1", "derive_setters", "rustc_ast", "rustc_ast_pretty", @@ -3831,7 +3841,7 @@ dependencies = [ name = "rustc_fluent_macro" version = "0.0.0" dependencies = [ - "annotate-snippets", + "annotate-snippets 0.10.1", "fluent-bundle", "fluent-syntax", "proc-macro2", @@ -4736,7 +4746,7 @@ dependencies = [ name = "rustfmt-nightly" version = "1.7.0" dependencies = [ - "annotate-snippets", + "annotate-snippets 0.9.1", "anyhow", "bytecount", "cargo_metadata 0.15.4", @@ -5726,7 +5736,7 @@ version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaf4bf7c184b8dfc7a4d3b90df789b1eb992ee42811cd115f32a7a1eb781058d" dependencies = [ - "annotate-snippets", + "annotate-snippets 0.9.1", "anyhow", "bstr", "cargo-platform", @@ -5857,9 +5867,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index fc3ff835a81..0c1fcecb571 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -annotate-snippets = "0.9" +annotate-snippets = "0.10" derive_setters = "0.1.6" rustc_ast = { path = "../rustc_ast" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index 5c0e210f147..e59188b3a93 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -12,8 +12,7 @@ use crate::{ CodeSuggestion, Diagnostic, DiagnosticId, DiagnosticMessage, Emitter, FluentBundle, LazyFallbackBundle, Level, MultiSpan, Style, SubDiagnostic, }; -use annotate_snippets::display_list::{DisplayList, FormatOptions}; -use annotate_snippets::snippet::*; +use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; use rustc_data_structures::sync::Lrc; use rustc_error_messages::FluentArgs; use rustc_span::source_map::SourceMap; @@ -190,11 +189,6 @@ impl AnnotateSnippetEmitter { annotation_type: annotation_type_for_level(*level), }), footer: vec![], - opt: FormatOptions { - color: true, - anonymized_line_numbers: self.ui_testing, - margin: None, - }, slices: annotated_files .iter() .map(|(file_name, source, line_index, annotations)| { @@ -222,7 +216,8 @@ impl AnnotateSnippetEmitter { // FIXME(#59346): Figure out if we can _always_ print to stderr or not. // `emitter.rs` has the `Destination` enum that lists various possible output // destinations. - eprintln!("{}", DisplayList::from(snippet)) + let renderer = Renderer::plain().anonymized_line_numbers(self.ui_testing); + eprintln!("{}", renderer.render(snippet)) } // FIXME(#59346): Is it ok to return None if there's no source_map? } diff --git a/compiler/rustc_fluent_macro/Cargo.toml b/compiler/rustc_fluent_macro/Cargo.toml index 872dd29a7a8..c5a53ae8313 100644 --- a/compiler/rustc_fluent_macro/Cargo.toml +++ b/compiler/rustc_fluent_macro/Cargo.toml @@ -8,7 +8,7 @@ proc-macro = true [dependencies] # tidy-alphabetical-start -annotate-snippets = "0.9" +annotate-snippets = "0.10" fluent-bundle = "0.15.2" fluent-syntax = "0.11" proc-macro2 = "1" diff --git a/compiler/rustc_fluent_macro/src/fluent.rs b/compiler/rustc_fluent_macro/src/fluent.rs index 3b1b63455ed..520a64aaf5e 100644 --- a/compiler/rustc_fluent_macro/src/fluent.rs +++ b/compiler/rustc_fluent_macro/src/fluent.rs @@ -1,7 +1,4 @@ -use annotate_snippets::{ - display_list::DisplayList, - snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation}, -}; +use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation}; use fluent_bundle::{FluentBundle, FluentError, FluentResource}; use fluent_syntax::{ ast::{ @@ -179,10 +176,9 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok range: (pos.start, pos.end - 1), }], }], - opt: Default::default(), }; - let dl = DisplayList::from(snippet); - eprintln!("{dl}\n"); + let renderer = Renderer::plain(); + eprintln!("{}\n", renderer.render(snippet)); } return failed(&crate_name); From 46cf55ac6fa8d0e45e1d4f47cc9d9dd467da90d4 Mon Sep 17 00:00:00 2001 From: klensy Date: Sat, 30 Dec 2023 20:13:25 +0300 Subject: [PATCH 02/26] tidy: add\remove deps --- src/tools/tidy/src/deps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 3c00027b9fd..f6769877a19 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -194,6 +194,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "aho-corasick", "allocator-api2", // FIXME: only appears in Cargo.lock due to https://github.com/rust-lang/cargo/issues/10801 "annotate-snippets", + "anstyle", "ar_archive_writer", "arrayvec", "autocfg", @@ -390,7 +391,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "windows_x86_64_gnullvm", "windows_x86_64_msvc", "writeable", - "yansi-term", // this is a false-positive: it's only used by rustfmt, but because it's enabled through a feature, tidy thinks it's used by rustc as well. "yoke", "yoke-derive", "zerocopy", From 784b50cece5df7cf6539cb7912a17ae270c9268d Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Thu, 11 Jan 2024 09:41:23 +0800 Subject: [PATCH 03/26] chore: remove unnecessary blank line Signed-off-by: hi-rustin --- library/alloc/src/raw_vec.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 74fa30456eb..45e82240164 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -552,7 +552,6 @@ fn handle_reserve(result: Result<(), TryReserveError>) { // `> isize::MAX` bytes will surely fail. On 32-bit and 16-bit we need to add // an extra guard for this in case we're running on a platform which can use // all 4GB in user-space, e.g., PAE or x32. - #[inline] fn alloc_guard(alloc_size: usize) -> Result<(), TryReserveError> { if usize::BITS < 64 && alloc_size > isize::MAX as usize { From 8f98b54a7e1568bab91d4a148139d241c44a83b3 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Wed, 3 Jan 2024 16:35:52 +1100 Subject: [PATCH 04/26] coverage: Extract helper function `term_for_bcb` --- compiler/rustc_mir_transform/src/coverage/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index dcd7014f4fc..5c1dabea987 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -141,14 +141,18 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> { let file_name = Symbol::intern(&source_file.name.for_codegen(self.tcx.sess).to_string_lossy()); + let term_for_bcb = |bcb| { + coverage_counters + .bcb_counter(bcb) + .expect("all BCBs with spans were given counters") + .as_term() + }; + coverage_spans .bcbs_with_coverage_spans() // For each BCB with spans, get a coverage term for its counter. .map(|(bcb, spans)| { - let term = coverage_counters - .bcb_counter(bcb) - .expect("all BCBs with spans were given counters") - .as_term(); + let term = term_for_bcb(bcb); (term, spans) }) // Flatten the spans into individual term/span pairs. From c5932182adfe57f38438f6b7509d1f8b9f95fd73 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Wed, 3 Jan 2024 16:42:41 +1100 Subject: [PATCH 05/26] coverage: Store extracted spans as a flat list of mappings This is less elegant in some ways, since we no longer visit a BCB's spans as a batch, but will make it much easier to add support for other kinds of coverage mapping regions (e.g. branch regions or gap regions). --- .../rustc_mir_transform/src/coverage/mod.rs | 13 ++---- .../rustc_mir_transform/src/coverage/spans.rs | 41 +++++++++++-------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index 5c1dabea987..b91afb19d8f 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -9,7 +9,7 @@ mod tests; use self::counters::{BcbCounter, CoverageCounters}; use self::graph::{BasicCoverageBlock, CoverageGraph}; -use self::spans::CoverageSpans; +use self::spans::{BcbMapping, CoverageSpans}; use crate::MirPass; @@ -149,16 +149,9 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> { }; coverage_spans - .bcbs_with_coverage_spans() - // For each BCB with spans, get a coverage term for its counter. - .map(|(bcb, spans)| { + .all_bcb_mappings() + .filter_map(|&BcbMapping { bcb, span }| { let term = term_for_bcb(bcb); - (term, spans) - }) - // Flatten the spans into individual term/span pairs. - .flat_map(|(term, spans)| spans.iter().map(move |&span| (term, span))) - // Convert each span to a code region, and create the final mapping. - .filter_map(|(term, span)| { let code_region = make_code_region(source_map, file_name, span, body_span)?; Some(Mapping { term, code_region }) }) diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index 5983189984d..be52f5b1129 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -1,5 +1,5 @@ use rustc_data_structures::graph::WithNumNodes; -use rustc_index::IndexVec; +use rustc_index::bit_set::BitSet; use rustc_middle::mir; use rustc_span::{BytePos, Span, DUMMY_SP}; @@ -8,9 +8,15 @@ use crate::coverage::ExtractedHirInfo; mod from_mir; +#[derive(Debug)] +pub(super) struct BcbMapping { + pub(super) bcb: BasicCoverageBlock, + pub(super) span: Span, +} + pub(super) struct CoverageSpans { - /// Map from BCBs to their list of coverage spans. - bcb_to_spans: IndexVec>, + bcb_has_mappings: BitSet, + mappings: Vec, } impl CoverageSpans { @@ -23,36 +29,37 @@ impl CoverageSpans { hir_info: &ExtractedHirInfo, basic_coverage_blocks: &CoverageGraph, ) -> Option { + let mut mappings = vec![]; + let coverage_spans = CoverageSpansGenerator::generate_coverage_spans( mir_body, hir_info, basic_coverage_blocks, ); + mappings.extend(coverage_spans.into_iter().map(|CoverageSpan { bcb, span, .. }| { + // Each span produced by the generator represents an ordinary code region. + BcbMapping { bcb, span } + })); - if coverage_spans.is_empty() { + if mappings.is_empty() { return None; } - // Group the coverage spans by BCB, with the BCBs in sorted order. - let mut bcb_to_spans = IndexVec::from_elem_n(Vec::new(), basic_coverage_blocks.num_nodes()); - for CoverageSpan { bcb, span, .. } in coverage_spans { - bcb_to_spans[bcb].push(span); + // Identify which BCBs have one or more mappings. + let mut bcb_has_mappings = BitSet::new_empty(basic_coverage_blocks.num_nodes()); + for &BcbMapping { bcb, span: _ } in &mappings { + bcb_has_mappings.insert(bcb); } - Some(Self { bcb_to_spans }) + Some(Self { bcb_has_mappings, mappings }) } pub(super) fn bcb_has_coverage_spans(&self, bcb: BasicCoverageBlock) -> bool { - !self.bcb_to_spans[bcb].is_empty() + self.bcb_has_mappings.contains(bcb) } - pub(super) fn bcbs_with_coverage_spans( - &self, - ) -> impl Iterator { - self.bcb_to_spans.iter_enumerated().filter_map(|(bcb, spans)| { - // Only yield BCBs that have at least one coverage span. - (!spans.is_empty()).then_some((bcb, spans.as_slice())) - }) + pub(super) fn all_bcb_mappings(&self) -> impl Iterator { + self.mappings.iter() } } From 124fff0777014323be34f0a990c78c5cfe9f40db Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 28 Dec 2023 14:07:18 +1100 Subject: [PATCH 06/26] coverage: Add enums to accommodate other kinds of coverage mappings --- .../src/coverageinfo/ffi.rs | 20 ++++++++++- .../src/coverageinfo/map_data.rs | 26 +++++++------- .../src/coverageinfo/mapgen.rs | 18 ++++------ compiler/rustc_middle/src/mir/coverage.rs | 36 ++++++++++++++----- compiler/rustc_middle/src/mir/pretty.rs | 4 +-- .../rustc_mir_transform/src/coverage/mod.rs | 10 +++--- .../rustc_mir_transform/src/coverage/spans.rs | 17 +++++++-- ...ument_coverage.bar.InstrumentCoverage.diff | 2 +- ...ment_coverage.main.InstrumentCoverage.diff | 10 +++--- 9 files changed, 94 insertions(+), 49 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs index 7ad2d03a5ed..017843c7e7d 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs @@ -1,4 +1,4 @@ -use rustc_middle::mir::coverage::{CounterId, CovTerm, ExpressionId}; +use rustc_middle::mir::coverage::{CodeRegion, CounterId, CovTerm, ExpressionId, MappingKind}; /// Must match the layout of `LLVMRustCounterKind`. #[derive(Copy, Clone, Debug)] @@ -149,6 +149,24 @@ pub struct CounterMappingRegion { } impl CounterMappingRegion { + pub(crate) fn from_mapping( + mapping_kind: &MappingKind, + local_file_id: u32, + code_region: &CodeRegion, + ) -> Self { + let &CodeRegion { file_name: _, start_line, start_col, end_line, end_col } = code_region; + match *mapping_kind { + MappingKind::Code(term) => Self::code_region( + Counter::from_term(term), + local_file_id, + start_line, + start_col, + end_line, + end_col, + ), + } + } + pub(crate) fn code_region( counter: Counter, file_id: u32, diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs index cd67fafb8e4..d85d9411f03 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs @@ -4,7 +4,8 @@ use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxIndexSet; use rustc_index::bit_set::BitSet; use rustc_middle::mir::coverage::{ - CodeRegion, CounterId, CovTerm, Expression, ExpressionId, FunctionCoverageInfo, Mapping, Op, + CodeRegion, CounterId, CovTerm, Expression, ExpressionId, FunctionCoverageInfo, Mapping, + MappingKind, Op, }; use rustc_middle::ty::Instance; use rustc_span::Symbol; @@ -64,8 +65,8 @@ impl<'tcx> FunctionCoverageCollector<'tcx> { // For each expression ID that is directly used by one or more mappings, // mark it as not-yet-seen. This indicates that we expect to see a // corresponding `ExpressionUsed` statement during MIR traversal. - for Mapping { term, .. } in &function_coverage_info.mappings { - if let &CovTerm::Expression(id) = term { + for term in function_coverage_info.mappings.iter().flat_map(|m| m.kind.terms()) { + if let CovTerm::Expression(id) = term { expressions_seen.remove(id); } } @@ -221,20 +222,21 @@ impl<'tcx> FunctionCoverage<'tcx> { /// that will be used by `mapgen` when preparing for FFI. pub(crate) fn counter_regions( &self, - ) -> impl Iterator + ExactSizeIterator { + ) -> impl Iterator + ExactSizeIterator { self.function_coverage_info.mappings.iter().map(move |mapping| { - let &Mapping { term, ref code_region } = mapping; - let counter = self.counter_for_term(term); - (counter, code_region) + let Mapping { kind, code_region } = mapping; + let kind = + kind.map_terms(|term| if self.is_zero_term(term) { CovTerm::Zero } else { term }); + (kind, code_region) }) } fn counter_for_term(&self, term: CovTerm) -> Counter { - if is_zero_term(&self.counters_seen, &self.zero_expressions, term) { - Counter::ZERO - } else { - Counter::from_term(term) - } + if self.is_zero_term(term) { Counter::ZERO } else { Counter::from_term(term) } + } + + fn is_zero_term(&self, term: CovTerm) -> bool { + is_zero_term(&self.counters_seen, &self.zero_expressions, term) } } diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 51df14df644..6116a6fd222 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -12,7 +12,6 @@ use rustc_hir::def_id::DefId; use rustc_index::IndexVec; use rustc_middle::bug; use rustc_middle::mir; -use rustc_middle::mir::coverage::CodeRegion; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::def_id::DefIdSet; use rustc_span::Symbol; @@ -237,7 +236,7 @@ fn encode_mappings_for_function( // Prepare file IDs for each filename, and prepare the mapping data so that // we can pass it through FFI to LLVM. for (file_name, counter_regions_for_file) in - &counter_regions.group_by(|(_counter, region)| region.file_name) + &counter_regions.group_by(|(_, region)| region.file_name) { // Look up the global file ID for this filename. let global_file_id = global_file_table.global_file_id_for_file_name(file_name); @@ -248,17 +247,12 @@ fn encode_mappings_for_function( // For each counter/region pair in this function+file, convert it to a // form suitable for FFI. - for (counter, region) in counter_regions_for_file { - let CodeRegion { file_name: _, start_line, start_col, end_line, end_col } = *region; - - debug!("Adding counter {counter:?} to map for {region:?}"); - mapping_regions.push(CounterMappingRegion::code_region( - counter, + for (mapping_kind, region) in counter_regions_for_file { + debug!("Adding counter {mapping_kind:?} to map for {region:?}"); + mapping_regions.push(CounterMappingRegion::from_mapping( + &mapping_kind, local_file_id.as_u32(), - start_line, - start_col, - end_line, - end_col, + region, )); } } diff --git a/compiler/rustc_middle/src/mir/coverage.rs b/compiler/rustc_middle/src/mir/coverage.rs index ec5edceb269..18e198eb9fc 100644 --- a/compiler/rustc_middle/src/mir/coverage.rs +++ b/compiler/rustc_middle/src/mir/coverage.rs @@ -160,16 +160,34 @@ pub struct Expression { #[derive(Clone, Debug)] #[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)] -pub struct Mapping { - pub code_region: CodeRegion, +pub enum MappingKind { + /// Associates a normal region of code with a counter/expression/zero. + Code(CovTerm), +} - /// Indicates whether this mapping uses a counter value, expression value, - /// or zero value. - /// - /// FIXME: When we add support for mapping kinds other than `Code` - /// (e.g. branch regions, expansion regions), replace this with a dedicated - /// mapping-kind enum. - pub term: CovTerm, +impl MappingKind { + /// Iterator over all coverage terms in this mapping kind. + pub fn terms(&self) -> impl Iterator { + let one = |a| std::iter::once(a); + match *self { + Self::Code(term) => one(term), + } + } + + /// Returns a copy of this mapping kind, in which all coverage terms have + /// been replaced with ones returned by the given function. + pub fn map_terms(&self, map_fn: impl Fn(CovTerm) -> CovTerm) -> Self { + match *self { + Self::Code(term) => Self::Code(map_fn(term)), + } + } +} + +#[derive(Clone, Debug)] +#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)] +pub struct Mapping { + pub kind: MappingKind, + pub code_region: CodeRegion, } /// Stores per-function coverage information attached to a `mir::Body`, diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index a1e5d73a0fd..1a6b0f4031d 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -493,8 +493,8 @@ fn write_function_coverage_info( for (id, expression) in expressions.iter_enumerated() { writeln!(w, "{INDENT}coverage {id:?} => {expression:?};")?; } - for coverage::Mapping { term, code_region } in mappings { - writeln!(w, "{INDENT}coverage {term:?} => {code_region:?};")?; + for coverage::Mapping { kind, code_region } in mappings { + writeln!(w, "{INDENT}coverage {kind:?} => {code_region:?};")?; } writeln!(w)?; diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index b91afb19d8f..a11d224e8f1 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -9,7 +9,7 @@ mod tests; use self::counters::{BcbCounter, CoverageCounters}; use self::graph::{BasicCoverageBlock, CoverageGraph}; -use self::spans::{BcbMapping, CoverageSpans}; +use self::spans::{BcbMapping, BcbMappingKind, CoverageSpans}; use crate::MirPass; @@ -150,10 +150,12 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> { coverage_spans .all_bcb_mappings() - .filter_map(|&BcbMapping { bcb, span }| { - let term = term_for_bcb(bcb); + .filter_map(|&BcbMapping { kind: bcb_mapping_kind, span }| { + let kind = match bcb_mapping_kind { + BcbMappingKind::Code(bcb) => MappingKind::Code(term_for_bcb(bcb)), + }; let code_region = make_code_region(source_map, file_name, span, body_span)?; - Some(Mapping { term, code_region }) + Some(Mapping { kind, code_region }) }) .collect::>() } diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index be52f5b1129..81f6c831206 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -8,9 +8,15 @@ use crate::coverage::ExtractedHirInfo; mod from_mir; +#[derive(Clone, Copy, Debug)] +pub(super) enum BcbMappingKind { + /// Associates an ordinary executable code span with its corresponding BCB. + Code(BasicCoverageBlock), +} + #[derive(Debug)] pub(super) struct BcbMapping { - pub(super) bcb: BasicCoverageBlock, + pub(super) kind: BcbMappingKind, pub(super) span: Span, } @@ -38,7 +44,7 @@ impl CoverageSpans { ); mappings.extend(coverage_spans.into_iter().map(|CoverageSpan { bcb, span, .. }| { // Each span produced by the generator represents an ordinary code region. - BcbMapping { bcb, span } + BcbMapping { kind: BcbMappingKind::Code(bcb), span } })); if mappings.is_empty() { @@ -47,8 +53,13 @@ impl CoverageSpans { // Identify which BCBs have one or more mappings. let mut bcb_has_mappings = BitSet::new_empty(basic_coverage_blocks.num_nodes()); - for &BcbMapping { bcb, span: _ } in &mappings { + let mut insert = |bcb| { bcb_has_mappings.insert(bcb); + }; + for &BcbMapping { kind, span: _ } in &mappings { + match kind { + BcbMappingKind::Code(bcb) => insert(bcb), + } } Some(Self { bcb_has_mappings, mappings }) diff --git a/tests/mir-opt/instrument_coverage.bar.InstrumentCoverage.diff b/tests/mir-opt/instrument_coverage.bar.InstrumentCoverage.diff index 1ef6b69ef5b..dec99ff4601 100644 --- a/tests/mir-opt/instrument_coverage.bar.InstrumentCoverage.diff +++ b/tests/mir-opt/instrument_coverage.bar.InstrumentCoverage.diff @@ -4,7 +4,7 @@ fn bar() -> bool { let mut _0: bool; -+ coverage Counter(0) => /the/src/instrument_coverage.rs:21:1 - 23:2; ++ coverage Code(Counter(0)) => /the/src/instrument_coverage.rs:21:1 - 23:2; + bb0: { + Coverage::CounterIncrement(0); diff --git a/tests/mir-opt/instrument_coverage.main.InstrumentCoverage.diff b/tests/mir-opt/instrument_coverage.main.InstrumentCoverage.diff index 14b4833a515..368088d1296 100644 --- a/tests/mir-opt/instrument_coverage.main.InstrumentCoverage.diff +++ b/tests/mir-opt/instrument_coverage.main.InstrumentCoverage.diff @@ -9,11 +9,11 @@ + coverage ExpressionId(0) => Expression { lhs: Counter(0), op: Add, rhs: Counter(1) }; + coverage ExpressionId(1) => Expression { lhs: Expression(0), op: Subtract, rhs: Counter(1) }; -+ coverage Counter(0) => /the/src/instrument_coverage.rs:12:1 - 12:11; -+ coverage Expression(0) => /the/src/instrument_coverage.rs:13:5 - 14:17; -+ coverage Expression(1) => /the/src/instrument_coverage.rs:15:13 - 15:18; -+ coverage Expression(1) => /the/src/instrument_coverage.rs:18:1 - 18:2; -+ coverage Counter(1) => /the/src/instrument_coverage.rs:16:10 - 16:11; ++ coverage Code(Counter(0)) => /the/src/instrument_coverage.rs:12:1 - 12:11; ++ coverage Code(Expression(0)) => /the/src/instrument_coverage.rs:13:5 - 14:17; ++ coverage Code(Expression(1)) => /the/src/instrument_coverage.rs:15:13 - 15:18; ++ coverage Code(Counter(1)) => /the/src/instrument_coverage.rs:16:10 - 16:11; ++ coverage Code(Expression(1)) => /the/src/instrument_coverage.rs:18:1 - 18:2; + bb0: { + Coverage::CounterIncrement(0); From f0a3684c1e792b6c16e32dc154de34328beef619 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 10 Jan 2024 14:27:02 +1100 Subject: [PATCH 07/26] Inline and remove `DiagCtxtInner::bump_{lint_err,err}_count`. They have one and two call sites respectively, and they just make the code harder to read. --- compiler/rustc_errors/src/lib.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 8fb539fc358..b2b74c7195a 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1168,7 +1168,8 @@ impl DiagCtxt { let mut inner = self.inner.borrow_mut(); if loud && lint_level.is_error() { - inner.bump_err_count(); + inner.err_count += 1; + inner.panic_if_treat_err_as_bug(); } inner.emitter.emit_unused_externs(lint_level, unused_externs) @@ -1353,10 +1354,11 @@ impl DiagCtxtInner { } if diagnostic.is_error() { if diagnostic.is_lint { - self.bump_lint_err_count(); + self.lint_err_count += 1; } else { - self.bump_err_count(); + self.err_count += 1; } + self.panic_if_treat_err_as_bug(); #[allow(deprecated)] { @@ -1447,16 +1449,6 @@ impl DiagCtxtInner { panic::panic_any(DelayedBugPanic); } - fn bump_lint_err_count(&mut self) { - self.lint_err_count += 1; - self.panic_if_treat_err_as_bug(); - } - - fn bump_err_count(&mut self) { - self.err_count += 1; - self.panic_if_treat_err_as_bug(); - } - fn panic_if_treat_err_as_bug(&self) { if self.treat_err_as_bug() { match ( From 2aac288c18f96c55677d90262e068820caf310f3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 10 Jan 2024 14:29:01 +1100 Subject: [PATCH 08/26] Use the right level with `-Ztreat-err-as-bug`. Errors in `DiagCtxtInner::emit_diagnostic` are never set to `Level::Bug`, because the condition never succeeds, because `self.treat_err_as_bug()` is called *before* the error counts are incremented. This commit switches to `self.treat_next_err_as_bug()`, fixing the problem. This changes the error message output to actually say "internal compiler error". --- compiler/rustc_errors/src/lib.rs | 2 +- tests/rustdoc-ui/ice-bug-report-url.stderr | 2 +- tests/ui/consts/const-eval/const-eval-query-stack.stderr | 2 +- tests/ui/impl-trait/issues/issue-86800.stderr | 2 +- tests/ui/panics/default-backtrace-ice.stderr | 2 +- tests/ui/treat-err-as-bug/err.stderr | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index b2b74c7195a..e60300bc3eb 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1256,7 +1256,7 @@ impl DiagCtxtInner { } fn emit_diagnostic(&mut self, mut diagnostic: Diagnostic) -> Option { - if matches!(diagnostic.level, Error | Fatal) && self.treat_err_as_bug() { + if matches!(diagnostic.level, Error | Fatal) && self.treat_next_err_as_bug() { diagnostic.level = Bug; } diff --git a/tests/rustdoc-ui/ice-bug-report-url.stderr b/tests/rustdoc-ui/ice-bug-report-url.stderr index 869fcd20fac..06a52691310 100644 --- a/tests/rustdoc-ui/ice-bug-report-url.stderr +++ b/tests/rustdoc-ui/ice-bug-report-url.stderr @@ -1,4 +1,4 @@ -error: expected one of `->`, `where`, or `{`, found `` +error: internal compiler error: expected one of `->`, `where`, or `{`, found `` --> $DIR/ice-bug-report-url.rs:14:10 | LL | fn wrong() diff --git a/tests/ui/consts/const-eval/const-eval-query-stack.stderr b/tests/ui/consts/const-eval/const-eval-query-stack.stderr index 01fb8153cf3..c748af608d1 100644 --- a/tests/ui/consts/const-eval/const-eval-query-stack.stderr +++ b/tests/ui/consts/const-eval/const-eval-query-stack.stderr @@ -1,4 +1,4 @@ -error[E0080]: evaluation of constant value failed +error: internal compiler error[E0080]: evaluation of constant value failed --> $DIR/const-eval-query-stack.rs:16:16 | LL | const X: i32 = 1 / 0; diff --git a/tests/ui/impl-trait/issues/issue-86800.stderr b/tests/ui/impl-trait/issues/issue-86800.stderr index 07ba8eb021b..7af4846a959 100644 --- a/tests/ui/impl-trait/issues/issue-86800.stderr +++ b/tests/ui/impl-trait/issues/issue-86800.stderr @@ -4,7 +4,7 @@ error: unconstrained opaque type LL | type TransactionFuture<'__, O> = impl '__ + Future>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -error[E0792]: expected generic lifetime parameter, found `'_` +error: internal compiler error[E0792]: expected generic lifetime parameter, found `'_` --> $DIR/issue-86800.rs:39:5 | LL | type TransactionFuture<'__, O> = impl '__ + Future>; diff --git a/tests/ui/panics/default-backtrace-ice.stderr b/tests/ui/panics/default-backtrace-ice.stderr index 4b00f135047..9d27cb22ae9 100644 --- a/tests/ui/panics/default-backtrace-ice.stderr +++ b/tests/ui/panics/default-backtrace-ice.stderr @@ -1,4 +1,4 @@ -error[E0425]: cannot find value `missing_ident` in this scope +error: internal compiler error[E0425]: cannot find value `missing_ident` in this scope --> $DIR/default-backtrace-ice.rs:21:13 | LL | fn main() { missing_ident; } diff --git a/tests/ui/treat-err-as-bug/err.stderr b/tests/ui/treat-err-as-bug/err.stderr index 3a56445a26b..4c5d0e5ae79 100644 --- a/tests/ui/treat-err-as-bug/err.stderr +++ b/tests/ui/treat-err-as-bug/err.stderr @@ -1,4 +1,4 @@ -error[E0080]: could not evaluate static initializer +error: internal compiler error[E0080]: could not evaluate static initializer --> $DIR/err.rs:11:21 | LL | pub static C: u32 = 0 - 1; From a0f5431e2385c08e40eb8c549249f4e94b32318c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 10 Jan 2024 14:45:38 +1100 Subject: [PATCH 09/26] Move code around. No point computing `warnings` and `errors` if we're going to return early before they're used. --- compiler/rustc_errors/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index e60300bc3eb..404c89ea01b 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -981,6 +981,10 @@ impl DiagCtxt { inner.emit_stashed_diagnostics(); + if inner.treat_err_as_bug() { + return; + } + let warnings = match inner.deduplicated_warn_count { 0 => Cow::from(""), 1 => Cow::from("1 warning emitted"), @@ -991,9 +995,6 @@ impl DiagCtxt { 1 => Cow::from("aborting due to 1 previous error"), count => Cow::from(format!("aborting due to {count} previous errors")), }; - if inner.treat_err_as_bug() { - return; - } match (errors.len(), warnings.len()) { (0, 0) => return, From 552bed8048d09fc313450f57430da29be94945f4 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 10 Jan 2024 15:00:20 +1100 Subject: [PATCH 10/26] Remove `DiagnosticBuilder::into_diagnostic` from `-Ztreat-err-as-bug` consideration. It seems very wrong to have a `-Ztreat-err-as-bug` check here before the error is even emitted. Once that's done: - `into_diagnostic` is infallible, so its return type doesn't need the `Option`; - the `&'a DiagCtxt` also isn't needed, because only one callsite uses it, and it already have access to it via `self.dcx`; - the comments about dcx disabling buffering are no longer true, this is unconditional now; - and the `debug!` seems unnecessary... the comment greatly overstates its importance because few diagnostics come through `into_diagnostic`, and `-Ztrack-diagnostics` exists anyway. --- .../rustc_errors/src/diagnostic_builder.rs | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index a02909f29c4..eda2f384fad 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -255,35 +255,18 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { /// Stashes diagnostic for possible later improvement in a different, /// later stage of the compiler. The diagnostic can be accessed with /// the provided `span` and `key` through [`DiagCtxt::steal_diagnostic()`]. - /// - /// As with `buffer`, this is unless the dcx has disabled such buffering. pub fn stash(self, span: Span, key: StashKey) { - if let Some((diag, dcx)) = self.into_diagnostic() { - dcx.stash_diagnostic(span, key, diag); - } + self.dcx.stash_diagnostic(span, key, self.into_diagnostic()); } - /// Converts the builder to a `Diagnostic` for later emission, - /// unless dcx has disabled such buffering. - fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a DiagCtxt)> { - if self.dcx.inner.lock().flags.treat_err_as_bug.is_some() { - self.emit(); - return None; - } - - let diag = self.take_diag(); - - // Logging here is useful to help track down where in logs an error was - // actually emitted. - debug!("buffer: diag={:?}", diag); - - Some((diag, self.dcx)) + /// Converts the builder to a `Diagnostic` for later emission. + fn into_diagnostic(mut self) -> Diagnostic { + self.take_diag() } - /// Buffers the diagnostic for later emission, - /// unless dcx has disabled such buffering. + /// Buffers the diagnostic for later emission. pub fn buffer(self, buffered_diagnostics: &mut Vec) { - buffered_diagnostics.extend(self.into_diagnostic().map(|(diag, _)| diag)); + buffered_diagnostics.push(self.into_diagnostic()); } /// Delay emission of this diagnostic as a bug. From f5c0cd0bd1c564985788fb72d73ee3c8d8beb1d7 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Jan 2024 13:50:00 +1100 Subject: [PATCH 11/26] Inline and remove three functions. Each of these has a single call site: `source_file_to_parser`, `try_file_to_source_file`, `file_to_source_file`. Having them separate just makes the code longer and harder to read. Also, `maybe_file_to_stream` doesn't need to be `pub`. --- compiler/rustc_parse/src/lib.rs | 53 +++++++++------------------------ 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index b93f08a21e3..106137299b4 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -113,19 +113,24 @@ pub fn maybe_new_parser_from_source_str( maybe_source_file_to_parser(sess, sess.source_map().new_source_file(name, source)) } -/// Creates a new parser, handling errors as appropriate if the file doesn't exist. -/// If a span is given, that is used on an error as the source of the problem. +/// Creates a new parser, aborting if the file doesn't exist. If a span is given, that is used on +/// an error as the source of the problem. pub fn new_parser_from_file<'a>(sess: &'a ParseSess, path: &Path, sp: Option) -> Parser<'a> { - source_file_to_parser(sess, file_to_source_file(sess, path, sp)) -} + let source_file = sess.source_map().load_file(path).unwrap_or_else(|e| { + let msg = format!("couldn't read {}: {}", path.display(), e); + let mut diag = Diagnostic::new(Level::Fatal, msg); + if let Some(sp) = sp { + diag.span(sp); + } + sess.dcx.emit_diagnostic(diag); + FatalError.raise(); + }); -/// Given a session and a `source_file`, returns a parser. -fn source_file_to_parser(sess: &ParseSess, source_file: Lrc) -> Parser<'_> { panictry_buffer!(&sess.dcx, maybe_source_file_to_parser(sess, source_file)) } -/// Given a session and a `source_file`, return a parser. Returns any buffered errors from lexing the -/// initial token stream. +/// Given a session and a `source_file`, return a parser. Returns any buffered errors from lexing +/// the initial token stream. fn maybe_source_file_to_parser( sess: &ParseSess, source_file: Lrc, @@ -142,36 +147,6 @@ fn maybe_source_file_to_parser( // Base abstractions -/// Given a session and a path and an optional span (for error reporting), -/// add the path to the session's source_map and return the new source_file or -/// error when a file can't be read. -fn try_file_to_source_file( - sess: &ParseSess, - path: &Path, - spanopt: Option, -) -> Result, Diagnostic> { - sess.source_map().load_file(path).map_err(|e| { - let msg = format!("couldn't read {}: {}", path.display(), e); - let mut diag = Diagnostic::new(Level::Fatal, msg); - if let Some(sp) = spanopt { - diag.span(sp); - } - diag - }) -} - -/// Given a session and a path and an optional span (for error reporting), -/// adds the path to the session's `source_map` and returns the new `source_file`. -fn file_to_source_file(sess: &ParseSess, path: &Path, spanopt: Option) -> Lrc { - match try_file_to_source_file(sess, path, spanopt) { - Ok(source_file) => source_file, - Err(d) => { - sess.dcx.emit_diagnostic(d); - FatalError.raise(); - } - } -} - /// Given a `source_file`, produces a sequence of token trees. pub fn source_file_to_stream( sess: &ParseSess, @@ -183,7 +158,7 @@ pub fn source_file_to_stream( /// Given a source file, produces a sequence of token trees. Returns any buffered errors from /// parsing the token stream. -pub fn maybe_file_to_stream( +fn maybe_file_to_stream( sess: &ParseSess, source_file: Lrc, override_span: Option, From d5aafb846b7d77aee03511059ea21cb1041d62f9 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Jan 2024 16:24:31 +1100 Subject: [PATCH 12/26] Use `struct_fatal` in `new_parser_from_file`. It's a little more concise, and the standard way to do it. --- compiler/rustc_parse/src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 106137299b4..55437de72b5 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -19,7 +19,7 @@ use rustc_ast::tokenstream::TokenStream; use rustc_ast::{AttrItem, Attribute, MetaItem}; use rustc_ast_pretty::pprust; use rustc_data_structures::sync::Lrc; -use rustc_errors::{Diagnostic, FatalError, Level, PResult}; +use rustc_errors::{Diagnostic, PResult}; use rustc_session::parse::ParseSess; use rustc_span::{FileName, SourceFile, Span}; @@ -118,12 +118,11 @@ pub fn maybe_new_parser_from_source_str( pub fn new_parser_from_file<'a>(sess: &'a ParseSess, path: &Path, sp: Option) -> Parser<'a> { let source_file = sess.source_map().load_file(path).unwrap_or_else(|e| { let msg = format!("couldn't read {}: {}", path.display(), e); - let mut diag = Diagnostic::new(Level::Fatal, msg); + let mut err = sess.dcx.struct_fatal(msg); if let Some(sp) = sp { - diag.span(sp); + err.span(sp); } - sess.dcx.emit_diagnostic(diag); - FatalError.raise(); + err.emit(); }); panictry_buffer!(&sess.dcx, maybe_source_file_to_parser(sess, source_file)) From 2668270dfb52c1241a10294bc61fa9b6da0d7933 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Jan 2024 10:35:56 +1100 Subject: [PATCH 13/26] Stop using `DiagnosticBuilder::buffer` in `WritebackCx`. --- compiler/rustc_hir_typeck/src/writeback.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index c56a028321a..3430a5fb00d 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -498,14 +498,14 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // order when emitting them. let err = self.tcx().dcx().struct_span_err(span, format!("user args: {user_args:?}")); - err.buffer(&mut errors_buffer); + errors_buffer.push(err); } } if !errors_buffer.is_empty() { errors_buffer.sort_by_key(|diag| diag.span.primary_span()); - for diag in errors_buffer { - self.tcx().dcx().emit_diagnostic(diag); + for err in errors_buffer { + err.emit(); } } } From 29c601aa0b6a1661f22da160be3ff58b6d79fe67 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Jan 2024 10:45:56 +1100 Subject: [PATCH 14/26] Stop using `DiagnosticBuilder::buffer` in `Checker`. This requires cancelling the "secondary" errors when they're not emitted, to prevent panics due to unconsumed `DiagnosticBuilder`s. --- .../src/transform/check_consts/check.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 738c532964a..ae9595d7e64 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -1,6 +1,6 @@ //! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations. -use rustc_errors::{Diagnostic, ErrorGuaranteed}; +use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_index::bit_set::BitSet; @@ -214,7 +214,7 @@ pub struct Checker<'mir, 'tcx> { local_has_storage_dead: Option>, error_emitted: Option, - secondary_errors: Vec, + secondary_errors: Vec>, } impl<'mir, 'tcx> Deref for Checker<'mir, 'tcx> { @@ -272,14 +272,17 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { } // If we got through const-checking without emitting any "primary" errors, emit any - // "secondary" errors if they occurred. + // "secondary" errors if they occurred. Otherwise, cancel the "secondary" errors. let secondary_errors = mem::take(&mut self.secondary_errors); if self.error_emitted.is_none() { for error in secondary_errors { - self.tcx.dcx().emit_diagnostic(error); + error.emit(); } } else { assert!(self.tcx.dcx().has_errors().is_some()); + for error in secondary_errors { + error.cancel(); + } } } @@ -347,7 +350,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { self.error_emitted = Some(reported); } - ops::DiagnosticImportance::Secondary => err.buffer(&mut self.secondary_errors), + ops::DiagnosticImportance::Secondary => self.secondary_errors.push(err), } } From fbe68bc40c6e49efa3a6ec4aa2640786853f2479 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Jan 2024 11:22:10 +1100 Subject: [PATCH 15/26] Stop using `DiagnosticBuilder::buffer` in `BorrowckErrors`. But we can't easily switch from `Vec` to `Vec>` because there's a mix of errors and warnings which result in different `G` types. So we must make `DiagnosticBuilder::into_diagnostic` public, but that's ok, and it will get more use in subsequent commits. --- compiler/rustc_borrowck/src/lib.rs | 19 ++++++++++--------- .../rustc_errors/src/diagnostic_builder.rs | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 495b255583c..0457b4e6ddc 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -2399,10 +2399,10 @@ mod error { /// and we want only the best of those errors. /// /// The `report_use_of_moved_or_uninitialized` function checks this map and replaces the - /// diagnostic (if there is one) if the `Place` of the error being reported is a prefix of the - /// `Place` of the previous most diagnostic. This happens instead of buffering the error. Once - /// all move errors have been reported, any diagnostics in this map are added to the buffer - /// to be emitted. + /// diagnostic (if there is one) if the `Place` of the error being reported is a prefix of + /// the `Place` of the previous most diagnostic. This happens instead of buffering the + /// error. Once all move errors have been reported, any diagnostics in this map are added + /// to the buffer to be emitted. /// /// `BTreeMap` is used to preserve the order of insertions when iterating. This is necessary /// when errors in the map are being re-added to the error buffer so that errors with the @@ -2410,7 +2410,8 @@ mod error { buffered_move_errors: BTreeMap, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)>, buffered_mut_errors: FxIndexMap, usize)>, - /// Diagnostics to be reported buffer. + /// Buffer of diagnostics to be reported. Uses `Diagnostic` rather than `DiagnosticBuilder` + /// because it has a mixture of error diagnostics and non-error diagnostics. buffered: Vec, /// Set to Some if we emit an error during borrowck tainted_by_errors: Option, @@ -2434,11 +2435,11 @@ mod error { "diagnostic buffered but not emitted", )) } - t.buffer(&mut self.buffered); + self.buffered.push(t.into_diagnostic()); } pub fn buffer_non_error_diag(&mut self, t: DiagnosticBuilder<'_, ()>) { - t.buffer(&mut self.buffered); + self.buffered.push(t.into_diagnostic()); } pub fn set_tainted_by_errors(&mut self, e: ErrorGuaranteed) { @@ -2486,13 +2487,13 @@ mod error { // Buffer any move errors that we collected and de-duplicated. for (_, (_, diag)) in std::mem::take(&mut self.errors.buffered_move_errors) { // We have already set tainted for this error, so just buffer it. - diag.buffer(&mut self.errors.buffered); + self.errors.buffered.push(diag.into_diagnostic()); } for (_, (mut diag, count)) in std::mem::take(&mut self.errors.buffered_mut_errors) { if count > 10 { diag.note(format!("...and {} other attempted mutable borrows", count - 10)); } - diag.buffer(&mut self.errors.buffered); + self.errors.buffered.push(diag.into_diagnostic()); } if !self.errors.buffered.is_empty() { diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index eda2f384fad..932b8793807 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -260,7 +260,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { } /// Converts the builder to a `Diagnostic` for later emission. - fn into_diagnostic(mut self) -> Diagnostic { + pub fn into_diagnostic(mut self) -> Diagnostic { self.take_diag() } From d02150fd45b4e63007a446f497ce032f48b1166e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Jan 2024 14:21:07 +1100 Subject: [PATCH 16/26] Fix lifetimes in `StringReader`. Two different lifetimes are conflated. This doesn't matter right now, but needs to be fixed for the next commit to work. And the more descriptive lifetime names make the code easier to read. --- compiler/rustc_parse/src/lexer/mod.rs | 24 +++++++++---------- compiler/rustc_parse/src/lexer/tokentrees.rs | 24 +++++++++++-------- .../rustc_parse/src/lexer/unicode_chars.rs | 2 +- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index 7db9291921f..9626d4e8171 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -42,9 +42,9 @@ pub struct UnmatchedDelim { pub candidate_span: Option, } -pub(crate) fn parse_token_trees<'a>( - sess: &'a ParseSess, - mut src: &'a str, +pub(crate) fn parse_token_trees<'sess, 'src>( + sess: &'sess ParseSess, + mut src: &'src str, mut start_pos: BytePos, override_span: Option, ) -> Result> { @@ -90,16 +90,16 @@ pub(crate) fn parse_token_trees<'a>( } } -struct StringReader<'a> { - sess: &'a ParseSess, +struct StringReader<'sess, 'src> { + sess: &'sess ParseSess, /// Initial position, read-only. start_pos: BytePos, /// The absolute offset within the source_map of the current character. pos: BytePos, /// Source text to tokenize. - src: &'a str, + src: &'src str, /// Cursor for getting lexer tokens. - cursor: Cursor<'a>, + cursor: Cursor<'src>, override_span: Option, /// When a "unknown start of token: \u{a0}" has already been emitted earlier /// in this file, it's safe to treat further occurrences of the non-breaking @@ -107,8 +107,8 @@ struct StringReader<'a> { nbsp_is_whitespace: bool, } -impl<'a> StringReader<'a> { - pub fn dcx(&self) -> &'a DiagCtxt { +impl<'sess, 'src> StringReader<'sess, 'src> { + pub fn dcx(&self) -> &'sess DiagCtxt { &self.sess.dcx } @@ -526,7 +526,7 @@ impl<'a> StringReader<'a> { /// Slice of the source text from `start` up to but excluding `self.pos`, /// meaning the slice does not include the character `self.ch`. - fn str_from(&self, start: BytePos) -> &'a str { + fn str_from(&self, start: BytePos) -> &'src str { self.str_from_to(start, self.pos) } @@ -537,12 +537,12 @@ impl<'a> StringReader<'a> { } /// Slice of the source text spanning from `start` up to but excluding `end`. - fn str_from_to(&self, start: BytePos, end: BytePos) -> &'a str { + fn str_from_to(&self, start: BytePos, end: BytePos) -> &'src str { &self.src[self.src_index(start)..self.src_index(end)] } /// Slice of the source text spanning from `start` until the end - fn str_from_to_end(&self, start: BytePos) -> &'a str { + fn str_from_to_end(&self, start: BytePos) -> &'src str { &self.src[self.src_index(start)..] } diff --git a/compiler/rustc_parse/src/lexer/tokentrees.rs b/compiler/rustc_parse/src/lexer/tokentrees.rs index 64b3928689a..c9ff2d58e2c 100644 --- a/compiler/rustc_parse/src/lexer/tokentrees.rs +++ b/compiler/rustc_parse/src/lexer/tokentrees.rs @@ -8,18 +8,18 @@ use rustc_ast_pretty::pprust::token_to_string; use rustc_errors::{Applicability, PErr}; use rustc_span::symbol::kw; -pub(super) struct TokenTreesReader<'a> { - string_reader: StringReader<'a>, +pub(super) struct TokenTreesReader<'sess, 'src> { + string_reader: StringReader<'sess, 'src>, /// The "next" token, which has been obtained from the `StringReader` but /// not yet handled by the `TokenTreesReader`. token: Token, diag_info: TokenTreeDiagInfo, } -impl<'a> TokenTreesReader<'a> { +impl<'sess, 'src> TokenTreesReader<'sess, 'src> { pub(super) fn parse_all_token_trees( - string_reader: StringReader<'a>, - ) -> (TokenStream, Result<(), Vec>>, Vec) { + string_reader: StringReader<'sess, 'src>, + ) -> (TokenStream, Result<(), Vec>>, Vec) { let mut tt_reader = TokenTreesReader { string_reader, token: Token::dummy(), @@ -35,7 +35,7 @@ impl<'a> TokenTreesReader<'a> { fn parse_token_trees( &mut self, is_delimited: bool, - ) -> (Spacing, TokenStream, Result<(), Vec>>) { + ) -> (Spacing, TokenStream, Result<(), Vec>>) { // Move past the opening delimiter. let (_, open_spacing) = self.bump(false); @@ -71,7 +71,7 @@ impl<'a> TokenTreesReader<'a> { } } - fn eof_err(&mut self) -> PErr<'a> { + fn eof_err(&mut self) -> PErr<'sess> { let msg = "this file contains an unclosed delimiter"; let mut err = self.string_reader.sess.dcx.struct_span_err(self.token.span, msg); for &(_, sp) in &self.diag_info.open_braces { @@ -99,7 +99,7 @@ impl<'a> TokenTreesReader<'a> { fn parse_token_tree_open_delim( &mut self, open_delim: Delimiter, - ) -> Result>> { + ) -> Result>> { // The span for beginning of the delimited section let pre_span = self.token.span; @@ -229,7 +229,11 @@ impl<'a> TokenTreesReader<'a> { (this_tok, this_spacing) } - fn unclosed_delim_err(&mut self, tts: TokenStream, mut errs: Vec>) -> Vec> { + fn unclosed_delim_err( + &mut self, + tts: TokenStream, + mut errs: Vec>, + ) -> Vec> { // If there are unclosed delims, see if there are diff markers and if so, point them // out instead of complaining about the unclosed delims. let mut parser = crate::stream_to_parser(self.string_reader.sess, tts, None); @@ -285,7 +289,7 @@ impl<'a> TokenTreesReader<'a> { return errs; } - fn close_delim_err(&mut self, delim: Delimiter) -> PErr<'a> { + fn close_delim_err(&mut self, delim: Delimiter) -> PErr<'sess> { // An unexpected closing delimiter (i.e., there is no // matching opening delimiter). let token_str = token_to_string(&self.token); diff --git a/compiler/rustc_parse/src/lexer/unicode_chars.rs b/compiler/rustc_parse/src/lexer/unicode_chars.rs index dac7569e385..a136abaa28b 100644 --- a/compiler/rustc_parse/src/lexer/unicode_chars.rs +++ b/compiler/rustc_parse/src/lexer/unicode_chars.rs @@ -337,7 +337,7 @@ const ASCII_ARRAY: &[(&str, &str, Option)] = &[ ]; pub(super) fn check_for_substitution( - reader: &StringReader<'_>, + reader: &StringReader<'_, '_>, pos: BytePos, ch: char, count: usize, From 6656413a5c9beb774dfde16804aa523cf9dbf1b5 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Jan 2024 14:22:44 +1100 Subject: [PATCH 17/26] Stop using `DiagnosticBuilder::buffer` in the parser. One consequence is that errors returned by `maybe_new_parser_from_source_str` now must be consumed, so a bunch of places that previously ignored those errors now cancel them. (Most of them explicitly dropped the errors before. I guess that was to indicate "we are explicitly ignoring these", though I'm not 100% sure.) --- compiler/rustc_interface/src/interface.rs | 11 +++++--- compiler/rustc_parse/src/lexer/mod.rs | 8 +++--- compiler/rustc_parse/src/lib.rs | 26 +++++++++---------- src/librustdoc/clean/render_macro_matchers.rs | 4 +-- src/librustdoc/doctest.rs | 8 +++--- .../src/doc/needless_doctest_main.rs | 2 +- src/tools/rustfmt/src/parse/parser.rs | 4 +-- src/tools/rustfmt/src/parse/session.rs | 8 +++--- 8 files changed, 39 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 6c000380e71..03335996c03 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -82,7 +82,7 @@ pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec) -> Cfg { Ok(..) => {} Err(err) => err.cancel(), }, - Err(errs) => drop(errs), + Err(errs) => errs.into_iter().for_each(|err| err.cancel()), } // If the user tried to use a key="value" flag, but is missing the quotes, provide @@ -129,9 +129,12 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec) -> CheckCfg { error!("expected `cfg(name, values(\"value1\", \"value2\", ... \"valueN\"))`") }; - let Ok(mut parser) = maybe_new_parser_from_source_str(&sess, filename, s.to_string()) - else { - expected_error(); + let mut parser = match maybe_new_parser_from_source_str(&sess, filename, s.to_string()) { + Ok(parser) => parser, + Err(errs) => { + errs.into_iter().for_each(|err| err.cancel()); + expected_error(); + } }; let meta_item = match parser.parse_meta_item() { diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index 9626d4e8171..d7ecf577ed6 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -7,7 +7,7 @@ use rustc_ast::ast::{self, AttrStyle}; use rustc_ast::token::{self, CommentKind, Delimiter, Token, TokenKind}; use rustc_ast::tokenstream::TokenStream; use rustc_ast::util::unicode::contains_text_flow_control_chars; -use rustc_errors::{error_code, Applicability, DiagCtxt, Diagnostic, StashKey}; +use rustc_errors::{error_code, Applicability, DiagCtxt, DiagnosticBuilder, StashKey}; use rustc_lexer::unescape::{self, EscapeError, Mode}; use rustc_lexer::{Base, DocStyle, RawStrError}; use rustc_lexer::{Cursor, LiteralKind}; @@ -47,7 +47,7 @@ pub(crate) fn parse_token_trees<'sess, 'src>( mut src: &'src str, mut start_pos: BytePos, override_span: Option, -) -> Result> { +) -> Result>> { // Skip `#!`, if present. if let Some(shebang_len) = rustc_lexer::strip_shebang(src) { src = &src[shebang_len..]; @@ -76,13 +76,13 @@ pub(crate) fn parse_token_trees<'sess, 'src>( let mut buffer = Vec::with_capacity(1); for unmatched in unmatched_delims { if let Some(err) = make_unclosed_delims_error(unmatched, sess) { - err.buffer(&mut buffer); + buffer.push(err); } } if let Err(errs) = res { // Add unclosing delimiter or diff marker errors for err in errs { - err.buffer(&mut buffer); + buffer.push(err); } } Err(buffer) diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 55437de72b5..c00e318f227 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -19,7 +19,7 @@ use rustc_ast::tokenstream::TokenStream; use rustc_ast::{AttrItem, Attribute, MetaItem}; use rustc_ast_pretty::pprust; use rustc_data_structures::sync::Lrc; -use rustc_errors::{Diagnostic, PResult}; +use rustc_errors::{DiagnosticBuilder, FatalError, PResult}; use rustc_session::parse::ParseSess; use rustc_span::{FileName, SourceFile, Span}; @@ -45,14 +45,13 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" } /// A variant of 'panictry!' that works on a `Vec` instead of a single /// `DiagnosticBuilder`. macro_rules! panictry_buffer { - ($handler:expr, $e:expr) => {{ - use rustc_errors::FatalError; + ($e:expr) => {{ use std::result::Result::{Err, Ok}; match $e { Ok(e) => e, Err(errs) => { for e in errs { - $handler.emit_diagnostic(e); + e.emit(); } FatalError.raise() } @@ -100,16 +99,17 @@ pub fn parse_stream_from_source_str( /// Creates a new parser from a source string. pub fn new_parser_from_source_str(sess: &ParseSess, name: FileName, source: String) -> Parser<'_> { - panictry_buffer!(&sess.dcx, maybe_new_parser_from_source_str(sess, name, source)) + panictry_buffer!(maybe_new_parser_from_source_str(sess, name, source)) } /// Creates a new parser from a source string. Returns any buffered errors from lexing the initial -/// token stream. +/// token stream; these must be consumed via `emit`, `cancel`, etc., otherwise a panic will occur +/// when they are dropped. pub fn maybe_new_parser_from_source_str( sess: &ParseSess, name: FileName, source: String, -) -> Result, Vec> { +) -> Result, Vec>> { maybe_source_file_to_parser(sess, sess.source_map().new_source_file(name, source)) } @@ -125,7 +125,7 @@ pub fn new_parser_from_file<'a>(sess: &'a ParseSess, path: &Path, sp: Option(sess: &'a ParseSess, path: &Path, sp: Option, -) -> Result, Vec> { +) -> Result, Vec>> { let end_pos = source_file.end_position(); let stream = maybe_file_to_stream(sess, source_file, None)?; let mut parser = stream_to_parser(sess, stream, None); @@ -152,16 +152,16 @@ pub fn source_file_to_stream( source_file: Lrc, override_span: Option, ) -> TokenStream { - panictry_buffer!(&sess.dcx, maybe_file_to_stream(sess, source_file, override_span)) + panictry_buffer!(maybe_file_to_stream(sess, source_file, override_span)) } /// Given a source file, produces a sequence of token trees. Returns any buffered errors from /// parsing the token stream. -fn maybe_file_to_stream( - sess: &ParseSess, +fn maybe_file_to_stream<'sess>( + sess: &'sess ParseSess, source_file: Lrc, override_span: Option, -) -> Result> { +) -> Result>> { let src = source_file.src.as_ref().unwrap_or_else(|| { sess.dcx.bug(format!( "cannot lex `source_file` without source: {}", diff --git a/src/librustdoc/clean/render_macro_matchers.rs b/src/librustdoc/clean/render_macro_matchers.rs index 605f9e496c7..b736f4a7956 100644 --- a/src/librustdoc/clean/render_macro_matchers.rs +++ b/src/librustdoc/clean/render_macro_matchers.rs @@ -69,8 +69,8 @@ fn snippet_equal_to_token(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Option parser, - Err(diagnostics) => { - drop(diagnostics); + Err(errs) => { + errs.into_iter().for_each(|err| err.cancel()); return None; } }; diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 9a900625268..82746a7ab03 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -589,7 +589,7 @@ pub(crate) fn make_test( let mut parser = match maybe_new_parser_from_source_str(&sess, filename, source) { Ok(p) => p, Err(errs) => { - drop(errs); + errs.into_iter().for_each(|err| err.cancel()); return (found_main, found_extern_crate, found_macro); } }; @@ -759,8 +759,10 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool { let mut parser = match maybe_new_parser_from_source_str(&sess, filename, source.to_owned()) { Ok(p) => p, - Err(_) => { - // If there is an unclosed delimiter, an error will be returned by the tokentrees. + Err(errs) => { + errs.into_iter().for_each(|err| err.cancel()); + // If there is an unclosed delimiter, an error will be returned by the + // tokentrees. return false; } }; diff --git a/src/tools/clippy/clippy_lints/src/doc/needless_doctest_main.rs b/src/tools/clippy/clippy_lints/src/doc/needless_doctest_main.rs index a744b69ecb4..8b018220c17 100644 --- a/src/tools/clippy/clippy_lints/src/doc/needless_doctest_main.rs +++ b/src/tools/clippy/clippy_lints/src/doc/needless_doctest_main.rs @@ -53,7 +53,7 @@ pub fn check( let mut parser = match maybe_new_parser_from_source_str(&sess, filename, code) { Ok(p) => p, Err(errs) => { - drop(errs); + errs.into_iter().for_each(|err| err.cancel()); return (false, test_attr_spans); }, }; diff --git a/src/tools/rustfmt/src/parse/parser.rs b/src/tools/rustfmt/src/parse/parser.rs index 7045a7dd9ce..31226cf8c30 100644 --- a/src/tools/rustfmt/src/parse/parser.rs +++ b/src/tools/rustfmt/src/parse/parser.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use rustc_ast::token::TokenKind; use rustc_ast::{ast, attr, ptr}; -use rustc_errors::Diagnostic; +use rustc_errors::DiagnosticBuilder; use rustc_parse::{new_parser_from_file, parser::Parser as RawParser}; use rustc_span::{sym, Span}; use thin_vec::ThinVec; @@ -65,7 +65,7 @@ impl<'a> ParserBuilder<'a> { fn parser( sess: &'a rustc_session::parse::ParseSess, input: Input, - ) -> Result, Option>> { + ) -> Result, Option>>> { match input { Input::File(ref file) => catch_unwind(AssertUnwindSafe(move || { new_parser_from_file(sess, file, None) diff --git a/src/tools/rustfmt/src/parse/session.rs b/src/tools/rustfmt/src/parse/session.rs index f4fb5073dfd..6dc3eac44d4 100644 --- a/src/tools/rustfmt/src/parse/session.rs +++ b/src/tools/rustfmt/src/parse/session.rs @@ -4,7 +4,9 @@ use std::sync::atomic::{AtomicBool, Ordering}; use rustc_data_structures::sync::{IntoDynSyncSend, Lrc}; use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter}; use rustc_errors::translation::Translate; -use rustc_errors::{ColorConfig, DiagCtxt, Diagnostic, Level as DiagnosticLevel}; +use rustc_errors::{ + ColorConfig, DiagCtxt, Diagnostic, DiagnosticBuilder, Level as DiagnosticLevel, +}; use rustc_session::parse::ParseSess as RawParseSess; use rustc_span::{ source_map::{FilePathMapping, SourceMap}, @@ -283,9 +285,9 @@ impl ParseSess { // Methods that should be restricted within the parse module. impl ParseSess { - pub(super) fn emit_diagnostics(&self, diagnostics: Vec) { + pub(super) fn emit_diagnostics(&self, diagnostics: Vec>) { for diagnostic in diagnostics { - self.parse_sess.dcx.emit_diagnostic(diagnostic); + diagnostic.emit(); } } From 4fd1db1aa56fba038fd11f70aa6d5c56e0059930 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Jan 2024 14:05:10 +1100 Subject: [PATCH 18/26] Remove `DiagnosticBuilder::buffer`. All its uses have been removed. --- compiler/rustc_errors/src/diagnostic_builder.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index 932b8793807..bd7c58d904e 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -264,11 +264,6 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { self.take_diag() } - /// Buffers the diagnostic for later emission. - pub fn buffer(self, buffered_diagnostics: &mut Vec) { - buffered_diagnostics.push(self.into_diagnostic()); - } - /// Delay emission of this diagnostic as a bug. /// /// This can be useful in contexts where an error indicates a bug but From 252ac152864528ef0a6f0a54458e1ecf07a7ddfc Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 10 Jan 2024 10:25:42 +0000 Subject: [PATCH 19/26] Bubble up error type --- compiler/rustc_hir_typeck/src/closure.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 7edb5912dd5..b6b33299315 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -802,7 +802,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .explicit_item_bounds(def_id) .iter_instantiated_copied(self.tcx, args) .find_map(|(p, s)| get_future_output(p.as_predicate(), s))?, - ty::Error(_) => return None, + ty::Error(_) => return Some(ret_ty), _ => span_bug!( closure_span, "async fn coroutine return type not an inference variable: {ret_ty}" From af7f8f9811e71e9b7b1885c6e5567a0b2f7b3d6a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 10 Jan 2024 10:31:06 +0000 Subject: [PATCH 20/26] Silence follow up errors if astconv already errored --- .../rustc_hir_analysis/src/astconv/mod.rs | 7 +++ compiler/rustc_hir_analysis/src/collect.rs | 15 ++++- .../rustc_hir_analysis/src/collect/type_of.rs | 6 +- .../issue-109071.no_gate.stderr | 2 +- .../associated-inherent-types/issue-109071.rs | 4 +- .../issue-109071.with_gate.stderr | 23 ++++---- .../issues/issue-71381.full.stderr | 2 +- .../issues/issue-71381.min.stderr | 20 +------ tests/ui/const-generics/issues/issue-71381.rs | 6 +- .../issues/issue-71611.min.stderr | 10 +--- tests/ui/const-generics/issues/issue-71611.rs | 3 +- .../generic-associated-types/issue-71176.rs | 3 - .../issue-71176.stderr | 55 +------------------ tests/ui/issues/issue-3214.rs | 1 - tests/ui/issues/issue-3214.stderr | 10 +--- tests/ui/layout/issue-84108.rs | 2 - tests/ui/layout/issue-84108.stderr | 24 +------- .../issues/issue-103748-ICE-wrong-braces.rs | 1 - .../issue-103748-ICE-wrong-braces.stderr | 17 +----- ...lid-assoc-type-suggestion-in-trait-impl.rs | 1 - ...assoc-type-suggestion-in-trait-impl.stderr | 8 +-- 21 files changed, 56 insertions(+), 164 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 1f47564649e..cfe9496367f 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -390,6 +390,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { infer_args, ); + if let Err(err) = &arg_count.correct + && let Some(reported) = err.reported + { + self.set_tainted_by_errors(reported); + } + // Skip processing if type has no generic parameters. // Traits always have `Self` as a generic parameter, which means they will not return early // here and so associated type bindings will be handled regardless of whether there are any @@ -568,6 +574,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { span, modifier: constness.as_str(), }); + self.set_tainted_by_errors(e); arg_count.correct = Err(GenericArgCountMismatch { reported: Some(e), invalid_args: vec![] }); } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index c9f89a0c3ef..e557f36037b 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -35,6 +35,7 @@ use rustc_target::spec::abi; use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::traits::error_reporting::suggestions::NextTypeParamName; use rustc_trait_selection::traits::ObligationCtxt; +use std::cell::Cell; use std::iter; use std::ops::Bound; @@ -119,6 +120,7 @@ pub fn provide(providers: &mut Providers) { pub struct ItemCtxt<'tcx> { tcx: TyCtxt<'tcx>, item_def_id: LocalDefId, + tainted_by_errors: Cell>, } /////////////////////////////////////////////////////////////////////////// @@ -343,7 +345,7 @@ fn bad_placeholder<'tcx>( impl<'tcx> ItemCtxt<'tcx> { pub fn new(tcx: TyCtxt<'tcx>, item_def_id: LocalDefId) -> ItemCtxt<'tcx> { - ItemCtxt { tcx, item_def_id } + ItemCtxt { tcx, item_def_id, tainted_by_errors: Cell::new(None) } } pub fn to_ty(&self, ast_ty: &hir::Ty<'_>) -> Ty<'tcx> { @@ -357,6 +359,13 @@ impl<'tcx> ItemCtxt<'tcx> { pub fn node(&self) -> hir::Node<'tcx> { self.tcx.hir_node(self.hir_id()) } + + fn check_tainted_by_errors(&self) -> Result<(), ErrorGuaranteed> { + match self.tainted_by_errors.get() { + Some(err) => Err(err), + None => Ok(()), + } + } } impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { @@ -492,8 +501,8 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { ty.ty_adt_def() } - fn set_tainted_by_errors(&self, _: ErrorGuaranteed) { - // There's no obvious place to track this, so just let it go. + fn set_tainted_by_errors(&self, err: ErrorGuaranteed) { + self.tainted_by_errors.set(Some(err)); } fn record_ty(&self, _hir_id: hir::HirId, _ty: Ty<'tcx>, _span: Span) { diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 3ceea3dc7ae..b936b0c0805 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -513,7 +513,11 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder $DIR/issue-109071.rs:16:22 + --> $DIR/issue-109071.rs:15:22 | LL | fn T() -> Option {} | ^^^^^^^^^^ diff --git a/tests/ui/associated-inherent-types/issue-109071.rs b/tests/ui/associated-inherent-types/issue-109071.rs index a897aaebc58..cbe8cce0924 100644 --- a/tests/ui/associated-inherent-types/issue-109071.rs +++ b/tests/ui/associated-inherent-types/issue-109071.rs @@ -9,13 +9,11 @@ impl Windows { //~ ERROR: missing generics for struct `Windows` //[no_gate]~^ ERROR: inherent associated types are unstable fn next() -> Option {} - //[with_gate]~^ ERROR type annotations needed } impl Windows { fn T() -> Option {} - //[no_gate]~^ ERROR: ambiguous associated type - //[with_gate]~^^ ERROR type annotations needed + //~^ ERROR: ambiguous associated type } fn main() {} diff --git a/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr b/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr index d413c65dccb..a7d17e2d5eb 100644 --- a/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr +++ b/tests/ui/associated-inherent-types/issue-109071.with_gate.stderr @@ -20,19 +20,20 @@ help: add missing generic argument LL | impl Windows { | +++ -error[E0282]: type annotations needed - --> $DIR/issue-109071.rs:11:18 - | -LL | fn next() -> Option {} - | ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` - -error[E0282]: type annotations needed - --> $DIR/issue-109071.rs:16:15 +error[E0223]: ambiguous associated type + --> $DIR/issue-109071.rs:15:22 | LL | fn T() -> Option {} - | ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` + | ^^^^^^^^^^ + | +help: use fully-qualified syntax + | +LL | fn T() -> Option< as IntoAsyncIterator>::Item> {} + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +LL | fn T() -> Option< as IntoIterator>::Item> {} + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0107, E0282, E0637. +Some errors have detailed explanations: E0107, E0223, E0637. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/const-generics/issues/issue-71381.full.stderr b/tests/ui/const-generics/issues/issue-71381.full.stderr index b6460e0017f..5d780074696 100644 --- a/tests/ui/const-generics/issues/issue-71381.full.stderr +++ b/tests/ui/const-generics/issues/issue-71381.full.stderr @@ -7,7 +7,7 @@ LL | pub fn call_me $DIR/issue-71381.rs:23:40 + --> $DIR/issue-71381.rs:22:40 | LL | const FN: unsafe extern "C" fn(Args), | ^^^^ the type must not depend on the parameter `Args` diff --git a/tests/ui/const-generics/issues/issue-71381.min.stderr b/tests/ui/const-generics/issues/issue-71381.min.stderr index e16d3b7a8a4..5d780074696 100644 --- a/tests/ui/const-generics/issues/issue-71381.min.stderr +++ b/tests/ui/const-generics/issues/issue-71381.min.stderr @@ -7,29 +7,13 @@ LL | pub fn call_me $DIR/issue-71381.rs:23:40 + --> $DIR/issue-71381.rs:22:40 | LL | const FN: unsafe extern "C" fn(Args), | ^^^^ the type must not depend on the parameter `Args` | = note: type parameters may not be used in the type of const parameters -error: using function pointers as const generic parameters is forbidden - --> $DIR/issue-71381.rs:14:61 - | -LL | pub fn call_me(&self) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - -error: using function pointers as const generic parameters is forbidden - --> $DIR/issue-71381.rs:23:19 - | -LL | const FN: unsafe extern "C" fn(Args), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0770`. diff --git a/tests/ui/const-generics/issues/issue-71381.rs b/tests/ui/const-generics/issues/issue-71381.rs index 8a878efb42a..75ad4545371 100644 --- a/tests/ui/const-generics/issues/issue-71381.rs +++ b/tests/ui/const-generics/issues/issue-71381.rs @@ -12,8 +12,7 @@ unsafe extern "C" fn pass(args: PassArg) { impl Test { pub fn call_me(&self) { - //[min]~^ ERROR: using function pointers as const generic parameters is forbidden - //~^^ ERROR: the type of const parameters must not depend on other generic parameters + //~^ ERROR: the type of const parameters must not depend on other generic parameters self.0 = Self::trampiline:: as _ } @@ -21,8 +20,7 @@ impl Test { Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args), - //[min]~^ ERROR: using function pointers as const generic parameters is forbidden - //~^^ ERROR: the type of const parameters must not depend on other generic parameters + //~^ ERROR: the type of const parameters must not depend on other generic parameters >( args: Args, ) { diff --git a/tests/ui/const-generics/issues/issue-71611.min.stderr b/tests/ui/const-generics/issues/issue-71611.min.stderr index b01936f4d25..6f6a9fc21a6 100644 --- a/tests/ui/const-generics/issues/issue-71611.min.stderr +++ b/tests/ui/const-generics/issues/issue-71611.min.stderr @@ -6,14 +6,6 @@ LL | fn func(outer: A) { | = note: type parameters may not be used in the type of const parameters -error: using function pointers as const generic parameters is forbidden - --> $DIR/issue-71611.rs:5:21 - | -LL | fn func(outer: A) { - | ^^^^^^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0770`. diff --git a/tests/ui/const-generics/issues/issue-71611.rs b/tests/ui/const-generics/issues/issue-71611.rs index c917f66818b..92930092482 100644 --- a/tests/ui/const-generics/issues/issue-71611.rs +++ b/tests/ui/const-generics/issues/issue-71611.rs @@ -3,8 +3,7 @@ #![cfg_attr(full, allow(incomplete_features))] fn func(outer: A) { - //[min]~^ ERROR: using function pointers as const generic parameters is forbidden - //~^^ ERROR: the type of const parameters must not depend on other generic parameters + //~^ ERROR: the type of const parameters must not depend on other generic parameters F(outer); } diff --git a/tests/ui/generic-associated-types/issue-71176.rs b/tests/ui/generic-associated-types/issue-71176.rs index e58b6f6091e..f0e162d825f 100644 --- a/tests/ui/generic-associated-types/issue-71176.rs +++ b/tests/ui/generic-associated-types/issue-71176.rs @@ -9,9 +9,6 @@ impl Provider for () { struct Holder { inner: Box>, //~^ ERROR: missing generics for associated type - //~| ERROR: missing generics for associated type - //~| ERROR: missing generics for associated type - //~| ERROR: the trait `Provider` cannot be made into an object } fn main() { diff --git a/tests/ui/generic-associated-types/issue-71176.stderr b/tests/ui/generic-associated-types/issue-71176.stderr index a1913bb618b..ed837f34753 100644 --- a/tests/ui/generic-associated-types/issue-71176.stderr +++ b/tests/ui/generic-associated-types/issue-71176.stderr @@ -14,57 +14,6 @@ help: add missing lifetime argument LL | inner: Box = B>>, | ++++ -error[E0107]: missing generics for associated type `Provider::A` - --> $DIR/issue-71176.rs:10:27 - | -LL | inner: Box>, - | ^ expected 1 lifetime argument - | -note: associated type defined here, with 1 lifetime parameter: `'a` - --> $DIR/issue-71176.rs:2:10 - | -LL | type A<'a>; - | ^ -- - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: add missing lifetime argument - | -LL | inner: Box = B>>, - | ++++ +error: aborting due to 1 previous error -error[E0107]: missing generics for associated type `Provider::A` - --> $DIR/issue-71176.rs:10:27 - | -LL | inner: Box>, - | ^ expected 1 lifetime argument - | -note: associated type defined here, with 1 lifetime parameter: `'a` - --> $DIR/issue-71176.rs:2:10 - | -LL | type A<'a>; - | ^ -- - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: add missing lifetime argument - | -LL | inner: Box = B>>, - | ++++ - -error[E0038]: the trait `Provider` cannot be made into an object - --> $DIR/issue-71176.rs:10:14 - | -LL | inner: Box>, - | ^^^^^^^^^^^^^^^^^^^ `Provider` cannot be made into an object - | -note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/issue-71176.rs:2:10 - | -LL | trait Provider { - | -------- this trait cannot be made into an object... -LL | type A<'a>; - | ^ ...because it contains the generic associated type `A` - = help: consider moving `A` to another trait - = help: only type `()` implements the trait, consider using it directly instead - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0038, E0107. -For more information about an error, try `rustc --explain E0038`. +For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/issues/issue-3214.rs b/tests/ui/issues/issue-3214.rs index 03d8d6ba246..b2c27f5be95 100644 --- a/tests/ui/issues/issue-3214.rs +++ b/tests/ui/issues/issue-3214.rs @@ -5,7 +5,6 @@ fn foo() { impl Drop for Foo { //~^ ERROR struct takes 0 generic arguments but 1 generic argument - //~| ERROR `T` is not constrained fn drop(&mut self) {} } } diff --git a/tests/ui/issues/issue-3214.stderr b/tests/ui/issues/issue-3214.stderr index 26ac6d39f60..5b57c1baf90 100644 --- a/tests/ui/issues/issue-3214.stderr +++ b/tests/ui/issues/issue-3214.stderr @@ -22,13 +22,7 @@ note: struct defined here, with 0 generic parameters LL | struct Foo { | ^^^ -error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-3214.rs:6:10 - | -LL | impl Drop for Foo { - | ^ unconstrained type parameter +error: aborting due to 2 previous errors -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0107, E0207, E0401. +Some errors have detailed explanations: E0107, E0401. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/layout/issue-84108.rs b/tests/ui/layout/issue-84108.rs index af21d1d6210..44d6ac8db72 100644 --- a/tests/ui/layout/issue-84108.rs +++ b/tests/ui/layout/issue-84108.rs @@ -8,8 +8,6 @@ static FOO: (dyn AsRef, u8) = ("hello", 42); const BAR: (&Path, [u8], usize) = ("hello", [], 42); //~^ ERROR cannot find type `Path` in this scope -//~| ERROR the size for values of type `[u8]` cannot be known at compilation time -//~| ERROR mismatched types static BAZ: ([u8], usize) = ([], 0); //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time diff --git a/tests/ui/layout/issue-84108.stderr b/tests/ui/layout/issue-84108.stderr index d6d75851034..58bddb069fc 100644 --- a/tests/ui/layout/issue-84108.stderr +++ b/tests/ui/layout/issue-84108.stderr @@ -21,25 +21,7 @@ LL + use std::path::Path; | error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/issue-84108.rs:9:12 - | -LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42); - | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: only the last element of a tuple may have a dynamically sized type - -error[E0308]: mismatched types - --> $DIR/issue-84108.rs:9:45 - | -LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42); - | ^^ expected `[u8]`, found `[_; 0]` - | - = note: expected slice `[u8]` - found array `[_; 0]` - -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/issue-84108.rs:14:13 + --> $DIR/issue-84108.rs:12:13 | LL | static BAZ: ([u8], usize) = ([], 0); | ^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -48,7 +30,7 @@ LL | static BAZ: ([u8], usize) = ([], 0); = note: only the last element of a tuple may have a dynamically sized type error[E0308]: mismatched types - --> $DIR/issue-84108.rs:14:30 + --> $DIR/issue-84108.rs:12:30 | LL | static BAZ: ([u8], usize) = ([], 0); | ^^ expected `[u8]`, found `[_; 0]` @@ -56,7 +38,7 @@ LL | static BAZ: ([u8], usize) = ([], 0); = note: expected slice `[u8]` found array `[_; 0]` -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0277, E0308, E0412. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs index 8012cb652bd..f6aa39df27d 100644 --- a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs +++ b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs @@ -5,4 +5,3 @@ struct Apple((Apple, Option(Banana ? Citron))); //~| ERROR expected one of `)` or `,`, found `Citron` //~| ERROR cannot find type `Citron` in this scope [E0412] //~| ERROR parenthesized type parameters may only be used with a `Fn` trait [E0214] -//~| ERROR recursive type `Apple` has infinite size [E0072] diff --git a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr index b0d8b03ae08..71d2d7b7975 100644 --- a/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr +++ b/tests/ui/parser/issues/issue-103748-ICE-wrong-braces.stderr @@ -34,18 +34,7 @@ help: use angle brackets instead LL | struct Apple((Apple, Option)); | ~ ~ -error[E0072]: recursive type `Apple` has infinite size - --> $DIR/issue-103748-ICE-wrong-braces.rs:3:1 - | -LL | struct Apple((Apple, Option(Banana ? Citron))); - | ^^^^^^^^^^^^ ----- recursive without indirection - | -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle - | -LL | struct Apple((Box, Option(Banana ? Citron))); - | ++++ + +error: aborting due to 4 previous errors -error: aborting due to 5 previous errors - -Some errors have detailed explanations: E0072, E0214, E0412. -For more information about an error, try `rustc --explain E0072`. +Some errors have detailed explanations: E0214, E0412. +For more information about an error, try `rustc --explain E0214`. diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs index 4cbc36f4650..52ecbcc9e2c 100644 --- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs +++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.rs @@ -39,7 +39,6 @@ impl> Struct {} trait YetAnotherTrait {} impl, U> YetAnotherTrait for Struct {} //~^ ERROR struct takes 1 generic argument but 2 generic arguments were supplied -//~| ERROR `U` is not constrained fn main() { diff --git a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr index 3c2b726fcce..e7ceb7372bf 100644 --- a/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr +++ b/tests/ui/traits/associated_type_bound/116464-invalid-assoc-type-suggestion-in-trait-impl.stderr @@ -116,13 +116,7 @@ error[E0207]: the type parameter `S` is not constrained by the impl trait, self LL | impl Trait for () {} | ^ unconstrained type parameter -error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates - --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:40:35 - | -LL | impl, U> YetAnotherTrait for Struct {} - | ^ unconstrained type parameter - -error: aborting due to 10 previous errors +error: aborting due to 9 previous errors Some errors have detailed explanations: E0107, E0207. For more information about an error, try `rustc --explain E0107`. From 55cab535e7dddc05c6fa57f4a0319ae9d0d36d9b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 10 Jan 2024 14:58:03 +0000 Subject: [PATCH 21/26] Taint more aggressively in astconv --- .../rustc_hir_analysis/src/astconv/bounds.rs | 4 +++- .../rustc_hir_analysis/src/astconv/errors.rs | 6 +++-- .../rustc_hir_analysis/src/astconv/mod.rs | 23 ++++++++++++------ .../src/astconv/object_safety.rs | 7 ++++-- tests/rustdoc-ui/unable-fulfill-trait.rs | 1 - tests/rustdoc-ui/unable-fulfill-trait.stderr | 23 +++--------------- tests/ui/associated-types/issue-23595-1.rs | 3 +-- .../ui/associated-types/issue-23595-1.stderr | 24 ++++--------------- tests/ui/derives/issue-97343.rs | 1 - tests/ui/derives/issue-97343.stderr | 14 ++--------- tests/ui/error-codes/E0227.rs | 4 +--- tests/ui/error-codes/E0227.stderr | 22 ++--------------- .../ui/lifetimes/unusual-rib-combinations.rs | 1 - .../lifetimes/unusual-rib-combinations.stderr | 11 +-------- 14 files changed, 43 insertions(+), 101 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/bounds.rs b/compiler/rustc_hir_analysis/src/astconv/bounds.rs index 1f88aaa6a4b..2ad96a24891 100644 --- a/compiler/rustc_hir_analysis/src/astconv/bounds.rs +++ b/compiler/rustc_hir_analysis/src/astconv/bounds.rs @@ -300,13 +300,15 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .expect("missing associated item"); if !assoc_item.visibility(tcx).is_accessible_from(def_scope, tcx) { - tcx.dcx() + let reported = tcx + .dcx() .struct_span_err( binding.span, format!("{} `{}` is private", assoc_item.kind, binding.item_name), ) .with_span_label(binding.span, format!("private {}", assoc_item.kind)) .emit(); + self.set_tainted_by_errors(reported); } tcx.check_stability(assoc_item.def_id, Some(hir_ref_id), binding.span, None); diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index fc2ed104b3d..7b23b74f829 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -354,7 +354,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ); err.span_label(name.span, format!("multiple `{name}` found")); self.note_ambiguous_inherent_assoc_type(&mut err, candidates, span); - err.emit() + let reported = err.emit(); + self.set_tainted_by_errors(reported); + reported } // FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate. @@ -843,7 +845,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } } - err.emit(); + self.set_tainted_by_errors(err.emit()); } } diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index cfe9496367f..2886ec21320 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -973,7 +973,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } } } - err.emit() + let reported = err.emit(); + self.set_tainted_by_errors(reported); + reported } // Search for a bound on a type parameter which includes the associated item @@ -1050,6 +1052,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { span, binding, ); + self.set_tainted_by_errors(reported); return Err(reported); }; debug!(?bound); @@ -1127,6 +1130,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { )); } let reported = err.emit(); + self.set_tainted_by_errors(reported); if !where_bounds.is_empty() { return Err(reported); } @@ -1381,6 +1385,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { assoc_ident.name, ) }; + self.set_tainted_by_errors(reported); return Err(reported); } }; @@ -1623,12 +1628,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let kind = tcx.def_kind_descr(kind, item); let msg = format!("{kind} `{name}` is private"); let def_span = tcx.def_span(item); - tcx.dcx() + let reported = tcx + .dcx() .struct_span_err(span, msg) .with_code(rustc_errors::error_code!(E0624)) .with_span_label(span, format!("private {kind}")) .with_span_label(def_span, format!("{kind} defined here")) .emit(); + self.set_tainted_by_errors(reported); } tcx.check_stability(item, Some(block), span, None); } @@ -1869,7 +1876,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { err.span_label(span, format!("not allowed on {what}")); } extend(&mut err); - err.emit(); + self.set_tainted_by_errors(err.emit()); emitted = true; } @@ -2191,7 +2198,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { { err.span_note(impl_.self_ty.span, "not a concrete type"); } - Ty::new_error(tcx, err.emit()) + let reported = err.emit(); + self.set_tainted_by_errors(reported); + Ty::new_error(tcx, reported) } else { ty } @@ -2593,7 +2602,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ); } - diag.emit(); + self.set_tainted_by_errors(diag.emit()); } // Find any late-bound regions declared in return type that do @@ -2693,7 +2702,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { err.note("consider introducing a named lifetime parameter"); } - err.emit(); + self.set_tainted_by_errors(err.emit()); } } @@ -2732,7 +2741,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // error. let r = derived_region_bounds[0]; if derived_region_bounds[1..].iter().any(|r1| r != *r1) { - tcx.dcx().emit_err(AmbiguousLifetimeBound { span }); + self.set_tainted_by_errors(tcx.dcx().emit_err(AmbiguousLifetimeBound { span })); } Some(r) } diff --git a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs index ea2f5f50b5c..f77f250cd28 100644 --- a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs +++ b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs @@ -116,7 +116,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { for more information on them, visit \ ", ); - err.emit(); + self.set_tainted_by_errors(err.emit()); } if regular_traits.is_empty() && auto_traits.is_empty() { @@ -127,6 +127,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .map(|trait_ref| tcx.def_span(trait_ref)); let reported = tcx.dcx().emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span }); + self.set_tainted_by_errors(reported); return Ty::new_error(tcx, reported); } @@ -290,7 +291,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if references_self { let def_id = i.bottom().0.def_id(); - struct_span_code_err!( + let reported = struct_span_code_err!( tcx.dcx(), i.bottom().1, E0038, @@ -303,6 +304,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .error_msg(), ) .emit(); + self.set_tainted_by_errors(reported); } ty::ExistentialTraitRef { def_id: trait_ref.def_id, args } @@ -389,6 +391,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } else { err.emit() }; + self.set_tainted_by_errors(e); ty::Region::new_error(tcx, e) }) } diff --git a/tests/rustdoc-ui/unable-fulfill-trait.rs b/tests/rustdoc-ui/unable-fulfill-trait.rs index 10887ab1903..a69f74b09ac 100644 --- a/tests/rustdoc-ui/unable-fulfill-trait.rs +++ b/tests/rustdoc-ui/unable-fulfill-trait.rs @@ -4,7 +4,6 @@ pub struct Foo<'a, 'b, T> { field1: dyn Bar<'a, 'b,>, //~^ ERROR //~| ERROR - //~| ERROR } pub trait Bar<'x, 's, U> diff --git a/tests/rustdoc-ui/unable-fulfill-trait.stderr b/tests/rustdoc-ui/unable-fulfill-trait.stderr index d7735a4fd11..72f35cb9224 100644 --- a/tests/rustdoc-ui/unable-fulfill-trait.stderr +++ b/tests/rustdoc-ui/unable-fulfill-trait.stderr @@ -5,7 +5,7 @@ LL | field1: dyn Bar<'a, 'b,>, | ^^^ expected 1 generic argument | note: trait defined here, with 1 generic parameter: `U` - --> $DIR/unable-fulfill-trait.rs:10:11 + --> $DIR/unable-fulfill-trait.rs:9:11 | LL | pub trait Bar<'x, 's, U> | ^^^ - @@ -20,24 +20,7 @@ error[E0227]: ambiguous lifetime bound, explicit lifetime bound required LL | field1: dyn Bar<'a, 'b,>, | ^^^^^^^^^^^^^^^^ -error[E0478]: lifetime bound not satisfied - --> $DIR/unable-fulfill-trait.rs:4:13 - | -LL | field1: dyn Bar<'a, 'b,>, - | ^^^^^^^^^^^^^^^^ - | -note: lifetime parameter instantiated with the lifetime `'b` as defined here - --> $DIR/unable-fulfill-trait.rs:3:20 - | -LL | pub struct Foo<'a, 'b, T> { - | ^^ -note: but lifetime parameter must outlive the lifetime `'a` as defined here - --> $DIR/unable-fulfill-trait.rs:3:16 - | -LL | pub struct Foo<'a, 'b, T> { - | ^^ +error: aborting due to 2 previous errors -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0107, E0227, E0478. +Some errors have detailed explanations: E0107, E0227. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/associated-types/issue-23595-1.rs b/tests/ui/associated-types/issue-23595-1.rs index 9222f5b6650..579fde34f53 100644 --- a/tests/ui/associated-types/issue-23595-1.rs +++ b/tests/ui/associated-types/issue-23595-1.rs @@ -5,9 +5,8 @@ use std::ops::Index; trait Hierarchy { type Value; type ChildKey; - type Children = dyn Index; + type Children = dyn Index; //~^ ERROR: the value of the associated types - //~| ERROR: the size for values of type fn data(&self) -> Option<(Self::Value, Self::Children)>; } diff --git a/tests/ui/associated-types/issue-23595-1.stderr b/tests/ui/associated-types/issue-23595-1.stderr index 46906ab3fb7..694b68ef090 100644 --- a/tests/ui/associated-types/issue-23595-1.stderr +++ b/tests/ui/associated-types/issue-23595-1.stderr @@ -1,27 +1,13 @@ error[E0191]: the value of the associated types `Value`, `ChildKey` and `Children` in `Hierarchy` must be specified - --> $DIR/issue-23595-1.rs:8:58 + --> $DIR/issue-23595-1.rs:8:60 | LL | type Value; | ---------- `Value` defined here LL | type ChildKey; | ------------- `ChildKey` defined here -LL | type Children = dyn Index; - | ------------- `Children` defined here ^^^^^^^^^ help: specify the associated types: `Hierarchy` +LL | type Children = dyn Index; + | ------------- `Children` defined here ^^^^^^^^^ help: specify the associated types: `Hierarchy` -error[E0277]: the size for values of type `(dyn Index<::ChildKey, Output = (dyn Hierarchy + 'static)> + 'static)` cannot be known at compilation time - --> $DIR/issue-23595-1.rs:8:21 - | -LL | type Children = dyn Index; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `(dyn Index<::ChildKey, Output = (dyn Hierarchy + 'static)> + 'static)` -note: required by a bound in `Hierarchy::Children` - --> $DIR/issue-23595-1.rs:8:5 - | -LL | type Children = dyn Index; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Hierarchy::Children` +error: aborting due to 1 previous error -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0191, E0277. -For more information about an error, try `rustc --explain E0191`. +For more information about this error, try `rustc --explain E0191`. diff --git a/tests/ui/derives/issue-97343.rs b/tests/ui/derives/issue-97343.rs index 91f0aa376e9..6f0e4d55aeb 100644 --- a/tests/ui/derives/issue-97343.rs +++ b/tests/ui/derives/issue-97343.rs @@ -2,7 +2,6 @@ use std::fmt::Debug; #[derive(Debug)] pub struct Irrelevant { //~ ERROR type arguments are not allowed on type parameter - //~^ ERROR `Irrelevant` must be used irrelevant: Irrelevant, } diff --git a/tests/ui/derives/issue-97343.stderr b/tests/ui/derives/issue-97343.stderr index 45612ae6f47..efb2fb70f5a 100644 --- a/tests/ui/derives/issue-97343.stderr +++ b/tests/ui/derives/issue-97343.stderr @@ -16,16 +16,6 @@ LL | pub struct Irrelevant { | ^^^^^^^^^^ = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0210]: type parameter `Irrelevant` must be used as the type parameter for some local type (e.g., `MyStruct`) - --> $DIR/issue-97343.rs:4:23 - | -LL | pub struct Irrelevant { - | ^^^^^^^^^^ type parameter `Irrelevant` must be used as the type parameter for some local type - | - = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local - = note: only traits defined in the current crate can be implemented for a type parameter +error: aborting due to 1 previous error -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0109, E0210. -For more information about an error, try `rustc --explain E0109`. +For more information about this error, try `rustc --explain E0109`. diff --git a/tests/ui/error-codes/E0227.rs b/tests/ui/error-codes/E0227.rs index 4dd4da55fa3..bab6d8af476 100644 --- a/tests/ui/error-codes/E0227.rs +++ b/tests/ui/error-codes/E0227.rs @@ -6,8 +6,6 @@ trait FooBar<'foo, 'bar>: Foo<'foo> + Bar<'bar> {} struct Baz<'foo, 'bar> { baz: dyn FooBar<'foo, 'bar>, //~^ ERROR ambiguous lifetime bound, explicit lifetime bound required - //~| ERROR lifetime bound not satisfied } -fn main() { -} +fn main() {} diff --git a/tests/ui/error-codes/E0227.stderr b/tests/ui/error-codes/E0227.stderr index 6338034a022..c77a2e98af7 100644 --- a/tests/ui/error-codes/E0227.stderr +++ b/tests/ui/error-codes/E0227.stderr @@ -4,24 +4,6 @@ error[E0227]: ambiguous lifetime bound, explicit lifetime bound required LL | baz: dyn FooBar<'foo, 'bar>, | ^^^^^^^^^^^^^^^^^^^^^^ -error[E0478]: lifetime bound not satisfied - --> $DIR/E0227.rs:7:10 - | -LL | baz: dyn FooBar<'foo, 'bar>, - | ^^^^^^^^^^^^^^^^^^^^^^ - | -note: lifetime parameter instantiated with the lifetime `'bar` as defined here - --> $DIR/E0227.rs:6:18 - | -LL | struct Baz<'foo, 'bar> { - | ^^^^ -note: but lifetime parameter must outlive the lifetime `'foo` as defined here - --> $DIR/E0227.rs:6:12 - | -LL | struct Baz<'foo, 'bar> { - | ^^^^ +error: aborting due to 1 previous error -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0227, E0478. -For more information about an error, try `rustc --explain E0227`. +For more information about this error, try `rustc --explain E0227`. diff --git a/tests/ui/lifetimes/unusual-rib-combinations.rs b/tests/ui/lifetimes/unusual-rib-combinations.rs index 2f5ba98445b..a2461cff932 100644 --- a/tests/ui/lifetimes/unusual-rib-combinations.rs +++ b/tests/ui/lifetimes/unusual-rib-combinations.rs @@ -28,6 +28,5 @@ fn d() {} trait Foo<'a> {} struct Bar Foo<'a>)>; //~^ ERROR the type of const parameters must not depend on other generic parameters -//~| ERROR `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter fn main() {} diff --git a/tests/ui/lifetimes/unusual-rib-combinations.stderr b/tests/ui/lifetimes/unusual-rib-combinations.stderr index 92a2ef2f432..e3b70232ef8 100644 --- a/tests/ui/lifetimes/unusual-rib-combinations.stderr +++ b/tests/ui/lifetimes/unusual-rib-combinations.stderr @@ -58,16 +58,7 @@ LL | fn d() {} = note: the only supported types are integers, `bool` and `char` = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types -error: `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter - --> $DIR/unusual-rib-combinations.rs:29:21 - | -LL | struct Bar Foo<'a>)>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the only supported types are integers, `bool` and `char` - = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types - -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors Some errors have detailed explanations: E0106, E0214, E0308, E0770. For more information about an error, try `rustc --explain E0106`. From 4580f4ab3f098e8f2ff2050626440cba52894c12 Mon Sep 17 00:00:00 2001 From: klensy Date: Thu, 11 Jan 2024 14:59:59 +0300 Subject: [PATCH 22/26] rustfmt.toml: don't ignore just any `tests` path, only root one --- rustfmt.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rustfmt.toml b/rustfmt.toml index e292a310742..e6cc298ec44 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -13,7 +13,7 @@ ignore = [ # tests for now are not formatted, as they are sometimes pretty-printing constrained # (and generally rustfmt can move around comments in UI-testing incompatible ways) - "tests", + "/tests/", # do not format submodules # FIXME: sync submodule list with tidy/bootstrap/etc From aa696c5a228a2c9730227eb5a0e99fb9d85eb61d Mon Sep 17 00:00:00 2001 From: klensy Date: Thu, 11 Jan 2024 15:04:48 +0300 Subject: [PATCH 23/26] apply fmt --- .../rustc_errors/src/markdown/tests/term.rs | 5 ++- library/alloc/tests/autotraits.rs | 7 +--- library/alloc/tests/vec.rs | 10 ++--- library/core/tests/array.rs | 2 +- library/core/tests/cell.rs | 16 ++++---- library/core/tests/error.rs | 2 +- library/core/tests/fmt/mod.rs | 8 ++-- library/core/tests/hash/mod.rs | 6 ++- library/core/tests/iter/adapters/chain.rs | 15 +++++-- library/core/tests/iter/adapters/flatten.rs | 2 +- library/core/tests/iter/adapters/step_by.rs | 22 +++++----- library/core/tests/iter/adapters/take.rs | 5 ++- library/core/tests/iter/adapters/zip.rs | 2 +- library/core/tests/iter/traits/iterator.rs | 10 ++++- library/core/tests/net/ip_addr.rs | 6 ++- library/core/tests/option.rs | 40 +++++++++---------- library/core/tests/ptr.rs | 24 +++++++++-- library/core/tests/time.rs | 24 +++++------ library/std/tests/process_spawning.rs | 2 +- src/bootstrap/src/tests/config.rs | 9 +++-- src/bootstrap/src/tests/helpers.rs | 2 +- 21 files changed, 125 insertions(+), 94 deletions(-) diff --git a/compiler/rustc_errors/src/markdown/tests/term.rs b/compiler/rustc_errors/src/markdown/tests/term.rs index a0d956bf0cd..bab47dcc175 100644 --- a/compiler/rustc_errors/src/markdown/tests/term.rs +++ b/compiler/rustc_errors/src/markdown/tests/term.rs @@ -5,7 +5,8 @@ use termcolor::{BufferWriter, ColorChoice}; use super::*; const INPUT: &str = include_str!("input.md"); -const OUTPUT_PATH: &[&str] = &[env!("CARGO_MANIFEST_DIR"), "src","markdown","tests","output.stdout"]; +const OUTPUT_PATH: &[&str] = + &[env!("CARGO_MANIFEST_DIR"), "src", "markdown", "tests", "output.stdout"]; const TEST_WIDTH: usize = 80; @@ -34,7 +35,7 @@ quis dolor non venenatis. Aliquam ut. "; fn test_wrapping_write() { WIDTH.with(|w| w.set(TEST_WIDTH)); let mut buf = BufWriter::new(Vec::new()); - let txt = TXT.replace("-\n","-").replace("_\n","_").replace('\n', " ").replace(" ", ""); + let txt = TXT.replace("-\n", "-").replace("_\n", "_").replace('\n', " ").replace(" ", ""); write_wrapping(&mut buf, &txt, 0, None).unwrap(); write_wrapping(&mut buf, &txt, 4, None).unwrap(); write_wrapping( diff --git a/library/alloc/tests/autotraits.rs b/library/alloc/tests/autotraits.rs index ba5e28f7293..6b82deeac8a 100644 --- a/library/alloc/tests/autotraits.rs +++ b/library/alloc/tests/autotraits.rs @@ -55,12 +55,7 @@ fn test_btree_map() { require_send_sync(async { let _v = None::< - alloc::collections::btree_map::ExtractIf< - '_, - &u32, - &u32, - fn(&&u32, &mut &u32) -> bool, - >, + alloc::collections::btree_map::ExtractIf<'_, &u32, &u32, fn(&&u32, &mut &u32) -> bool>, >; async {}.await; }); diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 9ec6f6ae1ac..0f5e0d99eca 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1,7 +1,7 @@ use core::alloc::{Allocator, Layout}; -use core::{assert_eq, assert_ne}; use core::num::NonZeroUsize; use core::ptr::NonNull; +use core::{assert_eq, assert_ne}; use std::alloc::System; use std::assert_matches::assert_matches; use std::borrow::Cow; @@ -1212,7 +1212,7 @@ fn test_in_place_specialization_step_up_down() { assert_eq!(sink.len(), 2); let mut src: Vec<[u8; 3]> = Vec::with_capacity(17); - src.resize( 8, [0; 3]); + src.resize(8, [0; 3]); let iter = src.into_iter().map(|[a, b, _]| [a, b]); assert_in_place_trait(&iter); let sink: Vec<[u8; 2]> = iter.collect(); @@ -1221,11 +1221,7 @@ fn test_in_place_specialization_step_up_down() { let src = vec![[0u8; 4]; 256]; let srcptr = src.as_ptr(); - let iter = src - .into_iter() - .flat_map(|a| { - a.into_iter().map(|b| b.wrapping_add(1)) - }); + let iter = src.into_iter().flat_map(|a| a.into_iter().map(|b| b.wrapping_add(1))); assert_in_place_trait(&iter); let sink = iter.collect::>(); assert_eq!(srcptr as *const u8, sink.as_ptr()); diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs index b1c1456ade1..ed52de3cbec 100644 --- a/library/core/tests/array.rs +++ b/library/core/tests/array.rs @@ -1,6 +1,6 @@ -use core::{array, assert_eq}; use core::num::NonZeroUsize; use core::sync::atomic::{AtomicUsize, Ordering}; +use core::{array, assert_eq}; #[test] fn array_from_ref() { diff --git a/library/core/tests/cell.rs b/library/core/tests/cell.rs index 71b8eb29600..d6a401c2b4d 100644 --- a/library/core/tests/cell.rs +++ b/library/core/tests/cell.rs @@ -466,14 +466,14 @@ fn const_cells() { const CELL: Cell = Cell::new(3); const _: i32 = CELL.into_inner(); -/* FIXME(#110395) - const UNSAFE_CELL_FROM: UnsafeCell = UnsafeCell::from(3); - const _: i32 = UNSAFE_CELL.into_inner(); + /* FIXME(#110395) + const UNSAFE_CELL_FROM: UnsafeCell = UnsafeCell::from(3); + const _: i32 = UNSAFE_CELL.into_inner(); - const REF_CELL_FROM: RefCell = RefCell::from(3); - const _: i32 = REF_CELL.into_inner(); + const REF_CELL_FROM: RefCell = RefCell::from(3); + const _: i32 = REF_CELL.into_inner(); - const CELL_FROM: Cell = Cell::from(3); - const _: i32 = CELL.into_inner(); -*/ + const CELL_FROM: Cell = Cell::from(3); + const _: i32 = CELL.into_inner(); + */ } diff --git a/library/core/tests/error.rs b/library/core/tests/error.rs index cb7cb5441d1..5e20c34ca6c 100644 --- a/library/core/tests/error.rs +++ b/library/core/tests/error.rs @@ -1,4 +1,4 @@ -use core::error::{request_value, request_ref, Request}; +use core::error::{request_ref, request_value, Request}; // Test the `Request` API. #[derive(Debug)] diff --git a/library/core/tests/fmt/mod.rs b/library/core/tests/fmt/mod.rs index c1c80c46c78..704d2461399 100644 --- a/library/core/tests/fmt/mod.rs +++ b/library/core/tests/fmt/mod.rs @@ -22,11 +22,11 @@ fn test_pointer_formats_data_pointer() { #[test] fn test_estimated_capacity() { assert_eq!(format_args!("").estimated_capacity(), 0); - assert_eq!(format_args!("{}", {""}).estimated_capacity(), 0); + assert_eq!(format_args!("{}", { "" }).estimated_capacity(), 0); assert_eq!(format_args!("Hello").estimated_capacity(), 5); - assert_eq!(format_args!("Hello, {}!", {""}).estimated_capacity(), 16); - assert_eq!(format_args!("{}, hello!", {"World"}).estimated_capacity(), 0); - assert_eq!(format_args!("{}. 16-bytes piece", {"World"}).estimated_capacity(), 32); + assert_eq!(format_args!("Hello, {}!", { "" }).estimated_capacity(), 16); + assert_eq!(format_args!("{}, hello!", { "World" }).estimated_capacity(), 0); + assert_eq!(format_args!("{}. 16-bytes piece", { "World" }).estimated_capacity(), 32); } #[test] diff --git a/library/core/tests/hash/mod.rs b/library/core/tests/hash/mod.rs index addc255de4a..3b9351457a9 100644 --- a/library/core/tests/hash/mod.rs +++ b/library/core/tests/hash/mod.rs @@ -35,7 +35,8 @@ impl Hasher for MyHasher { #[test] fn test_writer_hasher() { // FIXME(#110395) - /* const */ fn hash(t: &T) -> u64 { + /* const */ + fn hash(t: &T) -> u64 { let mut s = MyHasher { hash: 0 }; t.hash(&mut s); s.finish() @@ -140,7 +141,8 @@ impl Hash for Custom { #[test] fn test_custom_state() { // FIXME(#110395) - /* const */ fn hash(t: &T) -> u64 { + /* const */ + fn hash(t: &T) -> u64 { let mut c = CustomHasher { output: 0 }; t.hash(&mut c); c.finish() diff --git a/library/core/tests/iter/adapters/chain.rs b/library/core/tests/iter/adapters/chain.rs index 175a1b638e1..ad78a85a88d 100644 --- a/library/core/tests/iter/adapters/chain.rs +++ b/library/core/tests/iter/adapters/chain.rs @@ -42,7 +42,10 @@ fn test_iterator_chain_advance_by() { let mut iter = Unfuse::new(xs).chain(Unfuse::new(ys)); assert_eq!(iter.advance_by(xs.len() + i), Ok(())); assert_eq!(iter.next(), Some(&ys[i])); - assert_eq!(iter.advance_by(100), Err(NonZeroUsize::new(100 - (ys.len() - i - 1)).unwrap())); + assert_eq!( + iter.advance_by(100), + Err(NonZeroUsize::new(100 - (ys.len() - i - 1)).unwrap()) + ); assert_eq!(iter.advance_by(0), Ok(())); } @@ -71,7 +74,10 @@ fn test_iterator_chain_advance_back_by() { let mut iter = Unfuse::new(xs).chain(Unfuse::new(ys)); assert_eq!(iter.advance_back_by(i), Ok(())); assert_eq!(iter.next_back(), Some(&ys[ys.len() - i - 1])); - assert_eq!(iter.advance_back_by(100), Err(NonZeroUsize::new(100 - (len - i - 1)).unwrap())); + assert_eq!( + iter.advance_back_by(100), + Err(NonZeroUsize::new(100 - (len - i - 1)).unwrap()) + ); assert_eq!(iter.advance_back_by(0), Ok(())); } @@ -79,7 +85,10 @@ fn test_iterator_chain_advance_back_by() { let mut iter = Unfuse::new(xs).chain(Unfuse::new(ys)); assert_eq!(iter.advance_back_by(ys.len() + i), Ok(())); assert_eq!(iter.next_back(), Some(&xs[xs.len() - i - 1])); - assert_eq!(iter.advance_back_by(100), Err(NonZeroUsize::new(100 - (xs.len() - i - 1)).unwrap())); + assert_eq!( + iter.advance_back_by(100), + Err(NonZeroUsize::new(100 - (xs.len() - i - 1)).unwrap()) + ); assert_eq!(iter.advance_back_by(0), Ok(())); } diff --git a/library/core/tests/iter/adapters/flatten.rs b/library/core/tests/iter/adapters/flatten.rs index 91809c9e5fd..f429d90cd7d 100644 --- a/library/core/tests/iter/adapters/flatten.rs +++ b/library/core/tests/iter/adapters/flatten.rs @@ -1,5 +1,5 @@ -use core::assert_eq; use super::*; +use core::assert_eq; use core::iter::*; use core::num::NonZeroUsize; diff --git a/library/core/tests/iter/adapters/step_by.rs b/library/core/tests/iter/adapters/step_by.rs index 4c5b1dd9a6b..70c9906163a 100644 --- a/library/core/tests/iter/adapters/step_by.rs +++ b/library/core/tests/iter/adapters/step_by.rs @@ -245,7 +245,6 @@ fn test_step_by_skip() { assert_eq!((200..=255u8).step_by(10).nth(3), Some(230)); } - struct DeOpt(I); impl Iterator for DeOpt { @@ -265,17 +264,15 @@ impl DoubleEndedIterator for DeOpt { #[test] fn test_step_by_fold_range_specialization() { macro_rules! t { - ($range:expr, $var: ident, $body:tt) => { - { - // run the same tests for the non-optimized version - let mut $var = DeOpt($range); - $body - } - { - let mut $var = $range; - $body - } + ($range:expr, $var: ident, $body:tt) => {{ + // run the same tests for the non-optimized version + let mut $var = DeOpt($range); + $body } + { + let mut $var = $range; + $body + }}; } t!((1usize..5).step_by(1), r, { @@ -288,13 +285,12 @@ fn test_step_by_fold_range_specialization() { assert_eq!(r.sum::(), 2); }); - t!((0usize..5).step_by(2), r, { assert_eq!(r.next(), Some(0)); assert_eq!(r.sum::(), 6); }); - t!((usize::MAX - 6 .. usize::MAX).step_by(5), r, { + t!((usize::MAX - 6..usize::MAX).step_by(5), r, { assert_eq!(r.next(), Some(usize::MAX - 6)); assert_eq!(r.sum::(), usize::MAX - 1); }); diff --git a/library/core/tests/iter/adapters/take.rs b/library/core/tests/iter/adapters/take.rs index 3cad47c06de..ff6e362b065 100644 --- a/library/core/tests/iter/adapters/take.rs +++ b/library/core/tests/iter/adapters/take.rs @@ -93,7 +93,10 @@ fn test_take_advance_by() { assert_eq!((0..2).take(1).advance_back_by(10), Err(NonZeroUsize::new(9).unwrap())); assert_eq!((0..0).take(1).advance_back_by(1), Err(NonZeroUsize::new(1).unwrap())); assert_eq!((0..0).take(1).advance_back_by(0), Ok(())); - assert_eq!((0..usize::MAX).take(100).advance_back_by(usize::MAX), Err(NonZeroUsize::new(usize::MAX - 100).unwrap())); + assert_eq!( + (0..usize::MAX).take(100).advance_back_by(usize::MAX), + Err(NonZeroUsize::new(usize::MAX - 100).unwrap()) + ); } #[test] diff --git a/library/core/tests/iter/adapters/zip.rs b/library/core/tests/iter/adapters/zip.rs index c3508be8598..ba54de5822b 100644 --- a/library/core/tests/iter/adapters/zip.rs +++ b/library/core/tests/iter/adapters/zip.rs @@ -184,7 +184,7 @@ fn test_zip_nested_sideffectful() { let it = xs.iter_mut().map(|x| *x = 1).enumerate().zip(&ys); it.count(); } - let length_aware = &xs == &[1, 1, 1, 1, 0, 0]; + let length_aware = &xs == &[1, 1, 1, 1, 0, 0]; let probe_first = &xs == &[1, 1, 1, 1, 1, 0]; // either implementation is valid according to zip documentation diff --git a/library/core/tests/iter/traits/iterator.rs b/library/core/tests/iter/traits/iterator.rs index 995bbf0e261..9c1dce7b66d 100644 --- a/library/core/tests/iter/traits/iterator.rs +++ b/library/core/tests/iter/traits/iterator.rs @@ -168,7 +168,10 @@ fn test_iterator_advance_back_by() { let mut iter = v.iter(); assert_eq!(iter.advance_back_by(i), Ok(())); assert_eq!(iter.next_back().unwrap(), &v[v.len() - 1 - i]); - assert_eq!(iter.advance_back_by(100), Err(NonZeroUsize::new(100 - (v.len() - 1 - i)).unwrap())); + assert_eq!( + iter.advance_back_by(100), + Err(NonZeroUsize::new(100 - (v.len() - 1 - i)).unwrap()) + ); } assert_eq!(v.iter().advance_back_by(v.len()), Ok(())); @@ -183,7 +186,10 @@ fn test_iterator_rev_advance_back_by() { let mut iter = v.iter().rev(); assert_eq!(iter.advance_back_by(i), Ok(())); assert_eq!(iter.next_back().unwrap(), &v[i]); - assert_eq!(iter.advance_back_by(100), Err(NonZeroUsize::new(100 - (v.len() - 1 - i)).unwrap())); + assert_eq!( + iter.advance_back_by(100), + Err(NonZeroUsize::new(100 - (v.len() - 1 - i)).unwrap()) + ); } assert_eq!(v.iter().rev().advance_back_by(v.len()), Ok(())); diff --git a/library/core/tests/net/ip_addr.rs b/library/core/tests/net/ip_addr.rs index 7f7802c221a..3d13bffba92 100644 --- a/library/core/tests/net/ip_addr.rs +++ b/library/core/tests/net/ip_addr.rs @@ -664,7 +664,11 @@ fn ipv6_properties() { &[0x20, 1, 0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], global | unicast_global ); - check!("2001:30::", &[0x20, 1, 0, 0x30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], global | unicast_global); + check!( + "2001:30::", + &[0x20, 1, 0, 0x30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + global | unicast_global + ); check!("2001:40::", &[0x20, 1, 0, 0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], unicast_global); check!( diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs index 00a308b29d2..b1b9492f182 100644 --- a/library/core/tests/option.rs +++ b/library/core/tests/option.rs @@ -178,19 +178,19 @@ fn test_or_else() { assert_eq!(x.or_else(two), Some(2)); assert_eq!(x.or_else(none), None); -/* FIXME(#110395) - const FOO: Option = Some(1); - const A: Option = FOO.or_else(two); - const B: Option = FOO.or_else(none); - assert_eq!(A, Some(1)); - assert_eq!(B, Some(1)); + /* FIXME(#110395) + const FOO: Option = Some(1); + const A: Option = FOO.or_else(two); + const B: Option = FOO.or_else(none); + assert_eq!(A, Some(1)); + assert_eq!(B, Some(1)); - const BAR: Option = None; - const C: Option = BAR.or_else(two); - const D: Option = BAR.or_else(none); - assert_eq!(C, Some(2)); - assert_eq!(D, None); -*/ + const BAR: Option = None; + const C: Option = BAR.or_else(two); + const D: Option = BAR.or_else(none); + assert_eq!(C, Some(2)); + assert_eq!(D, None); + */ } #[test] @@ -486,15 +486,15 @@ const fn option_const_mut() { None => unreachable!(), } } -/* FIXME(const-hack) - { - let as_mut: Option<&mut usize> = Option::from(&mut option); - match as_mut { - Some(v) => *v = 42, - None => unreachable!(), + /* FIXME(const-hack) + { + let as_mut: Option<&mut usize> = Option::from(&mut option); + match as_mut { + Some(v) => *v = 42, + None => unreachable!(), + } } - } -*/ + */ } #[test] diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 238f29c5980..b68f2a50b32 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -478,7 +478,11 @@ fn align_offset_various_strides() { x |= test_stride::(ptr::invalid::(ptr), align); #[repr(packed)] - struct A10(#[allow(dead_code)] u32, #[allow(dead_code)] u32, #[allow(dead_code)] u16); + struct A10( + #[allow(dead_code)] u32, + #[allow(dead_code)] u32, + #[allow(dead_code)] u16, + ); x |= test_stride::(ptr::invalid::(ptr), align); x |= test_stride::(ptr::invalid::(ptr), align); @@ -532,7 +536,11 @@ fn align_offset_various_strides_const() { test_stride::(ptr::invalid::(ptr), ptr, align); #[repr(packed)] - struct A7(#[allow(dead_code)] u32, #[allow(dead_code)] u16, #[allow(dead_code)] u8); + struct A7( + #[allow(dead_code)] u32, + #[allow(dead_code)] u16, + #[allow(dead_code)] u8, + ); test_stride::(ptr::invalid::(ptr), ptr, align); #[repr(packed)] @@ -540,11 +548,19 @@ fn align_offset_various_strides_const() { test_stride::(ptr::invalid::(ptr), ptr, align); #[repr(packed)] - struct A9(#[allow(dead_code)] u32, #[allow(dead_code)] u32, #[allow(dead_code)] u8); + struct A9( + #[allow(dead_code)] u32, + #[allow(dead_code)] u32, + #[allow(dead_code)] u8, + ); test_stride::(ptr::invalid::(ptr), ptr, align); #[repr(packed)] - struct A10(#[allow(dead_code)] u32, #[allow(dead_code)] u32, #[allow(dead_code)] u16); + struct A10( + #[allow(dead_code)] u32, + #[allow(dead_code)] u32, + #[allow(dead_code)] u16, + ); test_stride::(ptr::invalid::(ptr), ptr, align); test_stride::(ptr::invalid::(ptr), ptr, align); diff --git a/library/core/tests/time.rs b/library/core/tests/time.rs index 24ab4be9d8c..23f07bf84b3 100644 --- a/library/core/tests/time.rs +++ b/library/core/tests/time.rs @@ -479,22 +479,22 @@ fn duration_const() { const CHECKED_MUL: Option = Duration::SECOND.checked_mul(1); assert_eq!(CHECKED_MUL, Some(Duration::SECOND)); -/* FIXME(#110395) - const MUL_F32: Duration = Duration::SECOND.mul_f32(1.0); - assert_eq!(MUL_F32, Duration::SECOND); + /* FIXME(#110395) + const MUL_F32: Duration = Duration::SECOND.mul_f32(1.0); + assert_eq!(MUL_F32, Duration::SECOND); - const MUL_F64: Duration = Duration::SECOND.mul_f64(1.0); - assert_eq!(MUL_F64, Duration::SECOND); + const MUL_F64: Duration = Duration::SECOND.mul_f64(1.0); + assert_eq!(MUL_F64, Duration::SECOND); - const CHECKED_DIV: Option = Duration::SECOND.checked_div(1); - assert_eq!(CHECKED_DIV, Some(Duration::SECOND)); + const CHECKED_DIV: Option = Duration::SECOND.checked_div(1); + assert_eq!(CHECKED_DIV, Some(Duration::SECOND)); - const DIV_F32: Duration = Duration::SECOND.div_f32(1.0); - assert_eq!(DIV_F32, Duration::SECOND); + const DIV_F32: Duration = Duration::SECOND.div_f32(1.0); + assert_eq!(DIV_F32, Duration::SECOND); - const DIV_F64: Duration = Duration::SECOND.div_f64(1.0); - assert_eq!(DIV_F64, Duration::SECOND); -*/ + const DIV_F64: Duration = Duration::SECOND.div_f64(1.0); + assert_eq!(DIV_F64, Duration::SECOND); + */ const DIV_DURATION_F32: f32 = Duration::SECOND.div_duration_f32(Duration::SECOND); assert_eq!(DIV_DURATION_F32, 1.0); diff --git a/library/std/tests/process_spawning.rs b/library/std/tests/process_spawning.rs index 46dc9ff00bd..59f67f9901f 100644 --- a/library/std/tests/process_spawning.rs +++ b/library/std/tests/process_spawning.rs @@ -1,4 +1,4 @@ -#![cfg(not(target_env="sgx"))] +#![cfg(not(target_env = "sgx"))] use std::env; use std::fs; diff --git a/src/bootstrap/src/tests/config.rs b/src/bootstrap/src/tests/config.rs index 6f432343882..c65067f8e8f 100644 --- a/src/bootstrap/src/tests/config.rs +++ b/src/bootstrap/src/tests/config.rs @@ -32,9 +32,12 @@ fn download_ci_llvm() { assert_eq!(parse_llvm("rust.channel = \"dev\""), if_unchanged); assert!(!parse_llvm("rust.channel = \"stable\"")); assert_eq!(parse_llvm("build.build = \"x86_64-unknown-linux-gnu\""), if_unchanged); - assert_eq!(parse_llvm( - "llvm.assertions = true \r\n build.build = \"x86_64-unknown-linux-gnu\" \r\n llvm.download-ci-llvm = \"if-unchanged\"" - ), if_unchanged); + assert_eq!( + parse_llvm( + "llvm.assertions = true \r\n build.build = \"x86_64-unknown-linux-gnu\" \r\n llvm.download-ci-llvm = \"if-unchanged\"" + ), + if_unchanged + ); assert!(!parse_llvm( "llvm.assertions = true \r\n build.build = \"aarch64-apple-darwin\" \r\n llvm.download-ci-llvm = \"if-unchanged\"" )); diff --git a/src/bootstrap/src/tests/helpers.rs b/src/bootstrap/src/tests/helpers.rs index 163594dbb2f..2d626fad417 100644 --- a/src/bootstrap/src/tests/helpers.rs +++ b/src/bootstrap/src/tests/helpers.rs @@ -1,4 +1,4 @@ -use crate::utils::helpers::{extract_beta_rev, hex_encode, make, check_cfg_arg}; +use crate::utils::helpers::{check_cfg_arg, extract_beta_rev, hex_encode, make}; use std::path::PathBuf; #[test] From 6b6f2a5a28ddd9031f6ac2104c7d2853e65c480e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 11 Jan 2024 09:03:33 +0100 Subject: [PATCH 24/26] rint: further doc tweaks --- library/core/src/intrinsics.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 3df3e8ea05c..5d917dc6fbb 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1787,8 +1787,9 @@ extern "rust-intrinsic" { /// so this rounds half-way cases to the number with an even least significant digit. /// /// May raise an inexact floating-point exception if the argument is not an integer. - /// However, Rust assumes floating-point exceptions cannot be observed, so this is not something that - /// can actually be used from Rust code. + /// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions + /// cannot actually be utilized from Rust code. + /// In other words, this intrinsic is equivalent in behavior to `nearbyintf32` and `roundevenf32`. /// /// The stabilized version of this intrinsic is /// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even) @@ -1798,8 +1799,9 @@ extern "rust-intrinsic" { /// so this rounds half-way cases to the number with an even least significant digit. /// /// May raise an inexact floating-point exception if the argument is not an integer. - /// However, Rust assumes floating-point exceptions cannot be observed, so this is not something that - /// can actually be used from Rust code. + /// However, Rust assumes floating-point exceptions cannot be observed, so these exceptions + /// cannot actually be utilized from Rust code. + /// In other words, this intrinsic is equivalent in behavior to `nearbyintf64` and `roundevenf64`. /// /// The stabilized version of this intrinsic is /// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even) From 90cc8ba4bc59e1034e275b67553d1b9cc9249798 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Thu, 11 Jan 2024 21:39:44 +0800 Subject: [PATCH 25/26] fix: update broken stderr Signed-off-by: hi-rustin --- tests/ui/hygiene/panic-location.run.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/hygiene/panic-location.run.stderr b/tests/ui/hygiene/panic-location.run.stderr index 5c552411da7..5824ef31211 100644 --- a/tests/ui/hygiene/panic-location.run.stderr +++ b/tests/ui/hygiene/panic-location.run.stderr @@ -1,3 +1,3 @@ -thread 'main' panicked at library/alloc/src/raw_vec.rs:571:5: +thread 'main' panicked at library/alloc/src/raw_vec.rs:570:5: capacity overflow note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace From db860566bc09bab45d7ef5ea3a70ab11c03b788d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 11 Jan 2024 14:57:12 +0100 Subject: [PATCH 26/26] give const-err4 a more descriptive name --- .../{const-err4.rs => const-err-enum-discriminant.rs} | 1 - ...4.32bit.stderr => const-err-enum-discriminant.stderr} | 2 +- tests/ui/consts/const-err4.64bit.stderr | 9 --------- 3 files changed, 1 insertion(+), 11 deletions(-) rename tests/ui/consts/{const-err4.rs => const-err-enum-discriminant.rs} (91%) rename tests/ui/consts/{const-err4.32bit.stderr => const-err-enum-discriminant.stderr} (87%) delete mode 100644 tests/ui/consts/const-err4.64bit.stderr diff --git a/tests/ui/consts/const-err4.rs b/tests/ui/consts/const-err-enum-discriminant.rs similarity index 91% rename from tests/ui/consts/const-err4.rs rename to tests/ui/consts/const-err-enum-discriminant.rs index 107dc3f8234..ebb3e551ba8 100644 --- a/tests/ui/consts/const-err4.rs +++ b/tests/ui/consts/const-err-enum-discriminant.rs @@ -1,4 +1,3 @@ -// stderr-per-bitwidth #[derive(Copy, Clone)] union Foo { a: isize, diff --git a/tests/ui/consts/const-err4.32bit.stderr b/tests/ui/consts/const-err-enum-discriminant.stderr similarity index 87% rename from tests/ui/consts/const-err4.32bit.stderr rename to tests/ui/consts/const-err-enum-discriminant.stderr index 582a848ca60..7cf34595dc9 100644 --- a/tests/ui/consts/const-err4.32bit.stderr +++ b/tests/ui/consts/const-err-enum-discriminant.stderr @@ -1,5 +1,5 @@ error[E0080]: evaluation of constant value failed - --> $DIR/const-err4.rs:9:21 + --> $DIR/const-err-enum-discriminant.rs:8:21 | LL | Boo = [unsafe { Foo { b: () }.a }; 4][3], | ^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory diff --git a/tests/ui/consts/const-err4.64bit.stderr b/tests/ui/consts/const-err4.64bit.stderr deleted file mode 100644 index 582a848ca60..00000000000 --- a/tests/ui/consts/const-err4.64bit.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0080]: evaluation of constant value failed - --> $DIR/const-err4.rs:9:21 - | -LL | Boo = [unsafe { Foo { b: () }.a }; 4][3], - | ^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0080`.