Auto merge of #120980 - matthiaskrgr:rollup-dsjsqql, r=matthiaskrgr · rust-lang/rust@b381d3a (original) (raw)

`@@ -426,19 +426,19 @@ pub struct UndefinedBehavior {

`

426

426

`pub trait ReportErrorExt {

`

427

427

`/// Returns the diagnostic message for this error.

`

428

428

`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>);

`

430

430

``

431

431

`fn debug(self) -> String

`

432

432

`where

`

433

433

`Self: Sized,

`

434

434

`{

`

435

435

` ty::tls::with(move |tcx| {

`

436

436

`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()));

`

438

438

`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();

`

442

442

` s

`

443

443

`})

`

444

444

`}

`

`@@ -505,20 +505,17 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {

`

505

505

`}

`

506

506

`}

`

507

507

``

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>) {

`

513

509

`use UndefinedBehaviorInfo::*;

`

``

510

`+

let dcx = diag.dcx;

`

514

511

`match self {

`

515

512

`Ub(_) => {}

`

516

513

`Custom(custom) => {

`

517

514

`(custom.add_args)(&mut |name, value| {

`

518

``

`-

builder.arg(name, value);

`

``

515

`+

diag.arg(name, value);

`

519

516

`});

`

520

517

`}

`

521

``

`-

ValidationError(e) => e.add_args(dcx, builder),

`

``

518

`+

ValidationError(e) => e.add_args(diag),

`

522

519

``

523

520

`Unreachable

`

524

521

` | DivisionByZero

`

`@@ -533,68 +530,66 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {

`

533

530

` | UninhabitedEnumVariantWritten(_)

`

534

531

` | UninhabitedEnumVariantRead(_) => {}

`

535

532

`BoundsCheckFailed { len, index } => {

`

536

``

`-

builder.arg("len", len);

`

537

``

`-

builder.arg("index", index);

`

``

533

`+

diag.arg("len", len);

`

``

534

`+

diag.arg("index", index);

`

538

535

`}

`

539

536

`UnterminatedCString(ptr) | InvalidFunctionPointer(ptr) | InvalidVTablePointer(ptr) => {

`

540

``

`-

builder.arg("pointer", ptr);

`

``

537

`+

diag.arg("pointer", ptr);

`

541

538

`}

`

542

539

`PointerUseAfterFree(alloc_id, msg) => {

`

543

``

`-

builder

`

544

``

`-

.arg("alloc_id", alloc_id)

`

``

540

`+

diag.arg("alloc_id", alloc_id)

`

545

541

`.arg("bad_pointer_message", bad_pointer_message(msg, dcx));

`

546

542

`}

`

547

543

`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)

`

550

545

`.arg("alloc_size", alloc_size.bytes())

`

551

546

`.arg("ptr_offset", ptr_offset)

`

552

547

`.arg("ptr_size", ptr_size.bytes())

`

553

548

`.arg("bad_pointer_message", bad_pointer_message(msg, dcx));

`

554

549

`}

`

555

550

`DanglingIntPointer(ptr, msg) => {

`

556

551

`if ptr != 0 {

`

557

``

`-

builder.arg("pointer", format!("{ptr:#x}[noalloc]"));

`

``

552

`+

diag.arg("pointer", format!("{ptr:#x}[noalloc]"));

`

558

553

`}

`

559

554

``

560

``

`-

builder.arg("bad_pointer_message", bad_pointer_message(msg, dcx));

`

``

555

`+

diag.arg("bad_pointer_message", bad_pointer_message(msg, dcx));

`

561

556

`}

`

562

557

`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:?}"));

`

566

561

`}

`

567

562

`WriteToReadOnly(alloc) | DerefFunctionPointer(alloc) | DerefVTablePointer(alloc) => {

`

568

``

`-

builder.arg("allocation", alloc);

`

``

563

`+

diag.arg("allocation", alloc);

`

569

564

`}

`

570

565

`InvalidBool(b) => {

`

571

``

`-

builder.arg("value", format!("{b:02x}"));

`

``

566

`+

diag.arg("value", format!("{b:02x}"));

`

572

567

`}

