Skip to content

Commit 62d7ed4

Browse files
committed
Auto merge of #119864 - matthiaskrgr:rollup-mc2qz13, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #119448 (annotate-snippets: update to 0.10) - #119813 (Silence some follow-up errors [2/x]) - #119836 (chore: remove unnecessary blank line) - #119841 (Remove `DiagnosticBuilder::buffer`) - #119842 (coverage: Add enums to accommodate other kinds of coverage mappings) - #119845 (rint: further doc tweaks) - #119852 (give const-err4 a more descriptive name) - #119853 (rustfmt.toml: don't ignore just any tests path, only root one) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4d31ed4 + b3d15eb commit 62d7ed4

File tree

98 files changed

+500
-634
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+500
-634
lines changed

Cargo.lock

+16-6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ dependencies = [
119119
"yansi-term",
120120
]
121121

122+
[[package]]
123+
name = "annotate-snippets"
124+
version = "0.10.1"
125+
source = "registry+https://github.com/rust-lang/crates.io-index"
126+
checksum = "0a433302f833baa830c0092100c481c7ea768c5981a3c36f549517a502f246dd"
127+
dependencies = [
128+
"anstyle",
129+
"unicode-width",
130+
]
131+
122132
[[package]]
123133
name = "ansi_term"
124134
version = "0.12.1"
@@ -3771,7 +3781,7 @@ dependencies = [
37713781
name = "rustc_errors"
37723782
version = "0.0.0"
37733783
dependencies = [
3774-
"annotate-snippets",
3784+
"annotate-snippets 0.10.1",
37753785
"derive_setters",
37763786
"rustc_ast",
37773787
"rustc_ast_pretty",
@@ -3831,7 +3841,7 @@ dependencies = [
38313841
name = "rustc_fluent_macro"
38323842
version = "0.0.0"
38333843
dependencies = [
3834-
"annotate-snippets",
3844+
"annotate-snippets 0.10.1",
38353845
"fluent-bundle",
38363846
"fluent-syntax",
38373847
"proc-macro2",
@@ -4738,7 +4748,7 @@ dependencies = [
47384748
name = "rustfmt-nightly"
47394749
version = "1.7.0"
47404750
dependencies = [
4741-
"annotate-snippets",
4751+
"annotate-snippets 0.9.1",
47424752
"anyhow",
47434753
"bytecount",
47444754
"cargo_metadata 0.15.4",
@@ -5728,7 +5738,7 @@ version = "0.21.2"
57285738
source = "registry+https://github.com/rust-lang/crates.io-index"
57295739
checksum = "aaf4bf7c184b8dfc7a4d3b90df789b1eb992ee42811cd115f32a7a1eb781058d"
57305740
dependencies = [
5731-
"annotate-snippets",
5741+
"annotate-snippets 0.9.1",
57325742
"anyhow",
57335743
"bstr",
57345744
"cargo-platform",
@@ -5859,9 +5869,9 @@ checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
58595869

58605870
[[package]]
58615871
name = "unicode-width"
5862-
version = "0.1.10"
5872+
version = "0.1.11"
58635873
source = "registry+https://github.com/rust-lang/crates.io-index"
5864-
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
5874+
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
58655875
dependencies = [
58665876
"compiler_builtins",
58675877
"rustc-std-workspace-core",

compiler/rustc_borrowck/src/lib.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -2399,18 +2399,19 @@ mod error {
23992399
/// and we want only the best of those errors.
24002400
///
24012401
/// The `report_use_of_moved_or_uninitialized` function checks this map and replaces the
2402-
/// diagnostic (if there is one) if the `Place` of the error being reported is a prefix of the
2403-
/// `Place` of the previous most diagnostic. This happens instead of buffering the error. Once
2404-
/// all move errors have been reported, any diagnostics in this map are added to the buffer
2405-
/// to be emitted.
2402+
/// diagnostic (if there is one) if the `Place` of the error being reported is a prefix of
2403+
/// the `Place` of the previous most diagnostic. This happens instead of buffering the
2404+
/// error. Once all move errors have been reported, any diagnostics in this map are added
2405+
/// to the buffer to be emitted.
24062406
///
24072407
/// `BTreeMap` is used to preserve the order of insertions when iterating. This is necessary
24082408
/// when errors in the map are being re-added to the error buffer so that errors with the
24092409
/// same primary span come out in a consistent order.
24102410
buffered_move_errors:
24112411
BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)>,
24122412
buffered_mut_errors: FxIndexMap<Span, (DiagnosticBuilder<'tcx>, usize)>,
2413-
/// Diagnostics to be reported buffer.
2413+
/// Buffer of diagnostics to be reported. Uses `Diagnostic` rather than `DiagnosticBuilder`
2414+
/// because it has a mixture of error diagnostics and non-error diagnostics.
24142415
buffered: Vec<Diagnostic>,
24152416
/// Set to Some if we emit an error during borrowck
24162417
tainted_by_errors: Option<ErrorGuaranteed>,
@@ -2434,11 +2435,11 @@ mod error {
24342435
"diagnostic buffered but not emitted",
24352436
))
24362437
}
2437-
t.buffer(&mut self.buffered);
2438+
self.buffered.push(t.into_diagnostic());
24382439
}
24392440

24402441
pub fn buffer_non_error_diag(&mut self, t: DiagnosticBuilder<'_, ()>) {
2441-
t.buffer(&mut self.buffered);
2442+
self.buffered.push(t.into_diagnostic());
24422443
}
24432444

24442445
pub fn set_tainted_by_errors(&mut self, e: ErrorGuaranteed) {
@@ -2486,13 +2487,13 @@ mod error {
24862487
// Buffer any move errors that we collected and de-duplicated.
24872488
for (_, (_, diag)) in std::mem::take(&mut self.errors.buffered_move_errors) {
24882489
// We have already set tainted for this error, so just buffer it.
2489-
diag.buffer(&mut self.errors.buffered);
2490+
self.errors.buffered.push(diag.into_diagnostic());
24902491
}
24912492
for (_, (mut diag, count)) in std::mem::take(&mut self.errors.buffered_mut_errors) {
24922493
if count > 10 {
24932494
diag.note(format!("...and {} other attempted mutable borrows", count - 10));
24942495
}
2495-
diag.buffer(&mut self.errors.buffered);
2496+
self.errors.buffered.push(diag.into_diagnostic());
24962497
}
24972498

24982499
if !self.errors.buffered.is_empty() {

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_middle::mir::coverage::{CounterId, CovTerm, ExpressionId};
1+
use rustc_middle::mir::coverage::{CodeRegion, CounterId, CovTerm, ExpressionId, MappingKind};
22

33
/// Must match the layout of `LLVMRustCounterKind`.
44
#[derive(Copy, Clone, Debug)]
@@ -149,6 +149,24 @@ pub struct CounterMappingRegion {
149149
}
150150

151151
impl CounterMappingRegion {
152+
pub(crate) fn from_mapping(
153+
mapping_kind: &MappingKind,
154+
local_file_id: u32,
155+
code_region: &CodeRegion,
156+
) -> Self {
157+
let &CodeRegion { file_name: _, start_line, start_col, end_line, end_col } = code_region;
158+
match *mapping_kind {
159+
MappingKind::Code(term) => Self::code_region(
160+
Counter::from_term(term),
161+
local_file_id,
162+
start_line,
163+
start_col,
164+
end_line,
165+
end_col,
166+
),
167+
}
168+
}
169+
152170
pub(crate) fn code_region(
153171
counter: Counter,
154172
file_id: u32,

compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use rustc_data_structures::captures::Captures;
44
use rustc_data_structures::fx::FxIndexSet;
55
use rustc_index::bit_set::BitSet;
66
use rustc_middle::mir::coverage::{
7-
CodeRegion, CounterId, CovTerm, Expression, ExpressionId, FunctionCoverageInfo, Mapping, Op,
7+
CodeRegion, CounterId, CovTerm, Expression, ExpressionId, FunctionCoverageInfo, Mapping,
8+
MappingKind, Op,
89
};
910
use rustc_middle::ty::Instance;
1011
use rustc_span::Symbol;
@@ -64,8 +65,8 @@ impl<'tcx> FunctionCoverageCollector<'tcx> {
6465
// For each expression ID that is directly used by one or more mappings,
6566
// mark it as not-yet-seen. This indicates that we expect to see a
6667
// corresponding `ExpressionUsed` statement during MIR traversal.
67-
for Mapping { term, .. } in &function_coverage_info.mappings {
68-
if let &CovTerm::Expression(id) = term {
68+
for term in function_coverage_info.mappings.iter().flat_map(|m| m.kind.terms()) {
69+
if let CovTerm::Expression(id) = term {
6970
expressions_seen.remove(id);
7071
}
7172
}
@@ -221,20 +222,21 @@ impl<'tcx> FunctionCoverage<'tcx> {
221222
/// that will be used by `mapgen` when preparing for FFI.
222223
pub(crate) fn counter_regions(
223224
&self,
224-
) -> impl Iterator<Item = (Counter, &CodeRegion)> + ExactSizeIterator {
225+
) -> impl Iterator<Item = (MappingKind, &CodeRegion)> + ExactSizeIterator {
225226
self.function_coverage_info.mappings.iter().map(move |mapping| {
226-
let &Mapping { term, ref code_region } = mapping;
227-
let counter = self.counter_for_term(term);
228-
(counter, code_region)
227+
let Mapping { kind, code_region } = mapping;
228+
let kind =
229+
kind.map_terms(|term| if self.is_zero_term(term) { CovTerm::Zero } else { term });
230+
(kind, code_region)
229231
})
230232
}
231233

232234
fn counter_for_term(&self, term: CovTerm) -> Counter {
233-
if is_zero_term(&self.counters_seen, &self.zero_expressions, term) {
234-
Counter::ZERO
235-
} else {
236-
Counter::from_term(term)
237-
}
235+
if self.is_zero_term(term) { Counter::ZERO } else { Counter::from_term(term) }
236+
}
237+
238+
fn is_zero_term(&self, term: CovTerm) -> bool {
239+
is_zero_term(&self.counters_seen, &self.zero_expressions, term)
238240
}
239241
}
240242

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc_hir::def_id::DefId;
1212
use rustc_index::IndexVec;
1313
use rustc_middle::bug;
1414
use rustc_middle::mir;
15-
use rustc_middle::mir::coverage::CodeRegion;
1615
use rustc_middle::ty::{self, TyCtxt};
1716
use rustc_span::def_id::DefIdSet;
1817
use rustc_span::Symbol;
@@ -237,7 +236,7 @@ fn encode_mappings_for_function(
237236
// Prepare file IDs for each filename, and prepare the mapping data so that
238237
// we can pass it through FFI to LLVM.
239238
for (file_name, counter_regions_for_file) in
240-
&counter_regions.group_by(|(_counter, region)| region.file_name)
239+
&counter_regions.group_by(|(_, region)| region.file_name)
241240
{
242241
// Look up the global file ID for this filename.
243242
let global_file_id = global_file_table.global_file_id_for_file_name(file_name);
@@ -248,17 +247,12 @@ fn encode_mappings_for_function(
248247

249248
// For each counter/region pair in this function+file, convert it to a
250249
// form suitable for FFI.
251-
for (counter, region) in counter_regions_for_file {
252-
let CodeRegion { file_name: _, start_line, start_col, end_line, end_col } = *region;
253-
254-
debug!("Adding counter {counter:?} to map for {region:?}");
255-
mapping_regions.push(CounterMappingRegion::code_region(
256-
counter,
250+
for (mapping_kind, region) in counter_regions_for_file {
251+
debug!("Adding counter {mapping_kind:?} to map for {region:?}");
252+
mapping_regions.push(CounterMappingRegion::from_mapping(
253+
&mapping_kind,
257254
local_file_id.as_u32(),
258-
start_line,
259-
start_col,
260-
end_line,
261-
end_col,
255+
region,
262256
));
263257
}
264258
}

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations.
22
3-
use rustc_errors::{Diagnostic, ErrorGuaranteed};
3+
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
44
use rustc_hir as hir;
55
use rustc_hir::def_id::DefId;
66
use rustc_index::bit_set::BitSet;
@@ -214,7 +214,7 @@ pub struct Checker<'mir, 'tcx> {
214214
local_has_storage_dead: Option<BitSet<Local>>,
215215

216216
error_emitted: Option<ErrorGuaranteed>,
217-
secondary_errors: Vec<Diagnostic>,
217+
secondary_errors: Vec<DiagnosticBuilder<'tcx>>,
218218
}
219219

220220
impl<'mir, 'tcx> Deref for Checker<'mir, 'tcx> {
@@ -272,14 +272,17 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
272272
}
273273

274274
// If we got through const-checking without emitting any "primary" errors, emit any
275-
// "secondary" errors if they occurred.
275+
// "secondary" errors if they occurred. Otherwise, cancel the "secondary" errors.
276276
let secondary_errors = mem::take(&mut self.secondary_errors);
277277
if self.error_emitted.is_none() {
278278
for error in secondary_errors {
279-
self.tcx.dcx().emit_diagnostic(error);
279+
error.emit();
280280
}
281281
} else {
282282
assert!(self.tcx.dcx().has_errors().is_some());
283+
for error in secondary_errors {
284+
error.cancel();
285+
}
283286
}
284287
}
285288

@@ -347,7 +350,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
347350
self.error_emitted = Some(reported);
348351
}
349352

350-
ops::DiagnosticImportance::Secondary => err.buffer(&mut self.secondary_errors),
353+
ops::DiagnosticImportance::Secondary => self.secondary_errors.push(err),
351354
}
352355
}
353356

compiler/rustc_errors/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
annotate-snippets = "0.9"
8+
annotate-snippets = "0.10"
99
derive_setters = "0.1.6"
1010
rustc_ast = { path = "../rustc_ast" }
1111
rustc_ast_pretty = { path = "../rustc_ast_pretty" }

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use crate::{
1212
CodeSuggestion, Diagnostic, DiagnosticId, DiagnosticMessage, Emitter, FluentBundle,
1313
LazyFallbackBundle, Level, MultiSpan, Style, SubDiagnostic,
1414
};
15-
use annotate_snippets::display_list::{DisplayList, FormatOptions};
16-
use annotate_snippets::snippet::*;
15+
use annotate_snippets::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
1716
use rustc_data_structures::sync::Lrc;
1817
use rustc_error_messages::FluentArgs;
1918
use rustc_span::source_map::SourceMap;
@@ -190,11 +189,6 @@ impl AnnotateSnippetEmitter {
190189
annotation_type: annotation_type_for_level(*level),
191190
}),
192191
footer: vec![],
193-
opt: FormatOptions {
194-
color: true,
195-
anonymized_line_numbers: self.ui_testing,
196-
margin: None,
197-
},
198192
slices: annotated_files
199193
.iter()
200194
.map(|(file_name, source, line_index, annotations)| {
@@ -222,7 +216,8 @@ impl AnnotateSnippetEmitter {
222216
// FIXME(#59346): Figure out if we can _always_ print to stderr or not.
223217
// `emitter.rs` has the `Destination` enum that lists various possible output
224218
// destinations.
225-
eprintln!("{}", DisplayList::from(snippet))
219+
let renderer = Renderer::plain().anonymized_line_numbers(self.ui_testing);
220+
eprintln!("{}", renderer.render(snippet))
226221
}
227222
// FIXME(#59346): Is it ok to return None if there's no source_map?
228223
}

compiler/rustc_errors/src/diagnostic_builder.rs

+4-26
Original file line numberDiff line numberDiff line change
@@ -255,35 +255,13 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
255255
/// Stashes diagnostic for possible later improvement in a different,
256256
/// later stage of the compiler. The diagnostic can be accessed with
257257
/// the provided `span` and `key` through [`DiagCtxt::steal_diagnostic()`].
258-
///
259-
/// As with `buffer`, this is unless the dcx has disabled such buffering.
260258
pub fn stash(self, span: Span, key: StashKey) {
261-
if let Some((diag, dcx)) = self.into_diagnostic() {
262-
dcx.stash_diagnostic(span, key, diag);
263-
}
264-
}
265-
266-
/// Converts the builder to a `Diagnostic` for later emission,
267-
/// unless dcx has disabled such buffering.
268-
fn into_diagnostic(mut self) -> Option<(Diagnostic, &'a DiagCtxt)> {
269-
if self.dcx.inner.lock().flags.treat_err_as_bug.is_some() {
270-
self.emit();
271-
return None;
272-
}
273-
274-
let diag = self.take_diag();
275-
276-
// Logging here is useful to help track down where in logs an error was
277-
// actually emitted.
278-
debug!("buffer: diag={:?}", diag);
279-
280-
Some((diag, self.dcx))
259+
self.dcx.stash_diagnostic(span, key, self.into_diagnostic());
281260
}
282261

283-
/// Buffers the diagnostic for later emission,
284-
/// unless dcx has disabled such buffering.
285-
pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>) {
286-
buffered_diagnostics.extend(self.into_diagnostic().map(|(diag, _)| diag));
262+
/// Converts the builder to a `Diagnostic` for later emission.
263+
pub fn into_diagnostic(mut self) -> Diagnostic {
264+
self.take_diag()
287265
}
288266

289267
/// Delay emission of this diagnostic as a bug.

0 commit comments

Comments
 (0)