Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dedup Fluent invalid ptr errors in const eval #116777

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 29 additions & 19 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 { .. }
Expand All @@ -784,8 +796,6 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
| UnsafeCell
| InvalidMetaSliceTooLarge { .. }
| InvalidMetaTooLarge { .. }
| DanglingPtrUseAfterFree { .. }
| DanglingPtrOutOfBounds { .. }
| UninhabitedEnumVariant
| PartialPointer => {}
}
Expand Down