Skip to content

Cannot use visibility modified in associated item declared inside const argument. #89342

Closed
@rodrimati1992

Description

@rodrimati1992

I tried this code:

struct Foo;

impl Default for Foo 
where
    [(); {
        impl Foo {
            pub const X: Self = Self;
        }
        0
    }]:
{
    fn default() -> Self {
        Self::X
    }
}

I expected the code to compile

Instead, the compiler errored with this message:

error[E0449]: unnecessary visibility qualifier
 --> src/main.rs:7:13
  |
7 |             pub const X: Self = Self;
  |             ^^^ `pub` not permitted here because it's implied

Meta

rustc --version --verbose:

rustc 1.57.0-nightly (98c861950 2021-09-27)
binary: rustc
commit-hash: 98c8619502093f34ca82f8f26ccf32e753924440
commit-date: 2021-09-27
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Assignees

Labels

A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.T-compilerRelevant to the compiler 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