File tree 2 files changed +24
-12
lines changed
2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -1945,6 +1945,14 @@ fn document_type_layout<'a, 'cx: 'a>(
1945
1945
ty_def_id : DefId ,
1946
1946
}
1947
1947
1948
+ #[ derive( Template ) ]
1949
+ #[ template( path = "type_layout_size.html" ) ]
1950
+ struct TypeLayoutSize {
1951
+ is_unsized : bool ,
1952
+ is_uninhabited : bool ,
1953
+ size : u64 ,
1954
+ }
1955
+
1948
1956
impl < ' a , ' cx : ' a > TypeLayout < ' a , ' cx > {
1949
1957
fn variants < ' b : ' a > ( & ' b self ) -> Option < & ' b IndexVec < VariantIdx , LayoutS > > {
1950
1958
if let Variants :: Multiple { variants, .. } =
@@ -1986,18 +1994,10 @@ fn document_type_layout<'a, 'cx: 'a>(
1986
1994
tag_size : u64 ,
1987
1995
) -> impl fmt:: Display + Captures < ' cx > + Captures < ' b > {
1988
1996
display_fn ( move |f| {
1989
- if layout. abi . is_unsized ( ) {
1990
- write ! ( f, "(unsized)" ) ?;
1991
- } else {
1992
- let size = layout. size . bytes ( ) - tag_size;
1993
- write ! ( f, "{size} byte{pl}" , pl = if size == 1 { "" } else { "s" } ) ?;
1994
- if layout. abi . is_uninhabited ( ) {
1995
- write ! (
1996
- f,
1997
- " (<a href=\" https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited\" >uninhabited</a>)"
1998
- ) ?;
1999
- }
2000
- }
1997
+ let is_unsized = layout. abi . is_unsized ( ) ;
1998
+ let is_uninhabited = layout. abi . is_uninhabited ( ) ;
1999
+ let size = layout. size . bytes ( ) - tag_size;
2000
+ TypeLayoutSize { is_unsized, is_uninhabited, size } . render_into ( f) . unwrap ( ) ;
2001
2001
Ok ( ( ) )
2002
2002
} )
2003
2003
}
Original file line number Diff line number Diff line change
1
+ {% if is_unsized %}
2
+ (unsized)
3
+ {% else %}
4
+ {% if size == 1 %}
5
+ 1 byte
6
+ {% else %}
7
+ {{ size +}} bytes
8
+ {% endif %}
9
+ {% if is_uninhabited %}
10
+ {# +#} (< a href ="https://doc.rust-lang.org/stable/reference/glossary.html#uninhabited "> uninhabited</ a > )
11
+ {% endif %}
12
+ {% endif %}
You can’t perform that action at this time.
0 commit comments