@@ -7,6 +7,8 @@ use rustc_span::symbol::sym;
77use rustc_span:: Span ;
88use rustc_target:: abi:: { HasDataLayout , TargetDataLayout } ;
99
10+ use crate :: errors:: { Abi , Align , HomogeneousAggregate , Layout , LayoutOf , Size , UnrecognizedField } ;
11+
1012pub fn test_layout ( tcx : TyCtxt < ' _ > ) {
1113 if tcx. features ( ) . rustc_attrs {
1214 // if the `rustc_attrs` feature is not enabled, don't bother testing layout
@@ -35,62 +37,64 @@ fn dump_layout_of<'tcx>(tcx: TyCtxt<'tcx>, item_def_id: LocalDefId, attr: &Attri
3537 for meta_item in meta_items {
3638 match meta_item. name_or_empty ( ) {
3739 sym:: abi => {
38- tcx. sess . span_err (
39- tcx. def_span ( item_def_id. to_def_id ( ) ) ,
40- & format ! ( "abi: {:?}" , ty_layout. abi) ,
41- ) ;
40+ tcx. sess . emit_err ( Abi {
41+ span : tcx. def_span ( item_def_id. to_def_id ( ) ) ,
42+ abi : format ! ( "{:?}" , ty_layout. abi) ,
43+ } ) ;
4244 }
4345
4446 sym:: align => {
45- tcx. sess . span_err (
46- tcx. def_span ( item_def_id. to_def_id ( ) ) ,
47- & format ! ( "align: {:?}" , ty_layout. align) ,
48- ) ;
47+ tcx. sess . emit_err ( Align {
48+ span : tcx. def_span ( item_def_id. to_def_id ( ) ) ,
49+ align : format ! ( "{:?}" , ty_layout. align) ,
50+ } ) ;
4951 }
5052
5153 sym:: size => {
52- tcx. sess . span_err (
53- tcx. def_span ( item_def_id. to_def_id ( ) ) ,
54- & format ! ( "size: {:?}" , ty_layout. size) ,
55- ) ;
54+ tcx. sess . emit_err ( Size {
55+ span : tcx. def_span ( item_def_id. to_def_id ( ) ) ,
56+ size : format ! ( "{:?}" , ty_layout. size) ,
57+ } ) ;
5658 }
5759
5860 sym:: homogeneous_aggregate => {
59- tcx. sess . span_err (
60- tcx. def_span ( item_def_id. to_def_id ( ) ) ,
61- & format ! (
62- "homogeneous_aggregate: {:?}" ,
63- ty_layout. homogeneous_aggregate( & UnwrapLayoutCx { tcx, param_env } ) ,
61+ tcx. sess . emit_err ( HomogeneousAggregate {
62+ span : tcx. def_span ( item_def_id. to_def_id ( ) ) ,
63+ homogeneous_aggregate : format ! (
64+ "{:?}" ,
65+ ty_layout. homogeneous_aggregate( & UnwrapLayoutCx { tcx, param_env } )
6466 ) ,
65- ) ;
67+ } ) ;
6668 }
6769
6870 sym:: debug => {
69- let normalized_ty = tcx. normalize_erasing_regions (
70- param_env. with_reveal_all_normalized ( tcx) ,
71- ty,
72- ) ;
73- tcx. sess . span_err (
74- tcx. def_span ( item_def_id. to_def_id ( ) ) ,
75- & format ! ( "layout_of({:?}) = {:#?}" , normalized_ty, * ty_layout) ,
71+ let normalized_ty = format ! (
72+ "{:?}" ,
73+ tcx. normalize_erasing_regions(
74+ param_env. with_reveal_all_normalized( tcx) ,
75+ ty,
76+ )
7677 ) ;
78+ let ty_layout = format ! ( "{:#?}" , * ty_layout) ;
79+ tcx. sess . emit_err ( LayoutOf {
80+ span : tcx. def_span ( item_def_id. to_def_id ( ) ) ,
81+ normalized_ty,
82+ ty_layout,
83+ } ) ;
7784 }
7885
7986 name => {
80- tcx. sess . span_err (
81- meta_item. span ( ) ,
82- & format ! ( "unrecognized field name `{}`" , name) ,
83- ) ;
87+ tcx. sess . emit_err ( UnrecognizedField { span : meta_item. span ( ) , name } ) ;
8488 }
8589 }
8690 }
8791 }
8892
8993 Err ( layout_error) => {
90- tcx. sess . span_err (
91- tcx. def_span ( item_def_id. to_def_id ( ) ) ,
92- & format ! ( "layout error: {:?}" , layout_error) ,
93- ) ;
94+ tcx. sess . emit_err ( Layout {
95+ span : tcx. def_span ( item_def_id. to_def_id ( ) ) ,
96+ layout_error : format ! ( "{:?}" , layout_error) ,
97+ } ) ;
9498 }
9599 }
96100}
0 commit comments