-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustdoc: show trait implementors in sidebar #91277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,8 @@ crate struct Context<'tcx> { | |
pub(super) deref_id_map: RefCell<FxHashMap<DefId, String>>, | ||
/// The map used to ensure all generated 'id=' attributes are unique. | ||
pub(super) id_map: RefCell<IdMap>, | ||
/// Converts the rustc id of an item to the html id so we can link to it | ||
pub(super) item_to_html_id_map: RefCell<FxHashMap<clean::ItemId, String>>, | ||
/// Shared mutable state. | ||
/// | ||
/// Issue for improving the situation: [#82381][] | ||
|
@@ -73,7 +75,7 @@ crate struct Context<'tcx> { | |
|
||
// `Context` is cloned a lot, so we don't want the size to grow unexpectedly. | ||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] | ||
rustc_data_structures::static_assert_size!(Context<'_>, 144); | ||
rustc_data_structures::static_assert_size!(Context<'_>, 184); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This increase seems to be fine, as when cloned, we create a new map, so perf is neutral (#91257) |
||
|
||
/// Shared mutable state used in [`Context`] and elsewhere. | ||
crate struct SharedContext<'tcx> { | ||
|
@@ -517,6 +519,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { | |
render_redirect_pages: false, | ||
id_map: RefCell::new(id_map), | ||
deref_id_map: RefCell::new(FxHashMap::default()), | ||
item_to_html_id_map: RefCell::new(FxHashMap::default()), | ||
shared: Rc::new(scx), | ||
include_sources, | ||
}; | ||
|
@@ -541,6 +544,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { | |
dst: self.dst.clone(), | ||
render_redirect_pages: self.render_redirect_pages, | ||
deref_id_map: RefCell::new(FxHashMap::default()), | ||
item_to_html_id_map: RefCell::new(FxHashMap::default()), | ||
id_map: RefCell::new(IdMap::new()), | ||
shared: Rc::clone(&self.shared), | ||
include_sources: self.include_sources, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,49 @@ | ||||||||||||||||||||||
// issue #56018: "Implementations on Foreign Types" sidebar items should link to specific impls | ||||||||||||||||||||||
|
||||||||||||||||||||||
#![crate_name = "foo"] | ||||||||||||||||||||||
|
||||||||||||||||||||||
// @has foo/trait.Foo.html | ||||||||||||||||||||||
// @has - '//*[@class="sidebar-title"]/a[@href="#foreign-impls"]' 'Implementations on Foreign Types' | ||||||||||||||||||||||
// @has - '//h2[@id="foreign-impls"]' 'Implementations on Foreign Types' | ||||||||||||||||||||||
// @has - '//*[@class="sidebar-links"]/a[@href="#impl-Foo-for-u32"]' 'u32' | ||||||||||||||||||||||
// @has - '//div[@id="impl-Foo-for-u32"]//h3[@class="code-header in-band"]' 'impl Foo for u32' | ||||||||||||||||||||||
// @has - '//*[@class="sidebar-links"]/a[@href="#impl-Foo-for-%26%27a%20str"]' "&'a str" | ||||||||||||||||||||||
// @has - '//div[@id="impl-Foo-for-%26%27a%20str"]//h3[@class="code-header in-band"]' "impl<'a> Foo for &'a str" | ||||||||||||||||||||||
pub trait Foo {} | ||||||||||||||||||||||
|
||||||||||||||||||||||
impl Foo for u32 {} | ||||||||||||||||||||||
|
||||||||||||||||||||||
impl<'a> Foo for &'a str {} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Issue #91118" "Implementors column on trait page is always empty" | ||||||||||||||||||||||
|
||||||||||||||||||||||
pub struct B; | ||||||||||||||||||||||
pub struct A; | ||||||||||||||||||||||
struct C; | ||||||||||||||||||||||
|
||||||||||||||||||||||
// @has foo/trait.Bar.html | ||||||||||||||||||||||
// @has - '//*[@class="sidebar-title"]/a[@href="#implementors"]' 'Implementors' | ||||||||||||||||||||||
// @has - '//h2[@id="implementors"]' 'Implementors' | ||||||||||||||||||||||
// @!has - '//*[@class="sidebar-title"]/a[@href="#foreign-impls"]' | ||||||||||||||||||||||
// @!has - '//h2[@id="foreign-impls"]' | ||||||||||||||||||||||
|
||||||||||||||||||||||
// @has - '//*[@class="sidebar-links"]/a[@href="#impl-Bar"]' '&A' | ||||||||||||||||||||||
// @has - '//*[@class="sidebar-links"]/a[@href="#impl-Bar-1"]' 'A' | ||||||||||||||||||||||
// @has - '//*[@class="sidebar-links"]/a[@href="#impl-Bar-2"]' 'B' | ||||||||||||||||||||||
|
||||||||||||||||||||||
// @has - '//div[@id="impl-Bar"]//h3[@class="code-header in-band"]' 'impl Bar for &A' | ||||||||||||||||||||||
// @has - '//div[@id="impl-Bar-1"]//h3[@class="code-header in-band"]' 'impl Bar for A' | ||||||||||||||||||||||
// @has - '//div[@id="impl-Bar-2"]//h3[@class="code-header in-band"]' 'impl Bar for B' | ||||||||||||||||||||||
pub trait Bar {} | ||||||||||||||||||||||
impl Bar for B {} | ||||||||||||||||||||||
impl Bar for A {} | ||||||||||||||||||||||
impl Bar for &A {} | ||||||||||||||||||||||
impl Bar for C {} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// @has foo/trait.NotImpled.html | ||||||||||||||||||||||
// @!has - '//*[@class="sidebar-title"]/a[@href="#implementors"]' | ||||||||||||||||||||||
// FIXME: Is this the semantics we want | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specificly the page is documented like Because we only write the "Implementations on Foreign Types" header when they are present ( rust/src/librustdoc/html/render/print_item.rs Line 755 in ccce985
rust/src/librustdoc/html/render/print_item.rs Lines 782 to 790 in ccce985
If theirs a reason for this, its fine to keep, otherwize I'll change it to be consistant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because the |
||||||||||||||||||||||
// @has - '//h2[@id="implementors"]' 'Implementors' | ||||||||||||||||||||||
// @!has - '//*[@class="sidebar-title"]/a[@href="#foreign-impls"]' | ||||||||||||||||||||||
// @!has - '//h2[@id="foreign-impls"]' | ||||||||||||||||||||||
pub trait NotImpled {} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function name is not accurate (see #86798). What do you intend for the behavior to be?