Skip to content

Commit 20b37f7

Browse files
committed
Auto merge of #37911 - liigo:rustdoc-playground, r=alexcrichton
rustdoc: get back missing crate-name when --playground-url is used follow up PR #37763 r? @alexcrichton (since you r+ed to #37763 ) ---- Edit: When `#![doc(html_playground_url="")]` is used, the current crate name is saved to `PLAYGROUND`, so rustdoc may generate `extern crate NAME;` into code snips automatically. But when `--playground-url` was introduced in PR #37763, I forgot saving crate name to `PLAYGROUND`. This PR fix that. ---- Update: - add test - unstable `--playground-url`
2 parents c8a401e + cefe62c commit 20b37f7

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

html/render.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ pub fn derive_id(candidate: String) -> String {
428428
/// Generates the documentation for `crate` into the directory `dst`
429429
pub fn run(mut krate: clean::Crate,
430430
external_html: &ExternalHtml,
431+
playground_url: Option<String>,
431432
dst: PathBuf,
432433
passes: FxHashSet<String>,
433434
css_file_extension: Option<PathBuf>,
@@ -451,6 +452,13 @@ pub fn run(mut krate: clean::Crate,
451452
css_file_extension: css_file_extension.clone(),
452453
};
453454

455+
// If user passed in `--playground-url` arg, we fill in crate name here
456+
if let Some(url) = playground_url {
457+
markdown::PLAYGROUND.with(|slot| {
458+
*slot.borrow_mut() = Some((Some(krate.name.clone()), url));
459+
});
460+
}
461+
454462
// Crawl the crate attributes looking for attributes which control how we're
455463
// going to emit HTML
456464
if let Some(attrs) = krate.module.as_ref().map(|m| &m.attrs) {

lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ pub fn opts() -> Vec<RustcOptGroup> {
160160
unstable(optmulti("Z", "",
161161
"internal and debugging options (only on nightly build)", "FLAG")),
162162
stable(optopt("", "sysroot", "Override the system root", "PATH")),
163-
stable(optopt("", "playground-url",
164-
"URL to send code snippets to, may be reset by --markdown-playground-url \
165-
or `#![doc(html_playground_url=...)]`",
166-
"URL")),
163+
unstable(optopt("", "playground-url",
164+
"URL to send code snippets to, may be reset by --markdown-playground-url \
165+
or `#![doc(html_playground_url=...)]`",
166+
"URL")),
167167
]
168168
}
169169

@@ -232,10 +232,6 @@ pub fn main_args(args: &[String]) -> isize {
232232
}
233233
};
234234

235-
if let Some(playground) = matches.opt_str("playground-url") {
236-
html::markdown::PLAYGROUND.with(|s| { *s.borrow_mut() = Some((None, playground)); });
237-
}
238-
239235
let test_args = matches.opt_strs("test-args");
240236
let test_args: Vec<String> = test_args.iter()
241237
.flat_map(|s| s.split_whitespace())
@@ -264,6 +260,7 @@ pub fn main_args(args: &[String]) -> isize {
264260
None => return 3
265261
};
266262
let crate_name = matches.opt_str("crate-name");
263+
let playground_url = matches.opt_str("playground-url");
267264

268265
match (should_test, markdown_input) {
269266
(true, true) => {
@@ -285,7 +282,7 @@ pub fn main_args(args: &[String]) -> isize {
285282
info!("going to format");
286283
match output_format.as_ref().map(|s| &**s) {
287284
Some("html") | None => {
288-
html::render::run(krate, &external_html,
285+
html::render::run(krate, &external_html, playground_url,
289286
output.unwrap_or(PathBuf::from("doc")),
290287
passes.into_iter().collect(),
291288
css_file_extension,

markdown.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
6363
Err(LoadStringError::ReadFail) => return 1,
6464
Err(LoadStringError::BadUtf8) => return 2,
6565
};
66-
if let Some(playground) = matches.opt_str("markdown-playground-url") {
66+
if let Some(playground) = matches.opt_str("markdown-playground-url").or(
67+
matches.opt_str("playground-url")) {
6768
markdown::PLAYGROUND.with(|s| { *s.borrow_mut() = Some((None, playground)); });
6869
}
6970

0 commit comments

Comments
 (0)