diff --git a/compiler/rustc_const_eval/messages.ftl b/compiler/rustc_const_eval/messages.ftl index d23e2a9f3e4e0..2cab2bdd3411b 100644 --- a/compiler/rustc_const_eval/messages.ftl +++ b/compiler/rustc_const_eval/messages.ftl @@ -406,12 +406,11 @@ const_eval_upcast_mismatch = const_eval_validation_box_to_mut = {$front_matter}: encountered a box pointing to mutable memory in a constant const_eval_validation_box_to_static = {$front_matter}: encountered a box pointing to a static variable in a constant const_eval_validation_box_to_uninhabited = {$front_matter}: encountered a box pointing to uninhabited type {$ty} -const_eval_validation_dangling_box_no_provenance = {$front_matter}: encountered a dangling box ({$pointer} has no provenance) -const_eval_validation_dangling_box_out_of_bounds = {$front_matter}: encountered a dangling box (going beyond the bounds of its allocation) -const_eval_validation_dangling_box_use_after_free = {$front_matter}: encountered a dangling box (use-after-free) -const_eval_validation_dangling_ref_no_provenance = {$front_matter}: encountered a dangling reference ({$pointer} has no provenance) -const_eval_validation_dangling_ref_out_of_bounds = {$front_matter}: encountered a dangling reference (going beyond the bounds of its allocation) -const_eval_validation_dangling_ref_use_after_free = {$front_matter}: encountered a dangling reference (use-after-free) +const_eval_validation_dangling_err_no_provenance = {$pointer} has no provenance +const_eval_validation_dangling_err_out_of_bounds = going beyond the bounds of its allocation +const_eval_validation_dangling_err_use_after_free = use-after-free +const_eval_validation_dangling_ptr_box = {$front_matter}: encountered a dangling box ({$subdiagnostic}) +const_eval_validation_dangling_ptr_ref = {$front_matter}: encountered a dangling reference ({$subdiagnostic}) const_eval_validation_expected_bool = expected a boolean const_eval_validation_expected_box = expected a box diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index b1599dd689482..ef684b324ee84 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -655,23 +655,15 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { NullPtr { ptr_kind: PointerKind::Box } => const_eval_validation_null_box, NullPtr { ptr_kind: PointerKind::Ref } => const_eval_validation_null_ref, - DanglingPtrNoProvenance { ptr_kind: PointerKind::Box, .. } => { - const_eval_validation_dangling_box_no_provenance + DanglingPtrNoProvenance { ptr_kind: PointerKind::Box, .. } + | DanglingPtrOutOfBounds { ptr_kind: PointerKind::Box } + | DanglingPtrUseAfterFree { ptr_kind: PointerKind::Box } => { + const_eval_validation_dangling_ptr_box } - DanglingPtrNoProvenance { ptr_kind: PointerKind::Ref, .. } => { - const_eval_validation_dangling_ref_no_provenance - } - DanglingPtrOutOfBounds { ptr_kind: PointerKind::Box } => { - const_eval_validation_dangling_box_out_of_bounds - } - DanglingPtrOutOfBounds { ptr_kind: PointerKind::Ref } => { - const_eval_validation_dangling_ref_out_of_bounds - } - DanglingPtrUseAfterFree { ptr_kind: PointerKind::Box } => { - const_eval_validation_dangling_box_use_after_free - } - DanglingPtrUseAfterFree { ptr_kind: PointerKind::Ref } => { - const_eval_validation_dangling_ref_use_after_free + DanglingPtrNoProvenance { ptr_kind: PointerKind::Ref, .. } + | DanglingPtrOutOfBounds { ptr_kind: PointerKind::Ref } + | DanglingPtrUseAfterFree { ptr_kind: PointerKind::Ref } => { + const_eval_validation_dangling_ptr_ref } InvalidBool { .. } => const_eval_validation_invalid_bool, InvalidChar { .. } => const_eval_validation_invalid_char, @@ -773,7 +765,27 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { err.set_arg("found_bytes", found_bytes); } DanglingPtrNoProvenance { pointer, .. } => { - err.set_arg("pointer", pointer); + let subdiagnostic = handler.eagerly_translate_to_string( + fluent::const_eval_validation_dangling_err_no_provenance, + [("pointer".into(), DiagnosticArgValue::Str(pointer.into()))] + .iter() + .map(|(a, b)| (a, b)), + ); + err.set_arg("subdiagnostic", subdiagnostic); + } + DanglingPtrUseAfterFree { .. } => { + let subdiagnostic = handler.eagerly_translate_to_string( + fluent::const_eval_validation_dangling_err_use_after_free, + [].into_iter(), + ); + err.set_arg("subdiagnostic", subdiagnostic); + } + DanglingPtrOutOfBounds { .. } => { + let subdiagnostic = handler.eagerly_translate_to_string( + fluent::const_eval_validation_dangling_err_out_of_bounds, + [].into_iter(), + ); + err.set_arg("subdiagnostic", subdiagnostic); } NullPtr { .. } | PtrToStatic { .. } @@ -784,8 +796,6 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { | UnsafeCell | InvalidMetaSliceTooLarge { .. } | InvalidMetaTooLarge { .. } - | DanglingPtrUseAfterFree { .. } - | DanglingPtrOutOfBounds { .. } | UninhabitedEnumVariant | PartialPointer => {} }