Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set playground-url value to default to "play.rust-lang.org" #86363

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ crate struct RenderOptions {
/// If present, playground URL to use in the "Run" button added to code samples.
///
/// Be aware: This option can come both from the CLI and from crate attributes!
///
/// If not set, it'll target "play.rust-lang.org" by default.
crate playground_url: Option<String>,
/// Whether to sort modules alphabetically on a module page instead of using declaration order.
/// `true` by default.
Expand Down Expand Up @@ -599,7 +601,11 @@ impl Options {
};
let crate_name = matches.opt_str("crate-name");
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
let playground_url = matches.opt_str("playground-url");
let playground_url = matches
.opt_str("playground-url")
.map(|s| s.trim().replace("\"", "").replace("\'", ""))
.or_else(|| Some("https://play.rust-lang.org/".to_owned()))
.filter(|s| !s.is_empty());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to pass an empty value if we want to disable it.

let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
let display_warnings = matches.opt_present("display-warnings");
let sort_modules_alphabetically = !matches.opt_present("sort-modules-by-appearance");
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/hidden-line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
/// ```
pub fn foo() {}

// @!has hidden_line/fn.foo.html invisible
// @!has hidden_line/fn.foo.html '// invisible'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it now appears in the url, I needed to make the check a bit bigger.

// @matches - //pre "#\[derive\(PartialEq\)\] // Bar"
8 changes: 4 additions & 4 deletions src/test/rustdoc/issue-41783.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// @has issue_41783/struct.Foo.html
// @!has - 'space'
// @!has - 'comment'
// @!has - ':space'
// @!has - ':comment'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

// @has - '# <span class="ident">single'
// @has - '## <span class="ident">double</span>'
// @has - '### <span class="ident">triple</span>'
// @has - '<span class="attribute">#[<span class="ident">outer</span>]</span>'
// @has - '<span class="attribute">#![<span class="ident">inner</span>]</span>'

/// ```no_run
/// # # space
/// # comment
/// # # :space
/// # :comment
/// ## single
/// ### double
/// #### triple
Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc/playground-default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![crate_name = "foo"]

// @has foo/fn.foo.html '//a[@class="test-arrow"]/@href' 'https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Alet%20x%20%3D%2012%3B%0A%7D&edition=2015'
/// ```
/// let x = 12;
/// ```
pub fn foo() {}
2 changes: 2 additions & 0 deletions src/test/rustdoc/playground-none.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// compile-flags: --playground-url="" -Z unstable-options
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test now ensures that we can disable it by providing an empty value to playground-url option.


#![crate_name = "foo"]

//! module docs
Expand Down