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

rustdoc: allow list syntax for #[doc(alias)] attributes #82846

Merged
merged 3 commits into from
Mar 19, 2021

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Mar 6, 2021

Fixes #81205.

It now allows to have:

#[doc(alias = "x")]
// and:
#[doc(alias("y", "z"))]

cc @jplatte
r? @jyn514

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 6, 2021
@GuillaumeGomez GuillaumeGomez changed the title Doc alias list rustdoc: allow list syntax for #[doc(alias)] attributes Mar 6, 2021
@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Mar 6, 2021
@jplatte
Copy link
Contributor

jplatte commented Mar 6, 2021

Nice! I didn't really think about syntax when creating #81205, I agree that this syntax looks better :)

compiler/rustc_passes/src/check_attr.rs Outdated Show resolved Hide resolved
compiler/rustc_passes/src/check_attr.rs Outdated Show resolved Hide resolved
src/doc/rustdoc/src/advanced-features.md Outdated Show resolved Hide resolved
src/librustdoc/clean/types.rs Outdated Show resolved Hide resolved
@jyn514 jyn514 added the needs-fcp This change is insta-stable, so needs a completed FCP to proceed. label Mar 7, 2021
@GuillaumeGomez
Copy link
Member Author

Updated!

compiler/rustc_passes/src/check_attr.rs Outdated Show resolved Hide resolved
compiler/rustc_passes/src/check_attr.rs Outdated Show resolved Hide resolved
@jyn514
Copy link
Member

jyn514 commented Mar 8, 2021

@rfcbot fcp merge

This allows writing #[doc(alias("y", "z")] instead of

#[doc(alias = "y")]
#[doc(alias = "z")]

This makes the code more convenient to write, and does not conflict with any other possible features.

@rfcbot
Copy link

rfcbot commented Mar 8, 2021

Team member @jyn514 has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Mar 8, 2021
Copy link
Member

@camelid camelid left a comment

Choose a reason for hiding this comment

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

The goal of this change seems good to me. However, I'm wondering how this new syntax would interact with what's proposed in #82000. That issue proposes this syntax:

#[doc(alias = "sprintf", lang = "C, C++, POSIX")]

but I wonder if a less ambiguous form might end up being:

#[doc(alias("sprintf", lang = "C, C++, POSIX"))]

Would something like that still be possible after this change? I think so, but I wanted to check.

compiler/rustc_passes/src/check_attr.rs Outdated Show resolved Hide resolved
@camelid
Copy link
Member

camelid commented Mar 9, 2021

Also, I noticed that @GuillaumeGomez proposed in #81205 that

Accepting both syntaxes seems like a good compromise. Well, I'll open a PR and we can debate over the syntax there.

Meaning accept both alias = ["one", "two"] and alias("one", "two"). What does this PR implement? I think it would be ideal to settle on only one syntax.

@bors
Copy link
Contributor

bors commented Mar 9, 2021

