Skip to content

effective visibilities: Count types leaked through trivial type aliases as reexported #120146

Open
@petrochenkov

Description

@petrochenkov
mod m {
    pub struct A {}
    pub struct B {}
}

pub use m::A as U;
pub type V = m::B;

In the example above struct A will be marked as reexported, but struct B will only be marked as reachable.
(This can be tested with #[rustc_effective_visibility] attribute.)

It may make sense to consider B reexported too, because there's not much difference between a use item and a trivial type alias.
This will remove some part of false positives from the unnameable_types lint in particular, because B is clearly nameable here.

The "promotion" to reexported should only happen when the alias is trivial - no generic parameters/where-clauses/bounds/etc, the RHS should also be a module-relative path without any generic arguments, including implicit ones.

There may be some unexpected consequences from doing this change.
For example, some import inlining code in rustdoc may assume that if B is reexported, then a reexport chain leading to B exists.
(Need to implement the change and see what breaks.)

This is a follow up to #48054.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-visibilityArea: Visibility / privacyC-enhancementCategory: An issue proposing an enhancement or a PR with one.L-unnameable_typesLint: unnameable_typesT-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