Commit Graph

443 Commits

Author SHA1 Message Date
Yoshua Wuyts
13749e782e move code around 2021-08-09 18:27:01 +02:00
Yoshua Wuyts
457eede795 Add gen default for tuple structs 2021-08-09 17:40:50 +02:00
Yoshua Wuyts
423860cd7e Add default body when implementing Default by hand 2021-08-09 17:12:18 +02:00
bors[bot]
5664a2b0b3
Merge #9814
9814: Generate default impl when converting `#[derive(Debug)]` to manual impl r=yoshuawuyts a=yoshuawuyts

This patch makes it so when you convert `#[derive(Debug)]` to a manual impl, a default body is provided that's equivalent to the original output of `#[derive(Debug)]`. This should make it drastically easier to write custom `Debug` impls, especially when all you want to do is quickly omit a single field which is `!Debug`.

This is implemented for enums, record structs, tuple structs, empty structs - and it sets us up to implement variations on this in the future for other traits (like `PartialEq` and `Hash`).

Thanks!

## Codegen diff
This is the difference in codegen for record structs with this patch:
```diff
struct Foo {
    bar: String,
}

impl fmt::Debug for Foo {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        todo!();
+        f.debug_struct("Foo").field("bar", &self.bar).finish()
    }
}
```

Co-authored-by: Irina Shestak <shestak.irina@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
2021-08-08 22:30:37 +00:00
Yoshua Wuyts
59cdb51ef3 Remove unwraps 2021-08-09 00:29:38 +02:00
Yoshua Wuyts
f64aacc0c1 Use minicore 2021-08-08 18:58:42 +02:00
Lukas Wirth
3b7c713af3 Implement if_to_bool_then assist 2021-08-08 17:56:34 +02:00
Yoshua Wuyts
dcbf385ffc use make::name_ref 2021-08-08 16:31:28 +02:00
Yoshua Wuyts
e26ba72333 Update replace_derive_with_manual_impl.rs 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
a2e5fc659d Improve naming and add comments 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
720508a2df dedup struct debug impl code 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
cc3ff1b486 Fix enum debug indent level 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
4b7ae9fedc generate Debug for enums 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
a1f2c7adcd rename variables
According to https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#variable-naming
2021-08-08 16:26:25 +02:00
Yoshua Wuyts
aa09141a8a finish debug_struct impls 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
fd7236c791 debug for record field structs 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
e2ab2e12a0 wip 2021-08-08 16:24:54 +02:00
Irina Shestak
f2e547d587 impl Debug def from trait 2021-08-08 16:24:54 +02:00
Lukas Wirth
c4a119f433 Simplify 2021-08-07 22:16:15 +02:00
Lukas Wirth
b6d574642d extract_type_alias extracts generics correctly 2021-08-05 02:54:06 +02:00
Lukas Wirth
01413dd7d4 extract_function does not move locals defined outside of loops 2021-08-04 20:00:45 +02:00
Lukas Wirth
29c4ae6f9a extract_assist is aware of the expression owner 2021-08-03 20:47:51 +02:00
Lukas Wirth
9edaf0cad8 extract_function is const aware 2021-08-03 18:43:28 +02:00
Lukas Wirth
e62ce6f61a Reorganize functions in extract_function assist 2021-08-03 18:24:33 +02:00
Lukas Wirth
027a99fc70 Do no tear comments apart in extract_function assist 2021-08-03 17:39:49 +02:00
Lukas Wirth
b96f1adf5c Give TypeInfo fields and methods more appropriate names 2021-08-03 17:28:51 +02:00
Lukas Wirth
8afa2722b2 Revise TypeInfo::ty usage 2021-08-03 17:24:43 +02:00
Lukas Wirth
25ff7171c4 Introduce TypeInfo 2021-08-03 16:41:53 +02:00
Lukas Wirth
432bb222c3 Simplify inline_local_variable assist 2021-08-02 15:27:47 +02:00
bors[bot]
93873b0ce1
Merge #9739
9739: generate function assist favors deref cmpt types r=matklad a=mahdi-frms

Fixes #9713

Although that's still not relying on sematic info.

Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
2021-07-31 15:08:29 +00:00
Lukas Wirth
b363755901 Fix hover range for derive inputs 2021-07-31 14:59:31 +02:00
Lukas Wirth
7c7c4543da Replace useless types 2021-07-31 14:29:15 +02:00
Lukas Wirth
778e6e8ba8 add_explicit_type is applicable for closure parameters 2021-07-31 14:04:34 +02:00
mahdi-frms
a5edf6de79 generate function assist favors deref cmpt types 2021-07-31 16:34:09 +04:30
bors[bot]
1f817833e7
Merge #9727
9727: internal: Simplify extract_function assist r=Veykril a=Veykril

also fixes #7839(blocked on #9728)

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-30 14:56:50 +00:00
Lukas Wirth
3e351cc0ba Add trailing comma when extracting match arm expressions into functions 2021-07-30 16:48:13 +02:00
bors[bot]
4cc961007f
Merge #9731
9731: feat: Add `replace_char_with_string` assist r=Veykril a=Veykril

Adds the counterpart for the `replace_string_with_char` assist and fixes the assist not escaping the `'` in the string `"'"` when transforming that to a char.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-30 14:47:38 +00:00
Lukas Wirth
17a47a830b Add replace_char_with_string assist 2021-07-30 16:46:06 +02:00
bors[bot]
0a3ac7a96c
Merge #9728
9728: fix: Attach comma token to MATCH_ARM instead of MATCH_ARM_LIST r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-30 14:11:37 +00:00
Lukas Wirth
82c1e61887 Fix assists assuming comma belonging to MATCH_ARM_LIST 2021-07-30 16:01:26 +02:00
Lukas Wirth
322513b06c Reorder definitions in extract_function 2021-07-29 22:10:40 +02:00
Lukas Wirth
b21f66fce3 Simplify extract_function assist 2021-07-29 22:07:56 +02:00
bors[bot]
8232804d3e
Merge #9706
9706: minor: perf and grammar fixes r=lnicola a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-07-29 16:14:10 +00:00
Lukas Wirth
b537cb186e Use more strictly typed syntax nodes for analysis in extract_function assist 2021-07-29 17:26:37 +02:00
Lukas Wirth
2b461c50d7 Refine extraction targets of extract_function assist 2021-07-29 15:45:05 +02:00
Jonas Schievink
18f86baa62 Stop reexporting hir_def's ItemInNs from HIR 2021-07-28 17:39:04 +02:00
Laurențiu Nicola
636933153d Small grammar fix 2021-07-28 12:40:21 +03:00
Lukas Wirth
456f5c6d09 Don't qualify self as crate in add_missing_impl_members assist 2021-07-27 19:29:47 +02:00
bors[bot]
d571ca814e
Merge #9593
9593: fix: Adding remove_unused_param for method and fixing same for assoc func r=matklad a=feniljain

Solves #9571 

Co-authored-by: vi_mi <fenil.jain2018@vitstudent.ac.in>
2021-07-26 10:36:31 +00:00
Lukas Wirth
0a13259fc6 Kepp catch-all arm in fill_match_arms if it has a non-empty expression 2021-07-25 15:51:47 +02:00