Skip to content

Commit ed57b8a

Browse files
Emit a warning if auto_cfg is not used when doc_auto_cfg feature is used
1 parent aaf98c1 commit ed57b8a

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/librustdoc/visit_ast.rs

+26-15
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,32 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
147147
.into_iter(),
148148
)
149149
.collect();
150-
// This feature is enabled by default starting the 2024 edition.
151-
self.cx.cache.doc_auto_cfg_active = self.cx.tcx.sess.edition() > Edition::Edition2021;
152-
if let Some(attr) = self
153-
.cx
154-
.tcx
155-
.hir()
156-
.attrs(CRATE_HIR_ID)
157-
.iter()
158-
.filter(|attr| attr.has_name(sym::doc))
159-
.flat_map(|attr| attr.meta_item_list().into_iter().flatten())
160-
.find(|attr| attr.has_name(sym::auto_cfg) || attr.has_name(sym::no_auto_cfg))
161-
{
162-
// If we find one of the two attributes, we update the default value of
163-
// `doc_auto_cfg_active`.
164-
self.cx.cache.doc_auto_cfg_active = attr.has_name(sym::auto_cfg);
150+
if self.cx.tcx.features().doc_auto_cfg {
151+
// This feature is enabled by default starting the 2024 edition.
152+
self.cx.cache.doc_auto_cfg_active = self.cx.tcx.sess.edition() > Edition::Edition2021;
153+
if let Some(attr) = self
154+
.cx
155+
.tcx
156+
.hir()
157+
.attrs(CRATE_HIR_ID)
158+
.iter()
159+
.filter(|attr| attr.has_name(sym::doc))
160+
.flat_map(|attr| attr.meta_item_list().into_iter().flatten())
161+
.find(|attr| attr.has_name(sym::auto_cfg) || attr.has_name(sym::no_auto_cfg))
162+
{
163+
// If we find one of the two attributes, we update the default value of
164+
// `doc_auto_cfg_active`.
165+
self.cx.cache.doc_auto_cfg_active = attr.has_name(sym::auto_cfg);
166+
} else {
167+
self.cx
168+
.sess()
169+
.diagnostic()
170+
.struct_warn(
171+
"the `doc_auto_cfg` feature is used but `#![doc(auto_cfg)]` isn't so it \
172+
won't do anything",
173+
)
174+
.emit();
175+
}
165176
}
166177

167178
self.cx.cache.exact_paths = self.exact_paths;

0 commit comments

Comments
 (0)