Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 12ee920

Browse files
committed
Only show type layout info if --show-type-layout is passed
1 parent 48da66f commit 12ee920

File tree

6 files changed

+21
-0
lines changed

6 files changed

+21
-0
lines changed

src/librustdoc/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ crate struct RenderOptions {
267267
crate document_hidden: bool,
268268
/// If `true`, generate a JSON file in the crate folder instead of HTML redirection files.
269269
crate generate_redirect_map: bool,
270+
/// Show the memory layout of types in the docs.
271+
crate show_type_layout: bool,
270272
crate unstable_features: rustc_feature::UnstableFeatures,
271273
crate emit: Vec<EmitType>,
272274
}
@@ -636,6 +638,7 @@ impl Options {
636638
let document_hidden = matches.opt_present("document-hidden-items");
637639
let run_check = matches.opt_present("check");
638640
let generate_redirect_map = matches.opt_present("generate-redirect-map");
641+
let show_type_layout = matches.opt_present("show-type-layout");
639642

640643
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
641644

@@ -695,6 +698,7 @@ impl Options {
695698
document_private,
696699
document_hidden,
697700
generate_redirect_map,
701+
show_type_layout,
698702
unstable_features: rustc_feature::UnstableFeatures::from_environment(
699703
crate_name.as_deref(),
700704
),

src/librustdoc/html/render/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ crate struct SharedContext<'tcx> {
9191
crate include_sources: bool,
9292
/// The local file sources we've emitted and their respective url-paths.
9393
crate local_sources: FxHashMap<PathBuf, String>,
94+
/// Show the memory layout of types in the docs.
95+
pub(super) show_type_layout: bool,
9496
/// Whether the collapsed pass ran
9597
collapsed: bool,
9698
/// The base-URL of the issue tracker for when an item has been tagged with
@@ -373,6 +375,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
373375
generate_search_filter,
374376
unstable_features,
375377
generate_redirect_map,
378+
show_type_layout,
376379
..
377380
} = options;
378381

@@ -446,6 +449,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
446449
all: RefCell::new(AllTypes::new()),
447450
errors: receiver,
448451
redirections: if generate_redirect_map { Some(Default::default()) } else { None },
452+
show_type_layout,
449453
};
450454

451455
// Add the default themes to the `Vec` of stylepaths

src/librustdoc/html/render/print_item.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,10 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) {
15361536
}
15371537

15381538
fn document_ty_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
1539+
if !cx.shared.show_type_layout {
1540+
return;
1541+
}
1542+
15391543
let param_env = cx.tcx().param_env(ty_def_id);
15401544
let ty = cx.tcx().type_of(ty_def_id);
15411545
match cx.tcx().layout_of(param_env.and(ty)) {

src/librustdoc/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,9 @@ fn opts() -> Vec<RustcOptGroup> {
594594
)
595595
}),
596596
unstable("no-run", |o| o.optflag("", "no-run", "Compile doctests without running them")),
597+
unstable("show-type-layout", |o| {
598+
o.optflag("", "show-type-layout", "Include the memory layout of types in the docs")
599+
}),
597600
]
598601
}
599602

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Tests that `--show-type-layout` is required in order to show layout info.
2+
3+
// @!has type_layout_flag_required/struct.Foo.html 'Size: '
4+
pub struct Foo(usize);

src/test/rustdoc/type-layout.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags: --show-type-layout -Z unstable-options
2+
13
// @has type_layout/struct.Foo.html 'Size: '
24
// @has - ' bytes'
35
pub struct Foo {

0 commit comments

Comments
 (0)