@@ -7,6 +7,8 @@ use rustc_span::symbol::sym;
7
7
use rustc_span:: Span ;
8
8
use rustc_target:: abi:: { HasDataLayout , TargetDataLayout } ;
9
9
10
+ use crate :: errors:: { Abi , Align , HomogeneousAggregate , Layout , LayoutOf , Size , UnrecognizedField } ;
11
+
10
12
pub fn test_layout ( tcx : TyCtxt < ' _ > ) {
11
13
if tcx. features ( ) . rustc_attrs {
12
14
// 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
35
37
for meta_item in meta_items {
36
38
match meta_item. name_or_empty ( ) {
37
39
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
+ } ) ;
42
44
}
43
45
44
46
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
+ } ) ;
49
51
}
50
52
51
53
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
+ } ) ;
56
58
}
57
59
58
60
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 } )
64
66
) ,
65
- ) ;
67
+ } ) ;
66
68
}
67
69
68
70
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
+ )
76
77
) ;
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
+ } ) ;
77
84
}
78
85
79
86
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 } ) ;
84
88
}
85
89
}
86
90
}
87
91
}
88
92
89
93
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
+ } ) ;
94
98
}
95
99
}
96
100
}
0 commit comments