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

Doc alias not allowed on associated constants and types in trait implementation block #80604

Open
nvzqz opened this issue Jan 1, 2021 · 5 comments
Labels
A-associated-items Area: Associated items such as associated types and consts. A-doc-alias Area: #[doc(alias)] A-traits Area: Trait system C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@nvzqz
Copy link
Contributor

nvzqz commented Jan 1, 2021

I tried this code:

pub trait Trait {
    const VALUE: u32;
}

pub struct Struct;

impl Trait for Struct {
    #[doc(alias = "kValue")]
    const VALUE: u32 = 42;
}

Similarly, I tried:

trait Trait {
    type Value;
}

struct Struct;

impl Trait for Struct {
    #[doc(alias = "ValueType")]
    type Value = u32;
}

I expected to see this happen: the code to compile and searching kValue or ValueType in the docs to produce Struct::VALUE or Struct::Value respectively.

Instead, this happened: These failed to compile with the following errors:

error: #[doc(alias = "...")] isn't allowed on associated constant in trait implementation block

error: #[doc(alias = "...")] isn't allowed on type alias in implementation block

This is very surprising because:

  • #[doc(alias)] works on fn trait members in impl blocks.
  • Doc comments are allowed on associated constants and types in impl blocks.

Meta

rustc --version --verbose:

rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-apple-darwin
release: 1.49.0
@nvzqz nvzqz added the C-bug Category: This is a bug. label Jan 1, 2021
@nvzqz nvzqz changed the title Doc alias not allowed on associated constant in trait implementation block Doc alias not allowed on associated constants and types in trait implementation block Jan 1, 2021
@nvzqz
Copy link
Contributor Author

nvzqz commented Jan 1, 2021

@rustbot modify labels: +A-doc-alias +A-traits +A-associated-items

@rustbot rustbot added A-associated-items Area: Associated items such as associated types and consts. A-doc-alias Area: #[doc(alias)] A-traits Area: Trait system labels Jan 1, 2021
@jyn514 jyn514 added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 2, 2021
@jyn514
Copy link
Member

jyn514 commented Jan 2, 2021

cc @GuillaumeGomez

@jyn514
Copy link
Member

jyn514 commented Jan 2, 2021

actually @ollie27 you said in #73721 (comment) that rustdoc should disallow this on associated constants, because they don't appear in the search index. But they do:
image. So I think prohibiting them was incorrect.

@jyn514
Copy link
Member

jyn514 commented Jan 2, 2021

Oh I see - that's the constant for the trait itself, not for the implementation.

@nvzqz try moving it to type Value; in the trait definition, that should work.

@nvzqz
Copy link
Contributor Author

nvzqz commented Jan 2, 2021

@jyn514 my use case is that I'm wrapping a C library and would like to use the doc alias for the associated constant's original name in the specific type's impl. So it doesn't make sense to have it inside the trait.

Perhaps rustdoc should support including associated constants/types in the search index?

@jyn514 jyn514 added C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed C-bug Category: This is a bug. labels Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items such as associated types and consts. A-doc-alias Area: #[doc(alias)] A-traits Area: Trait system C-feature-request Category: A feature request, i.e: not implemented / a PR. 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

4 participants