Skip to content

rustdoc: use descriptive tooltip if doctest is conditionally ignored #141517

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lolbinarycat
Copy link
Contributor

fixes #141092

here's what it looks like now:
screenshot

@rustbot
Copy link
Collaborator

rustbot commented May 24, 2025

r? @notriddle

rustbot has assigned @notriddle.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels May 24, 2025
@@ -80,18 +81,46 @@ fn write_header(
);

if tooltip != Tooltip::None {
let edition_code;
// variable for extending lifetimes of temporaries
Copy link
Contributor

@yotamofek yotamofek May 24, 2025

Choose a reason for hiding this comment

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

Consider maybe doing something like this:

if tooltip != Tooltip::None {
    let tooltip = fmt::from_fn(|f| match &tooltip {
        Tooltip::IgnoreAll => f.write_str("This example is not tested"),
        Tooltip::IgnoreSome(platforms) => {
            f.write_str("This example is not tested on ")?;
            match &platforms[..] {
                [] => unreachable!(),
                [platform] => f.write_str(platform)?,
                [first, second] => write!(f, "{first} or {second}")?,
                [platforms @ .., last] => {
                    for platform in platforms {
                        write!(f, "{platform}, ")?;
                    }
                    write!(f, "or {last}")?;
                }
            }
            Ok(())
        }
        Tooltip::CompileFail => f.write_str("This example deliberately fails to compile"),
        Tooltip::ShouldPanic => f.write_str("This example panics"),
        Tooltip::Edition(edition) => write!(f, "This example runs with edition {edition}"),
        Tooltip::None => unreachable!(),
    });
    write_str(out, format_args!("<a href=\"#\" class=\"tooltip\" title=\"{tooltip}\">ⓘ</a>"));
}
  • If you're already introducing a fmt::from_fn call, you can get rid of the tmp buffer and allocating to it (and that comment about lifetime extension is IMHO a bit redundant anyways)
  • Slice patterns allow for slightly nicer handling of printing that list and the oxford comma means we only need to special-case the last platform given more than 2 platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider a different tooltip for a partially ignored doctest
4 participants