Avoid cloning RenderOptions.
By moving `RenderOptions` out of `Option`, because the two structs' uses are almost entirely separate. The only complication is that `unstable_features` is needed in both structs, but it's a tiny `Copy` type so its duplication seems fine.
This commit is contained in:
@@ -142,8 +142,6 @@ pub(crate) struct Options {
|
|||||||
// Options that alter generated documentation pages
|
// Options that alter generated documentation pages
|
||||||
/// Crate version to note on the sidebar of generated docs.
|
/// Crate version to note on the sidebar of generated docs.
|
||||||
pub(crate) crate_version: Option<String>,
|
pub(crate) crate_version: Option<String>,
|
||||||
/// Collected options specific to outputting final pages.
|
|
||||||
pub(crate) render_options: RenderOptions,
|
|
||||||
/// The format that we output when rendering.
|
/// The format that we output when rendering.
|
||||||
///
|
///
|
||||||
/// Currently used only for the `--show-coverage` option.
|
/// Currently used only for the `--show-coverage` option.
|
||||||
@@ -159,6 +157,10 @@ pub(crate) struct Options {
|
|||||||
/// Configuration for scraping examples from the current crate. If this option is Some(..) then
|
/// Configuration for scraping examples from the current crate. If this option is Some(..) then
|
||||||
/// the compiler will scrape examples and not generate documentation.
|
/// the compiler will scrape examples and not generate documentation.
|
||||||
pub(crate) scrape_examples_options: Option<ScrapeExamplesOptions>,
|
pub(crate) scrape_examples_options: Option<ScrapeExamplesOptions>,
|
||||||
|
|
||||||
|
/// Note: this field is duplicated in `RenderOptions` because it's useful
|
||||||
|
/// to have it in both places.
|
||||||
|
pub(crate) unstable_features: rustc_feature::UnstableFeatures,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Options {
|
impl fmt::Debug for Options {
|
||||||
@@ -194,7 +196,6 @@ impl fmt::Debug for Options {
|
|||||||
.field("persist_doctests", &self.persist_doctests)
|
.field("persist_doctests", &self.persist_doctests)
|
||||||
.field("show_coverage", &self.show_coverage)
|
.field("show_coverage", &self.show_coverage)
|
||||||
.field("crate_version", &self.crate_version)
|
.field("crate_version", &self.crate_version)
|
||||||
.field("render_options", &self.render_options)
|
|
||||||
.field("runtool", &self.runtool)
|
.field("runtool", &self.runtool)
|
||||||
.field("runtool_args", &self.runtool_args)
|
.field("runtool_args", &self.runtool_args)
|
||||||
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
|
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
|
||||||
@@ -202,6 +203,7 @@ impl fmt::Debug for Options {
|
|||||||
.field("no_run", &self.no_run)
|
.field("no_run", &self.no_run)
|
||||||
.field("nocapture", &self.nocapture)
|
.field("nocapture", &self.nocapture)
|
||||||
.field("scrape_examples_options", &self.scrape_examples_options)
|
.field("scrape_examples_options", &self.scrape_examples_options)
|
||||||
|
.field("unstable_features", &self.unstable_features)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,6 +269,8 @@ pub(crate) struct RenderOptions {
|
|||||||
pub(crate) generate_redirect_map: bool,
|
pub(crate) generate_redirect_map: bool,
|
||||||
/// Show the memory layout of types in the docs.
|
/// Show the memory layout of types in the docs.
|
||||||
pub(crate) show_type_layout: bool,
|
pub(crate) show_type_layout: bool,
|
||||||
|
/// Note: this field is duplicated in `Options` because it's useful to have
|
||||||
|
/// it in both places.
|
||||||
pub(crate) unstable_features: rustc_feature::UnstableFeatures,
|
pub(crate) unstable_features: rustc_feature::UnstableFeatures,
|
||||||
pub(crate) emit: Vec<EmitType>,
|
pub(crate) emit: Vec<EmitType>,
|
||||||
/// If `true`, HTML source pages will generate links for items to their definition.
|
/// If `true`, HTML source pages will generate links for items to their definition.
|
||||||
@@ -316,7 +320,7 @@ impl Options {
|
|||||||
pub(crate) fn from_matches(
|
pub(crate) fn from_matches(
|
||||||
matches: &getopts::Matches,
|
matches: &getopts::Matches,
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
) -> Result<Options, i32> {
|
) -> Result<(Options, RenderOptions), i32> {
|
||||||
let args = &args[1..];
|
let args = &args[1..];
|
||||||
// Check for unstable options.
|
// Check for unstable options.
|
||||||
nightly_options::check_nightly_options(matches, &opts());
|
nightly_options::check_nightly_options(matches, &opts());
|
||||||
@@ -710,7 +714,9 @@ impl Options {
|
|||||||
let with_examples = matches.opt_strs("with-examples");
|
let with_examples = matches.opt_strs("with-examples");
|
||||||
let call_locations = crate::scrape_examples::load_call_locations(with_examples, &diag)?;
|
let call_locations = crate::scrape_examples::load_call_locations(with_examples, &diag)?;
|
||||||
|
|
||||||
Ok(Options {
|
let unstable_features =
|
||||||
|
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
|
||||||
|
let options = Options {
|
||||||
input,
|
input,
|
||||||
proc_macro_crate,
|
proc_macro_crate,
|
||||||
error_format,
|
error_format,
|
||||||
@@ -744,7 +750,13 @@ impl Options {
|
|||||||
run_check,
|
run_check,
|
||||||
no_run,
|
no_run,
|
||||||
nocapture,
|
nocapture,
|
||||||
render_options: RenderOptions {
|
crate_name,
|
||||||
|
output_format,
|
||||||
|
json_unused_externs,
|
||||||
|
scrape_examples_options,
|
||||||
|
unstable_features,
|
||||||
|
};
|
||||||
|
let render_options = RenderOptions {
|
||||||
output,
|
output,
|
||||||
external_html,
|
external_html,
|
||||||
id_map,
|
id_map,
|
||||||
@@ -767,19 +779,13 @@ impl Options {
|
|||||||
document_hidden,
|
document_hidden,
|
||||||
generate_redirect_map,
|
generate_redirect_map,
|
||||||
show_type_layout,
|
show_type_layout,
|
||||||
unstable_features: rustc_feature::UnstableFeatures::from_environment(
|
unstable_features,
|
||||||
crate_name.as_deref(),
|
|
||||||
),
|
|
||||||
emit,
|
emit,
|
||||||
generate_link_to_definition,
|
generate_link_to_definition,
|
||||||
call_locations,
|
call_locations,
|
||||||
no_emit_shared: false,
|
no_emit_shared: false,
|
||||||
},
|
};
|
||||||
crate_name,
|
Ok((options, render_options))
|
||||||
output_format,
|
|
||||||
json_unused_externs,
|
|
||||||
scrape_examples_options,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the file given as `self.input` is a Markdown file.
|
/// Returns `true` if the file given as `self.input` is a Markdown file.
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
|
|||||||
lint_cap: Some(options.lint_cap.unwrap_or(lint::Forbid)),
|
lint_cap: Some(options.lint_cap.unwrap_or(lint::Forbid)),
|
||||||
cg: options.codegen_options.clone(),
|
cg: options.codegen_options.clone(),
|
||||||
externs: options.externs.clone(),
|
externs: options.externs.clone(),
|
||||||
unstable_features: options.render_options.unstable_features,
|
unstable_features: options.unstable_features,
|
||||||
actually_rustdoc: true,
|
actually_rustdoc: true,
|
||||||
edition: options.edition,
|
edition: options.edition,
|
||||||
target_triple: options.target.clone(),
|
target_triple: options.target.clone(),
|
||||||
|
|||||||
@@ -430,7 +430,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
|||||||
extension_css,
|
extension_css,
|
||||||
resource_suffix,
|
resource_suffix,
|
||||||
static_root_path,
|
static_root_path,
|
||||||
unstable_features,
|
|
||||||
generate_redirect_map,
|
generate_redirect_map,
|
||||||
show_type_layout,
|
show_type_layout,
|
||||||
generate_link_to_definition,
|
generate_link_to_definition,
|
||||||
@@ -511,7 +510,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
|||||||
resource_suffix,
|
resource_suffix,
|
||||||
static_root_path,
|
static_root_path,
|
||||||
fs: DocFS::new(sender),
|
fs: DocFS::new(sender),
|
||||||
codes: ErrorCodes::from(unstable_features.is_nightly_build()),
|
codes: ErrorCodes::from(options.unstable_features.is_nightly_build()),
|
||||||
playground,
|
playground,
|
||||||
all: RefCell::new(AllTypes::new()),
|
all: RefCell::new(AllTypes::new()),
|
||||||
errors: receiver,
|
errors: receiver,
|
||||||
|
|||||||
@@ -720,7 +720,7 @@ fn main_args(at_args: &[String]) -> MainResult {
|
|||||||
|
|
||||||
// Note that we discard any distinction between different non-zero exit
|
// Note that we discard any distinction between different non-zero exit
|
||||||
// codes from `from_matches` here.
|
// codes from `from_matches` here.
|
||||||
let options = match config::Options::from_matches(&matches, args) {
|
let (options, render_options) = match config::Options::from_matches(&matches, args) {
|
||||||
Ok(opts) => opts,
|
Ok(opts) => opts,
|
||||||
Err(code) => {
|
Err(code) => {
|
||||||
return if code == 0 {
|
return if code == 0 {
|
||||||
@@ -743,7 +743,6 @@ fn main_args(at_args: &[String]) -> MainResult {
|
|||||||
(true, false) => return doctest::run(options),
|
(true, false) => return doctest::run(options),
|
||||||
(false, true) => {
|
(false, true) => {
|
||||||
let input = options.input.clone();
|
let input = options.input.clone();
|
||||||
let render_options = options.render_options.clone();
|
|
||||||
let edition = options.edition;
|
let edition = options.edition;
|
||||||
let config = core::create_config(options);
|
let config = core::create_config(options);
|
||||||
|
|
||||||
@@ -775,11 +774,8 @@ fn main_args(at_args: &[String]) -> MainResult {
|
|||||||
let crate_version = options.crate_version.clone();
|
let crate_version = options.crate_version.clone();
|
||||||
|
|
||||||
let output_format = options.output_format;
|
let output_format = options.output_format;
|
||||||
// FIXME: fix this clone (especially render_options)
|
|
||||||
let externs = options.externs.clone();
|
let externs = options.externs.clone();
|
||||||
let render_options = options.render_options.clone();
|
|
||||||
let scrape_examples_options = options.scrape_examples_options.clone();
|
let scrape_examples_options = options.scrape_examples_options.clone();
|
||||||
let document_private = options.render_options.document_private;
|
|
||||||
|
|
||||||
let config = core::create_config(options);
|
let config = core::create_config(options);
|
||||||
|
|
||||||
@@ -815,7 +811,7 @@ fn main_args(at_args: &[String]) -> MainResult {
|
|||||||
sess,
|
sess,
|
||||||
krate,
|
krate,
|
||||||
externs,
|
externs,
|
||||||
document_private,
|
render_options.document_private,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
(resolver.clone(), resolver_caches)
|
(resolver.clone(), resolver_caches)
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ pub(crate) fn test(options: Options) -> Result<(), String> {
|
|||||||
options.enable_per_target_ignores,
|
options.enable_per_target_ignores,
|
||||||
);
|
);
|
||||||
collector.set_position(DUMMY_SP);
|
collector.set_position(DUMMY_SP);
|
||||||
let codes = ErrorCodes::from(options.render_options.unstable_features.is_nightly_build());
|
let codes = ErrorCodes::from(options.unstable_features.is_nightly_build());
|
||||||
|
|
||||||
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores, None);
|
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores, None);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user