Commit graph

268 commits

Author SHA1 Message Date
unvalley
a310fc0cd5 docs: update assist comment 2023-01-09 12:23:06 +01:00
unvalley
872df2f413 chore: update assist label name 2023-01-09 12:22:29 +01:00
unvalley
285f09cfa8 feat: extract only expressions from format string 2023-01-09 12:22:29 +01:00
unvalley
796a106412 fix: ide assist handlers order 2023-01-09 12:22:25 +01:00
unvalley
9290399ec4 fix: rename to extract_expressions_from_format_string 2023-01-09 12:21:37 +01:00
bors
f77b68a3cb Auto merge of #13860 - danieleades:clippy, r=lnicola
fix a bunch of clippy lints

fixes a bunch of clippy lints for fun and profit

i'm aware of this repo's position on clippy. The changes are split into separate commits so they can be reviewed separately
2023-01-08 17:29:57 +00:00
Lukas Wirth
b996a54cd8 Skip lifetime elision on fn pointers and fn trait types 2023-01-03 11:58:31 +01:00
Daniel Eades
0a0817905e return value directly from if/else block 2023-01-02 15:02:54 +00:00
Daniel Eades
efd2c20e96 remove useless conversions 2023-01-02 15:02:54 +00:00
Daniel Eades
cc80c5bd07 remove unnecessary lazy evaluations 2023-01-02 15:02:54 +00:00
Daniel Eades
7530d76f00 use pointer args 2023-01-02 14:52:32 +00:00
Daniel Eades
ed128872eb remove needless borrows 2023-01-02 14:52:32 +00:00
Daniel Eades
77051679d7 use inline format args 2023-01-02 14:52:32 +00:00
Ryo Yoshida
332dd6ad6e
fix: merge multiple intersecting ranges 2022-12-31 22:08:53 +09:00
Yuri Astrakhan
e16c76e3c3 Inline all format arguments where possible
This makes code more readale and concise,
moving all format arguments like `format!("{}", foo)`
into the more compact `format!("{foo}")` form.

The change was automatically created with, so there are far less change
of an accidental typo.

```
cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2022-12-24 14:36:10 -05:00
Yuri Astrakhan
e341e996f7 Clippy-fix explicit auto-deref
Seems like these can be safely fixed. With one, I was particularly
surprised -- `Some(pats) => &**pats,` in body.rs?

```
cargo clippy --fix -- -A clippy::all -D clippy::explicit_auto_deref
```
2022-12-23 02:52:14 -05:00
Yuri Astrakhan
1d59c7b667 Remove non-needed clones
I am not certain if this will improve performance,
but it seems having a .clone() without any need should be removed.

This was done with clippy, and manually reviewed:

```
cargo clippy --fix -- -A clippy::all -D clippy::redundant_clone
```
2022-12-23 02:20:03 -05:00
Maybe Waffle
7ed0871ff6 Fix "needs parens" check in remove_parentheses assist 2022-12-13 00:06:00 +00:00
bors
4596847a88 Auto merge of #13746 - feniljain:fix_extract_function, r=jonas-schievink
fix: make make_body respect comments in extract_function

Possible fix for #13621

### Points to help in review:

- Earlier we were only considering statements in a block expr and hence comments were being ignored, now we handle tokens hence making it aware of comments and then preserving them using `hacky_block_expr_with_comments`

Seems like I am not able to attach output video, github is glitching for it :(
2022-12-12 14:51:03 +00:00
bors
e7dff7491a Auto merge of #13726 - feniljain:fix_assists, r=jonas-schievink
feat: allow unwrap block in let initializers

Possible fix for #13679

### Points to help in review:

- I just added a parent case for let statements and it seems everything else was in place already, so turned out to be a small fix
2022-12-12 14:06:45 +00:00
bors
3a7215b92e Auto merge of #13732 - rami3l:fix/gen-partial-eq, r=jonas-schievink
fix: add fallback case in generated `PartialEq` impl

Partially fixes #13727.

When generating `PartialEq` implementations for enums, the original code can already generate the following fallback case:

```rs
_ => std::mem::discriminant(self) == std::mem::discriminant(other),
```

However, it has been suppressed in the following example for no good reason:

```rs
enum Either<T, U> {
    Left(T),
    Right(U),
}

impl<T, U> PartialEq for Either<T, U> {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (Self::Left(l0), Self::Left(r0)) => l0 == r0,
            (Self::Right(l0), Self::Right(r0)) => l0 == r0,
            // _ => std::mem::discriminant(self) == std::mem::discriminant(other),
            // ^ this completes the match arms!
        }
    }
}
```

This PR has removed that suppression logic.

~~Of course, the PR could have suppressed the fallback case generation for single-variant enums instead, but I believe that this case is quite rare and should be caught by `#[warn(unreachable_patterns)]` anyway.~~

After this fix, when the enum has >1 variants, the following fallback arm will be generated :

* `_ => false,` if we've already gone through every case where the variants of `self` and `other` match;
* The original one (as stated above) in other cases.

---

Note: The code example is still wrong after the fix due to incorrect trait bounds.
2022-12-12 13:52:49 +00:00
feniljain
d7183fb5d0 fix: make make_body respect comments in extract_function 2022-12-09 18:30:30 +05:30
Maybe Waffle
ba6f0befc8 Simplify remove_parentheses's implementation 2022-12-08 18:54:08 +00:00
Maybe Waffle
8d42439a7d Move precedence handling to crates/syntax 2022-12-08 18:46:30 +00:00
Maybe Waffle
2870b01ec0 Explicitly say that the assist removes *redundant* parentheses 2022-12-08 18:22:57 +00:00
rami3l
57fb18e3bd fix: refine fallback case in generated PartialEq impl 2022-12-07 10:25:17 +08:00
Maybe Waffle
ab061945a1 Consider expression precedense in remove_parentheses assist 2022-12-06 19:11:24 +00:00
Maybe Waffle
5f79279b48 Add remove_parentheses assist 2022-12-06 16:18:25 +00:00
rami3l
fed74c8b71 fix: add fallback case in generated PartialEq impl 2022-12-06 21:54:53 +08:00
feniljain
4794572e36 feat: allow unwrap block in let initializers 2022-12-05 09:00:16 +05:30
Ryo Yoshida
6d4538734e
Add move_const_to_impl assist 2022-12-03 01:22:00 +09:00
Ryo Yoshida
8e03f18e37
fix: check if range contains tail expression 2022-11-27 00:31:02 +09:00
Ryo Yoshida
822c61f559
refactor: remove unnecessary stuff 2022-11-27 00:01:16 +09:00
bors
e668eca632 Auto merge of #13647 - nyz93:fix/tuple-to-named-struct, r=Veykril
fix: tuple to named struct inside macros

seems to fix #13634
2022-11-25 09:41:21 +00:00
bors
5e3ad5ddf6 Auto merge of #13592 - MihailMihov:trait_impl_assist, r=Veykril
Add assist to generate trait impl's

resolves #13553

This pull request adds a `generate_trait_impl` assist, which generates trait impl's for a type. It is almost the same as the one to generate impl's and I also reduced the trigger range to only outside the `RecordFieldList`. Also moved all the tests into separate test functions. A few of the old tests seemed redundant, so I didn't port them.
2022-11-24 20:44:33 +00:00
bors
63a676eedf Auto merge of #13576 - Bben01:supress_missing_impl_inside_block, r=jonas-schievink
Suppress "Implement default members" inside contained items

Fixes #13561
2022-11-24 15:16:36 +00:00
Mihail Mihov
469f620b06 Combine generate_impl and generate_trait_impl into a single file 2022-11-21 22:58:43 +02:00
Mihail Mihov
0bd11f8171 Reduce trigger range of generate_impl assist and update tests 2022-11-21 22:27:26 +02:00
Mihail Mihov
ecb15ca717 Add assist to generate trait impl's 2022-11-21 22:27:26 +02:00
Bben01
95b4a7487b Suppress "Implement default members" inside contained items 2022-11-21 22:17:04 +02:00
Nyikos Zoltán
23cfe0702d fix: tuple to named struct inside macros
seems to fix #13634
2022-11-19 20:08:01 +01:00
bors
2d9ed4fd48 Auto merge of #13641 - DesmondWillowbrook:fix-move-format-string, r=Veykril
fix: format expression parsing edge-cases

- Handle positional arguments with formatting options (i.e. `{:b}`). Previously copied `:b` as an argument, producing broken code.

- Handle indexed positional arguments (`{0}`) ([reference](https://doc.rust-lang.org/std/fmt/#positional-parameters)). Previously copied over `0` as an argument.

Note: the assist also breaks when named arguments are used (`"{name}$0", name = 2 + 2` is converted to `"{}"$0, name`. I'm working on fix for that as well.
2022-11-19 12:46:29 +00:00
bvanjoi
a4f071afd5 fix(assists): remove item_const which had default value when implement missing members` 2022-11-19 19:38:53 +08:00
Kartavya Vashishtha
a3f8fd71df
fix: format expression parsing edge-cases
handle positional arg with formatting

handle indexed positional args
2022-11-19 15:00:25 +05:30
Jonas Schievink
cd6459e7b3 Make "Remove dbg!()" assist work on selections 2022-11-17 17:39:31 +01:00
Ryo Yoshida
19306c070d
Fix tests that depended on loose visibility restriction 2022-11-11 20:31:46 +09:00
Ryo Yoshida
e75afebeb2
Resolve invisible defs in fix_visibility assist 2022-11-11 20:31:44 +09:00
Lukas Wirth
ffd7bf8bf9 Bump Cargo rust-version fields to latest stable 2022-11-07 12:59:51 +01:00
bors
d3d3806565 Auto merge of #12991 - TiddoLangerak:extract-method-from-trait-into-impl-root, r=Veykril
Feat: extracted method from trait impl is placed in existing impl

**Before**

https://user-images.githubusercontent.com/1759192/183872883-3b0eafd2-d1dc-440e-9e66-38e3372f8b64.mp4

**After**

https://user-images.githubusercontent.com/1759192/183875769-87f34c7d-52f0-4dfc-9766-f591ee738ebb.mp4

Previously, when triggering a method extraction from within an impl trait block, then this would always create a new impl block for
the struct, even if there already is one. Now, if there is already an existing trait-less impl block, then it'll put the extracted method in there.

**Caveats**:
- It currently requires the target impl block to be non-empty. This limitation is because the current architecture takes a `node_to_insert_after` as reference for where to insert the extracted function. An empty impl block doesn't have such a reference node, since it's empty. It seems that supporting this requires a much larger and more complex change.
- This is my first contribution in rust, so apologies for any beginner mistakes.
2022-11-07 11:07:12 +00:00
Lukas Wirth
f24fbc2027 rustfmt 2022-11-07 11:58:57 +01:00