diff options
| author | Kevin Reid <kpreid@switchb.org> | 2023-08-29 13:41:33 -0700 |
|---|---|---|
| committer | Kevin Reid <kpreid@switchb.org> | 2023-08-29 14:47:28 -0700 |
| commit | 7b837e075a335d482c583b574ebaf5006738655e (patch) | |
| tree | 20de6e8c87f8666649e848f70340ab6db8fa5e7b /tests/ui/error-codes | |
| parent | bb90f810703af79f6d4006d455bbb6782838854b (diff) | |
| download | rust-7b837e075a335d482c583b574ebaf5006738655e.tar.gz rust-7b837e075a335d482c583b574ebaf5006738655e.zip | |
Don't suggest adding parentheses to call an inaccessible method.
Previously, the test code would emit E0615, thus revealing the existence of private methods that the programmer probably does not care about. Now it ignores their existence instead, producing error E0609 (no field). The motivating example is: ```rust let x = std::rc::Rc::new(()); x.inner; ``` which would previously mention the private method `Rc::inner()`, even though `Rc<T>` intentionally has no public methods so that it can be a transparent smart pointer for any `T`.
Diffstat (limited to 'tests/ui/error-codes')
| -rw-r--r-- | tests/ui/error-codes/E0609-private-method.rs | 16 | ||||
| -rw-r--r-- | tests/ui/error-codes/E0609-private-method.stderr | 9 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/ui/error-codes/E0609-private-method.rs b/tests/ui/error-codes/E0609-private-method.rs new file mode 100644 index 00000000000..dfa97ad9a6f --- /dev/null +++ b/tests/ui/error-codes/E0609-private-method.rs @@ -0,0 +1,16 @@ +// This error is an E0609 and *not* an E0615 because the fact that the method exists is not +// relevant. +mod foo { + pub struct Foo { + x: u32, + } + + impl Foo { + fn method(&self) {} + } +} + +fn main() { + let f = foo::Foo { x: 0 }; + f.method; //~ ERROR E0609 +} diff --git a/tests/ui/error-codes/E0609-private-method.stderr b/tests/ui/error-codes/E0609-private-method.stderr new file mode 100644 index 00000000000..d2a11e90627 --- /dev/null +++ b/tests/ui/error-codes/E0609-private-method.stderr @@ -0,0 +1,9 @@ +error[E0609]: no field `method` on type `Foo` + --> $DIR/E0609-private-method.rs:15:7 + | +LL | f.method; + | ^^^^^^ unknown field + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0609`. |
