Skip to content

Commit f4bb5a7

Browse files
Move playground to shared context
1 parent c265180 commit f4bb5a7

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

src/librustdoc/html/render.rs

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ struct Context {
166166
/// The map used to ensure all generated 'id=' attributes are unique.
167167
id_map: Rc<RefCell<IdMap>>,
168168
pub shared: Arc<SharedContext>,
169-
playground: Option<markdown::Playground>,
170169
}
171170

172171
crate struct SharedContext {
@@ -208,6 +207,7 @@ crate struct SharedContext {
208207
/// The default edition used to parse doctests.
209208
pub edition: Edition,
210209
pub codes: ErrorCodes,
210+
playground: Option<markdown::Playground>,
211211
}
212212

213213
impl SharedContext {
@@ -518,31 +518,6 @@ pub fn run(mut krate: clean::Crate,
518518
_ => PathBuf::new(),
519519
};
520520
let mut errors = Arc::new(ErrorStorage::new());
521-
let mut scx = SharedContext {
522-
collapsed: krate.collapsed,
523-
src_root,
524-
include_sources: true,
525-
local_sources: Default::default(),
526-
issue_tracker_base_url: None,
527-
layout: layout::Layout {
528-
logo: String::new(),
529-
favicon: String::new(),
530-
external_html,
531-
krate: krate.name.clone(),
532-
css_file_extension: extension_css,
533-
generate_search_filter,
534-
},
535-
created_dirs: Default::default(),
536-
sort_modules_alphabetically,
537-
themes,
538-
resource_suffix,
539-
static_root_path,
540-
generate_redirect_pages,
541-
fs: DocFS::new(&errors),
542-
edition,
543-
codes: ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build()),
544-
};
545-
546521
// If user passed in `--playground-url` arg, we fill in crate name here
547522
let mut playground = None;
548523
if let Some(url) = playground_url {
@@ -551,17 +526,27 @@ pub fn run(mut krate: clean::Crate,
551526
url,
552527
});
553528
}
529+
let mut layout = layout::Layout {
530+
logo: String::new(),
531+
favicon: String::new(),
532+
external_html,
533+
krate: krate.name.clone(),
534+
css_file_extension: extension_css,
535+
generate_search_filter,
536+
};
537+
let mut issue_tracker_base_url = None;
538+
let mut include_sources = true;
554539

555540
// Crawl the crate attributes looking for attributes which control how we're
556541
// going to emit HTML
557542
if let Some(attrs) = krate.module.as_ref().map(|m| &m.attrs) {
558543
for attr in attrs.lists(sym::doc) {
559544
match (attr.name_or_empty(), attr.value_str()) {
560545
(sym::html_favicon_url, Some(s)) => {
561-
scx.layout.favicon = s.to_string();
546+
layout.favicon = s.to_string();
562547
}
563548
(sym::html_logo_url, Some(s)) => {
564-
scx.layout.logo = s.to_string();
549+
layout.logo = s.to_string();
565550
}
566551
(sym::html_playground_url, Some(s)) => {
567552
playground = Some(markdown::Playground {
@@ -570,15 +555,34 @@ pub fn run(mut krate: clean::Crate,
570555
});
571556
}
572557
(sym::issue_tracker_base_url, Some(s)) => {
573-
scx.issue_tracker_base_url = Some(s.to_string());
558+
issue_tracker_base_url = Some(s.to_string());
574559
}
575560
(sym::html_no_source, None) if attr.is_word() => {
576-
scx.include_sources = false;
561+
include_sources = false;
577562
}
578563
_ => {}
579564
}
580565
}
581566
}
567+
let mut scx = SharedContext {
568+
collapsed: krate.collapsed,
569+
src_root,
570+
include_sources,
571+
local_sources: Default::default(),
572+
issue_tracker_base_url,
573+
layout,
574+
created_dirs: Default::default(),
575+
sort_modules_alphabetically,
576+
themes,
577+
resource_suffix,
578+
static_root_path,
579+
generate_redirect_pages,
580+
fs: DocFS::new(&errors),
581+
edition,
582+
codes: ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build()),
583+
playground,
584+
};
585+
582586
let dst = output;
583587
scx.ensure_dir(&dst)?;
584588
krate = sources::render(&dst, &mut scx, krate)?;
@@ -588,7 +592,6 @@ pub fn run(mut krate: clean::Crate,
588592
render_redirect_pages: false,
589593
id_map: Rc::new(RefCell::new(id_map)),
590594
shared: Arc::new(scx),
591-
playground,
592595
};
593596

594597
// Crawl the crate to build various caches used for the output
@@ -2353,7 +2356,7 @@ fn render_markdown(
23532356
if is_hidden { " hidden" } else { "" },
23542357
prefix,
23552358
Markdown(md_text, &links, &mut ids,
2356-
cx.shared.codes, cx.shared.edition, &cx.playground).to_string())
2359+
cx.shared.codes, cx.shared.edition, &cx.shared.playground).to_string())
23572360
}
23582361

23592362
fn document_short(
@@ -2711,7 +2714,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
27112714
if let Some(note) = note {
27122715
let mut ids = cx.id_map.borrow_mut();
27132716
let html = MarkdownHtml(
2714-
&note, &mut ids, error_codes, cx.shared.edition, &cx.playground);
2717+
&note, &mut ids, error_codes, cx.shared.edition, &cx.shared.playground);
27152718
message.push_str(&format!(": {}", html.to_string()));
27162719
}
27172720
stability.push(format!("<div class='stab deprecated'>{}</div>", message));
@@ -2765,7 +2768,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
27652768
&mut ids,
27662769
error_codes,
27672770
cx.shared.edition,
2768-
&cx.playground,
2771+
&cx.shared.playground,
27692772
).to_string()
27702773
);
27712774
}
@@ -3961,7 +3964,7 @@ fn render_impl(w: &mut Buffer, cx: &Context, i: &Impl, link: AssocItemLink<'_>,
39613964
let mut ids = cx.id_map.borrow_mut();
39623965
write!(w, "<div class='docblock'>{}</div>",
39633966
Markdown(&*dox, &i.impl_item.links(), &mut ids,
3964-
cx.shared.codes, cx.shared.edition, &cx.playground).to_string());
3967+
cx.shared.codes, cx.shared.edition, &cx.shared.playground).to_string());
39653968
}
39663969
}
39673970

0 commit comments

Comments
 (0)