Skip to content

Commit 677489f

Browse files
committed
rustdoc-json: Don't also include #[deprecated] in Item::attrs
1 parent a8a913d commit 677489f

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/librustdoc/clean/types.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{fmt, iter};
55

66
use arrayvec::ArrayVec;
77
use rustc_abi::{ExternAbi, VariantIdx};
8-
use rustc_attr_parsing::{ConstStability, Deprecation, Stability, StableSince};
8+
use rustc_attr_parsing::{AttributeKind, ConstStability, Deprecation, Stability, StableSince};
99
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
1010
use rustc_hir::def::{CtorKind, DefKind, Res};
1111
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId};
@@ -768,7 +768,13 @@ impl Item {
768768
.iter()
769769
.filter_map(|attr| {
770770
if is_json {
771-
Some(rustc_hir_pretty::attribute_to_string(&tcx, attr))
771+
if matches!(attr, hir::Attribute::Parsed(AttributeKind::Deprecation { .. })) {
772+
// rustdoc-json stores this in `Item::deprecation`, so we
773+
// don't want it it `Item::attrs`.
774+
None
775+
} else {
776+
Some(rustc_hir_pretty::attribute_to_string(&tcx, attr))
777+
}
772778
} else if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
773779
Some(
774780
rustc_hir_pretty::attribute_to_string(&tcx, attr)
@@ -782,6 +788,7 @@ impl Item {
782788
})
783789
.collect();
784790

791+
// Add #[repr(...)]
785792
if !is_json
786793
&& let Some(def_id) = self.def_id()
787794
&& let ItemType::Struct | ItemType::Enum | ItemType::Union = self.type_()
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
//@ is "$.index[*][?(@.name=='not')].attrs" '[]'
1+
//@ is "$.index[*][?(@.name=='not')].attrs" []
22
//@ is "$.index[*][?(@.name=='not')].deprecation" null
33
pub fn not() {}
44

5-
//@ is "$.index[*][?(@.name=='raw')].attrs" '["#[attr = Deprecation {deprecation: Deprecation {since: Unspecified}}]\n"]'
5+
//@ is "$.index[*][?(@.name=='raw')].attrs" []
66
//@ is "$.index[*][?(@.name=='raw')].deprecation" '{"since": null, "note": null}'
77
#[deprecated]
88
pub fn raw() {}
99

10-
//@ is "$.index[*][?(@.name=='equals_string')].attrs" '["#[attr = Deprecation {deprecation: Deprecation {since: Unspecified, note:\n\"here is a reason\"}}]\n"]'
10+
//@ is "$.index[*][?(@.name=='equals_string')].attrs" []
1111
//@ is "$.index[*][?(@.name=='equals_string')].deprecation" '{"since": null, "note": "here is a reason"}'
1212
#[deprecated = "here is a reason"]
1313
pub fn equals_string() {}
1414

15-
//@ is "$.index[*][?(@.name=='since')].attrs" '["#[attr = Deprecation {deprecation: Deprecation {since:\nNonStandard(\"yoinks ago\")}}]\n"]'
15+
//@ is "$.index[*][?(@.name=='since')].attrs" []
1616
//@ is "$.index[*][?(@.name=='since')].deprecation" '{"since": "yoinks ago", "note": null}'
1717
#[deprecated(since = "yoinks ago")]
1818
pub fn since() {}
1919

20-
//@ is "$.index[*][?(@.name=='note')].attrs" '["#[attr = Deprecation {deprecation: Deprecation {since: Unspecified, note:\n\"7\"}}]\n"]'
20+
//@ is "$.index[*][?(@.name=='note')].attrs" []
2121
//@ is "$.index[*][?(@.name=='note')].deprecation" '{"since": null, "note": "7"}'
2222
#[deprecated(note = "7")]
2323
pub fn note() {}
2424

25-
//@ is "$.index[*][?(@.name=='since_and_note')].attrs" '["#[attr = Deprecation {deprecation: Deprecation {since:\nNonStandard(\"tomorrow\"), note: \"sorry\"}}]\n"]'
25+
//@ is "$.index[*][?(@.name=='since_and_note')].attrs" []
2626
//@ is "$.index[*][?(@.name=='since_and_note')].deprecation" '{"since": "tomorrow", "note": "sorry"}'
2727
#[deprecated(since = "tomorrow", note = "sorry")]
2828
pub fn since_and_note() {}
2929

30-
//@ is "$.index[*][?(@.name=='note_and_since')].attrs" '["#[attr = Deprecation {deprecation: Deprecation {since:\nNonStandard(\"a year from tomorrow\"), note: \"your welcome\"}}]\n"]'
30+
//@ is "$.index[*][?(@.name=='note_and_since')].attrs" []
3131
//@ is "$.index[*][?(@.name=='note_and_since')].deprecation" '{"since": "a year from tomorrow", "note": "your welcome"}'
3232
#[deprecated(note = "your welcome", since = "a year from tomorrow")]
3333
pub fn note_and_since() {}
3434

35-
//@ is "$.index[*][?(@.name=='neither_but_parens')].attrs" '["#[attr = Deprecation {deprecation: Deprecation {since: Unspecified}}]\n"]'
35+
//@ is "$.index[*][?(@.name=='neither_but_parens')].attrs" []
3636
//@ is "$.index[*][?(@.name=='neither_but_parens')].deprecation" '{"since": null, "note": null}'
3737
#[deprecated()]
3838
pub fn neither_but_parens() {}

0 commit comments

Comments
 (0)