Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b15e663

Browse files
authoredMar 17, 2025
Rollup merge of #138577 - aDotInTheVoid:deprecate-deprecations, r=GuillaumeGomez
rustdoc-json: Don't also include `#[deprecated]` in `Item::attrs` Closes #138378 Not sure if this should bump `FORMAT_VERSION` or not. CC `@Enselic` `@LukeMathWalker` `@obi1kenobi` r? `@GuillaumeGomez,` best reviewed commit-by-commit
2 parents 78d141f + 677489f commit b15e663

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed
 

‎src/librustdoc/clean/types.rs

+13-10
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};
@@ -756,12 +756,7 @@ impl Item {
756756
Some(tcx.visibility(def_id))
757757
}
758758

759-
pub(crate) fn attributes(
760-
&self,
761-
tcx: TyCtxt<'_>,
762-
cache: &Cache,
763-
keep_as_is: bool,
764-
) -> Vec<String> {
759+
pub(crate) fn attributes(&self, tcx: TyCtxt<'_>, cache: &Cache, is_json: bool) -> Vec<String> {
765760
const ALLOWED_ATTRIBUTES: &[Symbol] =
766761
&[sym::export_name, sym::link_section, sym::no_mangle, sym::non_exhaustive];
767762

@@ -772,8 +767,14 @@ impl Item {
772767
.other_attrs
773768
.iter()
774769
.filter_map(|attr| {
775-
if keep_as_is {
776-
Some(rustc_hir_pretty::attribute_to_string(&tcx, attr))
770+
if is_json {
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+
}
777778
} else if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
778779
Some(
779780
rustc_hir_pretty::attribute_to_string(&tcx, attr)
@@ -786,7 +787,9 @@ impl Item {
786787
}
787788
})
788789
.collect();
789-
if !keep_as_is
790+
791+
// Add #[repr(...)]
792+
if !is_json
790793
&& let Some(def_id) = self.def_id()
791794
&& let ItemType::Struct | ItemType::Enum | ItemType::Union = self.type_()
792795
{
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//@ is "$.index[*][?(@.name=='not')].attrs" []
2+
//@ is "$.index[*][?(@.name=='not')].deprecation" null
3+
pub fn not() {}
4+
5+
//@ is "$.index[*][?(@.name=='raw')].attrs" []
6+
//@ is "$.index[*][?(@.name=='raw')].deprecation" '{"since": null, "note": null}'
7+
#[deprecated]
8+
pub fn raw() {}
9+
10+
//@ is "$.index[*][?(@.name=='equals_string')].attrs" []
11+
//@ is "$.index[*][?(@.name=='equals_string')].deprecation" '{"since": null, "note": "here is a reason"}'
12+
#[deprecated = "here is a reason"]
13+
pub fn equals_string() {}
14+
15+
//@ is "$.index[*][?(@.name=='since')].attrs" []
16+
//@ is "$.index[*][?(@.name=='since')].deprecation" '{"since": "yoinks ago", "note": null}'
17+
#[deprecated(since = "yoinks ago")]
18+
pub fn since() {}
19+
20+
//@ is "$.index[*][?(@.name=='note')].attrs" []
21+
//@ is "$.index[*][?(@.name=='note')].deprecation" '{"since": null, "note": "7"}'
22+
#[deprecated(note = "7")]
23+
pub fn note() {}
24+
25+
//@ is "$.index[*][?(@.name=='since_and_note')].attrs" []
26+
//@ is "$.index[*][?(@.name=='since_and_note')].deprecation" '{"since": "tomorrow", "note": "sorry"}'
27+
#[deprecated(since = "tomorrow", note = "sorry")]
28+
pub fn since_and_note() {}
29+
30+
//@ is "$.index[*][?(@.name=='note_and_since')].attrs" []
31+
//@ is "$.index[*][?(@.name=='note_and_since')].deprecation" '{"since": "a year from tomorrow", "note": "your welcome"}'
32+
#[deprecated(note = "your welcome", since = "a year from tomorrow")]
33+
pub fn note_and_since() {}
34+
35+
//@ is "$.index[*][?(@.name=='neither_but_parens')].attrs" []
36+
//@ is "$.index[*][?(@.name=='neither_but_parens')].deprecation" '{"since": null, "note": null}'
37+
#[deprecated()]
38+
pub fn neither_but_parens() {}

0 commit comments

Comments
 (0)
Failed to load comments.