Commit graph

11251 commits

Author SHA1 Message Date
Jade
de0ed9860d Address final feedback
* rename ConstExtension->ConstExt
* refactor a manual construction of a Const
2021-05-15 18:51:18 -07:00
Jade
78d6b88f21 Add more tests, refactor array lengths/consteval work
Fix #2922: add unknown length as a condition for a type having unknown.

Incorporate reviews:

* Extract some of the const evaluation workings into functions
* Add fixmes on the hacks
* Add tests for impls on specific array lengths (these work!!! 😁)
* Add tests for const generics (indeed we don't support it yet)
2021-05-14 01:39:28 -07:00
Jade
32c600664e Test lowering byte strings some more 2021-05-12 21:22:46 -07:00
Jade
e666589e63 Add support for lengths in array repeats, if they are literals
Now we will get the type of `[0u8; 4]`.
2021-05-12 21:22:46 -07:00
Jade
73023c0299 Support length for ByteStrings
I am not confident that my added byte string parsing is right.
2021-05-12 21:22:46 -07:00
Jade
8b147624ff Add lowering of array lengths in types
Now e.g.

```rust
fn a(b: [u8; 2]) {
}
```

will know about the length of b.
2021-05-12 21:22:46 -07:00
bors[bot]
312f1fe20a
Merge #8799
8799: Add basic support for array lengths in types r=flodiebold a=lf-

This recognizes `let a = [1u8, 2, 3]` as having type `[u8; 3]` instead
of the previous `[u8; _]`. Byte strings and `[0u8; 2]` kinds of range
array declarations are unsupported as before.

I don't know why a bunch of our rustc tests had single quotes inside
strings un-escaped by `UPDATE_EXPECT=1 cargo t`, but I don't think it's
bad? Maybe something in a nightly?

Co-authored-by: Jade <software@lfcode.ca>
2021-05-12 14:49:43 +00:00
bors[bot]
1c927d2f8e
Merge #8802
8802: Keep comments and attrs when extracting struct from enum variant r=Veykril a=DropDemBits

Fixes #6730

Still unsure if existing visibilities of fields should be forced to pub (which is what was previously done), or if it's okay to keep it in the extracted struct.

Co-authored-by: DropDemBits <r3usrlnd@gmail.com>
2021-05-12 14:42:01 +00:00
Jonas Schievink
a272cdfecd Fix build script dependencies 2021-05-12 14:48:26 +02:00
Jonas Schievink
e78221bc58 Remove delimiters from proc macro input 2021-05-12 01:01:51 +02:00
Jonas Schievink
c868414dcd Revert "Strip delimiter from fn-like proc macro input"
This reverts commit bda68e2332.
2021-05-12 00:57:41 +02:00
bors[bot]
c6e2ba43bb
Merge #8806
8806: fix: Strip delimiter from fn-like macro invocations r=jonas-schievink a=jonas-schievink

This broke in https://github.com/rust-analyzer/rust-analyzer/pull/8796 (again), the fix is easy though

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-11 22:27:50 +00:00
Jonas Schievink
bda68e2332 Strip delimiter from fn-like proc macro input 2021-05-12 00:27:16 +02:00
Jade
f28c053c67 address review by @eddyb 2021-05-11 15:18:45 -07:00
Jonas Schievink
23cd6d0d56 Move dot invocation to rust-analyzer crate 2021-05-12 00:14:59 +02:00
Jonas Schievink
32560839d9 Use Cargo target name as crate name 2021-05-11 23:34:56 +02:00
bors[bot]
da80dfc022
Merge #8398
8398: Fix inference with conditionally compiled tails r=flodiebold a=DJMcNab

Fixes #8378

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2021-05-11 19:01:39 +00:00
bors[bot]
e290891dd7
Merge #8801
8801: feat: Allow viewing the crate graph in a webview r=jonas-schievink a=jonas-schievink

This uses `dot` to render the crate graph as an SVD file, and displays it in a VS Code panel. For simple crate graphs, it works quite well:

![screenshot-2021-05-11-16:19:32](https://user-images.githubusercontent.com/1786438/117831361-c4a48980-b274-11eb-9276-240cdf6919aa.png)

Unfortunately, on rust-analyzer itself (and most medium-sized dependency graphs), `dot` runs for around a minute and then produces this mess:

![screenshot-2021-05-11-16:41:37](https://user-images.githubusercontent.com/1786438/117834831-c754ae00-b277-11eb-850b-138495dbeba8.png)


Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-11 18:02:31 +00:00
Jonas Schievink
d1aa6bbe75 Better node label/shapes 2021-05-11 19:50:01 +02:00
bors[bot]
6afd9b2b8d
Merge #8796
8796: internal: rewrite `#[derive]` removal to be based on AST (take 2) r=jonas-schievink a=jonas-schievink

Second attempt of https://github.com/rust-analyzer/rust-analyzer/pull/8443, this uses syntactical attribute offsets in `hir_expand`, and changes `attr.rs` to make those easy to derive.

This will make it easy to add similar attribute removal for attribute macros, unblocking them.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-11 17:47:45 +00:00
Jonas Schievink
5b3af25121 Only include workspace crates 2021-05-11 19:17:43 +02:00
DropDemBits
7fefac4bdc
Keep comments and attrs when extracting struct from enum variant 2021-05-11 11:07:47 -04:00
Jonas Schievink
9e6d9baf2e
Update crates/ide/src/view_crate_graph.rs
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
2021-05-11 16:42:27 +02:00
Jonas Schievink
435c422963 Distinguish crates with identical name 2021-05-11 16:36:00 +02:00
Jonas Schievink
a85a2c4d15 Allow viewing the crate graph in a webview 2021-05-11 16:15:31 +02:00
bors[bot]
9fa9d166d8
Merge #8800
8800: feat: Make "pull assignments up" assist work in more cases r=Jesse-Bakker a=Jesse-Bakker

Fixes #8771

Co-authored-by: Jesse Bakker <github@jessebakker.com>
2021-05-11 13:14:55 +00:00
Jesse Bakker
5f37e34406 Make "pull assignments up" assist work in more cases 2021-05-11 15:14:23 +02:00
Jade
dc63fea427 Add basic support for array lengths in types
This recognizes `let a = [1u8, 2, 3]` as having type `[u8; 3]` instead
of the previous `[u8; _]`. Byte strings and `[0u8; 2]` kinds of range
array declarations are unsupported as before.

I don't know why a bunch of our rustc tests had single quotes inside
strings un-escaped by `UPDATE_EXPECT=1 cargo t`, but I don't think it's
bad? Maybe something in a nightly?
2021-05-11 05:25:19 -07:00
Jonas Schievink
8ea9d939d2 Rewrite #[derive] removal to be based on AST 2021-05-10 22:54:17 +02:00
bors[bot]
77f0c92fd8
Merge #8794
8794: Give MergeBehaviour variants better names r=Veykril a=Veykril

I never really liked the variant names I gave this enum from the beginning and then I found out about rustfmt's `imports_granularity` config:

> imports_granularity
>
> How imports should be grouped into use statements. Imports will be merged or split to the configured level of granularity.
> 
>     Default value: Preserve
>     Possible values: Preserve, Crate, Module, Item
>     Stable: No

I personally prefer using `crate` over `full` and `module` over last, they seem more descriptive. Keeping these similar between tooling also seems like a good plus point to me.

We might even wanna take over the entire enum at some point if we have a `format/cleanup imports` assists in the future which would probably want to also have the `preserve` and `item` options.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-10 20:10:59 +00:00
Lukas Wirth
59c2efe4b6 Update docs 2021-05-10 22:10:12 +02:00
Jonas Schievink
da08198bc9 Rewrite attr.rs to allow using syntax-based indices 2021-05-10 21:50:42 +02:00
Lukas Wirth
6a8d47e7f0 Give MergeBehaviour variants better names 2021-05-10 21:14:59 +02:00
mixio
aa9002c68a
Corrected 2 typos on line 83 2021-05-10 20:05:32 +02:00
Jonas Schievink
a87bec5148 Move AttrId back into hir_def 2021-05-10 16:35:06 +02:00
Jonas Schievink
e718c6b3e8 feat: auto-indent use tree lists 2021-05-10 15:10:56 +02:00
Aleksey Kladov
bf26e13cd2 simplify 2021-05-10 15:25:56 +03:00
Jonas Schievink
64f97fb2ad feat: auto-insert } when typing { in use item 2021-05-09 22:12:58 +02:00
bors[bot]
75a5c0a534
Merge #8783
8783: internal: introduce `ast::make::ext` module with common shortcuts r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-09 16:56:02 +00:00
Aleksey Kladov
4f3c0adc5a internal: introduce ast::make::ext module with common shortcuts
There's a tension between keeping a well-architectured minimal
orthogonal set of constructs, and providing convenience functions.
Relieve this pressure by introducing an dedicated module for
non-orthogonal shortcuts.

This is inspired by the django.shortcuts module which serves a similar
purpose architecturally.
2021-05-09 19:55:43 +03:00
bors[bot]
2fe329db48
Merge #8782
8782: internal: fix make API r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-09 16:23:03 +00:00
Aleksey Kladov
680a0d54e4 internal: fix make API 2021-05-09 19:22:33 +03:00
bors[bot]
a3b034938e
Merge #8781
8781: internal: rewrite **Repalce impl Trait** assist to mutable syntax trees r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-09 15:55:42 +00:00
Aleksey Kladov
5342800147 internal: rewrite **Repalce impl Trait** assist to mutable syntax trees 2021-05-09 18:20:37 +03:00
Aleksey Kladov
984d20aad8 cleanups 2021-05-09 18:01:54 +03:00
Aleksey Kladov
d9c9f6dc2c cleanups 2021-05-09 17:58:03 +03:00
Aleksey Kladov
edeb492782 minor: fix test style 2021-05-09 17:47:02 +03:00
Aleksey Kladov
5637ce4250 fix: join lines doesn't add space before closing quote 2021-05-09 17:46:41 +03:00
bors[bot]
0900beeaa2
Merge #8776
8776: fix: fix unnecessary recomputations due to macros r=jonas-schievink a=jonas-schievink

This computes a macro's fragment kind eagerly (when the calling file is still available in parsed form) and stores it in the `MacroCallLoc`. This means that during expansion we no longer have to reparse the file containing the macro call, avoiding the unnecessary salsa dependencies (https://github.com/rust-analyzer/rust-analyzer/pull/8746#issuecomment-834776349).

Marking as draft until I manage to find a test for this problem, since for some reason `typing_inside_a_function_should_not_invalidate_expansions` does not catch this (which might indicate that I misunderstand the problem).

I've manually confirmed that this fixes the issue described in https://github.com/rust-analyzer/rust-analyzer/pull/8746#issuecomment-834776349:

```
    7ms - parse_query @ FileId(179)
   12ms - SourceBinder::to_module_def
       12ms - crate_def_map:wait
            5ms - item_tree_query (1 calls)
            7ms - ???
```

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-09 14:40:49 +00:00
Jonas Schievink
fd5a1d1765 Test that none of the macros are reparsed 2021-05-09 16:39:47 +02:00