@@ -426,19 +426,19 @@ pub struct UndefinedBehavior {
426426pub 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
906892impl rustc_errors::IntoDiagnosticArg for InternKind {
0 commit comments