Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6630c14
Implement the `+whole-archive` modifier for `wasm-ld`
alexcrichton Sep 24, 2022
449a440
test attr: point at return type if Termination bound unsatisfied
fmease Oct 23, 2022
c0447b4
fix #103435, unused lint won't produce invalid code
chenyukang Oct 24, 2022
a46af18
fix parentheses surrounding spacing issue in parser
chenyukang Oct 24, 2022
32a2f0d
suggest calling the method of the same name when method not found
chenyukang Oct 25, 2022
2716449
add testcase for suggest self
chenyukang Oct 25, 2022
4b5cff5
Fix broken link in error code E0706 docs
PeteDevoy Nov 3, 2022
8e0cac1
rustdoc: refactor `notable_traits_decl` to just act on the type directly
notriddle Nov 7, 2022
303653e
rustdoc: use javascript to layout notable traits popups
notriddle Nov 7, 2022
a45151e
rustdoc: fix font color inheritance from body, and test
notriddle Nov 8, 2022
0e0bcd9
prevent uninitialized access in black_box for zero-sized-types
krasimirgg Nov 4, 2022
06a77af
Add retry flag to remote-test-server
Ayush1325 Nov 8, 2022
53e8b49
rustdoc: sort output to make it deterministic
notriddle Nov 9, 2022
50bb7a4
Tweak span for `#[must_use]`
estebank Aug 16, 2022
243496e
Consider `#[must_use]` annotation on `async fn` as also affecting the…
estebank Aug 16, 2022
8bd8484
review comments
estebank Aug 17, 2022
f57713b
Fix tests after rebase
estebank Nov 11, 2022
f12f8e5
Rollup merge of #100633 - estebank:must_use_async_fn_return, r=tmandry
Manishearth Nov 11, 2022
db8c8ee
Rollup merge of #102215 - alexcrichton:wasm-link-whole-archive, r=est…
Manishearth Nov 11, 2022
1e88697
Rollup merge of #103445 - fmease:fix-50291, r=estebank
Manishearth Nov 11, 2022
a778ce3
Rollup merge of #103468 - chenyukang:yukang/fix-103435-extra-parenthe…
Manishearth Nov 11, 2022
ba1ead5
Rollup merge of #103531 - chenyukang:yukang/fix-103474, r=estebank
Manishearth Nov 11, 2022
b906422
Rollup merge of #103924 - PeteDevoy:patch-1, r=estebank
Manishearth Nov 11, 2022
3706a6d
Rollup merge of #104110 - krasimirgg:msan-16, r=nagisa
Manishearth Nov 11, 2022
16b8651
Rollup merge of #104129 - notriddle:notriddle/102576-js-notable-trait…
Manishearth Nov 11, 2022
4fc9d1c
Rollup merge of #104146 - Ayush1325:remote-test-server, r=jyn514
Manishearth Nov 11, 2022
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
Prev Previous commit
Next Next commit
rustdoc: refactor notable_traits_decl to just act on the type directly
  • Loading branch information
notriddle committed Nov 7, 2022
commit 8e0cac18cd2951e2679ea55e15242d04e2d410c9
133 changes: 66 additions & 67 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,11 @@ fn assoc_method(
name = name,
generics = g.print(cx),
decl = d.full_print(header_len, indent, cx),
notable_traits = notable_traits_decl(d, cx),
notable_traits = d
.output
.as_return()
.and_then(|output| notable_traits_decl(output, cx))
.unwrap_or_default(),
where_clause = print_where_clause(g, cx, indent, end_newline),
)
}
Expand Down Expand Up @@ -1273,88 +1277,83 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
}
}

