Skip to content

Commit

Permalink
Rollup merge of #81302 - LeSeulArtichaut:80777-trait-render, r=jyn514
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
jonas-schievink authored Jan 24, 2021
2 parents 9089dd2 + 20a460e commit ee4461a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
51 changes: 21 additions & 30 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
fn render_implementor(
cx: &Context<'_>,
implementor: &Impl,
parent: &clean::Item,
trait_: &clean::Item,
w: &mut Buffer,
implementor_dups: &FxHashMap<Symbol, (DefId, bool)>,
aliases: &[String],
Expand All @@ -2494,11 +2494,11 @@ fn render_implementor(
w,
cx,
implementor,
parent,
trait_,
AssocItemLink::Anchor(None),
RenderMode::Normal,
implementor.impl_item.stable_since(cx.tcx()).as_deref(),
implementor.impl_item.const_stable_since(cx.tcx()).as_deref(),
trait_.stable_since(cx.tcx()).as_deref(),
trait_.const_stable_since(cx.tcx()).as_deref(),
false,
Some(use_absolute),
false,
Expand Down Expand Up @@ -2937,34 +2937,25 @@ fn render_stability_since_raw(
containing_ver: Option<&str>,
containing_const_ver: Option<&str>,
) {
let ver = ver.and_then(|inner| if !inner.is_empty() { Some(inner) } else { None });

let const_ver = const_ver.and_then(|inner| if !inner.is_empty() { Some(inner) } else { None });
let ver = ver.filter(|inner| !inner.is_empty());
let const_ver = const_ver.filter(|inner| !inner.is_empty());

if let Some(v) = ver {
if let Some(cv) = const_ver {
if const_ver != containing_const_ver {
write!(
w,
"<span class=\"since\" title=\"Stable since Rust version {0}, const since {1}\">{0} (const: {1})</span>",
v, cv
);
} else if ver != containing_ver {
write!(
w,
"<span class=\"since\" title=\"Stable since Rust version {0}\">{0}</span>",
v
);
}
} else {
if ver != containing_ver {
write!(
w,
"<span class=\"since\" title=\"Stable since Rust version {0}\">{0}</span>",
v
);
}
match (ver, const_ver) {
(Some(v), Some(cv)) if const_ver != containing_const_ver => {
write!(
w,
"<span class=\"since\" title=\"Stable since Rust version {0}, const since {1}\">{0} (const: {1})</span>",
v, cv
);
}
(Some(v), _) if ver != containing_ver => {
write!(
w,
"<span class=\"since\" title=\"Stable since Rust version {0}\">{0}</span>",
v
);
}
_ => {}
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/test/rustdoc/implementor-stable-version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![crate_name = "foo"]

#![feature(staged_api)]

#[stable(feature = "bar", since = "OLD 1.0")]
pub trait Bar {}

#[stable(feature = "baz", since = "OLD 1.0")]
pub trait Baz {}

pub struct Foo;

// @has foo/trait.Bar.html '//div[@id="implementors-list"]//span[@class="since"]' 'NEW 2.0'
#[stable(feature = "foobar", since = "NEW 2.0")]
impl Bar for Foo {}

// @!has foo/trait.Baz.html '//div[@id="implementors-list"]//span[@class="since"]' 'OLD 1.0'
#[stable(feature = "foobaz", since = "OLD 1.0")]
impl Baz for Foo {}

0 comments on commit ee4461a

Please sign in to comment.