Skip to content
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

Don't suggest adding parentheses to call an inaccessible method. #115363

Merged
merged 2 commits into from Aug 30, 2023

Conversation

kpreid
Copy link
Contributor

@kpreid kpreid commented Aug 29, 2023

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:

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.

error[E0615]: attempted to take value of method `inner` on type `Rc<()>`
 --> src/main.rs:3:3
  |
3 | x.inner;
  |   ^^^^^ method, not a field
  |
help: use parentheses to call the method
  |
3 | x.inner();
  |        ++

With this change, it emits E0609 and no suggestion.

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`.
@rustbot
Copy link
Collaborator

rustbot commented Aug 29, 2023

r? @TaKO8Ki

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 29, 2023
@@ -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
Copy link
Member

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 .awaiting 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() {}

Copy link
Contributor Author

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.)

Copy link
Member

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? 😅

Copy link
Contributor Author

@kpreid kpreid Aug 30, 2023

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.

@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 30, 2023

📌 Commit 4e9a2a6 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 30, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 30, 2023
…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
@bors bors merged commit ea23478 into rust-lang:master Aug 30, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Aug 30, 2023
@kpreid kpreid deleted the suggest-private branch August 30, 2023 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants