Skip to content

Commit 90f4b52

Browse files
committed
Auto merge of rust-lang#80041 - jyn514:shrink-item, r=GuillaumeGomez
Get rid of `clean::Deprecation` This brings the size of `item.deprecation` from 56 to 16 bytes. Helps with rust-lang#79103 and rust-lang#76382, in the same vein as rust-lang#79957. r? `@GuillaumeGomez`
2 parents c00a464 + 7d45243 commit 90f4b52

File tree

5 files changed

+21
-30
lines changed

5 files changed

+21
-30
lines changed

compiler/rustc_attr/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ pub fn eval_condition(
621621
}
622622
}
623623

624-
#[derive(Encodable, Decodable, Clone, HashStable_Generic)]
624+
#[derive(Debug, Encodable, Decodable, Clone, HashStable_Generic)]
625625
pub struct Deprecation {
626626
pub since: Option<Symbol>,
627627
/// The note to issue a reason.

src/librustdoc/clean/mod.rs

-10
Original file line numberDiff line numberDiff line change
@@ -2337,16 +2337,6 @@ impl Clean<Item> for (&hir::MacroDef<'_>, Option<Symbol>) {
23372337
}
23382338
}
23392339

2340-
impl Clean<Deprecation> for attr::Deprecation {
2341-
fn clean(&self, _: &DocContext<'_>) -> Deprecation {
2342-
Deprecation {
2343-
since: self.since.map(|s| s.to_string()).filter(|s| !s.is_empty()),
2344-
note: self.note.map(|n| n.to_string()).filter(|n| !n.is_empty()),
2345-
is_since_rustc_version: self.is_since_rustc_version,
2346-
}
2347-
}
2348-
}
2349-
23502340
impl Clean<TypeBinding> for hir::TypeBinding<'_> {
23512341
fn clean(&self, cx: &DocContext<'_>) -> TypeBinding {
23522342
TypeBinding { name: self.ident.name.clean(cx), kind: self.kind.clean(cx) }

src/librustdoc/clean/types.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_ast::attr;
1212
use rustc_ast::util::comments::beautify_doc_string;
1313
use rustc_ast::{self as ast, AttrStyle};
1414
use rustc_ast::{FloatTy, IntTy, UintTy};
15-
use rustc_attr::{ConstStability, Stability, StabilityLevel};
15+
use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
1616
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1717
use rustc_feature::UnstableFeatures;
1818
use rustc_hir as hir;
@@ -151,7 +151,7 @@ impl Item {
151151
attrs: cx.tcx.get_attrs(def_id).clean(cx),
152152
visibility: cx.tcx.visibility(def_id).clean(cx),
153153
stability: cx.tcx.lookup_stability(def_id).cloned(),
154-
deprecation: cx.tcx.lookup_deprecation(def_id).clean(cx),
154+
deprecation: cx.tcx.lookup_deprecation(def_id),
155155
const_stability: cx.tcx.lookup_const_stability(def_id).cloned(),
156156
}
157157
}
@@ -1821,13 +1821,6 @@ crate struct ProcMacro {
18211821
crate helpers: Vec<String>,
18221822
}
18231823

1824-
#[derive(Clone, Debug)]
1825-
crate struct Deprecation {
1826-
crate since: Option<String>,
1827-
crate note: Option<String>,
1828-
crate is_since_rustc_version: bool,
1829-
}
1830-
18311824
/// An type binding on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or
18321825
/// `A: Send + Sync` in `Foo<A: Send + Sync>`).
18331826
#[derive(Clone, PartialEq, Eq, Debug, Hash)]

src/librustdoc/html/render/mod.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use std::sync::Arc;
4949

5050
use itertools::Itertools;
5151
use rustc_ast_pretty::pprust;
52-
use rustc_attr::StabilityLevel;
52+
use rustc_attr::{Deprecation, StabilityLevel};
5353
use rustc_data_structures::flock;
5454
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5555
use rustc_data_structures::sync::Lrc;
@@ -65,7 +65,7 @@ use rustc_span::symbol::{kw, sym, Symbol};
6565
use serde::ser::SerializeSeq;
6666
use serde::{Serialize, Serializer};
6767

68-
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, RenderedLink, SelfTy, TypeKind};
68+
use crate::clean::{self, AttributesExt, GetDefId, RenderedLink, SelfTy, TypeKind};
6969
use crate::config::{RenderInfo, RenderOptions};
7070
use crate::docfs::{DocFS, PathError};
7171
use crate::doctree;
@@ -2219,7 +2219,10 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item) -> String {
22192219
// The trailing space after each tag is to space it properly against the rest of the docs.
22202220
if let Some(depr) = &item.deprecation {
22212221
let mut message = "Deprecated";
2222-
if !stability::deprecation_in_effect(depr.is_since_rustc_version, depr.since.as_deref()) {
2222+
if !stability::deprecation_in_effect(
2223+
depr.is_since_rustc_version,
2224+
depr.since.map(|s| s.as_str()).as_deref(),
2225+
) {
22232226
message = "Deprecation planned";
22242227
}
22252228
tags += &tag_html("deprecated", "", message);
@@ -2268,20 +2271,24 @@ fn short_item_info(item: &clean::Item, cx: &Context, parent: Option<&clean::Item
22682271
let mut extra_info = vec![];
22692272
let error_codes = cx.shared.codes;
22702273

2271-
if let Some(Deprecation { ref note, ref since, is_since_rustc_version }) = item.deprecation {
2274+
if let Some(Deprecation { note, since, is_since_rustc_version, suggestion: _ }) =
2275+
item.deprecation
2276+
{
22722277
// We display deprecation messages for #[deprecated] and #[rustc_deprecated]
22732278
// but only display the future-deprecation messages for #[rustc_deprecated].
22742279
let mut message = if let Some(since) = since {
2280+
let since = &since.as_str();
22752281
if !stability::deprecation_in_effect(is_since_rustc_version, Some(since)) {
2276-
format!("Deprecating in {}", Escape(&since))
2282+
format!("Deprecating in {}", Escape(since))
22772283
} else {
2278-
format!("Deprecated since {}", Escape(&since))
2284+
format!("Deprecated since {}", Escape(since))
22792285
}
22802286
} else {
22812287
String::from("Deprecated")
22822288
};
22832289

22842290
if let Some(note) = note {
2291+
let note = note.as_str();
22852292
let mut ids = cx.id_map.borrow_mut();
22862293
let html = MarkdownHtml(
22872294
&note,

src/librustdoc/json/conversions.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ impl JsonRenderer {
7777
}
7878
}
7979

80-
impl From<clean::Deprecation> for Deprecation {
81-
fn from(deprecation: clean::Deprecation) -> Self {
82-
let clean::Deprecation { since, note, is_since_rustc_version: _ } = deprecation;
83-
Deprecation { since, note }
80+
impl From<rustc_attr::Deprecation> for Deprecation {
81+
fn from(deprecation: rustc_attr::Deprecation) -> Self {
82+
#[rustfmt::skip]
83+
let rustc_attr::Deprecation { since, note, is_since_rustc_version: _, suggestion: _ } = deprecation;
84+
Deprecation { since: since.map(|s| s.to_string()), note: note.map(|s| s.to_string()) }
8485
}
8586
}
8687

0 commit comments

Comments
 (0)