Skip to content

Commit 7d45243

Browse files
committed
Get rid of clean::Deprecation
This brings the size of `item.deprecation` from 56 to 16 bytes.
1 parent cbab347 commit 7d45243

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
@@ -2342,16 +2342,6 @@ impl Clean<Item> for (&hir::MacroDef<'_>, Option<Symbol>) {
23422342
}
23432343
}
23442344

2345-
impl Clean<Deprecation> for attr::Deprecation {
2346-
fn clean(&self, _: &DocContext<'_>) -> Deprecation {
2347-
Deprecation {
2348-
since: self.since.map(|s| s.to_string()).filter(|s| !s.is_empty()),
2349-
note: self.note.map(|n| n.to_string()).filter(|n| !n.is_empty()),
2350-
is_since_rustc_version: self.is_since_rustc_version,
2351-
}
2352-
}
2353-
}
2354-
23552345
impl Clean<TypeBinding> for hir::TypeBinding<'_> {
23562346
fn clean(&self, cx: &DocContext<'_>) -> TypeBinding {
23572347
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;
@@ -156,7 +156,7 @@ impl Item {
156156
attrs: cx.tcx.get_attrs(def_id).clean(cx),
157157
visibility: cx.tcx.visibility(def_id).clean(cx),
158158
stability: cx.tcx.lookup_stability(def_id).cloned(),
159-
deprecation: cx.tcx.lookup_deprecation(def_id).clean(cx),
159+
deprecation: cx.tcx.lookup_deprecation(def_id),
160160
const_stability: cx.tcx.lookup_const_stability(def_id).cloned(),
161161
}
162162
}
@@ -1793,13 +1793,6 @@ crate struct ProcMacro {
17931793
crate helpers: Vec<String>,
17941794
}
17951795

1796-
#[derive(Clone, Debug)]
1797-
crate struct Deprecation {
1798-
crate since: Option<String>,
1799-
crate note: Option<String>,
1800-
crate is_since_rustc_version: bool,
1801-
}
1802-
18031796
/// An type binding on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or
18041797
/// `A: Send + Sync` in `Foo<A: Send + Sync>`).
18051798
#[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::{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)