-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Don't suggest adding parentheses to call an inaccessible method. #115363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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`.
r? @TaKO8Ki (rustbot has picked a reviewer for you, use r? to override) |
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just remove this argument? The only other true
is to suggest .await
ing on a missing method, but that one also provides sketchy suggestion if the method is private:
mod private {
pub struct Foo;
pub async fn foo() -> Foo { Foo }
impl Foo {
fn private(&self) {}
}
}
async fn test() {
private::foo().private();
}
fn main() {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Done. (I didn't add another test.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I didn't add another test.)
Why not? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I am intimidated by determining the correct location in tests/ui/
to put it.
@bors r+ rollup |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#113565 (Make SIGSEGV handler emit nicer backtraces) - rust-lang#114704 (parser: not insert dummy field in struct) - rust-lang#115272 (miri/diagnostics: don't forget to print_backtrace when ICEing on unexpected errors) - rust-lang#115313 (Make `get_return_block()` return `Some` only for HIR nodes in body) - rust-lang#115347 (suggest removing `impl` in generic trait bound position) - rust-lang#115355 (new solver: handle edge case of a recursion limit of 0) - rust-lang#115363 (Don't suggest adding parentheses to call an inaccessible method.) r? `@ghost` `@rustbot` modify labels: rollup
Previously, code of this form would emit E0615 (attempt to use a method as a field), thus emphasizing 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:
which would previously mention the private method
Rc::inner()
, even thoughRc<T>
intentionally has no public methods so that it can be a transparent smart pointer for anyT
.With this change, it emits E0609 and no suggestion.