fn notable_traits_decl(decl: &clean::FnDecl, cx: &Context<'_>) -> String {
fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> Option<String> {
let mut out = Buffer::html();

if let Some((did, ty)) = decl.output.as_return().and_then(|t| Some((t.def_id(cx.cache())?, t)))
let did = ty.def_id(cx.cache())?;

// Box has pass-through impls for Read, Write, Iterator, and Future when the
// boxed type implements one of those. We don't want to treat every Box return
// as being notably an Iterator (etc), though, so we exempt it. Pin has the same
// issue, with a pass-through impl for Future.
if Some(did) == cx.tcx().lang_items().owned_box()
|| Some(did) == cx.tcx().lang_items().pin_type()
{
// Box has pass-through impls for Read, Write, Iterator, and Future when the
// boxed type implements one of those. We don't want to treat every Box return
// as being notably an Iterator (etc), though, so we exempt it. Pin has the same
// issue, with a pass-through impl for Future.
if Some(did) == cx.tcx().lang_items().owned_box()
|| Some(did) == cx.tcx().lang_items().pin_type()
{
return "".to_string();
}
if let Some(impls) = cx.cache().impls.get(&did) {
for i in impls {
let impl_ = i.inner_impl();
if !impl_.for_.without_borrowed_ref().is_same(ty.without_borrowed_ref(), cx.cache())
{
// Two different types might have the same did,
// without actually being the same.
continue;
}
if let Some(trait_) = &impl_.trait_ {
let trait_did = trait_.def_id();

if cx
.cache()
.traits
.get(&trait_did)
.map_or(false, |t| t.is_notable_trait(cx.tcx()))
{
if out.is_empty() {
write!(
&mut out,
"<span class=\"notable\">Notable traits for {}</span>\
<code class=\"content\">",
impl_.for_.print(cx)
);
}
return None;
}
if let Some(impls) = cx.cache().impls.get(&did) {
for i in impls {
let impl_ = i.inner_impl();
if !impl_.for_.without_borrowed_ref().is_same(ty.without_borrowed_ref(), cx.cache()) {
// Two different types might have the same did,
// without actually being the same.
continue;
}
if let Some(trait_) = &impl_.trait_ {
let trait_did = trait_.def_id();

//use the "where" class here to make it small
if cx.cache().traits.get(&trait_did).map_or(false, |t| t.is_notable_trait(cx.tcx()))
{
if out.is_empty() {
write!(
&mut out,
"<span class=\"where fmt-newline\">{}</span>",
impl_.print(false, cx)
"<span class=\"notable\">Notable traits for {}</span>\
<code class=\"content\">",
impl_.for_.print(cx)
);
for it in &impl_.items {
if let clean::AssocTypeItem(ref tydef, ref _bounds) = *it.kind {
out.push_str("<span class=\"where fmt-newline\"> ");
let empty_set = FxHashSet::default();
let src_link =
AssocItemLink::GotoSource(trait_did.into(), &empty_set);
assoc_type(
&mut out,
it,
&tydef.generics,
&[], // intentionally leaving out bounds
Some(&tydef.type_),
src_link,
0,
cx,
);
out.push_str(";</span>");
}
}

//use the "where" class here to make it small
write!(
&mut out,
"<span class=\"where fmt-newline\">{}</span>",
impl_.print(false, cx)
);
for it in &impl_.items {
if let clean::AssocTypeItem(ref tydef, ref _bounds) = *it.kind {
out.push_str("<span class=\"where fmt-newline\"> ");
let empty_set = FxHashSet::default();
let src_link = AssocItemLink::GotoSource(trait_did.into(), &empty_set);
assoc_type(
&mut out,
it,
&tydef.generics,
&[], // intentionally leaving out bounds
Some(&tydef.type_),
src_link,
0,
cx,
);
out.push_str(";</span>");
}
}
}
}
}
}

if !out.is_empty() {
out.insert_str(
0,
"<span class=\"notable-traits\"><span class=\"notable-traits-tooltip\">ⓘ\
<span class=\"notable-traits-tooltiptext\"><span class=\"docblock\">",
);
out.push_str("</code></span></span></span></span>");
if out.is_empty() {
return None;
}

out.into_inner()
out.insert_str(
0,
"<span class=\"notable-traits\"><span class=\"notable-traits-tooltip\">ⓘ\
<span class=\"notable-traits-tooltiptext\"><span class=\"docblock\">",
);
out.push_str("</code></span></span></span></span>");

Some(out.into_inner())
}

#[derive(Clone, Copy, Debug)]
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,12 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle
generics = f.generics.print(cx),
where_clause = print_where_clause(&f.generics, cx, 0, Ending::Newline),
decl = f.decl.full_print(header_len, 0, cx),
notable_traits = notable_traits_decl(&f.decl, cx),
notable_traits = f
.decl
.output
.as_return()
.and_then(|output| notable_traits_decl(output, cx))
.unwrap_or_default(),
);
});
});
Expand Down