Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ fn synthesize_auto_trait_impl<'tcx>(
items: Vec::new(),
polarity,
kind: clean::ImplKind::Auto,
is_deprecated: false,
})),
item_id: clean::ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
cfg: None,
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ pub(crate) fn synthesize_blanket_impls(
None,
None,
))),
is_deprecated: tcx
.lookup_deprecation(impl_def_id)
.is_some_and(|deprecation| deprecation.is_in_effect()),
})),
cfg: None,
inline_stmt_id: None,
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ pub(crate) fn build_impl(
} else {
ImplKind::Normal
},
is_deprecated: tcx
.lookup_deprecation(did)
.is_some_and(|deprecation| deprecation.is_in_effect()),
})),
merged_attrs,
cfg,
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,9 @@ fn clean_impl<'tcx>(
)),
_ => None,
});
let is_deprecated = tcx
.lookup_deprecation(def_id.to_def_id())
.is_some_and(|deprecation| deprecation.is_in_effect());
let mut make_item = |trait_: Option<Path>, for_: Type, items: Vec<Item>| {
let kind = ImplItem(Box::new(Impl {
safety: match impl_.of_trait {
Expand All @@ -2902,6 +2905,7 @@ fn clean_impl<'tcx>(
} else {
ImplKind::Normal
},
is_deprecated,
}));
Item::from_def_id_and_parts(def_id.to_def_id(), None, kind, cx)
};
Expand Down
8 changes: 8 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ impl Item {
})
}

pub(crate) fn is_deprecated(&self, tcx: TyCtxt<'_>) -> bool {
self.deprecation(tcx).is_some_and(|deprecation| deprecation.is_in_effect())
}

pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {
self.item_id.as_def_id().map(|did| inner_docs(tcx.get_all_attrs(did))).unwrap_or(false)
}
Expand Down Expand Up @@ -1270,6 +1274,9 @@ impl Trait {
pub(crate) fn is_dyn_compatible(&self, tcx: TyCtxt<'_>) -> bool {
tcx.is_dyn_compatible(self.def_id)
}
pub(crate) fn is_deprecated(&self, tcx: TyCtxt<'_>) -> bool {
tcx.lookup_deprecation(self.def_id).is_some_and(|deprecation| deprecation.is_in_effect())
}
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -2254,6 +2261,7 @@ pub(crate) struct Impl {
pub(crate) items: Vec<Item>,
pub(crate) polarity: ty::ImplPolarity,
pub(crate) kind: ImplKind,
pub(crate) is_deprecated: bool,
}

impl Impl {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
cache,
);
let aliases = item.attrs.get_doc_aliases();
let deprecation = item.deprecation(tcx);
let is_deprecated = item.is_deprecated(tcx);
let index_item = IndexItem {
ty: item.type_(),
defid: Some(defid),
Expand All @@ -608,7 +608,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It
impl_id,
search_type,
aliases,
deprecation,
is_deprecated,
};

cache.search_index.push(index_item);
Expand Down
35 changes: 27 additions & 8 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub(crate) struct IndexItem {
pub(crate) impl_id: Option<DefId>,
pub(crate) search_type: Option<IndexItemFunctionType>,
pub(crate) aliases: Box<[Symbol]>,
pub(crate) deprecation: Option<Deprecation>,
pub(crate) is_deprecated: bool,
}

/// A type used for the search index.
Expand Down Expand Up @@ -1794,12 +1794,14 @@ fn render_impl(
let mut info_buffer = String::new();
let mut short_documented = true;

let mut trait_item_deprecated = false;
if render_method_item {
if !is_default_item {
if let Some(t) = trait_ {
// The trait item may have been stripped so we might not
// find any documentation or stability for it.
if let Some(it) = t.items.iter().find(|i| i.name == item.name) {
trait_item_deprecated = it.is_deprecated(cx.tcx());
// We need the stability of the item from the trait
// because impls can't have a stability.
if !item.doc_value().is_empty() {
Expand Down Expand Up @@ -1839,10 +1841,20 @@ fn render_impl(
Either::Right(boring)
};

let mut deprecation_class = if trait_item_deprecated || item.is_deprecated(cx.tcx()) {
" deprecated"
} else {
""
};

let toggled = !doc_buffer.is_empty();
if toggled {
let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" };
write!(w, "<details class=\"toggle{method_toggle_class}\" open><summary>")?;
write!(
w,
"<details class=\"toggle{method_toggle_class}{deprecation_class}\" open><summary>"
)?;
deprecation_class = "";
}
match &item.kind {
clean::MethodItem(..) | clean::RequiredMethodItem(_) => {
Expand All @@ -1859,7 +1871,7 @@ fn render_impl(
.map(|item| format!("{}.{name}", item.type_()));
write!(
w,
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">\
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
{}",
render_rightside(cx, item, render_mode)
)?;
Expand All @@ -1885,7 +1897,7 @@ fn render_impl(
let id = cx.derive_id(&source_id);
write!(
w,
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">\
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
{}",
render_rightside(cx, item, render_mode)
)?;
Expand All @@ -1912,7 +1924,7 @@ fn render_impl(
let id = cx.derive_id(&source_id);
write!(
w,
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">\
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
{}",
render_rightside(cx, item, render_mode),
)?;
Expand Down Expand Up @@ -1944,7 +1956,7 @@ fn render_impl(
let id = cx.derive_id(&source_id);
write!(
w,
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">\
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
{}",
render_rightside(cx, item, render_mode),
)?;
Expand All @@ -1971,7 +1983,7 @@ fn render_impl(
let id = cx.derive_id(&source_id);
write!(
w,
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">\
"<section id=\"{id}\" class=\"{item_type}{in_trait_class}{deprecation_class}\">\
{}",
render_rightside(cx, item, render_mode),
)?;
Expand Down Expand Up @@ -2143,11 +2155,18 @@ fn render_impl(
}
if render_mode == RenderMode::Normal {
let toggled = !(impl_items.is_empty() && default_impl_items.is_empty());
let deprecation_attr = if impl_.is_deprecated
|| trait_.is_some_and(|trait_| trait_.is_deprecated(cx.tcx()))
{
" deprecated"
} else {
""
};
if toggled {
close_tags.push("</details>");
write!(
w,
"<details class=\"toggle implementors-toggle\"{}>\
"<details class=\"toggle implementors-toggle{deprecation_attr}\"{}>\
<summary>",
if rendering_params.toggle_open_by_default { " open" } else { "" }
)?;
Expand Down
49 changes: 34 additions & 15 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ fn toggle_close(mut w: impl fmt::Write) {
}

fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> impl fmt::Display {
fn deprecation_class_attr(is_deprecated: bool) -> &'static str {
if is_deprecated { " class=\"deprecated\"" } else { "" }
}

fmt::from_fn(|w| {
write!(w, "{}", document(cx, item, None, HeadingOffset::H2))?;

Expand Down Expand Up @@ -370,11 +374,18 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
write!(w, "</code></dt>")?
}
clean::ImportItem(ref import) => {
let stab_tags =
import.source.did.map_or_else(String::new, |import_def_id| {
print_extra_info_tags(tcx, myitem, item, Some(import_def_id))
.to_string()
});
let (stab_tags, deprecation) = match import.source.did {
Some(import_def_id) => {
let stab_tags =
print_extra_info_tags(tcx, myitem, item, Some(import_def_id))
.to_string();
let deprecation = tcx
.lookup_deprecation(import_def_id)
.is_some_and(|deprecation| deprecation.is_in_effect());
(stab_tags, deprecation)
}
None => (String::new(), item.is_deprecated(tcx)),
};
let id = match import.kind {
clean::ImportKind::Simple(s) => {
format!(" id=\"{}\"", cx.derive_id(format!("reexport.{s}")))
Expand All @@ -383,8 +394,8 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
};
write!(
w,
"<dt{id}>\
<code>"
"<dt{id}{deprecation_attr}><code>",
deprecation_attr = deprecation_class_attr(deprecation)
)?;
render_attributes_in_code(w, myitem, "", cx)?;
write!(
Expand All @@ -396,9 +407,7 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
)?;
}
_ => {
if myitem.name.is_none() {
continue;
}
let Some(item_name) = myitem.name else { continue };

let unsafety_flag = match myitem.kind {
clean::FunctionItem(_) | clean::ForeignFunctionItem(..)
Expand Down Expand Up @@ -431,9 +440,10 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
.into_string();
let (docs_before, docs_after) =
if docs.is_empty() { ("", "") } else { ("<dd>", "</dd>") };
let deprecation_attr = deprecation_class_attr(myitem.is_deprecated(tcx));
write!(
w,
"<dt>\
"<dt{deprecation_attr}>\
<a class=\"{class}\" href=\"{href}\" title=\"{title1} {title2}\">\
{name}\
</a>\
Expand All @@ -442,12 +452,12 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
{stab_tags}\
</dt>\
{docs_before}{docs}{docs_after}",
name = EscapeBodyTextWithWbr(myitem.name.unwrap().as_str()),
name = EscapeBodyTextWithWbr(item_name.as_str()),
visibility_and_hidden = visibility_and_hidden,
stab_tags = print_extra_info_tags(tcx, myitem, item, None),
class = type_,
unsafety_flag = unsafety_flag,
href = print_item_path(type_, myitem.name.unwrap().as_str()),
href = print_item_path(type_, item_name.as_str()),
title1 = myitem.type_(),
title2 = full_path(cx, myitem),
)?;
Expand Down Expand Up @@ -778,15 +788,24 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt:

let content = document_full(m, cx, HeadingOffset::H5).to_string();

let mut deprecation_class =
if m.is_deprecated(cx.tcx()) { " deprecated" } else { "" };

let toggled = !content.is_empty();
if toggled {
let method_toggle_class =
if item_type.is_method() { " method-toggle" } else { "" };
write!(w, "<details class=\"toggle{method_toggle_class}\" open><summary>")?;
write!(
w,
"<details \
class=\"toggle{method_toggle_class}{deprecation_class}\" \
open><summary>"
)?;
deprecation_class = "";
}
write!(
w,
"<section id=\"{id}\" class=\"method\">\
"<section id=\"{id}\" class=\"method{deprecation_class}\">\
{}\
<h4 class=\"code-header\">{}</h4></section>",
render_rightside(cx, m, RenderMode::Normal),
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/search_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ pub(crate) fn build_index(
cache,
),
aliases: item.attrs.get_doc_aliases(),
deprecation: item.deprecation(tcx),
is_deprecated: item.is_deprecated(tcx),
});
}
}
Expand Down Expand Up @@ -1519,7 +1519,7 @@ pub(crate) fn build_index(
trait_parent: item.trait_parent_idx,
module_path,
exact_module_path,
deprecated: item.deprecation.is_some(),
deprecated: item.is_deprecated,
associated_item_disambiguator: if let Some(impl_id) = item.impl_id
&& let Some(parent_idx) = item.parent_idx
&& associated_item_duplicates
Expand Down
11 changes: 10 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ xmlns="http://www.w3.org/2000/svg" fill="black" height="18px">\
<path d="M3,5h16M3,11h16M3,17h16" stroke-width="2.75"/></svg>');
}

:root.sans-serif {
:root.sans-serif-fonts {
--font-family: "Fira Sans", sans-serif;
--font-family-code: "Fira Mono", monospace;
}
Expand Down Expand Up @@ -2642,6 +2642,15 @@ However, it's not needed with smaller screen width because the doc/code block is
}
}

/* Items on module pages */
.hide-deprecated-items dt.deprecated,
.hide-deprecated-items dt.deprecated + dd,
/* Items on item pages */
.hide-deprecated-items .deprecated,
.hide-deprecated-items .deprecated + .item-info {
display: none;
}

/*
WARNING: RUSTDOC_MOBILE_BREAKPOINT MEDIA QUERY
If you update this line, then you also need to update the line with the same warning
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4920,6 +4920,9 @@ async function addTab(results, query, display, finishedCallback, isTypeSearch) {

const link = document.createElement("a");
link.className = "result-" + type;
if (obj.item.deprecated) {
link.className += " deprecated";
}
link.href = obj.href;

const resultName = document.createElement("span");
Expand Down
Loading
Loading