-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Allow #![doc(test(attr(..)))]
at module level
#140560
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
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
This comment has been minimized.
This comment has been minimized.
516b680
to
715421c
Compare
This comment has been minimized.
This comment has been minimized.
715421c
to
7dbac96
Compare
This comment has been minimized.
This comment has been minimized.
7dbac96
to
ebd7505
Compare
This PR modifies cc @jieyouxu |
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.
Some small changes needed but otherwise it's pretty good as is. Once done, I'll start the FCP.
ebd7505
to
746ceb9
Compare
Just one last nit, I'll start the FCP afterward. Please note that I will add a concern about whether it should overload existing |
746ceb9
to
5a3cad2
Compare
I think all crate attributes support being overridden, so if a module doesn't want one from the parent (or crate-root) they can just revert to the old/default value, it's how If we were to overload the current list with the one from the current module alone, we would need to duplicate (for the Line 51 in f97b3c6
|
5a3cad2
to
6a84c99
Compare
Not always. Some attributes like |
Team member @GuillaumeGomez has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
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. |
Hum, indeed, didn't think of those. Currently both would be applied to every doctests in the crate, so to me adding a I could see rustdoc having an explicit way, like This would have the advantage of supporting both strategy: appending and overloading. |
Why is this limited to the module level? If it's being extended from crate level I would expect it to just work anywhere like most attributes. |
Allowing it at item level, that is for struct, enum, function, const, union, trait, impl, ... would be equivalent to put in directly inside the doctest. Doing, #[doc(test(attr(feature(my_feature))))]
/// ```
/// ```
pub struct A; would be identical to putting the attribute directly inside the doctest (which IMO is clearer), /// ```
/// #![feature(my_feature)]
/// ```
pub struct A; Then there is the case fields and variants, putting it directly on them would be the same as above; but putting it at the struct or enum level might be useful; but I don't have a usecase nor motivation for it. #[doc(test(attr(feature(my_feature))))]
pub struct A {
/// ```
/// # this doctest would receive #[feature(my_feature)] from the parent
/// # not sure how useful this would be
/// ```
pub field1: u32,
/// ```
/// # same here
/// ```
pub field2: u32,
} |
You can have multiple doctests on one item. The more relevant location I was thinking of was I do feel like modules would cover all usecases, with a little code rearranging for weird edgecases, it just seems like an artificial restriction to me. Are there other inherited attributes that have a similar restriction? All I'm aware of can be applied either at crate-level or anywhere. |
It's a good point indeed. |
This PR adds the ability to specify
#![doc(test(attr(..)))]
at module level in addition to allowing it at crate-root.This is motivated by a recent PR #140323 (by @tgross35) where we have to duplicate 2 attributes to every single
f16
andf128
doctests, by allowing#![doc(test(attr(..)))]
at module level we can omit them entirely and just have (in both module):Those new attributes are appended to the one found at crate-root or at a previous module. Those "global" attributes are compatible with merged doctests (they already were before).
Given the small addition that this is, I'm proposing to insta-stabilize it, but I can feature-gate it if preferred.
Best reviewed commit by commit.
r? @GuillaumeGomez