Skip to content

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

Open
@nvzqz

Description

@nvzqz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-doc-aliasArea: `#[doc(alias)]`A-trait-systemArea: Trait systemC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions