Skip to content

Visibility of inherent associated types is not checked on access #104243

Closed
@fmease

Description

@fmease

In the following code, I can successfully refer to the private inherent associated type m::T::P:

#![feature(inherent_associated_types)]
#![allow(dead_code, incomplete_features)]

mod m {
    pub struct T;
    impl T {
        type P = ();
    }
}
type U = m::T::P;

I expected to see an error denying the access.

If the associated item was a constant, this would indeed be the case:

error[E0624]: associated constant `P` is private
  --> src/lib.rs:10:21
   |
7  |         const P: () = ();
   |         ----------- private associated constant defined here
...
10 | const U: () = m::T::P;
   |                     ^ private associated constant

Meta

rustc --version --verbose:

rustc 1.67.0-nightly (85f4f41de 2022-11-08)
binary: rustc
commit-hash: 85f4f41deb1557ca8ab228319d33003dd2f20f45
commit-date: 2022-11-08
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

@rustbot label T-compiler requires-nightly A-associated-items A-visibility F-inherent_associated_types

Metadata

Metadata

Assignees

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.F-inherent_associated_types`#![feature(inherent_associated_types)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions