Allow #![doc(test(attr(..)))] at module level by Urgau · Pull Request #140560 · rust-lang/rust (original) (raw)

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, }