`

573

568

`InvalidChar(c) => {

`

574

``

`-

builder.arg("value", format!("{c:08x}"));

`

``

569

`+

diag.arg("value", format!("{c:08x}"));

`

575

570

`}

`

576

571

`InvalidTag(tag) => {

`

577

``

`-

builder.arg("tag", format!("{tag:x}"));

`

``

572

`+

diag.arg("tag", format!("{tag:x}"));

`

578

573

`}

`

579

574

`InvalidStr(err) => {

`

580

``

`-

builder.arg("err", format!("{err}"));

`

``

575

`+

diag.arg("err", format!("{err}"));

`

581

576

`}

`

582

577

`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);

`

586

581

`}

`

587

582

`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);

`

590

585

`}

`

591

586

`InvalidNichedEnumVariantWritten { enum_ty } => {

`

592

``

`-

builder.arg("ty", enum_ty.to_string());

`

``

587

`+

diag.arg("ty", enum_ty.to_string());

`

593

588

`}

`

594

589

`AbiMismatchArgument { caller_ty, callee_ty }

`

595

590

` | 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());

`

598

593

`}

`

599

594

`}

`

600

595

`}

`

`@@ -674,7 +669,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {

`

674

669

`}

`

675

670

`}

`

676

671

``

677

``

`-