☔ The latest upstream changes (presumably #82911) made this pull request unmergeable. Please resolve the merge conflicts.

@Manishearth
Copy link
Member

Would something like that still be possible after this change? I think so, but I wanted to check.

Yes

Meaning accept both alias = ["one", "two"] and alias("one", "two"). What does this PR implement? I think it would be ideal to settle on only one syntax.

I would prefer to accept only one. I'm okay with alias = "foo" and alias("foo", "bar") coexisting but not alias = ["foo", "bar"], that last one is pretty uncommon in attributes.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Mar 9, 2021

Also, I noticed that @GuillaumeGomez proposed in #81205 that

Accepting both syntaxes seems like a good compromise. Well, I'll open a PR and we can debate over the syntax there.

Meaning accept both alias = ["one", "two"] and alias("one", "two"). What does this PR implement? I think it would be ideal to settle on only one syntax.

I was referring to alias = "x" and alias("x", "y"). I said that using [] was a bad idea (because no other attributes is using it, making it seem on its own).

@GuillaumeGomez
Copy link
Member Author

@rfcbot fcp merge

This allows writing #[doc(alias("y", "z")] instead of

It's not instead of. Both syntaxes are working. :)

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Mar 9, 2021
@rfcbot
Copy link

rfcbot commented Mar 9, 2021

🔔 This is now entering its final comment period, as per the review above. 🔔

@GuillaumeGomez GuillaumeGomez force-pushed the doc-alias-list branch 2 times, most recently from 9b5d5cf to 6aa5007 Compare March 9, 2021 09:57
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member Author

Updated! Anything else to be done here?

@jyn514
Copy link
Member

jyn514 commented Mar 13, 2021

@GuillaumeGomez this is still waiting on FCP: #82846 (comment)

@pickfire
Copy link
Contributor

pickfire commented Mar 16, 2021

I find this not so intuitive since it is using = for one item and is likely to make a mistake here.

Can we have a suggestion when someone is trying #[doc(alias = ["a", "b"])]? I think I (or someone else) might try that.

At least they don't have to search the rust reference or online to find out how it works. Maybe we can have a clippy lint later on this to recommend using the multiple items style.

Also, why not just soft deprecate the old one since we just have this lately?

#[doc(alias = "\"")] //~ ERROR
#[doc(alias = "\n")] //~ ERROR
#[doc(alias = "
")] //~^ ERROR
#[doc(alias = "\t")] //~ ERROR
#[doc(alias = " hello")] //~ ERROR
#[doc(alias = "hello ")] //~ ERROR
#[doc(alias = "")] //~ ERROR
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[doc(alias = "")] //~ ERROR
#[doc(alias = "")] //~ ERROR
#[doc(alias = ["foo", "bar"])] //~ SUGGESTION

We should show users the correct way to have multiple aliases.

@GuillaumeGomez
Copy link
Member Author

I find this not so intuitive since it is using = for one item and is likely to make a mistake here.

Can we have a suggestion when someone is trying #[doc(alias = ["a", "b"])]? I think I (or someone else) might try that.

There is no attribute in the rust compiler using this syntax, so why would anyone use it? It'll return a compiler error because it's invalid syntax.

At least they don't have to search the rust reference or online to find out how it works. Maybe we can have a clippy lint later on this to recommend using the multiple items style.

Again, it's assuming that people would use a syntax which doesn't exist anywhere else in the compiler.

Also, why not just soft deprecate the old one since we just have this lately?

Both syntaxes are correct and working, so why deprecating one of them?

@pickfire
Copy link
Contributor

pickfire commented Mar 16, 2021

Again, it's assuming that people would use a syntax which doesn't exist anywhere else in the compiler.

It exists but not in attributes, it exists as [1, 2] as in array and vectors.

Is this the first compiler attribute does supports both single value and multiple values?

Both syntaxes are correct and working, so why deprecating one of them?

Because it seemed redundant, the alias("foo") can be done instead of alias = "foo".

@GuillaumeGomez
Copy link
Member Author

It exists but not in attributes, it exists as [1, 2] as in array and vectors.

It's completely out of scope here.

@pickfire
Copy link
Contributor

   Compiling playground v0.0.1 (/playground)
error: expected unsuffixed literal or identifier, found `[`
 --> src/lib.rs:1:15
  |
1 | #[doc(alias = ["foo"])]
  |               ^

error: aborting due to previous error

error: could not compile `playground`

The current compilation error does not seemed to be useful to let them know #[doc(alias("foo", "bar"))].

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=dcc601d35deecf1558b3dd66660bf8d5

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Mar 16, 2021

And once again: why would an attribute take an array whereas no other attributes is doing so?

@pickfire
Copy link
Contributor

pickfire commented Mar 17, 2021

And once again: why would an attribute take an array whereas no other attributes is doing so?

I don't mean to need it to take an array. What I am suggesting is that we show a better error just in case someone did that. Just error handling, still not valid code.

@GuillaumeGomez
Copy link
Member Author

I think the compiler error is clear enough: this is a syntax error, not an attribute one.

@jyn514
Copy link
Member

jyn514 commented Mar 17, 2021

I think the compiler error is clear enough: this is a syntax error, not an attribute one.

Right - this would need to be changed in the parser, not here, rustdoc has no control over it. @pickfire feel free to open an issue for that but it doesn't belong in this pr.

@rfcbot rfcbot added the finished-final-comment-period The final comment period is finished for this PR / Issue. label Mar 19, 2021
@rfcbot
Copy link

rfcbot commented Mar 19, 2021

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@rfcbot rfcbot added to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Mar 19, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 19, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Mar 19, 2021

📌 Commit 1d26e6b has been approved by jyn514

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 19, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 19, 2021
…n514

rustdoc: allow list syntax for #[doc(alias)] attributes

Fixes rust-lang#81205.

It now allows to have:

```rust
#[doc(alias = "x")]
// and:
#[doc(alias("y", "z"))]
```

cc `@jplatte`
r? `@jyn514`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 19, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#82500 (Reuse `std::sys::unsupported::pipe` on `hermit`)
 - rust-lang#82759 (Remove unwrap_none/expect_none from compiler/.)
 - rust-lang#82846 (rustdoc: allow list syntax for #[doc(alias)] attributes)
 - rust-lang#82892 (Clarify docs for Read::read's return value)
 - rust-lang#83179 (Extend `proc_macro_back_compat` lint to `actix-web`)
 - rust-lang#83197 (Move some test-only code to test files)
 - rust-lang#83208 (Fix gitattibutes for old git versions)
 - rust-lang#83215 (Deprecate std::os::haiku::raw, which accidentally wasn't deprecated)
 - rust-lang#83230 (Remove unnecessary `forward_inner_docs` hack)
 - rust-lang#83236 (Upgrade memmap to memmap2)
 - rust-lang#83270 (Fix typo/inaccuracy in the documentation of Iterator::skip_while)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 61372e1 into rust-lang:master Mar 19, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 19, 2021
@GuillaumeGomez GuillaumeGomez deleted the doc-alias-list branch March 19, 2021 18:59
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow multiple aliases in one doc(alias) attribute