Skip to content

Commit

Permalink
Only show type layout info if --show-type-layout is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed May 11, 2021
1 parent 48da66f commit 12ee920
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/librustdoc/config.rs
Expand Up @@ -267,6 +267,8 @@ crate struct RenderOptions {
crate document_hidden: bool,
/// If `true`, generate a JSON file in the crate folder instead of HTML redirection files.
crate generate_redirect_map: bool,
/// Show the memory layout of types in the docs.
crate show_type_layout: bool,
crate unstable_features: rustc_feature::UnstableFeatures,
crate emit: Vec<EmitType>,
}
Expand Down Expand Up @@ -636,6 +638,7 @@ impl Options {
let document_hidden = matches.opt_present("document-hidden-items");
let run_check = matches.opt_present("check");
let generate_redirect_map = matches.opt_present("generate-redirect-map");
let show_type_layout = matches.opt_present("show-type-layout");

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

Expand Down Expand Up @@ -695,6 +698,7 @@ impl Options {
document_private,
document_hidden,
generate_redirect_map,
show_type_layout,
unstable_features: rustc_feature::UnstableFeatures::from_environment(
crate_name.as_deref(),
),
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/html/render/context.rs
Expand Up @@ -91,6 +91,8 @@ crate struct SharedContext<'tcx> {
crate include_sources: bool,
/// The local file sources we've emitted and their respective url-paths.
crate local_sources: FxHashMap<PathBuf, String>,
/// Show the memory layout of types in the docs.
pub(super) show_type_layout: bool,
/// Whether the collapsed pass ran
collapsed: bool,
/// The base-URL of the issue tracker for when an item has been tagged with
Expand Down Expand Up @@ -373,6 +375,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
generate_search_filter,
unstable_features,
generate_redirect_map,
show_type_layout,
..
} = options;

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

// Add the default themes to the `Vec` of stylepaths
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/html/render/print_item.rs
Expand Up @@ -1536,6 +1536,10 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) {
}

fn document_ty_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
if !cx.shared.show_type_layout {
return;
}

let param_env = cx.tcx().param_env(ty_def_id);
let ty = cx.tcx().type_of(ty_def_id);
match cx.tcx().layout_of(param_env.and(ty)) {
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/lib.rs
Expand Up @@ -594,6 +594,9 @@ fn opts() -> Vec<RustcOptGroup> {
)
}),
unstable("no-run", |o| o.optflag("", "no-run", "Compile doctests without running them")),
unstable("show-type-layout", |o| {
o.optflag("", "show-type-layout", "Include the memory layout of types in the docs")
}),
]
}

Expand Down
4 changes: 4 additions & 0 deletions src/test/rustdoc/type-layout-flag-required.rs
@@ -0,0 +1,4 @@
// Tests that `--show-type-layout` is required in order to show layout info.

// @!has type_layout_flag_required/struct.Foo.html 'Size: '
pub struct Foo(usize);
2 changes: 2 additions & 0 deletions src/test/rustdoc/type-layout.rs
@@ -1,3 +1,5 @@
// compile-flags: --show-type-layout -Z unstable-options

// @has type_layout/struct.Foo.html 'Size: '
// @has - ' bytes'
pub struct Foo {
Expand Down

0 comments on commit 12ee920

Please sign in to comment.