Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #119864

Merged
merged 34 commits into from
Jan 11, 2024
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5b153b5
annotate-snippets: update to 0.10
klensy Dec 30, 2023
46cf55a
tidy: add\remove deps
klensy Dec 30, 2023
784b50c
chore: remove unnecessary blank line
Rustin170506 Jan 11, 2024
8f98b54
coverage: Extract helper function `term_for_bcb`
Zalathar Jan 3, 2024
c593218
coverage: Store extracted spans as a flat list of mappings
Zalathar Jan 3, 2024
124fff0
coverage: Add enums to accommodate other kinds of coverage mappings
Zalathar Dec 28, 2023
f0a3684
Inline and remove `DiagCtxtInner::bump_{lint_err,err}_count`.
nnethercote Jan 10, 2024
2aac288
Use the right level with `-Ztreat-err-as-bug`.
nnethercote Jan 10, 2024
a0f5431
Move code around.
nnethercote Jan 10, 2024
552bed8
Remove `DiagnosticBuilder::into_diagnostic` from `-Ztreat-err-as-bug`…
nnethercote Jan 10, 2024
f5c0cd0
Inline and remove three functions.
nnethercote Jan 11, 2024
d5aafb8
Use `struct_fatal` in `new_parser_from_file`.
nnethercote Jan 11, 2024
2668270
Stop using `DiagnosticBuilder::buffer` in `WritebackCx`.
nnethercote Jan 10, 2024
29c601a
Stop using `DiagnosticBuilder::buffer` in `Checker`.
nnethercote Jan 10, 2024
fbe68bc
Stop using `DiagnosticBuilder::buffer` in `BorrowckErrors`.
nnethercote Jan 11, 2024
d02150f
Fix lifetimes in `StringReader`.
nnethercote Jan 11, 2024
6656413
Stop using `DiagnosticBuilder::buffer` in the parser.
nnethercote Jan 11, 2024
4fd1db1
Remove `DiagnosticBuilder::buffer`.
nnethercote Jan 11, 2024
252ac15
Bubble up error type
oli-obk Jan 10, 2024
af7f8f9
Silence follow up errors if astconv already errored
oli-obk Jan 10, 2024
55cab53
Taint more aggressively in astconv
oli-obk Jan 10, 2024
4580f4a
rustfmt.toml: don't ignore just any `tests` path, only root one
klensy Jan 11, 2024
aa696c5
apply fmt
klensy Jan 11, 2024
6b6f2a5
rint: further doc tweaks
RalfJung Jan 11, 2024
90cc8ba
fix: update broken stderr
Rustin170506 Jan 11, 2024
db86056
give const-err4 a more descriptive name
RalfJung Jan 11, 2024
fe97e93
Rollup merge of #119448 - klensy:annotate-snippets-0.10, r=davidtwco
matthiaskrgr Jan 11, 2024
bd61caf
Rollup merge of #119813 - oli-obk:even_more_follow_up_errors2, r=este…
matthiaskrgr Jan 11, 2024
6beb676
Rollup merge of #119836 - hi-rustin:rustin-patch-docs-blank-line, r=C…
matthiaskrgr Jan 11, 2024
f5387a1
Rollup merge of #119841 - nnethercote:rm-DiagnosticBuilder-buffer, r=…
matthiaskrgr Jan 11, 2024
8294356
Rollup merge of #119842 - Zalathar:kind, r=oli-obk
matthiaskrgr Jan 11, 2024
1a4d3c9
Rollup merge of #119845 - RalfJung:rint, r=nagisa
matthiaskrgr Jan 11, 2024
ca17ce4
Rollup merge of #119852 - RalfJung:const-err4, r=compiler-errors
matthiaskrgr Jan 11, 2024
b3d15eb
Rollup merge of #119853 - klensy:rustfmt-ignore, r=cuviper
matthiaskrgr Jan 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
@@ -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"
@@ -3771,7 +3781,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",
@@ -4738,7 +4748,7 @@ dependencies = [
name = "rustfmt-nightly"
version = "1.7.0"
dependencies = [
"annotate-snippets",
"annotate-snippets 0.9.1",
"anyhow",
"bytecount",
"cargo_metadata 0.15.4",
@@ -5728,7 +5738,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",
@@ -5859,9 +5869,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",
19 changes: 10 additions & 9 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -2399,18 +2399,19 @@ 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
/// same primary span come out in a consistent order.
buffered_move_errors:
BTreeMap<Vec<MoveOutIndex>, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)>,
buffered_mut_errors: FxIndexMap<Span, (DiagnosticBuilder<'tcx>, 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<Diagnostic>,
/// Set to Some if we emit an error during borrowck
tainted_by_errors: Option<ErrorGuaranteed>,
@@ -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() {
20 changes: 19 additions & 1 deletion compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs
Original file line number Diff line number Diff line change
@@ -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,
26 changes: 14 additions & 12 deletions compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs
Original file line number Diff line number Diff line change
@@ -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<Item = (Counter, &CodeRegion)> + ExactSizeIterator {
) -> impl Iterator<Item = (MappingKind, &CodeRegion)> + 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)
}
}

18 changes: 6 additions & 12 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
@@ -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,
));
}
}
13 changes: 8 additions & 5 deletions compiler/rustc_const_eval/src/transform/check_consts/check.rs
Original file line number Diff line number Diff line change
@@ -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<BitSet<Local>>,

error_emitted: Option<ErrorGuaranteed>,
secondary_errors: Vec<Diagnostic>,
secondary_errors: Vec<DiagnosticBuilder<'tcx>>,
}

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),
}
}

2 changes: 1 addition & 1 deletion compiler/rustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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" }
11 changes: 3 additions & 8 deletions compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
@@ -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?
}
30 changes: 4 additions & 26 deletions compiler/rustc_errors/src/diagnostic_builder.rs
Original file line number Diff line number Diff line change
@@ -255,35 +255,13 @@ 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);
}
}

/// 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))
self.dcx.stash_diagnostic(span, key, self.into_diagnostic());
}

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

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