rust/compiler/rustc_hir_analysis/src
David Rheinsberg b0dadff6de error/E0691: include alignment in error message
Include the computed alignment of the violating field when rejecting
transparent types with non-trivially aligned ZSTs.

ZST member fields in transparent types must have an alignment of 1 (to
ensure it does not raise the layout requirements of the transparent
field). The current error message looks like this:

 LL | struct Foobar(u32, [u32; 0]);
    |                    ^^^^^^^^ has alignment larger than 1

This patch changes the report to include the alignment of the violating
field:

 LL | struct Foobar(u32, [u32; 0]);
    |                    ^^^^^^^^ has alignment of 4, which is larger than 1

In case of unknown alignments, it will yield:

 LL | struct Foobar<T>(u32, [T; 0]);
    |                       ^^^^^^ may have alignment larger than 1

This allows developers to get a better grasp why a specific field is
rejected. Knowing the alignment of the violating field makes it easier
to judge where that alignment-requirement originates, and thus hopefully
provide better hints on how to mitigate the problem.

This idea was proposed in 2022 in #98071 as part of a bigger change.
This commit simply extracts this error-message change, to decouple it
from the other diagnostic improvements.
2023-07-21 11:04:16 +02:00
..
astconv Make it clearer that edition functions are >=, not == 2023-07-19 16:38:35 +00:00
check error/E0691: include alignment in error message 2023-07-21 11:04:16 +02:00
coherence XSimplifiedType to SimplifiedType::X 2023-07-20 11:05:52 +02:00
collect Properly document lifetime_mapping in OpaqueTy 2023-07-17 14:56:33 +00:00
impl_wf_check refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
outlives refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
structured_errors Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
variance Rename arg_iter to iter_instantiated 2023-07-17 21:04:12 +00:00
autoderef.rs Move TyCtxt::mk_x to Ty::new_x where applicable 2023-07-05 20:27:07 +01:00
bounds.rs Fully fledged Clause type 2023-06-19 15:46:08 +00:00
check_unused.rs Querify unused trait check. 2023-07-16 21:51:00 +00:00
collect.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
constrained_generic_params.rs Migrate predicates_of and caller_bounds to Clause 2023-06-26 23:12:03 +00:00
errors.rs Require TAITs to be mentioned in the signatures of functions that register hidden types for them 2023-07-07 13:13:18 +00:00
hir_wf_check.rs s/Clause/ClauseKind 2023-06-19 14:57:42 +00:00
impl_wf_check.rs refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
lib.rs Querify unused trait check. 2023-07-16 21:51:00 +00:00
structured_errors.rs rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00