Skip to content
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

rustdoc: "Methods from Deref" appears inconsistently #91400

Closed
jyn514 opened this issue Nov 30, 2021 · 4 comments
Closed

rustdoc: "Methods from Deref" appears inconsistently #91400

jyn514 opened this issue Nov 30, 2021 · 4 comments
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Nov 30, 2021

I tried this code:

pub struct Bar(Baz);
impl std::ops::Deref for Bar {
    type Target = Baz;
    fn deref(&self) -> &Baz { &self.0 }
}

pub struct Baz {}
impl Baz {
    /// [prim@str]
    pub fn foo() {}
}

I expected to see this happen: Rustdoc generates a "Methods from Deref" section, the way it does if the struct derefs to Path:
image

Instead, this happened: Rustdoc doesn't generate the section:
image

Meta

rustdoc --version: rustdoc 1.58.0-nightly (936f260 2021-11-22)

cc @GuillaumeGomez

@jyn514 jyn514 added C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 30, 2021
@jyn514
Copy link
Member Author

jyn514 commented Nov 30, 2021

I thought originally this was related to Baz being in the current crate, but I moved it to an inner crate and that still didn't generate the right section.

@jyn514
Copy link
Member Author

jyn514 commented Nov 30, 2021

Relevant code:

fn render_assoc_items_inner(
w: &mut Buffer,
cx: &Context<'_>,
containing_item: &clean::Item,
it: DefId,
what: AssocItemRender<'_>,
derefs: &mut FxHashSet<DefId>,
) {
info!("Documenting associated items of {:?}", containing_item.name);
let cache = cx.cache();
let v = match cache.impls.get(&it) {
Some(v) => v,
None => return,
};
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
if !non_trait.is_empty() {
let mut tmp_buf = Buffer::empty_from(w);
let render_mode = match what {
AssocItemRender::All => {
tmp_buf.write_str(
"<h2 id=\"implementations\" class=\"small-section-header\">\
Implementations<a href=\"#implementations\" class=\"anchor\"></a>\
</h2>",
);
RenderMode::Normal
}
AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {
let id =
cx.derive_id(small_url_encode(format!("deref-methods-{:#}", type_.print(cx))));
if let Some(def_id) = type_.def_id(cx.cache()) {
cx.deref_id_map.borrow_mut().insert(def_id, id.clone());
}
write!(
tmp_buf,
"<h2 id=\"{id}\" class=\"small-section-header\">\
<span>Methods from {trait_}&lt;Target = {type_}&gt;</span>\
<a href=\"#{id}\" class=\"anchor\"></a>\
</h2>",
id = id,
trait_ = trait_.print(cx),
type_ = type_.print(cx),
);

@GuillaumeGomez
Copy link
Member

This is surprising. I'll take a look tomorrow.

@inquisitivecrystal inquisitivecrystal added the A-trait-system Area: Trait system label Dec 1, 2021
@GuillaumeGomez
Copy link
Member

This is the expected behaviour because they are not methods (they don't have a self argument). We call the function to check it here and the function itself is here.

This behaviour is tested in this test. Since this is the expected result, I'll close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants