Skip to content

Commit 6cddf7b

Browse files
committed
pr feedbacks + x tidy pass
1 parent fcfb089 commit 6cddf7b

10 files changed

Lines changed: 42 additions & 90 deletions

File tree

compiler/rustc_feature/src/unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ declare_features! (
316316
/// Allows builtin # foo() syntax
317317
(internal, builtin_syntax, "1.71.0", Some(110680)),
318318
/// Allows `#[doc(label_trait)]`.
319-
(unstable, doc_label_trait, "1.97.0", Some(156865)),
319+
(unstable, doc_label_trait, "CURRENT_RUSTC_VERSION", Some(156865)),
320320
/// Allows `#[doc(notable_trait)]`.
321321
/// Renamed from `doc_spotlight`.
322322
(unstable, doc_notable_trait, "1.52.0", Some(45040)),

src/doc/rustdoc/src/unstable-features.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ and enabled with a `#![feature(...)]` attribute in your crate.
6363
Important traits can be difficult to discover when lost in the noise.
6464
This `#![feature(doc_label_trait)]` allows you to tag traits important for your code base.
6565

66-
The traits with the attribute #![doc(label_trait)]` are rendered with a colored badge on top of their dedicated page, and accompanied with a smaller badge when referenced from elsewhere.
67-
68-
To customize the color: `#[doc(notable_trait)].
66+
The traits with the attribute #![doc(label_trait)]` are rendered with a colored badge at the top of their dedicated page.
6967

7068
Consider lookint into the `notable_trait` unstable attribure, which help with
7169
discoverability in other ways.

src/doc/unstable-book/src/language-features/doc-label_trait.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/librustdoc/html/render/context.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_ast::join_path_syms;
1010
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
1111
use rustc_hir::Attribute;
1212
use rustc_hir::attrs::AttributeKind;
13-
use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE};
13+
use rustc_hir::def_id::{DefIdMap, LOCAL_CRATE};
1414
use rustc_middle::ty::TyCtxt;
1515
use rustc_session::Session;
1616
use rustc_span::edition::Edition;
@@ -67,7 +67,6 @@ pub(crate) struct Context<'tcx> {
6767
pub(crate) shared: SharedContext<'tcx>,
6868
/// Collection of all types with notable traits referenced in the current module.
6969
pub(crate) types_with_notable_traits: RefCell<FxIndexSet<clean::Type>>,
70-
pub(crate) types_with_label_traits: RefCell<FxIndexMap<DefId, Vec<String>>>,
7170
/// Contains information that needs to be saved and reset after rendering an item which is
7271
/// not a module.
7372
pub(crate) info: ContextInfo,
@@ -630,7 +629,6 @@ impl<'tcx> Context<'tcx> {
630629
deref_id_map: Default::default(),
631630
shared: scx,
632631
types_with_notable_traits: RefCell::new(FxIndexSet::default()),
633-
types_with_label_traits: RefCell::default(),
634632
info: ContextInfo::new(include_sources),
635633
};
636634

@@ -658,7 +656,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
658656
self.deref_id_map.borrow_mut().clear();
659657
self.id_map.borrow_mut().clear();
660658
self.types_with_notable_traits.borrow_mut().clear();
661-
self.types_with_label_traits.borrow_mut().clear();
662659
self.info
663660
}
664661

src/librustdoc/html/render/mod.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod type_layout;
4040
mod write_shared;
4141

4242
use std::borrow::Cow;
43-
use std::collections::VecDeque;
43+
use std::collections::{BTreeMap, VecDeque};
4444
use std::fmt::{self, Display as _, Write};
4545
use std::iter::Peekable;
4646
use std::path::PathBuf;
@@ -1772,7 +1772,6 @@ fn notable_traits_json<'a>(tys: impl Iterator<Item = &'a clean::Type>, cx: &Cont
17721772

17731773
pub(crate) struct LabelTraitInfo {
17741774
pub name: String,
1775-
pub def_id: DefId,
17761775
pub full_path: String,
17771776
/// Relative URL to the trait page, or `None` if it cannot be linked.
17781777
pub href: Option<String>,
@@ -1790,35 +1789,26 @@ pub(crate) fn label_traits_for_item(item: &clean::Item, cx: &Context<'_>) -> Vec
17901789

17911790
let Some(impls) = cx.cache().impls.get(&did) else { return Vec::new() };
17921791

1793-
let mut out: Vec<LabelTraitInfo> = impls
1792+
impls
17941793
.iter()
17951794
.map(Impl::inner_impl)
17961795
.filter(|impl_| impl_.polarity == ty::ImplPolarity::Positive)
1797-
.filter_map(|impl_| impl_.trait_.as_ref())
1798-
.filter_map(|trait_| {
1799-
let trait_did = trait_.def_id();
1800-
let t = cx.cache().traits.get(&trait_did)?;
1801-
if !t.is_label_trait(cx.tcx()) {
1796+
.filter_map(|impl_| {
1797+
let path_ = impl_.trait_.as_ref()?;
1798+
let trait_did = path_.def_id();
1799+
if !cx.cache().traits.get(&trait_did)?.is_label_trait(cx.tcx()) {
18021800
return None;
18031801
}
18041802
let name = cx.tcx().item_name(trait_did).to_string();
18051803
let (full_path, href) = match href(trait_did, cx) {
18061804
Ok(info) => (join_path_syms(&info.rust_path), Some(info.url)),
18071805
Err(_) => (cx.tcx().def_path_str(trait_did), None),
18081806
};
1809-
Some(LabelTraitInfo { name, def_id: trait_did, full_path, href })
1807+
Some((name.clone(), LabelTraitInfo { name, full_path, href }))
18101808
})
1811-
.collect();
1812-
1813-
out.sort_by(|a, b| a.name.cmp(&b.name));
1814-
out.dedup_by(|a, b| a.def_id == b.def_id);
1815-
1816-
if !out.is_empty() {
1817-
cx.types_with_label_traits
1818-
.borrow_mut()
1819-
.insert(did, out.iter().map(|i| i.name.clone()).collect());
1820-
}
1821-
out
1809+
.collect::<BTreeMap<String, LabelTraitInfo>>()
1810+
.into_values()
1811+
.collect()
18221812
}
18231813

18241814
#[derive(Clone, Copy, Debug)]

src/librustdoc/html/render/print_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item) -> impl fmt::Disp
130130
// trait gets the same badge color across pages.
131131
// This won't be stable between releases though.
132132
let mut h = DefaultHasher::new();
133-
info.def_id.hash(&mut h);
133+
info.full_path.hash(&mut h);
134134
let v = h.finish();
135135
let style_attr = format!(
136136
"style=\"background: rgb({}, {}, {})\"",

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,22 +1645,22 @@ so that we can apply CSS-filters to change the arrow color in themes */
16451645
}
16461646

16471647
.impl-label-trait-full-badge-container {
1648-
padding: 0.5rem 0;
1649-
display: flex;
1650-
flex-wrap: wrap;
1651-
gap: 0.5rem;
1648+
padding: 0.5rem 0;
1649+
display: flex;
1650+
flex-wrap: wrap;
1651+
gap: 0.5rem;
16521652
}
16531653

16541654
.impl-label-trait-full-badge {
1655-
display: flex;
1656-
align-items: center;
1657-
width: fit-content;
1658-
height: 1.5rem;
1659-
padding: 0 0.5rem;
1660-
border-radius: 0.75rem;
1661-
font-size: 1rem;
1662-
font-weight: normal;
1663-
color: white;
1655+
display: flex;
1656+
align-items: center;
1657+
width: fit-content;
1658+
height: 1.5rem;
1659+
padding: 0 0.5rem;
1660+
border-radius: 0.75rem;
1661+
font-size: 1rem;
1662+
font-weight: normal;
1663+
color: white;
16641664
}
16651665

16661666
.rightside {

src/librustdoc/html/templates/print_item.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
{% if !path_components.is_empty() %}
33
<div class="rustdoc-breadcrumbs">
44
{% for (i, component) in path_components.iter().enumerate() %}
5-
{% if i != 0 %}
6-
::<wbr>
5+
{% if i != 0 %}
6+
::<wbr>
77
{% endif %}
8-
<a href="{{component.path|safe}}index.html">{{component.name}}</a>
8+
<a href="{{component.path|safe}}index.html">{{component.name}}</a>
99
{% endfor %}
1010
</div>
1111
{% endif %}
1212
<h1>
1313
{{typ}}
1414
<span{% if item_type !="mod" +%} class="{{item_type}}" {% endif %}>
15-
{{name|wrapped|safe}}
16-
</span>&nbsp;{# #}
17-
<button id="copy-path" title="Copy item path to clipboard"> {# #}
18-
Copy item path {# #}
19-
</button> {# #}
15+
{{name|wrapped|safe}}
16+
</span>&nbsp;{# #}
17+
<button id="copy-path" title="Copy item path to clipboard"> {# #}
18+
Copy item path {# #}
19+
</button> {# #}
2020
</h1> {# #}
2121
<rustdoc-toolbar></rustdoc-toolbar> {# #}
2222
<span class="sub-heading">
@@ -33,10 +33,10 @@ <h1>
3333
{{ stability_since_raw|safe +}}
3434
{% endif %}
3535
{% match src_href %}
36-
{% when Some with (href) %}
37-
{% if !stability_since_raw.is_empty() +%} · {%+ endif %}
38-
<a class="src" href="{{href|safe}}">Source</a> {#+ #}
39-
{% else %}
36+
{% when Some with (href) %}
37+
{% if !stability_since_raw.is_empty() +%} · {%+ endif %}
38+
<a class="src" href="{{href|safe}}">Source</a> {#+ #}
39+
{% else %}
4040
{% endmatch %}
4141
</span> {# #}
42-
</div> {# #}
42+
</div> {# #}

src/tools/rust-analyzer/crates/hir-def/src/attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ bitflags::bitflags! {
348348
const IS_MUST_USE = 1 << 50;
349349

350350
const DIAGNOSTIC_DO_NOT_RECOMMEND = 1 << 51;
351+
const IS_DOC_LABEL_TRAIT = 1 << 52;
351352
}
352353
}
353354

tests/rustdoc-html/label_trait/label-trait-negative.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ pub trait Labeled {}
77
// A negative impl must not produce a badge.
88
//@ count 'foo/struct.Neg.html' '//div[@class="impl-label-trait-full-badge-container"]' 0
99
pub struct Neg;
10-
impl !Labeled for Neg {}
10+
impl !Labeled for Neg {}

0 commit comments

Comments
 (0)