Skip to content

Incorrect private field diagnostic when self is passed #81447

@jam1garner

Description

@jam1garner

I tried this code (playground link):

mod some_module {
    pub struct Test<T: ?Sized>(T);
}

use some_module::Test;

struct TestBuilder;

impl TestBuilder {
    fn build(self) -> Test {
        Test(self)
    }
}

I expected to receive the "cannot initialize a tuple struct which contains private fields" lint.

Instead, this happened:

error[E0423]: expected function, tuple struct or tuple variant, found struct `Test`
  --> src/lib.rs:11:9
   |
11 |         Test(self)
   |         ^^^^------
   |         |
   |         help: try calling `Test` as a method: `self.Test()`

it appears the "method on self" lint takes priority over the "private field initialization" lint when it likely shouldn't, at least in this scenario.

Meta

rustc --version --verbose:

rustc 1.50.0-nightly (d9a105fdd 2020-11-23)
binary: rustc
commit-hash: d9a105fdd46c926ae606777a46dd90e5b838f92f
commit-date: 2020-11-23
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

(also happens on stable, see the playground link provided)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions