Skip to content

Commit ee4461a

Browse files
Rollup merge of #81302 - LeSeulArtichaut:80777-trait-render, r=jyn514
Fix rendering of stabilization version for trait implementors Rustdoc compares an item's stabilization version with its parent's to not render it if they are the same. Here, the implementor was compared with itself, resulting in the stabilization version never getting shown. This probably needs a test. Fixes #80777. r? `@jyn514`
2 parents 9089dd2 + 20a460e commit ee4461a

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

src/librustdoc/html/render/mod.rs

+21-30
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
24742474
fn render_implementor(
24752475
cx: &Context<'_>,
24762476
implementor: &Impl,
2477-
parent: &clean::Item,
2477+
trait_: &clean::Item,
24782478
w: &mut Buffer,
24792479
implementor_dups: &FxHashMap<Symbol, (DefId, bool)>,
24802480
aliases: &[String],
@@ -2494,11 +2494,11 @@ fn render_implementor(
24942494
w,
24952495
cx,
24962496
implementor,
2497-
parent,
2497+
trait_,
24982498
AssocItemLink::Anchor(None),
24992499
RenderMode::Normal,
2500-
implementor.impl_item.stable_since(cx.tcx()).as_deref(),
2501-
implementor.impl_item.const_stable_since(cx.tcx()).as_deref(),
2500+
trait_.stable_since(cx.tcx()).as_deref(),
2501+
trait_.const_stable_since(cx.tcx()).as_deref(),
25022502
false,
25032503
Some(use_absolute),
25042504
false,
@@ -2937,34 +2937,25 @@ fn render_stability_since_raw(
29372937
containing_ver: Option<&str>,
29382938
containing_const_ver: Option<&str>,
29392939
) {
2940-
let ver = ver.and_then(|inner| if !inner.is_empty() { Some(inner) } else { None });
2941-
2942-
let const_ver = const_ver.and_then(|inner| if !inner.is_empty() { Some(inner) } else { None });
2940+
let ver = ver.filter(|inner| !inner.is_empty());
2941+
let const_ver = const_ver.filter(|inner| !inner.is_empty());
29432942

2944-
if let Some(v) = ver {
2945-
if let Some(cv) = const_ver {
2946-
if const_ver != containing_const_ver {
2947-
write!(
2948-
w,
2949-
"<span class=\"since\" title=\"Stable since Rust version {0}, const since {1}\">{0} (const: {1})</span>",
2950-
v, cv
2951-
);
2952-
} else if ver != containing_ver {
2953-
write!(
2954-
w,
2955-
"<span class=\"since\" title=\"Stable since Rust version {0}\">{0}</span>",
2956-
v
2957-
);
2958-
}
2959-
} else {
2960-
if ver != containing_ver {
2961-
write!(
2962-
w,
2963-
"<span class=\"since\" title=\"Stable since Rust version {0}\">{0}</span>",
2964-
v
2965-
);
2966-
}
2943+
match (ver, const_ver) {
2944+
(Some(v), Some(cv)) if const_ver != containing_const_ver => {
2945+
write!(
2946+
w,
2947+
"<span class=\"since\" title=\"Stable since Rust version {0}, const since {1}\">{0} (const: {1})</span>",
2948+
v, cv
2949+
);
2950+
}
2951+
(Some(v), _) if ver != containing_ver => {
2952+
write!(
2953+
w,
2954+
"<span class=\"since\" title=\"Stable since Rust version {0}\">{0}</span>",
2955+
v
2956+
);
29672957
}
2958+
_ => {}
29682959
}
29692960
}
29702961

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![crate_name = "foo"]
2+
3+
#![feature(staged_api)]
4+
5+
#[stable(feature = "bar", since = "OLD 1.0")]
6+
pub trait Bar {}
7+
8+
#[stable(feature = "baz", since = "OLD 1.0")]
9+
pub trait Baz {}
10+
11+
pub struct Foo;
12+
13+
// @has foo/trait.Bar.html '//div[@id="implementors-list"]//span[@class="since"]' 'NEW 2.0'
14+
#[stable(feature = "foobar", since = "NEW 2.0")]
15+
impl Bar for Foo {}
16+
17+
// @!has foo/trait.Baz.html '//div[@id="implementors-list"]//span[@class="since"]' 'OLD 1.0'
18+
#[stable(feature = "foobaz", since = "OLD 1.0")]
19+
impl Baz for Foo {}

0 commit comments

Comments
 (0)