-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Prior doc comments #2374
Closed
Closed
Prior doc comments #2374
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
- Feature Name: prior_doc_comment | ||
- Start Date: 2018-03-26 | ||
- RFC PR: (leave this empty) | ||
- Rust Issue: (leave this empty) | ||
|
||
# Summary | ||
[summary]: #summary | ||
|
||
Allow `//!` (also called "outer doc comments" below) to be used to annotate the block just prior to them. | ||
|
||
# Motivation | ||
[motivation]: #motivation | ||
|
||
This usecase, where the doc comment is put after an enum variant, is likely to be most widely used: | ||
|
||
```rust | ||
enum E { | ||
/// doc comments used currently | ||
A, | ||
B, //! doc comments with this RFC | ||
C, | ||
} | ||
``` | ||
|
||
There are also people who prefer documentation after member. See [1](https://capnproto.org/language.html#comments) [2](https://internals.rust-lang.org/t/any-interest-in-same-line-doc-comments/3212). | ||
|
||
# Guide-level explanation | ||
[guide-level-explanation]: #guide-level-explanation | ||
|
||
`//!` can be used to document the enclosing block, and with this RFC can be used to document the prior block. | ||
|
||
For example: | ||
|
||
``` | ||
enum Option<T> { | ||
//! The `Option` type. See [the module level documentation](index.html) for more. | ||
None, //! No value | ||
Some(T), //! Some value `T` | ||
} | ||
``` | ||
|
||
# Reference-level explanation | ||
[reference-level-explanation]: #reference-level-explanation | ||
|
||
`//!` Documentation comments are now allowed after the identifier, and can be separated by a combination of whitespace or newlines. | ||
|
||
When there are both `///` and `//!` blocks, the doc comments are concatenated in order. | ||
|
||
It will be valid to interleave the two style of comments, although this is not a thing we want to do and we may issue an warning: | ||
|
||
``` | ||
enum E { | ||
//! A | ||
/// B | ||
//! C | ||
/// D | ||
X, | ||
//! E | ||
} | ||
``` | ||
|
||
The documentation for `enum E` will be: | ||
``` | ||
A | ||
C | ||
``` | ||
|
||
and the documentation for `E::X` will be: | ||
``` | ||
B | ||
D | ||
E | ||
``` | ||
|
||
# Drawbacks | ||
[drawbacks]: #drawbacks | ||
|
||
Rust have limited doc comment syntax for the sake of simplicity. While this RFC doesn't propose any new syntax, this may complicate the learning of Rust. | ||
|
||
# Rationale and alternatives | ||
[alternatives]: #alternatives | ||
|
||
TBD. This RFC is designed to be very conservative. | ||
|
||
# Prior art | ||
[prior-art]: #prior-art | ||
|
||
As mentioned in [motivation], [Cap'n Proto](https://capnproto.org/language.html#comments) has been recommending this as default | ||
and [Doxygen](http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html#memberdoc) has the support of such comments. | ||
|
||
# Unresolved questions | ||
[unresolved]: #unresolved-questions | ||
|
||
TBD |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to do this in Haskell with haddock like so (which you can mention in the Prior art if you like):
But I'm skeptical that this enhances readability for Rust. At least, if this is possible, I would like it to not be the recommended style by rustfmt.
This sparked an orthogonal question in my mind... What if we allowed the following:
or in Haskell:
I guess using
//!
in this way makes sense in that case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too keen on the return value. Mind the way this would most likely work is:
unless you want to propose serious changes (I think) to how rust tokenizes things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we would be introducing param documents immediately. Instead, I imagine if this will even be a part of this RFC, it will be just concatenated and we'll leave parameter description boilerplates up to the document author.