-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #106600 - compiler-errors:no-private-field-ty-err, r=…
…estebank Suppress type errors that come from private fields Fixes #57320 There was some discussion here (#57320 (comment)), but I honestly think the second error is worth suppressing regardless. I would be open to feedback though -- perhaps we can suppress the `.len()` suggestion if there's type error (since we have access to [`Expectation`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_typeck/enum.Expectation.html), we can determine that). r? ``@estebank``
- Loading branch information
Showing
5 changed files
with
38 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
fn main() { | ||
let x = foo::Foo::default(); | ||
if x.len { | ||
//~^ ERROR field `len` of struct `Foo` is private | ||
println!("foo"); | ||
} | ||
} | ||
|
||
mod foo { | ||
#[derive(Default)] | ||
pub struct Foo { | ||
len: String, | ||
} | ||
|
||
impl Foo { | ||
pub fn len(&self) -> usize { | ||
42 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0616]: field `len` of struct `Foo` is private | ||
--> $DIR/private-field-ty-err.rs:3:10 | ||
| | ||
LL | if x.len { | ||
| ^^^ private field | ||
| | ||
help: a method `len` also exists, call it with parentheses | ||
| | ||
LL | if x.len() { | ||
| ++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0616`. |