Only show type layout info if --show-type-layout
is passed
This commit is contained in:
parent
48da66f28f
commit
12ee920a7c
@ -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>,
|
||||
}
|
||||
@ -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);
|
||||
|
||||
@ -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(),
|
||||
),
|
||||
|
@ -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
|
||||
@ -373,6 +375,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
||||
generate_search_filter,
|
||||
unstable_features,
|
||||
generate_redirect_map,
|
||||
show_type_layout,
|
||||
..
|
||||
} = options;
|
||||
|
||||
@ -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
|
||||
|
@ -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)) {
|
||||
|
@ -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")
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
|
4
src/test/rustdoc/type-layout-flag-required.rs
Normal file
4
src/test/rustdoc/type-layout-flag-required.rs
Normal file
@ -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);
|
@ -1,3 +1,5 @@
|
||||
// compile-flags: --show-type-layout -Z unstable-options
|
||||
|
||||
// @has type_layout/struct.Foo.html 'Size: '
|
||||
// @has - ' bytes'
|
||||
pub struct Foo {
|
||||
|
Loading…
x
Reference in New Issue
Block a user