mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
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`.
This commit is contained in:
parent
bb90f81070
commit
7b837e075a
@ -2314,7 +2314,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
field,
|
||||
base_ty,
|
||||
expr.hir_id,
|
||||
true,
|
||||
false, // don't mention or suggest non-accessible methods
|
||||
expected.only_has_type(self),
|
||||
) {
|
||||
self.ban_take_value_of_method(expr, base_ty, field)
|
||||
|
16
tests/ui/error-codes/E0609-private-method.rs
Normal file
16
tests/ui/error-codes/E0609-private-method.rs
Normal file
@ -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
|
||||
}
|
9
tests/ui/error-codes/E0609-private-method.stderr
Normal file
9
tests/ui/error-codes/E0609-private-method.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user