Skip to content

Commit de200d8

Browse files
authored
Unrolled build for #152356
Rollup merge of #152356 - JonathanBrouwer:inline_diag4, r=jdonszelmann Improve the `inline_fluent!` macro For #151366 This PR turns `inline_fluent!` into a proc macro, so we can run validation on the messages in this macro :) I started a thread here because I don't like the name of the macro, but that's for a future PR: [#t-compiler > Bikeshed the new `inline_fluent!` macro](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Bikeshed.20the.20new.20.60inline_fluent!.60.20macro/with/572646242)
2 parents a423f68 + 6eb2a8f commit de200d8

File tree

20 files changed

+320
-275
lines changed

20 files changed

+320
-275
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@ fn report_eval_error<'tcx>(
471471
span,
472472
inline_fluent!(
473473
"evaluation of `{$instance}` failed {$num_frames ->
474-
[0] here
475-
*[other] inside this call
476-
}"
474+
[0] here
475+
*[other] inside this call
476+
}"
477477
),
478478
);
479479
for frame in frames {

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,10 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
491491
Err(err) => throw_ub_custom!(
492492
inline_fluent!(
493493
"invalid align passed to `{$name}`: {$align} is {$err_kind ->
494-
[not_power_of_two] not a power of 2
495-
[too_large] too large
496-
*[other] {\"\"}
497-
}"
494+
[not_power_of_two] not a power of 2
495+
[too_large] too large
496+
*[other] {\"\"}
497+
}"
498498
),
499499
name = "const_allocate",
500500
err_kind = err.diag_ident(),
@@ -521,10 +521,10 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
521521
Err(err) => throw_ub_custom!(
522522
inline_fluent!(
523523
"invalid align passed to `{$name}`: {$align} is {$err_kind ->
524-
[not_power_of_two] not a power of 2
525-
[too_large] too large
526-
*[other] {\"\"}
527-
}"
524+
[not_power_of_two] not a power of 2
525+
[too_large] too large
526+
*[other] {\"\"}
527+
}"
528528
),
529529
name = "const_deallocate",
530530
err_kind = err.diag_ident(),

compiler/rustc_const_eval/src/errors.rs

Lines changed: 110 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,17 @@ impl Subdiagnostic for FrameNote {
393393
}
394394
let msg = diag.eagerly_translate(inline_fluent!(
395395
r#"{$times ->
396-
[0] {const_eval_frame_note_inner}
397-
*[other] [... {$times} additional calls {const_eval_frame_note_inner} ...]
398-
}
399-
400-
const_eval_frame_note_inner = inside {$where_ ->
401-
[closure] closure
402-
[instance] `{$instance}`
403-
*[other] {""}
404-
}
405-
"#
396+
[0] inside {$where_ ->
397+
[closure] closure
398+
[instance] `{$instance}`
399+
*[other] {""}
400+
}
401+
*[other] [... {$times} additional calls inside {$where_ ->
402+
[closure] closure
403+
[instance] `{$instance}`
404+
*[other] {""}
405+
} ...]
406+
}"#
406407
));
407408
diag.remove_arg("times");
408409
diag.remove_arg("where_");
@@ -663,89 +664,96 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
663664
InvalidMeta(InvalidMetaKind::SliceTooBig) => "invalid metadata in wide pointer: slice is bigger than largest supported object".into(),
664665
InvalidMeta(InvalidMetaKind::TooBig) => "invalid metadata in wide pointer: total size is bigger than largest supported object".into(),
665666
UnterminatedCString(_) => "reading a null-terminated string starting at {$pointer} with no null found before end of allocation".into(),
666-
PointerUseAfterFree(_, _) => inline_fluent!("{$operation ->
667-
[MemoryAccess] memory access failed
668-
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
669-
*[Dereferenceable] pointer not dereferenceable
670-
}: {$alloc_id} has been freed, so this pointer is dangling"),
671-
PointerOutOfBounds { .. } => inline_fluent!("{$operation ->
672-
[MemoryAccess] memory access failed
673-
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
674-
*[Dereferenceable] pointer not dereferenceable
675-
}: {$operation ->
676-
[MemoryAccess] attempting to access {$inbounds_size ->
677-
[1] 1 byte
678-
*[x] {$inbounds_size} bytes
679-
}
680-
[InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
681-
[1] 1 byte
682-
*[x] {$inbounds_size} bytes
683-
}
684-
*[Dereferenceable] pointer must {$inbounds_size ->
685-
[0] point to some allocation
686-
[1] be dereferenceable for 1 byte
687-
*[x] be dereferenceable for {$inbounds_size} bytes
688-
}
689-
}, but got {$pointer} which {$ptr_offset_is_neg ->
690-
[true] points to before the beginning of the allocation
691-
*[false] {$inbounds_size_is_neg ->
692-
[false] {$alloc_size_minus_ptr_offset ->
693-
[0] is at or beyond the end of the allocation of size {$alloc_size ->
694-
[1] 1 byte
695-
*[x] {$alloc_size} bytes
696-
}
697-
[1] is only 1 byte from the end of the allocation
698-
*[x] is only {$alloc_size_minus_ptr_offset} bytes from the end of the allocation
699-
}
700-
*[true] {$ptr_offset_abs ->
701-
[0] is at the beginning of the allocation
702-
*[other] is only {$ptr_offset_abs} bytes from the beginning of the allocation
703-
}
704-
}
705-
}
706-
"),
707-
DanglingIntPointer { addr: 0, .. } => inline_fluent!("{$operation ->
708-
[MemoryAccess] memory access failed
709-
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
710-
*[Dereferenceable] pointer not dereferenceable
711-
}: {$operation ->
712-
[MemoryAccess] attempting to access {$inbounds_size ->
713-
[1] 1 byte
714-
*[x] {$inbounds_size} bytes
715-
}
716-
[InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
717-
[1] 1 byte
718-
*[x] {$inbounds_size} bytes
719-
}
720-
*[Dereferenceable] pointer must {$inbounds_size ->
721-
[0] point to some allocation
722-
[1] be dereferenceable for 1 byte
723-
*[x] be dereferenceable for {$inbounds_size} bytes
724-
}
725-
}, but got null pointer"),
726-
DanglingIntPointer { .. } => inline_fluent!("{$operation ->
727-
[MemoryAccess] memory access failed
728-
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
729-
*[Dereferenceable] pointer not dereferenceable
730-
}: {$operation ->
731-
[MemoryAccess] attempting to access {$inbounds_size ->
732-
[1] 1 byte
733-
*[x] {$inbounds_size} bytes
734-
}
735-
[InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
736-
[1] 1 byte
737-
*[x] {$inbounds_size} bytes
738-
}
739-
*[Dereferenceable] pointer must {$inbounds_size ->
740-
[0] point to some allocation
741-
[1] be dereferenceable for 1 byte
742-
*[x] be dereferenceable for {$inbounds_size} bytes
743-
}
744-
}, but got {$pointer} which is a dangling pointer (it has no provenance)"),
745-
AlignmentCheckFailed { .. } => inline_fluent!("{$msg ->
746-
[AccessedPtr] accessing memory
747-
*[other] accessing memory based on pointer
748-
} with alignment {$has}, but alignment {$required} is required"),
667+
PointerUseAfterFree(_, _) => inline_fluent!(
668+
"{$operation ->
669+
[MemoryAccess] memory access failed
670+
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
671+
*[Dereferenceable] pointer not dereferenceable
672+
}: {$alloc_id} has been freed, so this pointer is dangling"
673+
),
674+
PointerOutOfBounds { .. } => inline_fluent!(
675+
"{$operation ->
676+
[MemoryAccess] memory access failed
677+
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
678+
*[Dereferenceable] pointer not dereferenceable
679+
}: {$operation ->
680+
[MemoryAccess] attempting to access {$inbounds_size ->
681+
[1] 1 byte
682+
*[x] {$inbounds_size} bytes
683+
}
684+
[InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
685+
[1] 1 byte
686+
*[x] {$inbounds_size} bytes
687+
}
688+
*[Dereferenceable] pointer must {$inbounds_size ->
689+
[0] point to some allocation
690+
[1] be dereferenceable for 1 byte
691+
*[x] be dereferenceable for {$inbounds_size} bytes
692+
}
693+
}, but got {$pointer} which {$ptr_offset_is_neg ->
694+
[true] points to before the beginning of the allocation
695+
*[false] {$inbounds_size_is_neg ->
696+
[false] {$alloc_size_minus_ptr_offset ->
697+
[0] is at or beyond the end of the allocation of size {$alloc_size ->
698+
[1] 1 byte
699+
*[x] {$alloc_size} bytes
700+
}
701+
[1] is only 1 byte from the end of the allocation
702+
*[x] is only {$alloc_size_minus_ptr_offset} bytes from the end of the allocation
703+
}
704+
*[true] {$ptr_offset_abs ->
705+
[0] is at the beginning of the allocation
706+
*[other] is only {$ptr_offset_abs} bytes from the beginning of the allocation
707+
}
708+
}
709+
}"
710+
),
711+
DanglingIntPointer { addr: 0, .. } => inline_fluent!(
712+
"{$operation ->
713+
[MemoryAccess] memory access failed
714+
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
715+
*[Dereferenceable] pointer not dereferenceable
716+
}: {$operation ->
717+
[MemoryAccess] attempting to access {$inbounds_size ->
718+
[1] 1 byte
719+
*[x] {$inbounds_size} bytes
720+
}
721+
[InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
722+
[1] 1 byte
723+
*[x] {$inbounds_size} bytes
724+
}
725+
*[Dereferenceable] pointer must {$inbounds_size ->
726+
[0] point to some allocation
727+
[1] be dereferenceable for 1 byte
728+
*[x] be dereferenceable for {$inbounds_size} bytes
729+
}
730+
}, but got null pointer"),
731+
DanglingIntPointer { .. } => inline_fluent!(
732+
"{$operation ->
733+
[MemoryAccess] memory access failed
734+
[InboundsPointerArithmetic] in-bounds pointer arithmetic failed
735+
*[Dereferenceable] pointer not dereferenceable
736+
}: {$operation ->
737+
[MemoryAccess] attempting to access {$inbounds_size ->
738+
[1] 1 byte
739+
*[x] {$inbounds_size} bytes
740+
}
741+
[InboundsPointerArithmetic] attempting to offset pointer by {$inbounds_size ->
742+
[1] 1 byte
743+
*[x] {$inbounds_size} bytes
744+
}
745+
*[Dereferenceable] pointer must {$inbounds_size ->
746+
[0] point to some allocation
747+
[1] be dereferenceable for 1 byte
748+
*[x] be dereferenceable for {$inbounds_size} bytes
749+
}
750+
}, but got {$pointer} which is a dangling pointer (it has no provenance)"),
751+
AlignmentCheckFailed { .. } => inline_fluent!(
752+
"{$msg ->
753+
[AccessedPtr] accessing memory
754+
*[other] accessing memory based on pointer
755+
} with alignment {$has}, but alignment {$required} is required"
756+
),
749757
WriteToReadOnly(_) => inline_fluent!("writing to {$allocation} which is read-only"),
750758
DerefFunctionPointer(_) => inline_fluent!("accessing {$allocation} which contains a function"),
751759
DerefVTablePointer(_) => inline_fluent!("accessing {$allocation} which contains a vtable"),
@@ -936,9 +944,9 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
936944
NullFnPtr { .. } => {
937945
inline_fluent!(
938946
"{$front_matter}: encountered a {$maybe ->
939-
[true] maybe-null
940-
*[false] null
941-
} function pointer"
947+
[true] maybe-null
948+
*[false] null
949+
} function pointer"
942950
)
943951
}
944952
NeverVal => {
@@ -1021,17 +1029,17 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
10211029
NullPtr { ptr_kind: PointerKind::Box, .. } => {
10221030
inline_fluent!(
10231031
"{$front_matter}: encountered a {$maybe ->
1024-
[true] maybe-null
1025-
*[false] null
1026-
} box"
1032+
[true] maybe-null
1033+
*[false] null
1034+
} box"
10271035
)
10281036
}
10291037
NullPtr { ptr_kind: PointerKind::Ref(_), .. } => {
10301038
inline_fluent!(
10311039
"{$front_matter}: encountered a {$maybe ->
1032-
[true] maybe-null
1033-
*[false] null
1034-
} reference"
1040+
[true] maybe-null
1041+
*[false] null
1042+
} reference"
10351043
)
10361044
}
10371045
DanglingPtrNoProvenance { ptr_kind: PointerKind::Box, .. } => {

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
466466
// a < b
467467
if intrinsic_name == sym::ptr_offset_from_unsigned {
468468
throw_ub_custom!(
469-
inline_fluent!("`ptr_offset_from_unsigned` called when first pointer has smaller {$is_addr ->
470-
[true] address
471-
*[false] offset
472-
} than second: {$a_offset} < {$b_offset}"),
469+
inline_fluent!(
470+
"`ptr_offset_from_unsigned` called when first pointer has smaller {$is_addr ->
471+
[true] address
472+
*[false] offset
473+
} than second: {$a_offset} < {$b_offset}"
474+
),
473475
a_offset = a_offset,
474476
b_offset = b_offset,
475477
is_addr = is_addr,

0 commit comments

Comments
 (0)