@@ -6,16 +6,14 @@ use rustc_hir as hir;
6
6
use rustc_hir:: def:: CtorKind ;
7
7
use rustc_hir:: def_id:: DefId ;
8
8
use rustc_middle:: middle:: stability;
9
- use rustc_middle:: span_bug;
10
- use rustc_middle:: ty:: layout:: LayoutError ;
11
- use rustc_middle:: ty:: { self , Adt , TyCtxt } ;
9
+ use rustc_middle:: ty:: { self , TyCtxt } ;
12
10
use rustc_span:: hygiene:: MacroKind ;
13
11
use rustc_span:: symbol:: { kw, sym, Symbol } ;
14
- use rustc_target:: abi:: { Primitive , TagEncoding , Variants } ;
15
12
use std:: cmp:: Ordering ;
16
13
use std:: fmt;
17
14
use std:: rc:: Rc ;
18
15
16
+ use super :: type_layout:: document_type_layout;
19
17
use super :: {
20
18
collect_paths_for_type, document, ensure_trailing_slash, get_filtered_impls_for_reference,
21
19
item_ty_to_section, notable_traits_button, notable_traits_json, render_all_impls,
@@ -1932,79 +1930,6 @@ fn document_non_exhaustive<'a>(item: &'a clean::Item) -> impl fmt::Display + 'a
1932
1930
} )
1933
1931
}
1934
1932
1935
- fn document_type_layout < ' a , ' cx : ' a > (
1936
- cx : & ' a Context < ' cx > ,
1937
- ty_def_id : DefId ,
1938
- ) -> impl fmt:: Display + ' a + Captures < ' cx > {
1939
- #[ derive( Template ) ]
1940
- #[ template( path = "type_layout.html" ) ]
1941
- struct TypeLayout < ' cx > {
1942
- variants : Vec < ( Symbol , TypeLayoutSize ) > ,
1943
- type_layout_size : Result < TypeLayoutSize , LayoutError < ' cx > > ,
1944
- }
1945
-
1946
- #[ derive( Template ) ]
1947
- #[ template( path = "type_layout_size.html" ) ]
1948
- struct TypeLayoutSize {
1949
- is_unsized : bool ,
1950
- is_uninhabited : bool ,
1951
- size : u64 ,
1952
- }
1953
-
1954
- display_fn ( move |f| {
1955
- if !cx. shared . show_type_layout {
1956
- return Ok ( ( ) ) ;
1957
- }
1958
-
1959
- let tcx = cx. tcx ( ) ;
1960
- let param_env = tcx. param_env ( ty_def_id) ;
1961
- let ty = tcx. type_of ( ty_def_id) . subst_identity ( ) ;
1962
- let type_layout = tcx. layout_of ( param_env. and ( ty) ) ;
1963
-
1964
- let variants =
1965
- if let Ok ( type_layout) = type_layout &&
1966
- let Variants :: Multiple { variants, tag, tag_encoding, .. } =
1967
- type_layout. layout . variants ( ) &&
1968
- !variants. is_empty ( )
1969
- {
1970
- let tag_size =
1971
- if let TagEncoding :: Niche { .. } = tag_encoding {
1972
- 0
1973
- } else if let Primitive :: Int ( i, _) = tag. primitive ( ) {
1974
- i. size ( ) . bytes ( )
1975
- } else {
1976
- span_bug ! ( cx. tcx( ) . def_span( ty_def_id) , "tag is neither niche nor int" )
1977
- } ;
1978
- let variants = variants
1979
- . iter_enumerated ( )
1980
- . map ( |( variant_idx, variant_layout) | {
1981
- let Adt ( adt, _) = type_layout. ty . kind ( ) else {
1982
- span_bug ! ( cx. tcx( ) . def_span( ty_def_id) , "not an adt" )
1983
- } ;
1984
- let name = adt. variant ( variant_idx) . name ;
1985
- let is_unsized = variant_layout. abi . is_unsized ( ) ;
1986
- let is_uninhabited = variant_layout. abi . is_uninhabited ( ) ;
1987
- let size = variant_layout. size . bytes ( ) - tag_size;
1988
- let type_layout_size = TypeLayoutSize { is_unsized, is_uninhabited, size } ;
1989
- ( name, type_layout_size)
1990
- } ) . collect ( ) ;
1991
- variants
1992
- } else {
1993
- Vec :: new ( )
1994
- }
1995
- ;
1996
-
1997
- let type_layout_size = tcx. layout_of ( param_env. and ( ty) ) . map ( |layout| {
1998
- let is_unsized = layout. abi . is_unsized ( ) ;
1999
- let is_uninhabited = layout. abi . is_uninhabited ( ) ;
2000
- let size = layout. size . bytes ( ) ;
2001
- TypeLayoutSize { is_unsized, is_uninhabited, size }
2002
- } ) ;
2003
-
2004
- Ok ( TypeLayout { variants, type_layout_size } . render_into ( f) . unwrap ( ) )
2005
- } )
2006
- }
2007
-
2008
1933
fn pluralize ( count : usize ) -> & ' static str {
2009
1934
if count > 1 { "s" } else { "" }
2010
1935
}
0 commit comments