Skip to content
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

Incorrect suggestion of private struct members #92999

Closed
SadiinsoSnowfall opened this issue Jan 17, 2022 · 3 comments · Fixed by #93039
Closed

Incorrect suggestion of private struct members #92999

SadiinsoSnowfall opened this issue Jan 17, 2022 · 3 comments · Fixed by #93039
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@SadiinsoSnowfall
Copy link

SadiinsoSnowfall commented Jan 17, 2022

Lets consider the following code (playground) :

pub struct S {
   pub val: String
}

pub fn test(s: S) {
   dbg!(s.cap)
}

Here, we try to access a property cap on an object of type struct S.
Up to the 1.50 version, the error message was the following :

rror[E0609]: no field `cap` on type `S`
--> <source>:6:12
  |
6 |     dbg!(s.cap)
  |            ^^^ unknown field
  |
 = note: available fields are: `val`

However, since Rust 1.51 and onward, the diagnostic message changed to this:

rror[E0609]: no field `cap` on type `S`
--> <source>:6:12
  |
6 |     dbg!(s.cap)
  |            ^^^ unknown field
  |
 = note: available fields are: `val`
help: one of the expressions' fields has a field of the same name
  |
6 |     dbg!(s.val.vec.buf.cap)
  |            ^^^^^^^^^^^^

While there is indead a cap property on the RawVec struct, this can't be accessed like that, applying the compiler suggestion implies making the buf property of std::vec::Vec public, which is not possible.

The compiler should not look at non-pub properties when searching for properties with a matching name for diagnostic purposes.

@SadiinsoSnowfall SadiinsoSnowfall added the C-bug Category: This is a bug. label Jan 17, 2022
@terrarier2111
Copy link
Contributor

@rustbot claim

@pierwill
Copy link
Member

@rustbot label +A-diagnostics

@rustbot rustbot added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 18, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Jan 22, 2022

Related issue: #93210

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 30, 2022
@bors bors closed this as completed in 71efe90 Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants