diff --git a/RELEASES.md b/RELEASES.md
index 3fb74b52292c1..038a83cde84d6 100644
--- a/RELEASES.md
+++ b/RELEASES.md
@@ -1,3 +1,96 @@
+Version 1.76.0 (2024-02-08)
+==========================
+
+
+
+Language
+--------
+- [Document Rust ABI compatibility between various types](https://github.com/rust-lang/rust/pull/115476/)
+- [Also: guarantee that char and u32 are ABI-compatible](https://github.com/rust-lang/rust/pull/118032/)
+- [Warn against ambiguous wide pointer comparisons](https://github.com/rust-lang/rust/pull/117758/)
+
+
+
+Compiler
+--------
+- [Lint pinned `#[must_use]` pointers (in particular, `Box` where `T` is `#[must_use]`) in `unused_must_use`.](https://github.com/rust-lang/rust/pull/118054/)
+- [Soundness fix: fix computing the offset of an unsized field in a packed struct](https://github.com/rust-lang/rust/pull/118540/)
+- [Soundness fix: fix dynamic size/align computation logic for packed types with dyn Trait tail](https://github.com/rust-lang/rust/pull/118538/)
+- [Add `$message_type` field to distinguish json diagnostic outputs](https://github.com/rust-lang/rust/pull/115691/)
+- [Enable Rust to use the EHCont security feature of Windows](https://github.com/rust-lang/rust/pull/118013/)
+- [Add tier 3 {x86_64,i686}-win7-windows-msvc targets](https://github.com/rust-lang/rust/pull/118150/)
+- [Add tier 3 aarch64-apple-watchos target](https://github.com/rust-lang/rust/pull/119074/)
+- [Add tier 3 arm64e-apple-ios & arm64e-apple-darwin targets](https://github.com/rust-lang/rust/pull/115526/)
+
+Refer to Rust's [platform support page][platform-support-doc]
+for more information on Rust's tiered platform support.
+
+
+
+Libraries
+---------
+- [Add a column number to `dbg!()`](https://github.com/rust-lang/rust/pull/114962/)
+- [Add `std::hash::{DefaultHasher, RandomState}` exports](https://github.com/rust-lang/rust/pull/115694/)
+- [Fix rounding issue with exponents in fmt](https://github.com/rust-lang/rust/pull/116301/)
+- [Add T: ?Sized to `RwLockReadGuard` and `RwLockWriteGuard`'s Debug impls.](https://github.com/rust-lang/rust/pull/117138/)
+- [Windows: Allow `File::create` to work on hidden files](https://github.com/rust-lang/rust/pull/116438/)
+
+
+
+Stabilized APIs
+---------------
+
+- [`Arc::unwrap_or_clone`](https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#method.unwrap_or_clone)
+- [`Rc::unwrap_or_clone`](https://doc.rust-lang.org/stable/std/rc/struct.Rc.html#method.unwrap_or_clone)
+- [`Result::inspect`](https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.inspect)
+- [`Result::inspect_err`](https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.inspect_err)
+- [`Option::inspect`](https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.inspect)
+- [`type_name_of_val`](https://doc.rust-lang.org/stable/std/any/fn.type_name_of_val.html)
+- [`std::hash::{DefaultHasher, RandomState}`](https://doc.rust-lang.org/stable/std/hash/index.html#structs)
+ These were previously available only through `std::collections::hash_map`.
+- [`ptr::{from_ref, from_mut}`](https://doc.rust-lang.org/stable/std/ptr/fn.from_ref.html)
+- [`ptr::addr_eq`](https://doc.rust-lang.org/stable/std/ptr/fn.addr_eq.html)
+
+
+
+Cargo
+-----
+
+See [Cargo release notes](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-176-2024-02-08).
+
+
+
+Rustdoc
+-------
+
+- [Don't merge cfg and doc(cfg) attributes for re-exports](https://github.com/rust-lang/rust/pull/113091/)
+- [rustdoc: allow resizing the sidebar / hiding the top bar](https://github.com/rust-lang/rust/pull/115660/)
+- [rustdoc-search: add support for traits and associated types](https://github.com/rust-lang/rust/pull/116085/)
+- [rustdoc: Add highlighting for comments in items declaration](https://github.com/rust-lang/rust/pull/117869/)
+
+
+
+Compatibility Notes
+-------------------
+- [Add allow-by-default lint for unit bindings](https://github.com/rust-lang/rust/pull/112380/)
+ This is expected to be upgraded to a warning by default in a future Rust
+ release. Some macros emit bindings with type `()` with user-provided spans,
+ which means that this lint will warn for user code.
+- [Remove x86_64-sun-solaris target.](https://github.com/rust-lang/rust/pull/118091/)
+- [Remove asmjs-unknown-emscripten target](https://github.com/rust-lang/rust/pull/117338/)
+- [Report errors in jobserver inherited through environment variables](https://github.com/rust-lang/rust/pull/113730/)
+ This [may warn](https://github.com/rust-lang/rust/issues/120515) on benign problems too.
+- [Update the minimum external LLVM to 16.](https://github.com/rust-lang/rust/pull/117947/)
+- [Improve `print_tts`](https://github.com/rust-lang/rust/pull/114571/)
+ This change can break some naive manual parsing of token trees in proc macro
+ code which expect a particular structure after `.to_string()`, rather than just arbitrary Rust code.
+- [Make `IMPLIED_BOUNDS_ENTAILMENT` into a hard error from a lint](https://github.com/rust-lang/rust/pull/117984/)
+- [Vec's allocation behavior was changed when collecting some iterators](https://github.com/rust-lang/rust/pull/110353)
+ Allocation behavior is currently not specified, nevertheless changes can be surprising.
+ See [`impl FromIterator for Vec`](https://doc.rust-lang.org/nightly/std/vec/struct.Vec.html#impl-FromIterator%3CT%3E-for-Vec%3CT%3E)
+ for more details.
+- [Properly reject `default` on free const items](https://github.com/rust-lang/rust/pull/117818/)
+
Version 1.75.0 (2023-12-28)
==========================
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index dd3f7289a60b2..6b772c1295f55 100644
--- a/compiler/rustc_ast_lowering/src/item.rs
+++ b/compiler/rustc_ast_lowering/src/item.rs
@@ -25,7 +25,7 @@ pub(super) struct ItemLowerer<'a, 'hir> {
pub(super) tcx: TyCtxt<'hir>,
pub(super) resolver: &'a mut ResolverAstLowering,
pub(super) ast_index: &'a IndexSlice>,
- pub(super) owners: &'a mut IndexVec>>,
+ pub(super) owners: &'a mut IndexVec>,
}
/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set the span
@@ -64,10 +64,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
}
}
- pub(super) fn lower_node(
- &mut self,
- def_id: LocalDefId,
- ) -> hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>> {
+ pub(super) fn lower_node(&mut self, def_id: LocalDefId) -> hir::MaybeOwner<'hir> {
let owner = self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom);
if let hir::MaybeOwner::Phantom = owner {
let node = self.ast_index[def_id];
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index 3621844efc8d2..f26b1331ef388 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -99,7 +99,7 @@ struct LoweringContext<'a, 'hir> {
/// Attributes inside the owner being lowered.
attrs: SortedMap,
/// Collect items that were created by lowering the current owner.
- children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>,
+ children: Vec<(LocalDefId, hir::MaybeOwner<'hir>)>,
coroutine_kind: Option,
@@ -415,7 +415,7 @@ fn index_crate<'a>(
/// This hash will then be part of the crate_hash which is stored in the metadata.
fn compute_hir_hash(
tcx: TyCtxt<'_>,
- owners: &IndexSlice>>,
+ owners: &IndexSlice>,
) -> Fingerprint {
let mut hir_body_nodes: Vec<_> = owners
.iter_enumerated()
diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs
index 8a275a8363010..6cbcda37f50b8 100644
--- a/compiler/rustc_borrowck/src/borrowck_errors.rs
+++ b/compiler/rustc_borrowck/src/borrowck_errors.rs
@@ -130,7 +130,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
noun_old: &str,
old_opt_via: &str,
previous_end_span: Option,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_code_err!(
self.dcx(),
new_loan_span,
@@ -162,7 +162,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
old_opt_via: &str,
previous_end_span: Option,
second_borrow_desc: &str,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let mut err = struct_span_code_err!(
self.dcx(),
new_loan_span,
@@ -194,7 +194,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
kind_old: &str,
msg_old: &str,
old_load_end_span: Option,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
let mut err = struct_span_code_err!(
self.dcx(),
@@ -235,7 +235,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
span: Span,
borrow_span: Span,
desc: &str,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
struct_span_code_err!(
self.dcx(),
span,
@@ -252,7 +252,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
span: Span,
desc: &str,
is_arg: bool,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" };
struct_span_code_err!(self.dcx(), span, E0384, "cannot assign {} {}", msg, desc)
}
@@ -265,7 +265,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
move_from_span: Span,
move_from_desc: &str,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
struct_span_code_err!(
self.dcx(),
move_from_span,
@@ -283,7 +283,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
move_from_span: Span,
ty: Ty<'_>,
is_index: Option,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let type_name = match (&ty.kind(), is_index) {
(&ty::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array",
(&ty::Slice(_), _) => "slice",
@@ -304,7 +304,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
&self,
move_from_span: Span,
container_ty: Ty<'_>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
struct_span_code_err!(
self.dcx(),
move_from_span,
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index 2e83072b8d132..b0b7cc076bab5 100644
--- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
@@ -327,7 +327,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut self,
mpi: MovePathIndex,
move_span: Span,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut DiagnosticBuilder<'tcx>,
in_pattern: &mut bool,
move_spans: UseSpans<'_>,
) {
@@ -486,7 +486,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
desired_action: InitializationRequiringAction,
span: Span,
use_spans: UseSpans<'tcx>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
// We need all statements in the body where the binding was assigned to later find all
// the branching code paths where the binding *wasn't* assigned to.
let inits = &self.move_data.init_path_map[mpi];
@@ -880,7 +880,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
location: Location,
(place, _span): (Place<'tcx>, Span),
borrow: &BorrowData<'tcx>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let borrow_spans = self.retrieve_borrow_spans(borrow);
let borrow_span = borrow_spans.args_or_use();
@@ -930,7 +930,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
(place, span): (Place<'tcx>, Span),
gen_borrow_kind: BorrowKind,
issued_borrow: &BorrowData<'tcx>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let issued_spans = self.retrieve_borrow_spans(issued_borrow);
let issued_span = issued_spans.args_or_use();
@@ -2129,7 +2129,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
drop_span: Span,
borrow_spans: UseSpans<'tcx>,
explanation: BorrowExplanation<'tcx>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
debug!(
"report_local_value_does_not_live_long_enough(\
{:?}, {:?}, {:?}, {:?}, {:?}\
@@ -2304,7 +2304,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut self,
drop_span: Span,
borrow_span: Span,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
debug!(
"report_thread_local_value_does_not_live_long_enough(\
{:?}, {:?}\
@@ -2329,7 +2329,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
borrow_spans: UseSpans<'tcx>,
proper_span: Span,
explanation: BorrowExplanation<'tcx>,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
if let BorrowExplanation::MustBeValidFor { category, span, from_closure: false, .. } =
explanation
{
@@ -2440,7 +2440,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
"consider consuming the `{ty}` when turning it into an \
`Iterator`",
),
- "into_iter".to_string(),
+ "into_iter",
Applicability::MaybeIncorrect,
);
}
@@ -2496,7 +2496,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
return_span: Span,
category: ConstraintCategory<'tcx>,
opt_place_desc: Option<&String>,
- ) -> Option> {
+ ) -> Option> {
let return_kind = match category {
ConstraintCategory::Return(_) => "return",
ConstraintCategory::Yield => "yield",
@@ -2591,7 +2591,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
constraint_span: Span,
captured_var: &str,
scope: &str,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let tcx = self.infcx.tcx;
let args_span = use_span.args_or_use();
@@ -2699,7 +2699,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
upvar_span: Span,
upvar_name: Symbol,
escape_span: Span,
- ) -> DiagnosticBuilder<'cx> {
+ ) -> DiagnosticBuilder<'tcx> {
let tcx = self.infcx.tcx;
let escapes_from = tcx.def_descr(self.mir_def_id().to_def_id());
diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs
index fb3525e8998c0..0a0bb75a2a3a6 100644
--- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs
@@ -288,7 +288,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
&mut self,
place: Place<'tcx>,
span: Span,
- ) -> DiagnosticBuilder<'a> {
+ ) -> DiagnosticBuilder<'tcx> {
let description = if place.projection.len() == 1 {
format!("static item {}", self.describe_any_place(place.as_ref()))
} else {
@@ -310,7 +310,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
deref_target_place: Place<'tcx>,
span: Span,
use_spans: Option>,
- ) -> DiagnosticBuilder<'a> {
+ ) -> DiagnosticBuilder<'tcx> {
// Inspect the type of the content behind the
// borrow to provide feedback about why this
// was a move rather than a copy.
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
index 0a6b758efa564..3fddf67f55b97 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
@@ -198,12 +198,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
{
let span = self.body.local_decls[local].source_info.span;
mut_error = Some(span);
- if let Some((buffer, c)) = self.get_buffered_mut_error(span) {
+ if let Some((buffered_err, c)) = self.get_buffered_mut_error(span) {
// We've encountered a second (or more) attempt to mutably borrow an
// immutable binding, so the likely problem is with the binding
// declaration, not the use. We collect these in a single diagnostic
// and make the binding the primary span of the error.
- err = buffer;
+ err = buffered_err;
count = c + 1;
if count == 2 {
err.replace_span_with(span, false);
@@ -924,7 +924,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_suggestion_verbose(
expr.span.shrink_to_lo(),
"use a mutable iterator instead",
- "mut ".to_string(),
+ "mut ",
Applicability::MachineApplicable,
);
}
diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs
index ad66c677c78f5..bac1d9dd57f6b 100644
--- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs
@@ -251,6 +251,6 @@ impl OutlivesSuggestionBuilder {
diag.sort_span = mir_span.shrink_to_hi();
// Buffer the diagnostic
- mbcx.buffer_non_error_diag(diag);
+ mbcx.buffer_non_error(diag);
}
}
diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs
index ea48e78509b7c..8b5e548345c97 100644
--- a/compiler/rustc_borrowck/src/lib.rs
+++ b/compiler/rustc_borrowck/src/lib.rs
@@ -19,7 +19,7 @@ extern crate tracing;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::dominators::Dominators;
-use rustc_errors::{Diagnostic, DiagnosticBuilder};
+use rustc_errors::DiagnosticBuilder;
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
@@ -173,12 +173,11 @@ fn do_mir_borrowck<'tcx>(
}
}
- let mut errors = error::BorrowckErrors::new(infcx.tcx);
+ let mut diags = diags::BorrowckDiags::new();
// Gather the upvars of a closure, if any.
if let Some(e) = input_body.tainted_by_errors {
infcx.set_tainted_by_errors(e);
- errors.set_tainted_by_errors(e);
}
// Replace all regions with fresh inference variables. This
@@ -244,7 +243,7 @@ fn do_mir_borrowck<'tcx>(
®ioncx,
&opt_closure_req,
&opaque_type_values,
- &mut errors,
+ &mut diags,
);
// The various `flow_*` structures can be large. We drop `flow_inits` here
@@ -305,11 +304,11 @@ fn do_mir_borrowck<'tcx>(
next_region_name: RefCell::new(1),
polonius_output: None,
move_errors: Vec::new(),
- errors,
+ diags,
};
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
promoted_mbcx.report_move_errors();
- errors = promoted_mbcx.errors;
+ diags = promoted_mbcx.diags;
struct MoveVisitor<'a, 'cx, 'tcx> {
ctxt: &'a mut MirBorrowckCtxt<'cx, 'tcx>,
@@ -346,7 +345,7 @@ fn do_mir_borrowck<'tcx>(
next_region_name: RefCell::new(1),
polonius_output,
move_errors: Vec::new(),
- errors,
+ diags,
};
// Compute and report region errors, if any.
@@ -574,7 +573,7 @@ struct MirBorrowckCtxt<'cx, 'tcx> {
/// Results of Polonius analysis.
polonius_output: Option>,
- errors: error::BorrowckErrors<'tcx>,
+ diags: diags::BorrowckDiags<'tcx>,
move_errors: Vec>,
}
@@ -2125,7 +2124,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
| WriteKind::MutableBorrow(BorrowKind::Fake),
) => {
if self.is_mutable(place.as_ref(), is_local_mutation_allowed).is_err()
- && !self.has_buffered_errors()
+ && !self.has_buffered_diags()
{
// rust-lang/rust#46908: In pure NLL mode this code path should be
// unreachable, but we use `span_delayed_bug` because we can hit this when
@@ -2383,17 +2382,30 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}
-mod error {
+mod diags {
use rustc_errors::ErrorGuaranteed;
use super::*;
- pub struct BorrowckErrors<'tcx> {
- tcx: TyCtxt<'tcx>,
+ enum BufferedDiag<'tcx> {
+ Error(DiagnosticBuilder<'tcx>),
+ NonError(DiagnosticBuilder<'tcx, ()>),
+ }
+
+ impl<'tcx> BufferedDiag<'tcx> {
+ fn sort_span(&self) -> Span {
+ match self {
+ BufferedDiag::Error(diag) => diag.sort_span,
+ BufferedDiag::NonError(diag) => diag.sort_span,
+ }
+ }
+ }
+
+ pub struct BorrowckDiags<'tcx> {
/// This field keeps track of move errors that are to be reported for given move indices.
///
- /// There are situations where many errors can be reported for a single move out (see #53807)
- /// and we want only the best of those errors.
+ /// There are situations where many errors can be reported for a single move out (see
+ /// #53807) 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
@@ -2406,51 +2418,38 @@ mod error {
/// same primary span come out in a consistent order.
buffered_move_errors:
BTreeMap, (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)>,
+
buffered_mut_errors: FxIndexMap, usize)>,
- /// 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,
+
+ /// Buffer of diagnostics to be reported. A mixture of error and non-error diagnostics.
+ buffered_diags: Vec>,
}
- impl<'tcx> BorrowckErrors<'tcx> {
- pub fn new(tcx: TyCtxt<'tcx>) -> Self {
- BorrowckErrors {
- tcx,
+ impl<'tcx> BorrowckDiags<'tcx> {
+ pub fn new() -> Self {
+ BorrowckDiags {
buffered_move_errors: BTreeMap::new(),
buffered_mut_errors: Default::default(),
- buffered: Default::default(),
- tainted_by_errors: None,
- }
- }
-
- pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_>) {
- if let None = self.tainted_by_errors {
- self.tainted_by_errors = Some(self.tcx.dcx().span_delayed_bug(
- t.span.clone_ignoring_labels(),
- "diagnostic buffered but not emitted",
- ))
+ buffered_diags: Default::default(),
}
- self.buffered.push(t.into_diagnostic());
}
- pub fn buffer_non_error_diag(&mut self, t: DiagnosticBuilder<'_, ()>) {
- self.buffered.push(t.into_diagnostic());
+ pub fn buffer_error(&mut self, t: DiagnosticBuilder<'tcx>) {
+ self.buffered_diags.push(BufferedDiag::Error(t));
}
- pub fn set_tainted_by_errors(&mut self, e: ErrorGuaranteed) {
- self.tainted_by_errors = Some(e);
+ pub fn buffer_non_error(&mut self, t: DiagnosticBuilder<'tcx, ()>) {
+ self.buffered_diags.push(BufferedDiag::NonError(t));
}
}
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
- pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_>) {
- self.errors.buffer_error(t);
+ pub fn buffer_error(&mut self, t: DiagnosticBuilder<'tcx>) {
+ self.diags.buffer_error(t);
}
- pub fn buffer_non_error_diag(&mut self, t: DiagnosticBuilder<'_, ()>) {
- self.errors.buffer_non_error_diag(t);
+ pub fn buffer_non_error(&mut self, t: DiagnosticBuilder<'tcx, ()>) {
+ self.diags.buffer_non_error(t);
}
pub fn buffer_move_error(
@@ -2459,7 +2458,7 @@ mod error {
place_and_err: (PlaceRef<'tcx>, DiagnosticBuilder<'tcx>),
) -> bool {
if let Some((_, diag)) =
- self.errors.buffered_move_errors.insert(move_out_indices, place_and_err)
+ self.diags.buffered_move_errors.insert(move_out_indices, place_and_err)
{
// Cancel the old diagnostic so we don't ICE
diag.cancel();
@@ -2473,47 +2472,50 @@ mod error {
&mut self,
span: Span,
) -> Option<(DiagnosticBuilder<'tcx>, usize)> {
- self.errors.buffered_mut_errors.remove(&span)
+ self.diags.buffered_mut_errors.remove(&span)
}
pub fn buffer_mut_error(&mut self, span: Span, t: DiagnosticBuilder<'tcx>, count: usize) {
- self.errors.buffered_mut_errors.insert(span, (t, count));
+ self.diags.buffered_mut_errors.insert(span, (t, count));
}
pub fn emit_errors(&mut self) -> Option {
+ let mut res = None;
+
// Buffer any move errors that we collected and de-duplicated.
- for (_, (_, diag)) in std::mem::take(&mut self.errors.buffered_move_errors) {
+ for (_, (_, diag)) in std::mem::take(&mut self.diags.buffered_move_errors) {
// We have already set tainted for this error, so just buffer it.
- self.errors.buffered.push(diag.into_diagnostic());
+ self.diags.buffered_diags.push(BufferedDiag::Error(diag));
}
- for (_, (mut diag, count)) in std::mem::take(&mut self.errors.buffered_mut_errors) {
+ for (_, (mut diag, count)) in std::mem::take(&mut self.diags.buffered_mut_errors) {
if count > 10 {
diag.note(format!("...and {} other attempted mutable borrows", count - 10));
}
- self.errors.buffered.push(diag.into_diagnostic());
+ self.diags.buffered_diags.push(BufferedDiag::Error(diag));
}
- if !self.errors.buffered.is_empty() {
- self.errors.buffered.sort_by_key(|diag| diag.sort_span);
-
- let dcx = self.dcx();
- for diag in self.errors.buffered.drain(..) {
- dcx.emit_diagnostic(diag);
+ if !self.diags.buffered_diags.is_empty() {
+ self.diags.buffered_diags.sort_by_key(|buffered_diag| buffered_diag.sort_span());
+ for buffered_diag in self.diags.buffered_diags.drain(..) {
+ match buffered_diag {
+ BufferedDiag::Error(diag) => res = Some(diag.emit()),
+ BufferedDiag::NonError(diag) => diag.emit(),
+ }
}
}
- self.errors.tainted_by_errors
+ res
}
- pub fn has_buffered_errors(&self) -> bool {
- self.errors.buffered.is_empty()
+ pub(crate) fn has_buffered_diags(&self) -> bool {
+ self.diags.buffered_diags.is_empty()
}
pub fn has_move_error(
&self,
move_out_indices: &[MoveOutIndex],
- ) -> Option<&(PlaceRef<'tcx>, DiagnosticBuilder<'cx>)> {
- self.errors.buffered_move_errors.get(move_out_indices)
+ ) -> Option<&(PlaceRef<'tcx>, DiagnosticBuilder<'tcx>)> {
+ self.diags.buffered_move_errors.get(move_out_indices)
}
}
}
diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs
index cc8208e9dc306..7ace013975e1b 100644
--- a/compiler/rustc_borrowck/src/nll.rs
+++ b/compiler/rustc_borrowck/src/nll.rs
@@ -264,7 +264,7 @@ pub(super) fn dump_annotation<'tcx>(
regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option>,
opaque_type_values: &FxIndexMap>,
- errors: &mut crate::error::BorrowckErrors<'tcx>,
+ diags: &mut crate::diags::BorrowckDiags<'tcx>,
) {
let tcx = infcx.tcx;
let base_def_id = tcx.typeck_root_def_id(body.source.def_id());
@@ -310,7 +310,7 @@ pub(super) fn dump_annotation<'tcx>(
err.note(format!("Inferred opaque type values:\n{opaque_type_values:#?}"));
}
- errors.buffer_non_error_diag(err);
+ diags.buffer_non_error(err);
}
fn for_each_region_constraint<'tcx>(
diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs
index 03f8f43ff1643..f8f054db65ede 100644
--- a/compiler/rustc_codegen_gcc/src/lib.rs
+++ b/compiler/rustc_codegen_gcc/src/lib.rs
@@ -408,7 +408,7 @@ pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &Locke
.filter(|_feature| {
target_info.cpu_supports(_feature)
/*
- adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512ifma,
+ adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512fp16, avx512ifma,
avx512pf, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpopcntdq,
bmi1, bmi2, cmpxchg16b, ermsb, f16c, fma, fxsr, gfni, lzcnt, movbe, pclmulqdq, popcnt, rdrand, rdseed, rtm,
sha, sse, sse2, sse3, sse4.1, sse4.2, sse4a, ssse3, tbm, vaes, vpclmulqdq, xsave, xsavec, xsaveopt, xsaves
diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs
index d82ff6656f4d3..e839d278bea7c 100644
--- a/compiler/rustc_codegen_llvm/src/errors.rs
+++ b/compiler/rustc_codegen_llvm/src/errors.rs
@@ -102,7 +102,7 @@ pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
impl IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
let diag: DiagnosticBuilder<'_, G> = self.0.into_diagnostic(dcx, level);
- let (message, _) = diag.messages().first().expect("`LlvmError` with no message");
+ let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
let message = dcx.eagerly_translate_to_string(message.clone(), diag.args());
DiagnosticBuilder::new(dcx, level, fluent::codegen_llvm_parse_target_machine_config)
diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs
index 06edb79453727..4211f875dd01a 100644
--- a/compiler/rustc_codegen_ssa/src/back/write.rs
+++ b/compiler/rustc_codegen_ssa/src/back/write.rs
@@ -39,7 +39,6 @@ use rustc_target::spec::{MergeFunctions, SanitizerSet};
use crate::errors::ErrorCreatingRemarkDir;
use std::any::Any;
-use std::borrow::Cow;
use std::fs;
use std::io;
use std::marker::PhantomData;
@@ -1812,12 +1811,12 @@ impl Translate for SharedEmitter {
impl Emitter for SharedEmitter {
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
- let args: FxHashMap, DiagnosticArgValue> =
+ let args: FxHashMap =
diag.args().map(|(name, arg)| (name.clone(), arg.clone())).collect();
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
msgs: diag.messages.clone(),
args: args.clone(),
- code: diag.code.clone(),
+ code: diag.code,
lvl: diag.level(),
})));
for child in &diag.children {
diff --git a/compiler/rustc_const_eval/src/const_eval/error.rs b/compiler/rustc_const_eval/src/const_eval/error.rs
index dabf78ef90e5f..1ebc82ad6d4b2 100644
--- a/compiler/rustc_const_eval/src/const_eval/error.rs
+++ b/compiler/rustc_const_eval/src/const_eval/error.rs
@@ -1,6 +1,8 @@
use std::mem;
-use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg};
+use rustc_errors::{
+ DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, IntoDiagnostic, IntoDiagnosticArg,
+};
use rustc_hir::CRATE_HIR_ID;
use rustc_middle::mir::AssertKind;
use rustc_middle::query::TyCtxtAt;
@@ -32,10 +34,7 @@ impl MachineStopType for ConstEvalErrKind {
AssertFailure(x) => x.diagnostic_message(),
}
}
- fn add_args(
- self: Box,
- adder: &mut dyn FnMut(std::borrow::Cow<'static, str>, DiagnosticArgValue),
- ) {
+ fn add_args(self: Box, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue)) {
use ConstEvalErrKind::*;
match *self {
ConstAccessesStatic | ModifiedGlobal => {}
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs
index b87eef07fd53a..8ad4925cff288 100644
--- a/compiler/rustc_errors/src/diagnostic.rs
+++ b/compiler/rustc_errors/src/diagnostic.rs
@@ -33,7 +33,10 @@ pub type DiagnosticArgName = Cow<'static, str>;
#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
pub enum DiagnosticArgValue {
Str(Cow<'static, str>),
- Number(i128),
+ // This gets converted to a `FluentNumber`, which is an `f64`. An `i32`
+ // safely fits in an `f64`. Any integers bigger than that will be converted
+ // to strings in `into_diagnostic_arg` and stored using the `Str` variant.
+ Number(i32),
StrListSepByAnd(Vec>),
}
@@ -113,7 +116,7 @@ pub struct Diagnostic {
/// With `-Ztrack_diagnostics` enabled,
/// we print where in rustc this error was emitted.
- pub emitted_at: DiagnosticLocation,
+ pub(crate) emitted_at: DiagnosticLocation,
}
#[derive(Clone, Debug, Encodable, Decodable)]
@@ -162,10 +165,10 @@ impl DiagnosticStyledString {
DiagnosticStyledString(vec![])
}
pub fn push_normal>(&mut self, t: S) {
- self.0.push(StringPart::Normal(t.into()));
+ self.0.push(StringPart::normal(t));
}
pub fn push_highlighted>(&mut self, t: S) {
- self.0.push(StringPart::Highlighted(t.into()));
+ self.0.push(StringPart::highlighted(t));
}
pub fn push>(&mut self, t: S, highlight: bool) {
if highlight {
@@ -175,35 +178,34 @@ impl DiagnosticStyledString {
}
}
pub fn normal>(t: S) -> DiagnosticStyledString {
- DiagnosticStyledString(vec![StringPart::Normal(t.into())])
+ DiagnosticStyledString(vec![StringPart::normal(t)])
}
pub fn highlighted>(t: S) -> DiagnosticStyledString {
- DiagnosticStyledString(vec![StringPart::Highlighted(t.into())])
+ DiagnosticStyledString(vec![StringPart::highlighted(t)])
}
pub fn content(&self) -> String {
- self.0.iter().map(|x| x.content()).collect::()
+ self.0.iter().map(|x| x.content.as_str()).collect::()
}
}
#[derive(Debug, PartialEq, Eq)]
-pub enum StringPart {
- Normal(String),
- Highlighted(String),
+pub struct StringPart {
+ content: String,
+ style: Style,
}
impl StringPart {
- pub fn content(&self) -> &str {
- match self {
- &StringPart::Normal(ref s) | &StringPart::Highlighted(ref s) => s,
- }
+ pub fn normal>(content: S) -> StringPart {
+ StringPart { content: content.into(), style: Style::NoStyle }
+ }
+
+ pub fn highlighted>(content: S) -> StringPart {
+ StringPart { content: content.into(), style: Style::Highlight }
}
}
-// Note: most of these methods are setters that return `&mut Self`. The small
-// number of simple getter functions all have `get_` prefixes to distinguish
-// them from the setters.
impl Diagnostic {
#[track_caller]
pub fn new>(level: Level, message: M) -> Self {
@@ -389,19 +391,16 @@ impl Diagnostic {
} else {
(0, found_label.len() - expected_label.len())
};
- let mut msg: Vec<_> =
- vec![(format!("{}{} `", " ".repeat(expected_padding), expected_label), Style::NoStyle)];
- msg.extend(expected.0.iter().map(|x| match *x {
- StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
- StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
- }));
- msg.push((format!("`{expected_extra}\n"), Style::NoStyle));
- msg.push((format!("{}{} `", " ".repeat(found_padding), found_label), Style::NoStyle));
- msg.extend(found.0.iter().map(|x| match *x {
- StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
- StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
- }));
- msg.push((format!("`{found_extra}"), Style::NoStyle));
+ let mut msg = vec![StringPart::normal(format!(
+ "{}{} `",
+ " ".repeat(expected_padding),
+ expected_label
+ ))];
+ msg.extend(expected.0.into_iter());
+ msg.push(StringPart::normal(format!("`{expected_extra}\n")));
+ msg.push(StringPart::normal(format!("{}{} `", " ".repeat(found_padding), found_label)));
+ msg.extend(found.0.into_iter());
+ msg.push(StringPart::normal(format!("`{found_extra}")));
// For now, just attach these as notes.
self.highlighted_note(msg);
@@ -410,9 +409,9 @@ impl Diagnostic {
pub fn note_trait_signature(&mut self, name: Symbol, signature: String) -> &mut Self {
self.highlighted_note(vec![
- (format!("`{name}` from trait: `"), Style::NoStyle),
- (signature, Style::Highlight),
- ("`".to_string(), Style::NoStyle),
+ StringPart::normal(format!("`{name}` from trait: `")),
+ StringPart::highlighted(signature),
+ StringPart::normal("`"),
]);
self
}
@@ -424,10 +423,7 @@ impl Diagnostic {
self
}
- fn highlighted_note>(
- &mut self,
- msg: Vec<(M, Style)>,
- ) -> &mut Self {
+ fn highlighted_note(&mut self, msg: Vec) -> &mut Self {
self.sub_with_highlights(Level::Note, msg, MultiSpan::new());
self
}
@@ -496,7 +492,7 @@ impl Diagnostic {
}
/// Add a help message attached to this diagnostic with a customizable highlighted message.
- pub fn highlighted_help(&mut self, msg: Vec<(String, Style)>) -> &mut Self {
+ pub fn highlighted_help(&mut self, msg: Vec) -> &mut Self {
self.sub_with_highlights(Level::Help, msg, MultiSpan::new());
self
}
@@ -890,15 +886,6 @@ impl Diagnostic {
self
}
- pub fn clear_code(&mut self) -> &mut Self {
- self.code = None;
- self
- }
-
- pub fn get_code(&self) -> Option {
- self.code
- }
-
pub fn primary_message(&mut self, msg: impl Into) -> &mut Self {
self.messages[0] = (msg.into(), Style::NoStyle);
self
@@ -913,7 +900,7 @@ impl Diagnostic {
pub fn arg(
&mut self,
- name: impl Into>,
+ name: impl Into,
arg: impl IntoDiagnosticArg,
) -> &mut Self {
self.args.insert(name.into(), arg.into_diagnostic_arg());
@@ -924,10 +911,6 @@ impl Diagnostic {
self.args = args;
}
- pub fn messages(&self) -> &[(DiagnosticMessage, Style)] {
- &self.messages
- }
-
/// Helper function that takes a `SubdiagnosticMessage` and returns a `DiagnosticMessage` by
/// combining it with the primary message of the diagnostic (if translatable, otherwise it just
/// passes the user's string along).
@@ -958,15 +941,10 @@ impl Diagnostic {
/// Convenience function for internal use, clients should use one of the
/// public methods above.
- fn sub_with_highlights>(
- &mut self,
- level: Level,
- messages: Vec<(M, Style)>,
- span: MultiSpan,
- ) {
+ fn sub_with_highlights(&mut self, level: Level, messages: Vec, span: MultiSpan) {
let messages = messages
.into_iter()
- .map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1))
+ .map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.content), m.style))
.collect();
let sub = SubDiagnostic { level, messages, span };
self.children.push(sub);
diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs
index 8bfb181648628..faff7f0b52673 100644
--- a/compiler/rustc_errors/src/diagnostic_builder.rs
+++ b/compiler/rustc_errors/src/diagnostic_builder.rs
@@ -255,13 +255,8 @@ 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()`].
- pub fn stash(self, span: Span, key: StashKey) {
- self.dcx.stash_diagnostic(span, key, self.into_diagnostic());
- }
-
- /// Converts the builder to a `Diagnostic` for later emission.
- pub fn into_diagnostic(mut self) -> Diagnostic {
- self.take_diag()
+ pub fn stash(mut self, span: Span, key: StashKey) {
+ self.dcx.stash_diagnostic(span, key, self.take_diag());
}
/// Delay emission of this diagnostic as a bug.
diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs
index faab3fc663a82..15effd3cbec9b 100644
--- a/compiler/rustc_errors/src/diagnostic_impls.rs
+++ b/compiler/rustc_errors/src/diagnostic_impls.rs
@@ -63,12 +63,8 @@ macro_rules! into_diagnostic_arg_for_number {
$(
impl IntoDiagnosticArg for $ty {
fn into_diagnostic_arg(self) -> DiagnosticArgValue {
- // HACK: `FluentNumber` the underline backing struct represent
- // numbers using a f64 which can't represent all the i128 numbers
- // So in order to be able to use fluent selectors and still
- // have all the numbers representable we only convert numbers
- // below a certain threshold.
- if let Ok(n) = TryInto::::try_into(self) && n >= -100 && n <= 100 {
+ // Convert to a string if it won't fit into `Number`.
+ if let Ok(n) = TryInto::::try_into(self) {
DiagnosticArgValue::Number(n)
} else {
self.to_string().into_diagnostic_arg()
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 9f76c1dd248b0..4be5ed923e5e0 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -558,7 +558,7 @@ impl Emitter for HumanEmitter {
/// failures of rustc, as witnessed e.g. in issue #89358.
pub struct SilentEmitter {
pub fatal_dcx: DiagCtxt,
- pub fatal_note: Option,
+ pub fatal_note: String,
}
impl Translate for SilentEmitter {
@@ -576,13 +576,11 @@ impl Emitter for SilentEmitter {
None
}
- fn emit_diagnostic(&mut self, d: &Diagnostic) {
- if d.level == Level::Fatal {
- let mut d = d.clone();
- if let Some(ref note) = self.fatal_note {
- d.note(note.clone());
- }
- self.fatal_dcx.emit_diagnostic(d);
+ fn emit_diagnostic(&mut self, diag: &Diagnostic) {
+ if diag.level == Level::Fatal {
+ let mut diag = diag.clone();
+ diag.note(self.fatal_note.clone());
+ self.fatal_dcx.emit_diagnostic(diag);
}
}
}
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index 960b68196ff02..b2bd4d8eb956e 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -34,7 +34,7 @@ extern crate self as rustc_errors;
pub use codes::*;
pub use diagnostic::{
AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgName,
- DiagnosticArgValue, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
+ DiagnosticArgValue, DiagnosticStyledString, IntoDiagnosticArg, StringPart, SubDiagnostic,
};
pub use diagnostic_builder::{
BugAbort, DiagnosticBuilder, EmissionGuarantee, FatalAbort, IntoDiagnostic,
@@ -102,7 +102,6 @@ pub type PResult<'a, T> = Result>;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
// `PResult` is used a lot. Make sure it doesn't unintentionally get bigger.
-// (See also the comment on `DiagnosticBuilderInner`'s `diagnostic` field.)
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(PResult<'_, ()>, 16);
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
@@ -1039,10 +1038,6 @@ impl DiagCtxt {
}
}
- pub fn take_future_breakage_diagnostics(&self) -> Vec {
- std::mem::take(&mut self.inner.borrow_mut().future_breakage_diagnostics)
- }
-
pub fn abort_if_errors(&self) {
let mut inner = self.inner.borrow_mut();
inner.emit_stashed_diagnostics();
@@ -1150,8 +1145,12 @@ impl DiagCtxt {
self.inner.borrow_mut().emitter.emit_artifact_notification(path, artifact_type);
}
- pub fn emit_future_breakage_report(&self, diags: Vec) {
- self.inner.borrow_mut().emitter.emit_future_breakage_report(diags)
+ pub fn emit_future_breakage_report(&self) {
+ let mut inner = self.inner.borrow_mut();
+ let diags = std::mem::take(&mut inner.future_breakage_diagnostics);
+ if !diags.is_empty() {
+ inner.emitter.emit_future_breakage_report(diags);
+ }
}
pub fn emit_unused_externs(
@@ -1224,9 +1223,8 @@ impl DiagCtxtInner {
/// Emit all stashed diagnostics.
fn emit_stashed_diagnostics(&mut self) -> Option {
let has_errors = self.has_errors();
- let diags = self.stashed_diagnostics.drain(..).map(|x| x.1).collect::>();
let mut reported = None;
- for diag in diags {
+ for (_, diag) in std::mem::take(&mut self.stashed_diagnostics).into_iter() {
// Decrement the count tracking the stash; emitting will increment it.
if diag.is_error() {
if diag.is_lint.is_some() {
@@ -1254,7 +1252,7 @@ impl DiagCtxtInner {
// be stored. Instead, they are buffered until the `LintExpectationId` is replaced by
// a stable one by the `LintLevelsBuilder`.
if let Some(LintExpectationId::Unstable { .. }) = diagnostic.level.get_expectation_id() {
- self.unstable_expect_diagnostics.push(diagnostic.clone());
+ self.unstable_expect_diagnostics.push(diagnostic);
return None;
}
@@ -1269,16 +1267,14 @@ impl DiagCtxtInner {
DelayedBug(DelayedBugKind::Normal) => {
let backtrace = std::backtrace::Backtrace::capture();
self.span_delayed_bugs
- .push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));
-
+ .push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
#[allow(deprecated)]
return Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
}
DelayedBug(DelayedBugKind::GoodPath) => {
let backtrace = std::backtrace::Backtrace::capture();
self.good_path_delayed_bugs
- .push(DelayedDiagnostic::with_backtrace(diagnostic.clone(), backtrace));
-
+ .push(DelayedDiagnostic::with_backtrace(diagnostic, backtrace));
return None;
}
_ => {}
@@ -1424,7 +1420,7 @@ impl DiagCtxtInner {
&mut out,
"delayed span bug: {}\n{}\n",
bug.inner
- .messages()
+ .messages
.iter()
.filter_map(|(msg, _)| msg.as_str())
.collect::(),
diff --git a/compiler/rustc_errors/src/snippet.rs b/compiler/rustc_errors/src/snippet.rs
index 98eb70b5fceee..b55f78538852a 100644
--- a/compiler/rustc_errors/src/snippet.rs
+++ b/compiler/rustc_errors/src/snippet.rs
@@ -197,7 +197,7 @@ pub struct StyledString {
pub style: Style,
}
-#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)]
pub enum Style {
MainHeaderMsg,
HeaderMsg,
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 681e228a0f2ff..de1b28acb1267 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -894,34 +894,23 @@ impl<'tcx> OwnerInfo<'tcx> {
}
#[derive(Copy, Clone, Debug, HashStable_Generic)]
-pub enum MaybeOwner {
- Owner(T),
+pub enum MaybeOwner<'tcx> {
+ Owner(&'tcx OwnerInfo<'tcx>),
NonOwner(HirId),
/// Used as a placeholder for unused LocalDefId.
Phantom,
}
-impl MaybeOwner {
- pub fn as_owner(self) -> Option {
+impl<'tcx> MaybeOwner<'tcx> {
+ pub fn as_owner(self) -> Option<&'tcx OwnerInfo<'tcx>> {
match self {
MaybeOwner::Owner(i) => Some(i),
MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => None,
}
}
- pub fn map(self, f: impl FnOnce(T) -> U) -> MaybeOwner {
- match self {
- MaybeOwner::Owner(i) => MaybeOwner::Owner(f(i)),
- MaybeOwner::NonOwner(hir_id) => MaybeOwner::NonOwner(hir_id),
- MaybeOwner::Phantom => MaybeOwner::Phantom,
- }
- }
-
- pub fn unwrap(self) -> T {
- match self {
- MaybeOwner::Owner(i) => i,
- MaybeOwner::NonOwner(_) | MaybeOwner::Phantom => panic!("Not a HIR owner"),
- }
+ pub fn unwrap(self) -> &'tcx OwnerInfo<'tcx> {
+ self.as_owner().unwrap_or_else(|| panic!("Not a HIR owner"))
}
}
@@ -933,7 +922,7 @@ impl MaybeOwner {
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
#[derive(Debug)]
pub struct Crate<'hir> {
- pub owners: IndexVec>>,
+ pub owners: IndexVec>,
// Only present when incr. comp. is enabled.
pub opt_hir_hash: Option,
}
diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs
index 407517b15ef5e..e67a44d96ad43 100644
--- a/compiler/rustc_hir_analysis/src/astconv/errors.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs
@@ -247,7 +247,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
err.span_suggestion_verbose(
assoc_name.span,
fluent::hir_analysis_assoc_item_not_found_similar_in_other_trait_with_bound_sugg,
- suggested_name.to_string(),
+ suggested_name,
Applicability::MaybeIncorrect,
);
}
diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs
index 3674a760cbf9d..5cdcc1bb860b2 100644
--- a/compiler/rustc_hir_analysis/src/collect/type_of.rs
+++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs
@@ -590,7 +590,6 @@ fn infer_placeholder_type<'a>(
// The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
// We are typeck and have the real type, so remove that and suggest the actual type.
- // FIXME(eddyb) this looks like it should be functionality on `Diagnostic`.
if let Ok(suggestions) = &mut err.suggestions {
suggestions.clear();
}
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 2bbef11fa2450..1adde8c21b8e2 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -1000,7 +1000,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_suggestion_verbose(
lhs.span.shrink_to_hi(),
"you might have meant to write a semicolon here",
- ";".to_string(),
+ ";",
Applicability::MachineApplicable,
);
return true;
diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs
index 6c9501e93fa11..904961d9eba26 100644
--- a/compiler/rustc_hir_typeck/src/method/suggest.rs
+++ b/compiler/rustc_hir_typeck/src/method/suggest.rs
@@ -1116,9 +1116,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
item_name.span,
format!(
"you might have meant to use `{}`",
- inherent_method.name.as_str()
+ inherent_method.name
),
- inherent_method.name.as_str(),
+ inherent_method.name,
Applicability::MaybeIncorrect,
);
break 'outer;
@@ -2019,7 +2019,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
diag.span_suggestion_verbose(
sm.span_extend_while(seg1.ident.span.shrink_to_hi(), |c| c == ':').unwrap(),
"you may have meant to call an instance method",
- ".".to_string(),
+ ".",
Applicability::MaybeIncorrect,
);
}
diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs
index b7f28ef958aa8..fcf4b59e93fcd 100644
--- a/compiler/rustc_hir_typeck/src/pat.rs
+++ b/compiler/rustc_hir_typeck/src/pat.rs
@@ -576,7 +576,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if (lhs, rhs).references_error() {
err.downgrade_to_delayed_bug();
}
- if self.tcx.sess.teach(err.get_code().unwrap()) {
+ if self.tcx.sess.teach(err.code.unwrap()) {
err.note(
"In a match expression, only numbers and characters can be matched \
against a range. This is because the compiler checks that the range \
@@ -847,7 +847,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
type_str
);
err.span_label(span, format!("type `{type_str}` cannot be dereferenced"));
- if self.tcx.sess.teach(err.get_code().unwrap()) {
+ if self.tcx.sess.teach(err.code.unwrap()) {
err.note(CANNOT_IMPLICITLY_DEREF_POINTER_TRAIT_OBJ);
}
return Err(err.emit());
@@ -1669,7 +1669,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
- if tcx.sess.teach(err.get_code().unwrap()) {
+ if tcx.sess.teach(err.code.unwrap()) {
err.note(
"This error indicates that a struct pattern attempted to \
extract a nonexistent field from a struct. Struct fields \
diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
index 0e7c641e0e0b8..0452d4fe6c806 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
@@ -195,7 +195,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
}
diag.help("type parameters must be constrained to match other types");
- if tcx.sess.teach(diag.get_code().unwrap()) {
+ if tcx.sess.teach(diag.code.unwrap()) {
diag.help(
"given a type parameter `T` and a method `foo`:
```
@@ -678,7 +678,7 @@ impl Trait for X {
https://doc.rust-lang.org/book/ch19-03-advanced-traits.html",
);
}
- if tcx.sess.teach(diag.get_code().unwrap()) {
+ if tcx.sess.teach(diag.code.unwrap()) {
diag.help(
"given an associated type `T` and a method `foo`:
```
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs
index 5ca8809099675..8a4705e0056e1 100644
--- a/compiler/rustc_interface/src/interface.rs
+++ b/compiler/rustc_interface/src/interface.rs
@@ -45,20 +45,19 @@ pub struct Compiler {
pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec) -> Cfg {
cfgs.into_iter()
.map(|s| {
- let sess = ParseSess::with_silent_emitter(Some(format!(
+ let sess = ParseSess::with_silent_emitter(format!(
"this error occurred on the command line: `--cfg={s}`"
- )));
+ ));
let filename = FileName::cfg_spec_source_code(&s);
macro_rules! error {
($reason: expr) => {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
- dcx.struct_fatal(format!(
+ dcx.fatal(format!(
concat!("invalid `--cfg` argument: `{}` (", $reason, ")"),
s
- ))
- .emit();
+ ));
};
}
@@ -108,20 +107,19 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec) -> CheckCfg {
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() };
for s in specs {
- let sess = ParseSess::with_silent_emitter(Some(format!(
+ let sess = ParseSess::with_silent_emitter(format!(
"this error occurred on the command line: `--check-cfg={s}`"
- )));
+ ));
let filename = FileName::cfg_spec_source_code(&s);
macro_rules! error {
($reason:expr) => {
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
- dcx.struct_fatal(format!(
+ dcx.fatal(format!(
concat!("invalid `--check-cfg` argument: `{}` (", $reason, ")"),
s
))
- .emit()
};
}
diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs
index 211da80020297..3ebbcd650302f 100644
--- a/compiler/rustc_middle/src/error.rs
+++ b/compiler/rustc_middle/src/error.rs
@@ -1,7 +1,6 @@
-use std::borrow::Cow;
use std::fmt;
-use rustc_errors::{codes::*, DiagnosticArgValue, DiagnosticMessage};
+use rustc_errors::{codes::*, DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage};
use rustc_macros::Diagnostic;
use rustc_span::{Span, Symbol};
@@ -95,14 +94,14 @@ pub(super) struct ConstNotUsedTraitAlias {
pub struct CustomSubdiagnostic<'a> {
pub msg: fn() -> DiagnosticMessage,
- pub add_args: Box, DiagnosticArgValue)) + 'a>,
+ pub add_args: Box,
}
impl<'a> CustomSubdiagnostic<'a> {
pub fn label(x: fn() -> DiagnosticMessage) -> Self {
Self::label_and_then(x, |_| {})
}
- pub fn label_and_then, DiagnosticArgValue)) + 'a>(
+ pub fn label_and_then(
msg: fn() -> DiagnosticMessage,
f: F,
) -> Self {
diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs
index b54e438f6144d..94191df30a5e6 100644
--- a/compiler/rustc_middle/src/hir/mod.rs
+++ b/compiler/rustc_middle/src/hir/mod.rs
@@ -127,12 +127,11 @@ pub fn provide(providers: &mut Providers) {
providers.hir_crate_items = map::hir_crate_items;
providers.crate_hash = map::crate_hash;
providers.hir_module_items = map::hir_module_items;
- providers.opt_local_def_id_to_hir_id = |tcx, id| {
- let owner = tcx.hir_crate(()).owners[id].map(|_| ());
- Some(match owner {
- MaybeOwner::Owner(_) => HirId::make_owner(id),
- MaybeOwner::Phantom => bug!("No HirId for {:?}", id),
+ providers.opt_local_def_id_to_hir_id = |tcx, def_id| {
+ Some(match tcx.hir_crate(()).owners[def_id] {
+ MaybeOwner::Owner(_) => HirId::make_owner(def_id),
MaybeOwner::NonOwner(hir_id) => hir_id,
+ MaybeOwner::Phantom => bug!("No HirId for {:?}", def_id),
})
};
providers.opt_hir_owner_nodes =
diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs
index 95574aee499f2..0f69ab93452f7 100644
--- a/compiler/rustc_middle/src/mir/interpret/error.rs
+++ b/compiler/rustc_middle/src/mir/interpret/error.rs
@@ -5,7 +5,9 @@ use crate::mir::{ConstAlloc, ConstValue};
use crate::ty::{layout, tls, Ty, TyCtxt, ValTree};
use rustc_data_structures::sync::Lock;
-use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg};
+use rustc_errors::{
+ DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg,
+};
use rustc_macros::HashStable;
use rustc_session::CtfeBacktrace;
use rustc_span::{def_id::DefId, Span, DUMMY_SP};
@@ -485,7 +487,7 @@ pub trait MachineStopType: Any + fmt::Debug + Send {
fn diagnostic_message(&self) -> DiagnosticMessage;
/// Add diagnostic arguments by passing name and value pairs to `adder`, which are passed to
/// fluent for formatting the translated diagnostic message.
- fn add_args(self: Box, adder: &mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue));
+ fn add_args(self: Box, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue));
}
impl dyn MachineStopType {
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs
index 37c5bba46a7d8..c9e69253701c5 100644
--- a/compiler/rustc_middle/src/mir/mod.rs
+++ b/compiler/rustc_middle/src/mir/mod.rs
@@ -14,7 +14,9 @@ use crate::ty::{AdtDef, InstanceDef, UserTypeAnnotationIndex};
use crate::ty::{GenericArg, GenericArgsRef};
use rustc_data_structures::captures::Captures;
-use rustc_errors::{DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg};
+use rustc_errors::{
+ DiagnosticArgName, DiagnosticArgValue, DiagnosticMessage, ErrorGuaranteed, IntoDiagnosticArg,
+};
use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
use rustc_hir::{self, CoroutineDesugaring, CoroutineKind, ImplicitSelfKind};
diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs
index 0fe33e441f430..91b7952bec5e8 100644
--- a/compiler/rustc_middle/src/mir/terminator.rs
+++ b/compiler/rustc_middle/src/mir/terminator.rs
@@ -292,7 +292,7 @@ impl AssertKind {
}
}
- pub fn add_args(self, adder: &mut dyn FnMut(Cow<'static, str>, DiagnosticArgValue))
+ pub fn add_args(self, adder: &mut dyn FnMut(DiagnosticArgName, DiagnosticArgValue))
where
O: fmt::Debug,
{
diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index 1b01df6a18714..a272a51f32747 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -185,8 +185,8 @@ impl EraseType for Option>> {
type Result = [u8; size_of::