Rollup merge of #90508 - nbdd0121:issue-90483, r=davidtwco

Apply adjustments for field expression even if inaccessible

The adjustments are used later by ExprUseVisitor to build Place projections and without adjustments it can produce invalid result.

Fix #90483

``@rustbot`` label: T-compiler
This commit is contained in:
Matthias Krüger 2021-11-06 23:12:03 +01:00 committed by GitHub
commit 4c49db35fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 3 deletions

View file

@ -0,0 +1,14 @@
// edition:2021
mod m {
pub struct S { foo: i32 }
impl S {
pub fn foo(&self) -> i32 { 42 }
}
}
fn bar(s: &m::S) {
|| s.foo() + s.foo; //~ ERROR E0616
}
fn main() {}

View file

@ -0,0 +1,14 @@
error[E0616]: field `foo` of struct `S` is private
--> $DIR/issue-90483-inaccessible-field-adjustment.rs:11:18
|
LL | || s.foo() + s.foo;
| ^^^ private field
|
help: a method `foo` also exists, call it with parentheses
|
LL | || s.foo() + s.foo();
| ++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0616`.