-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement RFC 3631: add rustdoc doc_cfg features #138907
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?
Changes from all commits
0cd6acc
c528423
a121293
33ec47f
691a80f
6d304d3
4fca459
dcfa375
2d11fd1
0c7c3e7
6f2991b
686558a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ use std::cell::Cell; | |
use std::collections::hash_map::Entry; | ||
|
||
use rustc_abi::{Align, ExternAbi, Size}; | ||
use rustc_ast::{AttrStyle, LitKind, MetaItemInner, MetaItemKind, MetaItemLit, ast}; | ||
use rustc_ast::{AttrStyle, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, ast}; | ||
use rustc_attr_data_structures::{AttributeKind, ReprAttr, find_attr}; | ||
use rustc_data_structures::fx::FxHashMap; | ||
use rustc_errors::{Applicability, DiagCtxtHandle, IntoDiagArg, MultiSpan, StashKey}; | ||
|
@@ -1303,16 +1303,53 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | |
} | ||
} | ||
|
||
/// Check that the `#![doc(cfg_hide(...))]` attribute only contains a list of attributes. | ||
/// | ||
fn check_doc_cfg_hide(&self, meta: &MetaItemInner, hir_id: HirId) { | ||
if meta.meta_item_list().is_none() { | ||
self.tcx.emit_node_span_lint( | ||
INVALID_DOC_ATTRIBUTES, | ||
hir_id, | ||
meta.span(), | ||
errors::DocCfgHideTakesList, | ||
); | ||
/// Check that the `#![doc(auto_cfg(..))]` attribute has expected input. | ||
fn check_doc_auto_cfg(&self, meta: &MetaItem, hir_id: HirId) { | ||
match &meta.kind { | ||
MetaItemKind::Word => {} | ||
MetaItemKind::NameValue(lit) => { | ||
if !matches!(lit.kind, LitKind::Bool(_)) { | ||
self.tcx.emit_node_span_lint( | ||
INVALID_DOC_ATTRIBUTES, | ||
hir_id, | ||
meta.span, | ||
errors::DocAutoCfgWrongLiteral, | ||
); | ||
} | ||
} | ||
MetaItemKind::List(list) => { | ||
for item in list { | ||
let Some(attr_name) = item.name() else { continue }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add test cases for this missing error, along with the ones below. |
||
if attr_name != sym::hide && attr_name != sym::show { | ||
self.tcx.emit_node_span_lint( | ||
INVALID_DOC_ATTRIBUTES, | ||
hir_id, | ||
meta.span, | ||
errors::DocAutoCfgExpectsHideOrShow, | ||
); | ||
} else if let Some(list) = item.meta_item_list() { | ||
for item in list { | ||
if item.meta_item_list().is_some() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we also error if there is no meta item list but the item is an invalid cfg (e.g. a boolean, or a multi-segment path)? |
||
self.tcx.emit_node_span_lint( | ||
INVALID_DOC_ATTRIBUTES, | ||
hir_id, | ||
item.span(), | ||
errors::DocAutoCfgHideShowUnexpectedItem { | ||
attr_name: attr_name.as_str(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
); | ||
} | ||
} | ||
} else { | ||
self.tcx.emit_node_span_lint( | ||
INVALID_DOC_ATTRIBUTES, | ||
hir_id, | ||
meta.span, | ||
errors::DocAutoCfgHideShowExpectsList { attr_name: attr_name.as_str() }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -1375,10 +1412,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | |
self.check_attr_crate_level(attr, meta, hir_id); | ||
} | ||
|
||
Some(sym::cfg_hide) => { | ||
if self.check_attr_crate_level(attr, meta, hir_id) { | ||
self.check_doc_cfg_hide(meta, hir_id); | ||
} | ||
Some(sym::auto_cfg) => { | ||
self.check_doc_auto_cfg(i_meta, hir_id); | ||
} | ||
|
||
Some(sym::inline | sym::no_inline) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -520,6 +520,7 @@ symbols! { | |
attributes, | ||
audit_that, | ||
augmented_assignments, | ||
auto_cfg, | ||
auto_traits, | ||
autodiff, | ||
automatically_derived, | ||
|
@@ -1101,6 +1102,8 @@ symbols! { | |
hashset_iter_ty, | ||
hexagon_target_feature, | ||
hidden, | ||
hidden_cfg, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why'd you add this symbol? It seems to be unused unless I'm missing something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I think we can also remove the |
||
hide, | ||
hint, | ||
homogeneous_aggregate, | ||
host, | ||
|
@@ -1905,6 +1908,7 @@ symbols! { | |
shl_assign, | ||
shorter_tail_lifetimes, | ||
should_panic, | ||
show, | ||
shr, | ||
shr_assign, | ||
sig_dfl, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,15 +64,29 @@ | |
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", | ||
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))) | ||
)] | ||
#![doc(cfg_hide( | ||
not(test), | ||
not(any(test, bootstrap)), | ||
no_global_oom_handling, | ||
not(no_global_oom_handling), | ||
not(no_rc), | ||
not(no_sync), | ||
target_has_atomic = "ptr" | ||
))] | ||
#![cfg_attr( | ||
bootstrap, | ||
doc(cfg_hide( | ||
not(test), | ||
not(any(test, bootstrap)), | ||
no_global_oom_handling, | ||
not(no_global_oom_handling), | ||
not(no_rc), | ||
not(no_sync), | ||
target_has_atomic = "ptr" | ||
)) | ||
)] | ||
#![cfg_attr( | ||
not(bootstrap), | ||
doc(auto_cfg(hide( | ||
bootstrap, | ||
no_global_oom_handling, | ||
no_global_oom_handling, | ||
no_rc, | ||
no_sync, | ||
target_has_atomic = "ptr" | ||
))) | ||
)] | ||
Comment on lines
+67
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
#![doc(rust_logo)] | ||
#![feature(rustdoc_internals)] | ||
#![no_std] | ||
|
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.
nit: