Skip to content

Commit ca2561a

Browse files
committed
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.
1 parent 38988e6 commit ca2561a

File tree

5 files changed

+48
-47
lines changed

5 files changed

+48
-47
lines changed

Diff for: src/librustdoc/config.rs

+43-37
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ pub(crate) struct Options {
142142
// Options that alter generated documentation pages
143143
/// Crate version to note on the sidebar of generated docs.
144144
pub(crate) crate_version: Option<String>,
145-
/// Collected options specific to outputting final pages.
146-
pub(crate) render_options: RenderOptions,
147145
/// The format that we output when rendering.
148146
///
149147
/// Currently used only for the `--show-coverage` option.
@@ -159,6 +157,10 @@ pub(crate) struct Options {
159157
/// Configuration for scraping examples from the current crate. If this option is Some(..) then
160158
/// the compiler will scrape examples and not generate documentation.
161159
pub(crate) scrape_examples_options: Option<ScrapeExamplesOptions>,
160+
161+
/// Note: this field is duplicated in `RenderOptions` because it's useful
162+
/// to have it in both places.
163+
pub(crate) unstable_features: rustc_feature::UnstableFeatures,
162164
}
163165

164166
impl fmt::Debug for Options {
@@ -194,14 +196,14 @@ impl fmt::Debug for Options {
194196
.field("persist_doctests", &self.persist_doctests)
195197
.field("show_coverage", &self.show_coverage)
196198
.field("crate_version", &self.crate_version)
197-
.field("render_options", &self.render_options)
198199
.field("runtool", &self.runtool)
199200
.field("runtool_args", &self.runtool_args)
200201
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
201202
.field("run_check", &self.run_check)
202203
.field("no_run", &self.no_run)
203204
.field("nocapture", &self.nocapture)
204205
.field("scrape_examples_options", &self.scrape_examples_options)
206+
.field("unstable_features", &self.unstable_features)
205207
.finish()
206208
}
207209
}
@@ -267,6 +269,8 @@ pub(crate) struct RenderOptions {
267269
pub(crate) generate_redirect_map: bool,
268270
/// Show the memory layout of types in the docs.
269271
pub(crate) show_type_layout: bool,
272+
/// Note: this field is duplicated in `Options` because it's useful to have
273+
/// it in both places.
270274
pub(crate) unstable_features: rustc_feature::UnstableFeatures,
271275
pub(crate) emit: Vec<EmitType>,
272276
/// If `true`, HTML source pages will generate links for items to their definition.
@@ -316,7 +320,7 @@ impl Options {
316320
pub(crate) fn from_matches(
317321
matches: &getopts::Matches,
318322
args: Vec<String>,
319-
) -> Result<Options, i32> {
323+
) -> Result<(Options, RenderOptions), i32> {
320324
let args = &args[1..];
321325
// Check for unstable options.
322326
nightly_options::check_nightly_options(matches, &opts());
@@ -710,7 +714,9 @@ impl Options {
710714
let with_examples = matches.opt_strs("with-examples");
711715
let call_locations = crate::scrape_examples::load_call_locations(with_examples, &diag)?;
712716

713-
Ok(Options {
717+
let unstable_features =
718+
rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref());
719+
let options = Options {
714720
input,
715721
proc_macro_crate,
716722
error_format,
@@ -744,42 +750,42 @@ impl Options {
744750
run_check,
745751
no_run,
746752
nocapture,
747-
render_options: RenderOptions {
748-
output,
749-
external_html,
750-
id_map,
751-
playground_url,
752-
module_sorting,
753-
themes,
754-
extension_css,
755-
extern_html_root_urls,
756-
extern_html_root_takes_precedence,
757-
default_settings,
758-
resource_suffix,
759-
enable_minification,
760-
enable_index_page,
761-
index_page,
762-
static_root_path,
763-
markdown_no_toc,
764-
markdown_css,
765-
markdown_playground_url,
766-
document_private,
767-
document_hidden,
768-
generate_redirect_map,
769-
show_type_layout,
770-
unstable_features: rustc_feature::UnstableFeatures::from_environment(
771-
crate_name.as_deref(),
772-
),
773-
emit,
774-
generate_link_to_definition,
775-
call_locations,
776-
no_emit_shared: false,
777-
},
778753
crate_name,
779754
output_format,
780755
json_unused_externs,
781756
scrape_examples_options,
782-
})
757+
unstable_features,
758+
};
759+
let render_options = RenderOptions {
760+
output,
761+
external_html,
762+
id_map,
763+
playground_url,
764+
module_sorting,
765+
themes,
766+
extension_css,
767+
extern_html_root_urls,
768+
extern_html_root_takes_precedence,
769+
default_settings,
770+
resource_suffix,
771+
enable_minification,
772+
enable_index_page,
773+
index_page,
774+
static_root_path,
775+
markdown_no_toc,
776+
markdown_css,
777+
markdown_playground_url,
778+
document_private,
779+
document_hidden,
780+
generate_redirect_map,
781+
show_type_layout,
782+
unstable_features,
783+
emit,
784+
generate_link_to_definition,
785+
call_locations,
786+
no_emit_shared: false,
787+
};
788+
Ok((options, render_options))
783789
}
784790

785791
/// Returns `true` if the file given as `self.input` is a Markdown file.

Diff for: src/librustdoc/doctest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
7979
lint_cap: Some(options.lint_cap.unwrap_or(lint::Forbid)),
8080
cg: options.codegen_options.clone(),
8181
externs: options.externs.clone(),
82-
unstable_features: options.render_options.unstable_features,
82+
unstable_features: options.unstable_features,
8383
actually_rustdoc: true,
8484
edition: options.edition,
8585
target_triple: options.target.clone(),

Diff for: src/librustdoc/html/render/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
430430
extension_css,
431431
resource_suffix,
432432
static_root_path,
433-
unstable_features,
434433
generate_redirect_map,
435434
show_type_layout,
436435
generate_link_to_definition,
@@ -511,7 +510,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
511510
resource_suffix,
512511
static_root_path,
513512
fs: DocFS::new(sender),
514-
codes: ErrorCodes::from(unstable_features.is_nightly_build()),
513+
codes: ErrorCodes::from(options.unstable_features.is_nightly_build()),
515514
playground,
516515
all: RefCell::new(AllTypes::new()),
517516
errors: receiver,

Diff for: src/librustdoc/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ fn main_args(at_args: &[String]) -> MainResult {
720720

721721
// Note that we discard any distinction between different non-zero exit
722722
// codes from `from_matches` here.
723-
let options = match config::Options::from_matches(&matches, args) {
723+
let (options, render_options) = match config::Options::from_matches(&matches, args) {
724724
Ok(opts) => opts,
725725
Err(code) => {
726726
return if code == 0 {
@@ -743,7 +743,6 @@ fn main_args(at_args: &[String]) -> MainResult {
743743
(true, false) => return doctest::run(options),
744744
(false, true) => {
745745
let input = options.input.clone();
746-
let render_options = options.render_options.clone();
747746
let edition = options.edition;
748747
let config = core::create_config(options);
749748

@@ -775,11 +774,8 @@ fn main_args(at_args: &[String]) -> MainResult {
775774
let crate_version = options.crate_version.clone();
776775

777776
let output_format = options.output_format;
778-
// FIXME: fix this clone (especially render_options)
779777
let externs = options.externs.clone();
780-
let render_options = options.render_options.clone();
781778
let scrape_examples_options = options.scrape_examples_options.clone();
782-
let document_private = options.render_options.document_private;
783779

784780
let config = core::create_config(options);
785781

@@ -815,7 +811,7 @@ fn main_args(at_args: &[String]) -> MainResult {
815811
sess,
816812
krate,
817813
externs,
818-
document_private,
814+
render_options.document_private,
819815
)
820816
});
821817
(resolver.clone(), resolver_caches)

Diff for: src/librustdoc/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub(crate) fn test(options: Options) -> Result<(), String> {
143143
options.enable_per_target_ignores,
144144
);
145145
collector.set_position(DUMMY_SP);
146-
let codes = ErrorCodes::from(options.render_options.unstable_features.is_nightly_build());
146+
let codes = ErrorCodes::from(options.unstable_features.is_nightly_build());
147147

148148
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores, None);
149149

0 commit comments

Comments
 (0)