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

Improve include macro documentation #106453

Merged
merged 4 commits into from
Jan 7, 2023
Merged

Conversation

coastalwhite
Copy link
Contributor

@coastalwhite coastalwhite commented Jan 4, 2023

As outlined in #106118, the include! macro is a SEO problem when it comes to the Rust documentation. Beginners may see it as a replacement to include syntax in other languages. I feel like this documentation should quite explicitly link to the modules' documentation.

The primary goal of this PR is to address that issue by adding a warning to the documentation. While I was here, I also added some other parts. This included a Uses section and some (intra doc) links to other relevant topics.

I hope this can help beginners to Rust more quickly understand some multi-file project intricacies.

References

@rustbot
Copy link
Collaborator

rustbot commented Jan 4, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thomcc (or someone else) soon.

Please see the contribution instructions for more information.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 4, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jan 4, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

Comment on lines 1332 to 1335
/// If the included file is parsed as an expression, it is placed in the surrounding code
/// [unhygienically](https://doc.rust-lang.org/reference/macros-by-example.html#hygiene). This
/// could result in variables or functions being different from what the file expected if there
/// are variables or functions that have the same name in the current file.
Copy link
Member

Choose a reason for hiding this comment

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

This wording makes it sound like it's hygienic when in item context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The latest commit alters the wording on the hygiene of the macro. This should make it clear that even for an item, it is unhygienic.

@thomcc
Copy link
Member

thomcc commented Jan 4, 2023

Can you show a screenshot of what this warning ends up looking like?

@thomcc
Copy link
Member

thomcc commented Jan 4, 2023

@rustbot author

(use at-rustbot ready to push it back into my queue when ready)

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 4, 2023
@coastalwhite
Copy link
Contributor Author

coastalwhite commented Jan 5, 2023

Can you show a screenshot of what this warning ends up looking like?

Currently, it looks like this.

Right now

It is a pretty tame comment box. I tried it with a block quote, but I feel it does not really add the proper weight to it. There are some alternatives. I am not sure which fits best. Maybe the warning with the tooltip is the most appropriate one, since it states "Warning"?

Alternatives

Option 2. Error without tooltip

With Should Panic

Option 3. Error with tooltip

With Tooltip

Option 4. Warning with tooltip

With Warning

@coastalwhite
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 5, 2023
@Noratrieb
Copy link
Member

Are there other places in the std docs where we have similar warnings?

@coastalwhite
Copy link
Contributor Author

coastalwhite commented Jan 5, 2023

Are there other places in the std docs where we have similar warnings?

There are some examples, but none introduce a new semi-<pre> block. I do feel like it is easy to read over it in this case, which warrants the block.

Other examples:

There are plenty of other examples, but none introduce a non-pre block. std::boxed does the closest to introducing a block that I could find. Most use a Warning:, capitalization, header or a combination of those things.

Overall, it seems like there isn't a convention on how to do Warning. The same for Note. For some cases, I would argue the block is way better and will prevent people from reading over critical information. It also isn't unheard of to add inline HTML to the documentation (std::pin).

@thomcc
Copy link
Member

thomcc commented Jan 6, 2023

Hm. TBH, this doesn't really feel like a t-libs decision, both because it's a documentation change (and documentation style change), and because include! is really a language feature and not part of the library. I'm going to punt it to the doc team here.

r? docs

@rustbot rustbot assigned GuillaumeGomez and unassigned thomcc Jan 6, 2023
@thomcc thomcc added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Jan 6, 2023
/// way at compile time. So, for instance, an invocation with a Windows path
/// containing backslashes `\` would not compile correctly on Unix.
/// <div class="example-wrap" style="display:inline-block">
/// <pre class="compile_fail" style="white-space:normal;font:inherit;">
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is the right way to do this because if someone enables the "see code blocks lines", it'll make a very weird output. We are talking about adding such a feature in #79710. I re-started the debate and hopefully, we might be able to have something not too far in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you be open to me removing the <div> so that this can be merged? This PR generally improves the documentation, so I see no reason in the html blocking the PR. I will follow the discussion on the better support for warning blocks and update it when the time comes.

Copy link
Member

Choose a reason for hiding this comment

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

Just remove the HTML tags and then it's good for me. We can come back to this at a later time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :)

@GuillaumeGomez
Copy link
Member

Thanks!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jan 6, 2023

📌 Commit ae667be has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 6, 2023
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 6, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 7, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#106287 (Add some docs to `bug`, `span_bug` and `delay_span_bug`)
 - rust-lang#106341 (refactor: clean up `errors.rs` and `error_codes_check.rs`)
 - rust-lang#106453 (Improve include macro documentation)
 - rust-lang#106466 (Fix rustdoc source code rendering for `#[path = "../path/to/mod.rs"]` links)
 - rust-lang#106528 (Tiny formatting fix)
 - rust-lang#106534 (rustdoc-gui: Use new block syntax for define-function in goml scripts)
 - rust-lang#106542 (Add default and latest stable edition to --edition in rustc (attempt 2))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 72d650f into rust-lang:master Jan 7, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants