Closed
Description
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.