Skip to content

Diagnostic regression (1.47 -> 1.48): public enum fields incorrectly described as "inaccessible fields". #79593

Closed

Description

Test example (try on playground):

mod foo {
    pub struct Pub { private: () }

    pub enum Enum {
        Variant { x: (), y: () },
        Other
    }
    
    fn correct() {
        Pub {};
        Enum::Variant { x: () };
    }
}

fn correct() {
    foo::Pub {};
}

fn wrong() {
    foo::Enum::Variant { x: () };
}

Only foo::Pub {} in the top level correct should say "cannot construct ... due to inaccessible fields", the other 3 errors should be "missing field ... in initializer", but it seems like it's treating the enum field as private (even though it inherits pub from the enum).

The "cannot construct ... due to inaccessible fields" error seems to be new in 1.48, as part of #76524, and unmodified since.

It's using field.vis.is_accessible_from(...) which seems correct, but it's possible enum fields are incapable of giving the right result, if they don't track the enum's own privacy (and they only know they inherit it, whatever it is).

cc @davidtwco @estebank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions