Skip to content

Suggest using dotdot for ignoring pat fields #137623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

TaKO8Ki
Copy link
Member

@TaKO8Ki TaKO8Ki commented Feb 25, 2025

Fixes a part of #135903

The following case where multiple fields are ignored, as shown below, has been excluded from this implementation. In such cases, all underscores should be replaced with ... However, in the current implementation of the ItemIsPrivate error, errors for different fields are output as completely separate errors. To fix this, a somewhat substantial change to the TypePrivacyVisitor is necessary.

Also, a similar suggestion for struct patterns has not been implemented in this pull request.

match v {
    foo::Foo::A(_, _) => {}
}

@rustbot
Copy link
Collaborator

rustbot commented Feb 25, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2025
@compiler-errors
Copy link
Member

I think this PR is way too specific for a single error case, since this only works for singular wildcard patterns for tuple structs. I don't think this is worth the implementation complexity unless it can be generalized.

@petrochenkov
Copy link
Contributor

petrochenkov commented Mar 13, 2025

Hmm, why does the test example even compiles with ..?
We shouldn't suggest it, it should produce a type privacy error because foo::Foo::A has a private type (due to the private Bar in the signature).
Let me check.

@petrochenkov
Copy link
Contributor

foo::Foo::A has a private type

Compare:

mod foo {
    struct Bar;
    pub enum Foo {
        #[allow(private_interfaces)]
        A(Bar),
    }
}

fn main() {
    let _ = foo::Foo::A; // error: type `Bar` is private
}

@petrochenkov
Copy link
Contributor

I've submitted a fix for the privacy hole in #138458, but even if we are not able to land it due to regressions, using it is probably not something that we should recommend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants