-
Notifications
You must be signed in to change notification settings - Fork 13.5k
WIP: rustdoc-json: Structured attributes #142936
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
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 |
---|---|---|
|
@@ -37,8 +37,8 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc | |
// will instead cause conflicts. See #94591 for more. (This paragraph and the "Latest feature" line | ||
// are deliberately not in a doc comment, because they need not be in public docs.) | ||
// | ||
// Latest feature: Pretty printing of no_mangle attributes changed | ||
pub const FORMAT_VERSION: u32 = 53; | ||
// Latest feature: Structed Attributes | ||
pub const FORMAT_VERSION: u32 = 54; | ||
|
||
/// The root of the emitted JSON blob. | ||
/// | ||
|
@@ -195,13 +195,56 @@ pub struct Item { | |
/// - `#[repr(C)]` and other reprs also appear as themselves, | ||
/// though potentially with a different order: e.g. `repr(i8, C)` may become `repr(C, i8)`. | ||
/// Multiple repr attributes on the same item may be combined into an equivalent single attr. | ||
pub attrs: Vec<String>, | ||
pub attrs: Vec<Attribute>, | ||
/// Information about the item’s deprecation, if present. | ||
pub deprecation: Option<Deprecation>, | ||
/// The type-specific fields describing this item. | ||
pub inner: ItemEnum, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
/// An attribute, eg `#[repr(C)]` | ||
/// | ||
/// This doesn't include: | ||
/// - `#[doc = "Doc Comment"]` or `/// Doc comment`. These are in [`Item::docs`] instead. | ||
/// - `#[depricate]`. These are in [`Item::deprecation`] instead. | ||
pub enum Attribute { | ||
/// `#[non_exaustive]` | ||
NonExhaustive, | ||
|
||
/// `#[must_use]` | ||
MustUse { | ||
reason: Option<String>, | ||
}, | ||
|
||
/// `#[automatically_derived]` | ||
AutomaticallyDerived, | ||
|
||
/// `#[repr]` | ||
Repr(AttributeRepr), | ||
Comment on lines
+223
to
+224
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. Just noting for myself later that we'll need to also represent cases like I saw the |
||
|
||
ExportName(String), | ||
/// `#[doc(hidden)]` | ||
DocHidden, | ||
/// `#[no_mangle]` | ||
NoMangle, | ||
|
||
/// Something else. | ||
/// | ||
/// Things here are explicitly *not* covered by the [`FORMAT_VERSION`] | ||
/// constant, and may change without bumping the format version. If you rely | ||
/// on an attibute here, please open an issue about adding a new variant for | ||
/// that attr. | ||
Other(String), | ||
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. Would love to break out 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. Totally doable after #142876 lands, which is probably before this PR. |
||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
pub enum AttributeRepr { | ||
C, | ||
Transparent, | ||
Rust, | ||
} | ||
|
||
/// A range of source code. | ||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
pub struct Span { | ||
|
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.