7617: Add getter/setter assists r=Veykril a=yoshuawuyts
This patch makes progress towards the design outlined in https://github.com/rust-analyzer/rust-analyzer/issues/5943, and includes a small refactor which closes https://github.com/rust-analyzer/rust-analyzer/issues/7607. All together this patch does 4 things:
- Adds a `generate_getter` assist.
- Adds a `generate_getter_mut` assist.
- Adds a `generate_setter` assist.
- Moves the `generate_impl_text` function from `generate_new` into `utils` (which closes#7607).
## Design Notes
I've chosen to follow the [Rust API guidelines on getters](https://rust-lang.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getter) as closely as possible. This deliberately leaves "builder pattern"-style setters out of scope.
Also, similar to https://github.com/rust-analyzer/rust-analyzer/pull/7570 this assist generates doc comments. I think this should work well in most cases, and for the few where it doesn't it's probably easily edited. This makes it slightly less correct than the #7570 implementation, but I think this is still useful enough to include for many of the same reasons.
The reason why this PR contains 3 assists, rather than 1, is because each of them is so similar to the others that it felt more noisy to do them separately than all at once. The amount of code added does not necessarily reflect that, but hope that still makes sense.
## Examples
**Input**
```rust
struct Person {
name: String, // <- cursor on "name"
}
```
**generate getter**
```rust
struct Person {
name: String,
}
impl Person {
/// Get a reference to the person's name.
fn name(&self) -> &String {
&self.name
}
}
```
**generate mut getter**
```rust
struct Person {
name: String,
}
impl Person {
/// Get a mutable reference to the person's name.
fn name_mut(&mut self) -> &mut String {
&mut self.name
}
}
```
**generate setter**
```rust
struct Person {
name: String,
}
impl Person {
/// Set the person's name.
fn set_name(&mut self, name: String) {
self.name = name;
}
}
```
Co-authored-by: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
7619: Add #[track_caller] to assist tests r=matklad a=yoshuawuyts
This points the source of a failed assertion to the code which called it, rather than the location within the assertion helper method. While working on https://github.com/rust-analyzer/rust-analyzer/pull/7617 I had trouble locating some failing tests, and it was only by adding these attributes during development that I was able to locate them.
This is only applied to test helpers, which means it comes at no runtime cost. And even then: I didn't experience any noticeable performance with this enabled or disabled. Mostly just a more pleasant experience debugging test failures (:
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
7597: Set remote branch on xtask promote r=matklad a=lnicola
to hopefully fix this:
```
$ git switch master
Already on 'master'
Your branch is up to date with 'upstream/master'.
$ git fetch upstream
$ git reset --hard upstream/master
HEAD is now at 921ec4b3fca Auto merge of #81313 - LeSeulArtichaut:revert-32558, r=jyn514
$ git submodule update --recursive
Submodule path 'src/tools/rust-analyzer': checked out '1a59f75cdaa730c16a694a4294eccf6dfe6fe0ad'
$ git switch -c rust-analyzer-2021-02-08
Switched to a new branch 'rust-analyzer-2021-02-08'
$ git fetch origin
$ git reset --hard origin/release
HEAD is now at 336909b63 Merge #7587
$ git add src/tools/rust-analyzer
$ git commit "-m⬆️ rust-analyzer"
[rust-analyzer-2021-02-08 1774ec1a683] ⬆️ rust-analyzer
1 file changed, 1 insertion(+), 1 deletion(-)
$ git push
fatal: The current branch rust-analyzer-2021-02-08 has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin rust-analyzer-2021-02-08
Error: command `git push` failed, exit code: 128
```
Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>