Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
6630c14
Implement the `+whole-archive` modifier for `wasm-ld`
alexcrichton Sep 24, 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
4f3a988
teach ./miri how to do Josh syncs
RalfJung Oct 29, 2022
39598e4
merge rustup-toolchain into ./miri
RalfJung Oct 29, 2022
2a3a53b
explain how to go back to rustup-managed Miri
RalfJung Oct 29, 2022
18a23a5
Auto merge of #2635 - RalfJung:rustup-managed-miri, r=RalfJung
bors Oct 29, 2022
79a48ce
Auto merge of #2634 - RalfJung:miri-script, r=oli-obk
bors Oct 29, 2022
1470e99
Stacked Borrows: make scalar field retagging the default
RalfJung Oct 29, 2022
c162fd3
Auto merge of #2636 - RalfJung:scalar-field-retag, r=oli-obk
bors Oct 29, 2022
bfe23b9
Merge from rustc
RalfJung Oct 30, 2022
0b49a5d
rustup
RalfJung Oct 30, 2022
962bf63
Auto merge of #2639 - RalfJung:rustup, r=RalfJung
bors Oct 30, 2022
41c368b
fix dupe word typos
Rageking8 Oct 31, 2022
224dff4
add acquire when init once is already complete
beepster4096 Oct 31, 2022
21669d2
Auto merge of #2640 - Rageking8:fix-dupe-word-typos, r=saethlin
bors Oct 31, 2022
a1cd279
followup for pr 2640
Rageking8 Oct 31, 2022
02c5ded
Auto merge of #2642 - Rageking8:followup-for-pr-2640, r=RalfJung
bors Oct 31, 2022
9554907
fix ./miri bench
RalfJung Nov 2, 2022
9d9157e
Auto merge of #2645 - RalfJung:miri-bench, r=RalfJung
bors Nov 2, 2022
fa1b720
refactor into private functions
beepster4096 Nov 4, 2022
cb6f7a6
clarify no_data_race_after_complete test
beepster4096 Nov 4, 2022
4492c02
Auto merge of #2641 - DrMeepster:init_once_acquire, r=RalfJung
bors Nov 4, 2022
83239c2
Merge from rustc
RalfJung Nov 5, 2022
7910caf
Auto merge of #2650 - RalfJung:rustup, r=RalfJung
bors Nov 5, 2022
a1d94d4
impl condvars for windows
beepster4096 Oct 30, 2022
a2f7e84
use enum for condvar locks
beepster4096 Oct 30, 2022
2eb07a0
fix shared behavior and add tests
beepster4096 Oct 31, 2022
f60a2ae
Auto merge of #2638 - DrMeepster:windows-condvars, r=RalfJung
bors Nov 6, 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
e636af7
lint auto pass
AndyJado Sep 14, 2022
a0cee0a
remove old var_span_path_only
AndyJado Nov 4, 2022
abf259c
var_subdiag refinement
AndyJado Nov 9, 2022
057d8e5
struct error E0505
AndyJado Nov 9, 2022
53e8b49
rustdoc: sort output to make it deterministic
notriddle Nov 9, 2022
5c25d30
Allow specialized const trait impls.
BGR360 Mar 25, 2022
ce03d25
Disallow specializing on const impls with non-const impls.
BGR360 Sep 14, 2022
d492b9b
Add #[const_trait] where needed in tests.
BGR360 Nov 6, 2022
c0ae62e
Require `~const` qualifier on trait bounds in specializing impls if p…
BGR360 Nov 6, 2022
fe53cac
Apply PR feedback.
BGR360 Nov 10, 2022
0f2e45b
make `Sized` coinductive
lcnr Mar 29, 2021
8ec6c84
add some more tests
lcnr Apr 27, 2021
43ad19b
bless tests
compiler-errors Aug 10, 2022
fea8d0e
More nits
compiler-errors Nov 10, 2022
94f67e6
Oops, bless this test.
BGR360 Nov 11, 2022
05824cd
rustdoc: fix HTML validation failure by escaping `data-ty`
notriddle Nov 11, 2022
cd30ccf
Rollup merge of #95292 - BGR360:const-trait-specialize, r=lcnr
Manishearth Nov 11, 2022
76ce198
Rollup merge of #100386 - compiler-errors:sized-coinductive-redux, r=…
Manishearth Nov 11, 2022
9553fea
Rollup merge of #102215 - alexcrichton:wasm-link-whole-archive, r=est…
Manishearth Nov 11, 2022
fd5ff82
Rollup merge of #103468 - chenyukang:yukang/fix-103435-extra-parenthe…
Manishearth Nov 11, 2022
f00897e
Rollup merge of #103531 - chenyukang:yukang/fix-103474, r=estebank
Manishearth Nov 11, 2022
a13809a
Rollup merge of #103960 - AndyJado:var_path_only_diag, r=davidtwco
Manishearth Nov 11, 2022
e8bc6e1
Rollup merge of #104051 - RalfJung:miri, r=RalfJung
Manishearth Nov 11, 2022
b74d042
Rollup merge of #104129 - notriddle:notriddle/102576-js-notable-trait…
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: use javascript to layout notable traits popups
Fixes #102576
  • Loading branch information
notriddle committed Nov 8, 2022
commit 303653ef65a337b21226a52546615936225fb5af
4 changes: 0 additions & 4 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ impl Buffer {
self.buffer
}

pub(crate) fn insert_str(&mut self, idx: usize, s: &str) {
self.buffer.insert_str(idx, s);
}

pub(crate) fn push_str(&mut self, s: &str) {
self.buffer.push_str(s);
}
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ pub(crate) struct Context<'tcx> {
/// the source files are present in the html rendering, then this will be
/// `true`.
pub(crate) include_sources: bool,
/// Collection of all types with notable traits referenced in the current module.
pub(crate) types_with_notable_traits: FxHashSet<clean::Type>,
}

// `Context` is cloned a lot, so we don't want the size to grow unexpectedly.
#[cfg(all(not(windows), target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Context<'_>, 128);
rustc_data_structures::static_assert_size!(Context<'_>, 160);

/// Shared mutable state used in [`Context`] and elsewhere.
pub(crate) struct SharedContext<'tcx> {
Expand Down Expand Up @@ -532,6 +534,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
deref_id_map: FxHashMap::default(),
shared: Rc::new(scx),
include_sources,
types_with_notable_traits: FxHashSet::default(),
};

if emit_crate {
Expand Down Expand Up @@ -560,6 +563,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
id_map: IdMap::new(),
shared: Rc::clone(&self.shared),
include_sources: self.include_sources,
types_with_notable_traits: FxHashSet::default(),
}
}

Expand Down Expand Up @@ -803,6 +807,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
}
}
}

Ok(())
}

Expand Down
145 changes: 97 additions & 48 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use rustc_span::{
symbol::{sym, Symbol},
BytePos, FileName, RealFileName,
};
use serde::ser::SerializeSeq;
use serde::ser::{SerializeMap, SerializeSeq};
use serde::{Serialize, Serializer};

use crate::clean::{self, ItemId, RenderedLink, SelfTy};
Expand Down Expand Up @@ -803,7 +803,7 @@ fn assoc_method(
d: &clean::FnDecl,
link: AssocItemLink<'_>,
parent: ItemType,
cx: &Context<'_>,
cx: &mut Context<'_>,
render_mode: RenderMode,
) {
let tcx = cx.tcx();
Expand Down Expand Up @@ -836,6 +836,8 @@ fn assoc_method(
+ name.as_str().len()
+ generics_len;

let notable_traits = d.output.as_return().and_then(|output| notable_traits_button(output, cx));

let (indent, indent_str, end_newline) = if parent == ItemType::Trait {
header_len += 4;
let indent_str = " ";
Expand All @@ -861,13 +863,9 @@ fn assoc_method(
name = name,
generics = g.print(cx),
decl = d.full_print(header_len, indent, cx),
notable_traits = d
.output
.as_return()
.and_then(|output| notable_traits_decl(output, cx))
.unwrap_or_default(),
notable_traits = notable_traits.unwrap_or_default(),
where_clause = print_where_clause(g, cx, indent, end_newline),
)
);
}

/// Writes a span containing the versions at which an item became stable and/or const-stable. For
Expand Down Expand Up @@ -967,7 +965,7 @@ fn render_assoc_item(
item: &clean::Item,
link: AssocItemLink<'_>,
parent: ItemType,
cx: &Context<'_>,
cx: &mut Context<'_>,
render_mode: RenderMode,
) {
match &*item.kind {
Expand Down Expand Up @@ -1277,8 +1275,8 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) ->
}
}

fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> Option<String> {
let mut out = Buffer::html();
pub(crate) fn notable_traits_button(ty: &clean::Type, cx: &mut Context<'_>) -> Option<String> {
let mut has_notable_trait = false;

let did = ty.def_id(cx.cache())?;

Expand All @@ -1291,6 +1289,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> Option<String> {
{
return None;
}

if let Some(impls) = cx.cache().impls.get(&did) {
for i in impls {
let impl_ = i.inner_impl();
Expand All @@ -1304,56 +1303,106 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> Option<String> {

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)
);
}
has_notable_trait = true;
}
}
}
}

if has_notable_trait {
cx.types_with_notable_traits.insert(ty.clone());
Some(format!(
"<span class=\"notable-traits\" data-ty=\"{ty:#}\">\
<span class=\"notable-traits-tooltip\">ⓘ</span>\
</span>",
ty = ty.print(cx),
))
} else {
None
}
}

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

let did = ty.def_id(cx.cache()).expect("notable_traits_button already checked this");

//use the "where" class here to make it small
let impls = cx.cache().impls.get(&did).expect("notable_traits_button already checked this");

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=\"where fmt-newline\">{}</span>",
impl_.print(false, cx)
"<h3 class=\"notable\">Notable traits for <code>{}</code></h3>\
<pre class=\"content\"><code>",
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() {
return None;
write!(&mut out, "</code></pre>",);
}

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>");
(format!("{:#}", ty.print(cx)), out.into_inner())
}

Some(out.into_inner())
pub(crate) fn notable_traits_json<'a>(
tys: impl Iterator<Item = &'a clean::Type>,
cx: &Context<'_>,
) -> String {
let mp: Vec<(String, String)> = tys.map(|ty| notable_traits_decl(ty, cx)).collect();
struct NotableTraitsMap(Vec<(String, String)>);
impl Serialize for NotableTraitsMap {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut map = serializer.serialize_map(Some(self.0.len()))?;
for item in &self.0 {
map.serialize_entry(&item.0, &item.1)?;
}
map.end()
}
}
serde_json::to_string(&NotableTraitsMap(mp))
.expect("serialize (string, string) -> json object cannot fail")
}

#[derive(Clone, Copy, Debug)]
Expand Down
29 changes: 19 additions & 10 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ use std::rc::Rc;

use super::{
collect_paths_for_type, document, ensure_trailing_slash, get_filtered_impls_for_reference,
item_ty_to_section, notable_traits_decl, render_all_impls, render_assoc_item,
render_assoc_items, render_attributes_in_code, render_attributes_in_pre, render_impl,
render_rightside, render_stability_since_raw, AssocItemLink, Context, ImplRenderingParameters,
item_ty_to_section, notable_traits_button, notable_traits_json, render_all_impls,
render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre,
render_impl, render_rightside, render_stability_since_raw, AssocItemLink, Context,
ImplRenderingParameters,
};
use crate::clean;
use crate::config::ModuleSorting;
Expand Down Expand Up @@ -183,6 +184,16 @@ pub(super) fn print_item(
unreachable!();
}
}

// Render notable-traits.js used for all methods in this module.
if !cx.types_with_notable_traits.is_empty() {
write!(
buf,
r#"<script type="text/json" id="notable-traits-data">{}</script>"#,
notable_traits_json(cx.types_with_notable_traits.iter(), cx)
);
cx.types_with_notable_traits.clear();
}
}

/// For large structs, enums, unions, etc, determine whether to hide their fields
Expand Down Expand Up @@ -516,6 +527,9 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle
+ name.as_str().len()
+ generics_len;

let notable_traits =
f.decl.output.as_return().and_then(|output| notable_traits_button(output, cx));

wrap_into_item_decl(w, |w| {
wrap_item(w, "fn", |w| {
render_attributes_in_pre(w, it, "");
Expand All @@ -533,16 +547,11 @@ 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 = f
.decl
.output
.as_return()
.and_then(|output| notable_traits_decl(output, cx))
.unwrap_or_default(),
notable_traits = notable_traits.unwrap_or_default(),
);
});
});
document(w, cx, it, None, HeadingOffset::H2)
document(w, cx, it, None, HeadingOffset::H2);
}

fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean::Trait) {
Expand Down
6 changes: 6 additions & 0 deletions src/librustdoc/html/static/css/noscript.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ nav.sub {
.source .sidebar {
display: none;
}

.notable-traits {
/* layout requires javascript
https://github.com/rust-lang/rust/issues/102576 */
display: none;
}
23 changes: 14 additions & 9 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ h4.code-header {
font-weight: 600;
margin: 0;
padding: 0;
/* position notable traits in mobile mode within the header */
position: relative;
}

#crate-search,
Expand Down Expand Up @@ -1268,13 +1270,12 @@ h3.variant {
cursor: pointer;
}

.notable-traits:hover .notable-traits-tooltiptext,
.notable-traits .notable-traits-tooltiptext.force-tooltip {
.notable-traits .notable-traits-tooltiptext {
display: inline-block;
visibility: hidden;
}

.notable-traits .notable-traits-tooltiptext {
display: none;
.notable-traits-tooltiptext {
padding: 5px 3px 3px 3px;
border-radius: 6px;
margin-left: 5px;
Expand All @@ -1292,22 +1293,26 @@ h3.variant {
content: "\00a0\00a0\00a0";
}

.notable-traits .docblock {
.notable-traits-tooltiptext .docblock {
margin: 0;
}

.notable-traits .notable {
margin: 0;
margin-bottom: 13px;
.notable-traits-tooltiptext .notable {
font-size: 1.1875rem;
font-weight: 600;
display: block;
}

.notable-traits .docblock code.content {
.notable-traits-tooltiptext pre, .notable-traits-tooltiptext code {
background: transparent;
}

.notable-traits-tooltiptext .docblock pre.content {
margin: 0;
padding: 0;
font-size: 1.25rem;
white-space: pre-wrap;
overflow: hidden;
}

.search-failed {
Expand Down
Loading