fn add_args<G: EmissionGuarantee>(self, dcx: &DiagCtxt, err: &mut DiagnosticBuilder<'_, G>) {

`

``

672

`+

fn add_args<G: EmissionGuarantee>(self, err: &mut DiagnosticBuilder<'_, G>) {

`

678

673

`use crate::fluent_generated as fluent;

`

679

674

`use rustc_middle::mir::interpret::ValidationErrorKind::*;

`

680

675

``

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

`

684

679

`}

`

685

680

``

686

681

`let message = if let Some(path) = self.path {

`

687

``

`-

dcx.eagerly_translate_to_string(

`

``

682

`+

err.dcx.eagerly_translate_to_string(

`

688

683

` fluent::const_eval_validation_front_matter_invalid_value_with_path,

`

689

684

`[("path".into(), DiagnosticArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),

`

690

685

`)

`

691

686

`} else {

`

692

``

`-

dcx.eagerly_translate_to_string(

`

``

687

`+

err.dcx.eagerly_translate_to_string(

`

693

688

` fluent::const_eval_validation_front_matter_invalid_value,

`

694

689

`[].into_iter(),

`

695

690

`)

`

`@@ -700,7 +695,6 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {

`

700

695

`fn add_range_arg<G: EmissionGuarantee>(

`

701

696

`r: WrappingRange,

`

702

697

`max_hi: u128,

`

703

``

`-

dcx: &DiagCtxt,

`

704

698

`err: &mut DiagnosticBuilder<'_, G>,

`

705

699

`) {

`

706

700

`let WrappingRange { start: lo, end: hi } = r;

`

`@@ -724,7 +718,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {

`

724

718

`("hi".into(), DiagnosticArgValue::Str(hi.to_string().into())),

`

725

719

`];

`

726

720

`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);

`

728

722

` err.arg("in_range", message);

`

729

723

`}

`

730

724

``

`@@ -746,7 +740,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {

`

746

740

`ExpectedKind::EnumTag => fluent::const_eval_validation_expected_enum_tag,

`

747

741

`ExpectedKind::Str => fluent::const_eval_validation_expected_str,

`

748

742

`};

`

749

``

`-

let msg = dcx.eagerly_translate_to_string(msg, [].into_iter());

`

``

743

`+

let msg = err.dcx.eagerly_translate_to_string(msg, [].into_iter());

`

750

744

` err.arg("expected", msg);

`

751

745

`}

`

752

746

`InvalidEnumTag { value }

`

`@@ -757,11 +751,11 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {

`

757

751

` err.arg("value", value);

`

758

752

`}

`

759

753

`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)

`

761

755

`}

`

762

756

`OutOfRange { range, max_value, value } => {

`

763

757

` err.arg("value", value);

`

764

``

`-

add_range_arg(range, max_value, dcx, err);

`

``

758

`+

add_range_arg(range, max_value, err);

`

765

759

`}

`

766

760

`UnalignedPtr { required_bytes, found_bytes, .. } => {

`

767

761

` err.arg("required_bytes", required_bytes);

`

`@@ -802,24 +796,24 @@ impl ReportErrorExt for UnsupportedOpInfo {

`

802

796

`UnsupportedOpInfo::ExternStatic(_) => const_eval_extern_static,

`

803

797

`}

`

804

798

`}

`

805

``

`-

fn add_args<G: EmissionGuarantee>(self, _: &DiagCtxt, builder: &mut DiagnosticBuilder<'_, G>) {

`

``

799

`+

fn add_args<G: EmissionGuarantee>(self, diag: &mut DiagnosticBuilder<'_, G>) {

`

806

800

`use crate::fluent_generated::*;

`

807

801

``

808

802

`use UnsupportedOpInfo::*;

`

809

803

`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);

`

812

806

`}

`

813

807

`match self {

`

814

808

`` // ReadPointerAsInt(Some(info)) is never printed anyway, it only serves as an error to

``

815

809

`// be further processed by validity checking which then turns it into something nice to

`

816

810

`` // print. So it's not worth the effort of having diagnostics that can print the info.

``

817

811

`UnsizedLocal | Unsupported() | ReadPointerAsInt() => {}

`

818

812

`OverwritePartialPointer(ptr) | ReadPartialPointer(ptr) => {

`

819

``

`-

builder.arg("ptr", ptr);

`

``

813

`+

diag.arg("ptr", ptr);

`

820

814

`}

`

821

815

`ThreadLocalStatic(did) | ExternStatic(did) => {

`

822

``

`-

builder.arg("did", format!("{did:?}"));

`

``

816

`+

diag.arg("did", format!("{did:?}"));

`

823

817

`}

`

824

818

`}

`

825

819

`}

`

`@@ -835,18 +829,14 @@ impl<'tcx> ReportErrorExt for InterpError<'tcx> {

`

835

829

`InterpError::MachineStop(e) => e.diagnostic_message(),

`

836

830

`}

`

837

831

`}

`

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>) {

`

843

833

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

`

848

838

`InterpError::MachineStop(e) => e.add_args(&mut |name, value| {

`

849

``

`-

builder.arg(name, value);

`

``

839

`+

diag.arg(name, value);

`

850

840

`}),

`

851

841

`}

`

852

842

`}

`

`@@ -864,28 +854,24 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {

`

864

854

`}

`

865

855

`}

`

866

856

`}

`

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>) {

`

872

858

`match self {

`

873

859

`InvalidProgramInfo::TooGeneric | InvalidProgramInfo::AlreadyReported(_) => {}

`

874

860

`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.

``

876

862

`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());

`

881

867

`}

`

882

``

`-

diag.cancel();

`

``

868

`+

dummy_diag.cancel();

`

883

869

`}

`

884

870

`InvalidProgramInfo::FnAbiAdjustForForeignAbi(

`

885

871

`AdjustForForeignAbiError::Unsupported { arch, abi },

`

886

872

`) => {

`

887

``

`-

builder.arg("arch", arch);

`

888

``

`-

builder.arg("abi", abi.name());

`

``

873

`+

diag.arg("arch", arch);

`

``

874

`+

diag.arg("abi", abi.name());

`

889

875

`}

`

890

876

`}

`

891

877

`}

`

`@@ -900,7 +886,7 @@ impl ReportErrorExt for ResourceExhaustionInfo {

`

900

886

`ResourceExhaustionInfo::AddressSpaceFull => const_eval_address_space_full,

`

901

887

`}

`

902

888

`}

`

903

``

`-

fn add_args<G: EmissionGuarantee>(self, _: &DiagCtxt, _: &mut DiagnosticBuilder<'_, G>) {}

`

``

889

`+

fn add_args<G: EmissionGuarantee>(self, _: &mut DiagnosticBuilder<'_, G>) {}

`

904

890

`}

`

905

891

``

906

892

`impl rustc_errors::IntoDiagnosticArg for InternKind {

`