Improve code comments and extend tests for doc_cfg feature
This commit is contained in:
@@ -925,7 +925,8 @@ pub(crate) fn hir_attr_lists<'a, I: IntoIterator<Item = &'a hir::Attribute>>(
|
||||
/// This type keeps track of (doc) cfg information as we go down the item tree.
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct CfgInfo {
|
||||
/// List of `doc(auto_cfg(hide(...)))` cfgs.
|
||||
/// List of currently active `doc(auto_cfg(hide(...)))` cfgs,minus currently active
|
||||
/// `doc(auto_cfg(show(...)))` cfgs.
|
||||
hidden_cfg: FxHashSet<Cfg>,
|
||||
/// Current computed `cfg`. Each time we enter a new item, this field is updated as well while
|
||||
/// taking into account the `hidden_cfg` information.
|
||||
@@ -1181,7 +1182,8 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
|
||||
Some(Arc::new(cfg_info.current_cfg.clone()))
|
||||
}
|
||||
} else {
|
||||
// Since we always want to collect all `cfg` items, we remove the hidden ones afterward.
|
||||
// If `doc(auto_cfg)` feature is enabled, we want to collect all `cfg` items, we remove the
|
||||
// hidden ones afterward.
|
||||
match cfg_info.current_cfg.strip_hidden(&cfg_info.hidden_cfg) {
|
||||
None | Some(Cfg::True) => None,
|
||||
Some(cfg) => Some(Arc::new(cfg)),
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#[doc(auto_cfg(hide(42)))] //~ ERROR
|
||||
#[doc(auto_cfg(hide("a")))] //~ ERROR
|
||||
#[doc(auto_cfg(hide(foo::bar)))] //~ ERROR
|
||||
#[doc(auto_cfg = 42)] //~ ERROR
|
||||
#[doc(auto_cfg = "a")] //~ ERROR
|
||||
// Shouldn't lint
|
||||
#[doc(auto_cfg(hide(windows)))]
|
||||
#[doc(auto_cfg(hide(feature = "windows")))]
|
||||
|
||||
@@ -30,6 +30,18 @@ error: `#![doc(auto_cfg(hide(...)))]` only accepts identifiers or key/value item
|
||||
LL | #[doc(auto_cfg(hide(foo::bar)))]
|
||||
| ^^^^^^^^
|
||||
|
||||
error: `expected boolean for #[doc(auto_cfg = ...)]`
|
||||
--> $DIR/doc-cfg.rs:16:7
|
||||
|
|
||||
LL | #[doc(auto_cfg = 42)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: `expected boolean for #[doc(auto_cfg = ...)]`
|
||||
--> $DIR/doc-cfg.rs:17:7
|
||||
|
|
||||
LL | #[doc(auto_cfg = "a")]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
warning: unexpected `cfg` condition name: `foo`
|
||||
--> $DIR/doc-cfg.rs:6:11
|
||||
|
|
||||
@@ -74,5 +86,5 @@ error: multiple `cfg` predicates are specified
|
||||
LL | #[doc(cfg(foo, bar))]
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 9 previous errors; 2 warnings emitted
|
||||
error: aborting due to 11 previous errors; 2 warnings emitted
|
||||
|
||||
|
||||
@@ -20,3 +20,16 @@ mod x {
|
||||
// 'Available on non-crate feature pistache only.'
|
||||
#[cfg(not(feature = "pistache"))]
|
||||
pub use crate::x::B;
|
||||
|
||||
// Now checking that `cfg`s are not applied on non-inlined reexports.
|
||||
pub mod pub_sub_mod {
|
||||
//@ has 'foo/pub_sub_mod/index.html'
|
||||
// There should be only only item with `cfg` note.
|
||||
//@ count - '//*[@class="stab portability"]' 1
|
||||
// And obviously the item should be "blabla".
|
||||
//@ has - '//dt' 'blablaNon-pistache'
|
||||
#[cfg(not(feature = "pistache"))]
|
||||
pub fn blabla() {}
|
||||
|
||||
pub use self::blabla as another;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user