Skip to content

Commit b381d3a

Browse files
committed
Auto merge of #120980 - matthiaskrgr:rollup-dsjsqql, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #120765 (Reorder diagnostics API) - #120833 (More internal emit diagnostics cleanups) - #120899 (Gracefully handle non-WF alias in `assemble_alias_bound_candidates_recur`) - #120917 (Remove a bunch of dead parameters in functions) - #120928 (Add test for recently fixed issue) - #120933 (check_consts: fix duplicate errors, make importance consistent) - #120936 (improve `btree_cursors` functions documentation) - #120944 (Check that the ABI of the instance we are inlining is correct) - #120956 (Clean inlined type alias with correct param-env) - #120962 (Add myself to library/std review) - #120972 (fix ICE for deref coercions with type errors) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bdc1592 + 8e5f722 commit b381d3a

File tree

62 files changed

+824
-809
lines changed

Some content is hidden

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

62 files changed

+824
-809
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3018,7 +3018,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
30183018
/// assignment to `x.f`).
30193019
pub(crate) fn report_illegal_reassignment(
30203020
&mut self,
3021-
_location: Location,
30223021
(place, span): (Place<'tcx>, Span),
30233022
assigned_span: Span,
30243023
err_place: Place<'tcx>,

compiler/rustc_borrowck/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10361036
self,
10371037
self.infcx.tcx,
10381038
self.body,
1039-
location,
10401039
(sd, place_span.0),
10411040
&borrow_set,
10421041
|borrow_index| borrows_in_scope.contains(borrow_index),
@@ -2174,7 +2173,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21742173
// report the error as an illegal reassignment
21752174
let init = &self.move_data.inits[init_index];
21762175
let assigned_span = init.span(self.body);
2177-
self.report_illegal_reassignment(location, (place, span), assigned_span, place);
2176+
self.report_illegal_reassignment((place, span), assigned_span, place);
21782177
} else {
21792178
self.report_mutability_error(place, span, the_place_err, error_access, location)
21802179
}

compiler/rustc_borrowck/src/path_utils.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub(super) fn each_borrow_involving_path<'tcx, F, I, S>(
2727
s: &mut S,
2828
tcx: TyCtxt<'tcx>,
2929
body: &Body<'tcx>,
30-
_location: Location,
3130
access_place: (AccessDepth, Place<'tcx>),
3231
borrow_set: &BorrowSet<'tcx>,
3332
is_candidate: I,

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ impl<'cx, 'tcx> LoanInvalidationsGenerator<'cx, 'tcx> {
340340
self,
341341
self.tcx,
342342
self.body,
343-
location,
344343
(sd, place),
345344
self.borrow_set,
346345
|_| true,

compiler/rustc_borrowck/src/region_infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
662662
polonius_output: Option<Rc<PoloniusOutput>>,
663663
) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
664664
let mir_def_id = body.source.def_id();
665-
self.propagate_constraints(body);
665+
self.propagate_constraints();
666666

667667
let mut errors_buffer = RegionErrors::new(infcx.tcx);
668668

@@ -716,8 +716,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
716716
/// for each region variable until all the constraints are
717717
/// satisfied. Note that some values may grow **too** large to be
718718
/// feasible, but we check this later.
719-
#[instrument(skip(self, _body), level = "debug")]
720-
fn propagate_constraints(&mut self, _body: &Body<'tcx>) {
719+
#[instrument(skip(self), level = "debug")]
720+
fn propagate_constraints(&mut self) {
721721
debug!("constraints={:#?}", {
722722
let mut constraints: Vec<_> = self.outlives_constraints().collect();
723723
constraints.sort_by_key(|c| (c.sup, c.sub));

compiler/rustc_const_eval/src/const_eval/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ where
151151
let mut err = tcx.dcx().create_err(err);
152152

153153
let msg = error.diagnostic_message();
154-
error.add_args(tcx.dcx(), &mut err);
154+
error.add_args(&mut err);
155155

156156
// Use *our* span to label the interp error
157157
err.span_label(our_span, msg);

compiler/rustc_const_eval/src/errors.rs

+60-74
Original file line numberDiff line numberDiff line change
@@ -426,19 +426,19 @@ pub struct UndefinedBehavior {
426426
pub trait ReportErrorExt {
427427
/// Returns the diagnostic message for this error.
428428
fn diagnostic_message(&self) -> DiagnosticMessage;
429-
fn add_args<G: EmissionGuarantee>(self, dcx: &DiagCtxt, builder: &mut DiagnosticBuilder<'_, G>);
429+
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>);
430430

431431
fn debug(self) -> String
432432
where
433433
Self: Sized,
434434
{
435435
ty::tls::with(move |tcx| {
436436
let dcx = tcx.dcx();
437-
let mut builder = dcx.struct_allow(DiagnosticMessage::Str(String::new().into()));
437+
let mut diag = dcx.struct_allow(DiagnosticMessage::Str(String::new().into()));
438438
let message = self.diagnostic_message();
439-
self.add_args(dcx, &mut builder);
440-
let s = dcx.eagerly_translate_to_string(message, builder.args());
441-
builder.cancel();
439+
self.add_args(&mut diag);
440+
let s = dcx.eagerly_translate_to_string(message, diag.args());
441+
diag.cancel();
442442
s
443443
})
444444
}
@@ -505,20 +505,17 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
505505
}
506506
}
507507

508-
fn add_args<G: EmissionGuarantee>(
509-
self,
510-
dcx: &DiagCtxt,
511-
builder: &mut DiagnosticBuilder<'_, G>,
512-
) {
508+
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
513509
use UndefinedBehaviorInfo::*;
510+
let dcx = diag.dcx;
514511
match self {
515512
Ub(_) => {}
516513
Custom(custom) => {
517514
(custom.add_args)(&mut |name, value| {
518-
builder.arg(name, value);
515+
diag.arg(name, value);
519516
});
520517
}
521-
ValidationError(e) => e.add_args(dcx, builder),
518+
ValidationError(e) => e.add_args(diag),
522519

523520
Unreachable
524521
| DivisionByZero
@@ -533,68 +530,66 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
533530
| UninhabitedEnumVariantWritten(_)
534531
| UninhabitedEnumVariantRead(_) => {}
535532
BoundsCheckFailed { len, index } => {
536-
builder.arg("len", len);
537-
builder.arg("index", index);
533+
diag.arg("len", len);
534+
diag.arg("index", index);
538535
}
539536
UnterminatedCString(ptr) | InvalidFunctionPointer(ptr) | InvalidVTablePointer(ptr) => {
540-
builder.arg("pointer", ptr);
537+
diag.arg("pointer", ptr);
541538
}
542539
PointerUseAfterFree(alloc_id, msg) => {
543-
builder
544-
.arg("alloc_id", alloc_id)
540+
diag.arg("alloc_id", alloc_id)
545541
.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
546542
}
547543
PointerOutOfBounds { alloc_id, alloc_size, ptr_offset, ptr_size, msg } => {
548-
builder
549-
.arg("alloc_id", alloc_id)
544+
diag.arg("alloc_id", alloc_id)
550545
.arg("alloc_size", alloc_size.bytes())
551546
.arg("ptr_offset", ptr_offset)
552547
.arg("ptr_size", ptr_size.bytes())
553548
.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
554549
}
555550
DanglingIntPointer(ptr, msg) => {
556551
if ptr != 0 {
557-
builder.arg("pointer", format!("{ptr:#x}[noalloc]"));
552+
diag.arg("pointer", format!("{ptr:#x}[noalloc]"));
558553
}
559554

560-
builder.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
555+
diag.arg("bad_pointer_message", bad_pointer_message(msg, dcx));
561556
}
562557
AlignmentCheckFailed(Misalignment { required, has }, msg) => {
563-
builder.arg("required", required.bytes());
564-
builder.arg("has", has.bytes());
565-
builder.arg("msg", format!("{msg:?}"));
558+
diag.arg("required", required.bytes());
559+
diag.arg("has", has.bytes());
560+
diag.arg("msg", format!("{msg:?}"));
566561
}
567562
WriteToReadOnly(alloc) | DerefFunctionPointer(alloc) | DerefVTablePointer(alloc) => {
568-
builder.arg("allocation", alloc);
563+
diag.arg("allocation", alloc);
569564
}
570565
InvalidBool(b) => {
571-
builder.arg("value", format!("{b:02x}"));
566+
diag.arg("value", format!("{b:02x}"));
572567
}
573568
InvalidChar(c) => {
574-
builder.arg("value", format!("{c:08x}"));
569+
diag.arg("value", format!("{c:08x}"));
575570
}
576571
InvalidTag(tag) => {
577-
builder.arg("tag", format!("{tag:x}"));
572+
diag.arg("tag", format!("{tag:x}"));
578573
}
579574
InvalidStr(err) => {
580-
builder.arg("err", format!("{err}"));
575+
diag.arg("err", format!("{err}"));
581576
}
582577
InvalidUninitBytes(Some((alloc, info))) => {
583-
builder.arg("alloc", alloc);
584-
builder.arg("access", info.access);
585-
builder.arg("uninit", info.bad);
578+
diag.arg("alloc", alloc);
579+
diag.arg("access", info.access);
580+
diag.arg("uninit", info.bad);
586581
}
587582
ScalarSizeMismatch(info) => {
588-
builder.arg("target_size", info.target_size);
589-
builder.arg("data_size", info.data_size);
583+
diag.arg("target_size", info.target_size);
584+
diag.arg("data_size", info.data_size);
590585
}
591586
InvalidNichedEnumVariantWritten { enum_ty } => {
592-
builder.arg("ty", enum_ty.to_string());
587+
diag.arg("ty", enum_ty.to_string());
593588
}
594589
AbiMismatchArgument { caller_ty, callee_ty }
595590
| AbiMismatchReturn { caller_ty, callee_ty } => {
596-
builder.arg("caller_ty", caller_ty.to_string());
597-
builder.arg("callee_ty", callee_ty.to_string());
591+
diag.arg("caller_ty", caller_ty.to_string());
592+
diag.arg("callee_ty", callee_ty.to_string());
598593
}
599594
}
600595
}
@@ -674,7 +669,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
674669
}
675670
}
676671

677-
fn add_args<G: EmissionGuarantee>(self, dcx: &DiagCtxt, err: &mut DiagnosticBuilder<'_, G>) {
672+
fn add_args<G: EmissionGuarantee>(self, err: &mut DiagnosticBuilder<'_, G>) {
678673
use crate::fluent_generated as fluent;
679674
use rustc_middle::mir::interpret::ValidationErrorKind::*;
680675

@@ -684,12 +679,12 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
684679
}
685680

686681
let message = if let Some(path) = self.path {
687-
dcx.eagerly_translate_to_string(
682+
err.dcx.eagerly_translate_to_string(
688683
fluent::const_eval_validation_front_matter_invalid_value_with_path,
689684
[("path".into(), DiagnosticArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
690685
)
691686
} else {
692-
dcx.eagerly_translate_to_string(
687+
err.dcx.eagerly_translate_to_string(
693688
fluent::const_eval_validation_front_matter_invalid_value,
694689
[].into_iter(),
695690
)
@@ -700,7 +695,6 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
700695
fn add_range_arg<G: EmissionGuarantee>(
701696
r: WrappingRange,
702697
max_hi: u128,
703-
dcx: &DiagCtxt,
704698
err: &mut DiagnosticBuilder<'_, G>,
705699
) {
706700
let WrappingRange { start: lo, end: hi } = r;
@@ -724,7 +718,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
724718
("hi".into(), DiagnosticArgValue::Str(hi.to_string().into())),
725719
];
726720
let args = args.iter().map(|(a, b)| (a, b));
727-
let message = dcx.eagerly_translate_to_string(msg, args);
721+
let message = err.dcx.eagerly_translate_to_string(msg, args);
728722
err.arg("in_range", message);
729723
}
730724

@@ -746,7 +740,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
746740
ExpectedKind::EnumTag => fluent::const_eval_validation_expected_enum_tag,
747741
ExpectedKind::Str => fluent::const_eval_validation_expected_str,
748742
};
749-
let msg = dcx.eagerly_translate_to_string(msg, [].into_iter());
743+
let msg = err.dcx.eagerly_translate_to_string(msg, [].into_iter());
750744
err.arg("expected", msg);
751745
}
752746
InvalidEnumTag { value }
@@ -757,11 +751,11 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
757751
err.arg("value", value);
758752
}
759753
NullablePtrOutOfRange { range, max_value } | PtrOutOfRange { range, max_value } => {
760-
add_range_arg(range, max_value, dcx, err)
754+
add_range_arg(range, max_value, err)
761755
}
762756
OutOfRange { range, max_value, value } => {
763757
err.arg("value", value);
764-
add_range_arg(range, max_value, dcx, err);
758+
add_range_arg(range, max_value, err);
765759
}
766760
UnalignedPtr { required_bytes, found_bytes, .. } => {
767761
err.arg("required_bytes", required_bytes);
@@ -802,24 +796,24 @@ impl ReportErrorExt for UnsupportedOpInfo {
802796
UnsupportedOpInfo::ExternStatic(_) => const_eval_extern_static,
803797
}
804798
}
805-
fn add_args<G: EmissionGuarantee>(self, _: &DiagCtxt, builder: &mut DiagnosticBuilder<'_, G>) {
799+
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
806800
use crate::fluent_generated::*;
807801

808802
use UnsupportedOpInfo::*;
809803
if let ReadPointerAsInt(_) | OverwritePartialPointer(_) | ReadPartialPointer(_) = self {
810-
builder.help(const_eval_ptr_as_bytes_1);
811-
builder.help(const_eval_ptr_as_bytes_2);
804+
diag.help(const_eval_ptr_as_bytes_1);
805+
diag.help(const_eval_ptr_as_bytes_2);
812806
}
813807
match self {
814808
// `ReadPointerAsInt(Some(info))` is never printed anyway, it only serves as an error to
815809
// be further processed by validity checking which then turns it into something nice to
816810
// print. So it's not worth the effort of having diagnostics that can print the `info`.
817811
UnsizedLocal | Unsupported(_) | ReadPointerAsInt(_) => {}
818812
OverwritePartialPointer(ptr) | ReadPartialPointer(ptr) => {
819-
builder.arg("ptr", ptr);
813+
diag.arg("ptr", ptr);
820814
}
821815
ThreadLocalStatic(did) | ExternStatic(did) => {
822-
builder.arg("did", format!("{did:?}"));
816+
diag.arg("did", format!("{did:?}"));
823817
}
824818
}
825819
}
@@ -835,18 +829,14 @@ impl<'tcx> ReportErrorExt for InterpError<'tcx> {
835829
InterpError::MachineStop(e) => e.diagnostic_message(),
836830
}
837831
}
838-
fn add_args<G: EmissionGuarantee>(
839-
self,
840-
dcx: &DiagCtxt,
841-
builder: &mut DiagnosticBuilder<'_, G>,
842-
) {
832+
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
843833
match self {
844-
InterpError::UndefinedBehavior(ub) => ub.add_args(dcx, builder),
845-
InterpError::Unsupported(e) => e.add_args(dcx, builder),
846-
InterpError::InvalidProgram(e) => e.add_args(dcx, builder),
847-
InterpError::ResourceExhaustion(e) => e.add_args(dcx, builder),
834+
InterpError::UndefinedBehavior(ub) => ub.add_args(diag),
835+
InterpError::Unsupported(e) => e.add_args(diag),
836+
InterpError::InvalidProgram(e) => e.add_args(diag),
837+
InterpError::ResourceExhaustion(e) => e.add_args(diag),
848838
InterpError::MachineStop(e) => e.add_args(&mut |name, value| {
849-
builder.arg(name, value);
839+
diag.arg(name, value);
850840
}),
851841
}
852842
}
@@ -864,28 +854,24 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
864854
}
865855
}
866856
}
867-
fn add_args<G: EmissionGuarantee>(
868-
self,
869-
dcx: &DiagCtxt,
870-
builder: &mut DiagnosticBuilder<'_, G>,
871-
) {
857+
fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {
872858
match self {
873859
InvalidProgramInfo::TooGeneric | InvalidProgramInfo::AlreadyReported(_) => {}
874860
InvalidProgramInfo::Layout(e) => {
875-
// The level doesn't matter, `diag` is consumed without it being used.
861+
// The level doesn't matter, `dummy_diag` is consumed without it being used.
876862
let dummy_level = Level::Bug;
877-
let diag: DiagnosticBuilder<'_, ()> =
878-
e.into_diagnostic().into_diagnostic(dcx, dummy_level);
879-
for (name, val) in diag.args() {
880-
builder.arg(name.clone(), val.clone());
863+
let dummy_diag: DiagnosticBuilder<'_, ()> =
864+
e.into_diagnostic().into_diagnostic(diag.dcx, dummy_level);
865+
for (name, val) in dummy_diag.args() {
866+
diag.arg(name.clone(), val.clone());
881867
}
882-
diag.cancel();
868+
dummy_diag.cancel();
883869
}
884870
InvalidProgramInfo::FnAbiAdjustForForeignAbi(
885871
AdjustForForeignAbiError::Unsupported { arch, abi },
886872
) => {
887-
builder.arg("arch", arch);
888-
builder.arg("abi", abi.name());
873+
diag.arg("arch", arch);
874+
diag.arg("abi", abi.name());
889875
}
890876
}
891877
}
@@ -900,7 +886,7 @@ impl ReportErrorExt for ResourceExhaustionInfo {
900886
ResourceExhaustionInfo::AddressSpaceFull => const_eval_address_space_full,
901887
}
902888
}
903-
fn add_args<G: EmissionGuarantee>(self, _: &DiagCtxt, _: &mut DiagnosticBuilder<'_, G>) {}
889+
fn add_args<G: EmissionGuarantee>(self, _: &mut DiagnosticBuilder<'_, G>) {}
904890
}
905891

906892
impl rustc_errors::IntoDiagnosticArg for InternKind {

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ pub fn format_interp_error<'tcx>(dcx: &DiagCtxt, e: InterpErrorInfo<'tcx>) -> St
445445
#[allow(rustc::untranslatable_diagnostic)]
446446
let mut diag = dcx.struct_allow("");
447447
let msg = e.diagnostic_message();
448-
e.add_args(dcx, &mut diag);
448+
e.add_args(&mut diag);
449449
let s = dcx.eagerly_translate_to_string(msg, diag.args());
450450
diag.cancel();
451451
s

0 commit comments

Comments
 (0)