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

Tweak suggestion for this -> self #75509

Merged
merged 3 commits into from
Aug 15, 2020

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Aug 14, 2020

  • When referring to this in associated fns always suggest self.
  • Point at ident for fn lacking self
  • Suggest adding self to assoc fns when appropriate

Improvements based on the narrative in https://fasterthanli.me/articles/i-am-a-java-csharp-c-or-cplusplus-dev-time-to-do-some-rust

@rust-highfive
Copy link
Collaborator

r? @lcnr

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 14, 2020
@estebank estebank force-pushed the coming-merrily-from-java-land branch from 409e4f7 to 360388b Compare August 14, 2020 01:01
self.r
.session
.source_map()
.span_through_char(*fn_span, '(')
Copy link
Contributor

@lcnr lcnr Aug 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be incorrect for fn test<const N: [u8; 3 / (7 + 2)]>(). Not sure how easy this is to fix but it seems like getting an empty span after the opening paren of the argument list might be something we can put into a method after getting it right once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct. This is not the only place where that problem exists though, and wanted to keep this PR small by not threading a Span from the AST all the way to resolve for this corner case. It seems to me that the cases where the suggestion is needed are unlikely to be using const generics, but even then they are not yet stable :)

I'll follow up in a bigger PR to refactor all the Span wrangling cases at a later date, including this one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that the cases where the suggestion is needed are unlikely to be using const generics, but even then they are not yet stable :)

This won't even be a problem with min_const_generics because arrays won't be allowed as const params at the start, so this isn't really a pressing issue, though it is something I should keep in mind before trying to stabilize it 😅

};
err.span_suggestion_verbose(
span,
"you are also missing a `self` receiver argument",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is a slightly too strong suggestion as there are often cases where I instead have to rename self.

Maybe "you might be missing a self receiver argument"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion is predicated on the previous one also being "correct". I can change the wording to something like "if you meant to use self, then you are also...".

help: you are also missing a `self` receiver argument
|
LL | fn a(&self) -> A {
| ^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is a slightly too strong suggestion as there are often cases where I instead have to rename self.

^

@lcnr
Copy link
Contributor

lcnr commented Aug 14, 2020

looks good to me

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 14, 2020

📌 Commit 4ecdec1 has been approved by lcnr

@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 14, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 14, 2020
Rollup of 17 pull requests

Successful merges:

 - rust-lang#73943 (Document the unsafe keyword)
 - rust-lang#74062 (deny(unsafe_op_in_unsafe_fn) in libstd/ffi/c_str.rs)
 - rust-lang#74185 (Remove liballoc unneeded explicit link)
 - rust-lang#74192 (Improve documentation on process::Child.std* fields)
 - rust-lang#74409 (Change Debug impl of SocketAddr and IpAddr to match their Display output)
 - rust-lang#75195 (BTreeMap: purge innocent use of into_kv_mut)
 - rust-lang#75214 (Use intra-doc links in `mem::manually_drop` & `mem::maybe_uninit`)
 - rust-lang#75432 (Switch to intra-doc links in `std::process`)
 - rust-lang#75482 (Clean up E0752 explanation)
 - rust-lang#75501 (Move to intra doc links in std::ffi)
 - rust-lang#75509 (Tweak suggestion for `this` -> `self`)
 - rust-lang#75511 (Do not emit E0228 when it is implied by E0106)
 - rust-lang#75515 (Bump std's libc version to 0.2.74)
 - rust-lang#75517 (Promotion and const interning comments)
 - rust-lang#75519 (BTreeMap: refactor splitpoint and move testing over to unit test)
 - rust-lang#75530 (Switch to intra-doc links in os/raw/*.md)
 - rust-lang#75531 (Migrate unit tests of btree collections to their native breeding ground)

Failed merges:

r? @ghost
@bors bors merged commit 2fb2af4 into rust-lang:master Aug 15, 2020
@estebank estebank deleted the coming-merrily-from-java-land branch November 9, 2023 05:16
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants