diff options
| author | Michael Goulet <michael@errs.io> | 2023-01-08 19:57:55 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-08 19:57:55 -0800 |
| commit | 29420a8e7ab5d5aeeacdd8103eed7c8c19be7001 (patch) | |
| tree | 576f5152401f8c1bce7563b8a1dd691664651cc1 /src/test/ui | |
| parent | 70f1566b2bbdf92dffb40fa122986a58b2c4ee86 (diff) | |
| parent | 59aa421f3518b28bba5ebc883714638e65b0a3c5 (diff) | |
| download | rust-29420a8e7ab5d5aeeacdd8103eed7c8c19be7001.tar.gz rust-29420a8e7ab5d5aeeacdd8103eed7c8c19be7001.zip | |
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 (https://github.com/rust-lang/rust/issues/57320#issuecomment-451308420), 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``
Diffstat (limited to 'src/test/ui')
| -rw-r--r-- | src/test/ui/issues/issue-25386.rs | 1 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-25386.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/privacy/private-field-ty-err.rs | 20 | ||||
| -rw-r--r-- | src/test/ui/privacy/private-field-ty-err.stderr | 14 |
4 files changed, 35 insertions, 8 deletions
diff --git a/src/test/ui/issues/issue-25386.rs b/src/test/ui/issues/issue-25386.rs index a76d8a615f6..b26cc77680d 100644 --- a/src/test/ui/issues/issue-25386.rs +++ b/src/test/ui/issues/issue-25386.rs @@ -24,5 +24,4 @@ macro_rules! check_ptr_exist { fn main() { let item = stuff::Item::new(); println!("{}", check_ptr_exist!(item, name)); - //~^ ERROR field `name` of struct `CObj` is private } diff --git a/src/test/ui/issues/issue-25386.stderr b/src/test/ui/issues/issue-25386.stderr index bce269393ee..727b9690829 100644 --- a/src/test/ui/issues/issue-25386.stderr +++ b/src/test/ui/issues/issue-25386.stderr @@ -9,12 +9,6 @@ LL | println!("{}", check_ptr_exist!(item, name)); | = note: this error originates in the macro `check_ptr_exist` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0616]: field `name` of struct `CObj` is private - --> $DIR/issue-25386.rs:26:43 - | -LL | println!("{}", check_ptr_exist!(item, name)); - | ^^^^ private field - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0616`. diff --git a/src/test/ui/privacy/private-field-ty-err.rs b/src/test/ui/privacy/private-field-ty-err.rs new file mode 100644 index 00000000000..10db6069567 --- /dev/null +++ b/src/test/ui/privacy/private-field-ty-err.rs @@ -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 + } + } +} diff --git a/src/test/ui/privacy/private-field-ty-err.stderr b/src/test/ui/privacy/private-field-ty-err.stderr new file mode 100644 index 00000000000..e583a25fd8f --- /dev/null +++ b/src/test/ui/privacy/private-field-ty-err.stderr @@ -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`. |
