Commit graph

17804 commits

Author SHA1 Message Date
Lukas Wirth
76acf3b992 internal: Analyze all bodies in analysis-stats, not just functions 2023-06-16 19:14:46 +02:00
bors
4143890316 Auto merge of #15065 - Veykril:remove-alloc, r=Veykril
internal: Do not allocate unnecessarily when importing macros from parent modules
2023-06-16 16:42:01 +00:00
Lukas Wirth
bd093d1ccd Sort methods in generate_delegate_methods listing 2023-06-16 18:41:25 +02:00
Lukas Wirth
3484b5a116 internal: Do not allocate unnecessarily when importing macros from parent modules 2023-06-16 18:41:06 +02:00
ponyii
7e08933a26 the "implement missing members" assist's const transformation patched 2023-06-16 20:34:44 +04:00
hkalbasi
527dfede48 Support Pointee trait 2023-06-16 16:43:43 +03:30
ponyii
8a3c21442e refactoring 2023-06-15 17:56:08 +04:00
hkalbasi
922be8714d Add more log in "terminator is none" assert 2023-06-15 12:05:15 +03:30
hkalbasi
e55a1f1916 Map our diagnostics to rustc and clippy's ones 2023-06-15 01:47:22 +03:30
bors
9c967d3809 Auto merge of #15053 - Veykril:crate-root-module-id, r=Veykril
internal: Add a CrateRootModuleId that encodes a module id that is always a crate root
2023-06-14 14:41:06 +00:00
Lukas Wirth
cf178cba8f internal: Add a CrateRootModuleId that encodes a module id that is always a crate root 2023-06-14 15:41:06 +02:00
ponyii
b07490ffe9 made the add_missing_impl_members and add_missing_default_members assists transform default generic types 2023-06-14 17:37:34 +04:00
bors
51939db8d3 Auto merge of #15052 - lnicola:fmt-arguments, r=Veykril
minor: Rename minicore ArgumentV1 to match libcore
2023-06-14 12:13:58 +00:00
Laurențiu Nicola
6d6354e5b5 Rename minicore ArgumentV1 to match libcore 2023-06-14 07:33:37 +03:00
bors
f8dec25bd7 Auto merge of #15047 - Veykril:crate-graph-root-deps, r=Veykril
internal: Record file dependencies in crate graph construction

Should fix the bug mentioned in https://github.com/rust-lang/rust-analyzer/issues/8623 where removing a crate root file will panic. I'm not too happy with the way this is done here but I can't think of a better way right now.
2023-06-13 10:56:51 +00:00
Lukas Wirth
b322805918 internal: Record file dependencies in crate graph construction 2023-06-13 12:29:24 +02:00
bors
25f1c728b4 Auto merge of #15044 - lowr:fix/deduplicate-compl-fields, r=lnicola
Deduplicate tuple indices for completion

Follow-up to #15026

A tuple struct may dereference to a primitive tuple (though unusual, which is why I previously overlooked this case). We should not show the same tuple index in completion in such cases.

Deduplication of indices among multiple tuple structs is already handled in the previous PR.
2023-06-13 09:20:41 +00:00
Ryo Yoshida
d01283b1f7
Deduplicate tuple indices for completion 2023-06-13 18:01:54 +09:00
bors
07bc6cbcad Auto merge of #15040 - lnicola:hash-state-name, r=Veykril
fix: Use a more obscure hasher name in derive expansion

Closes #15039
2023-06-13 06:13:35 +00:00
Laurențiu Nicola
0b441ca6a5 Use a more obscure hasher name in derive expansion 2023-06-13 08:50:27 +03:00
Lukas Wirth
abe249559d internal: Give ConstBlockId and InTypeConstId named Location types 2023-06-12 18:21:17 +02:00
ponyii
5ce65a1d92 the "implement missing members" assist's const transformation implemented 2023-06-12 20:16:22 +04:00
bors
6b3659d38f Auto merge of #15026 - lowr:fix/deduplicate-compl-fields, r=Veykril
fix: deduplicate fields and types in completion

Fixes #15024

- `hir_ty::autoderef()` (which is only meant to be used outside `hir-ty`) now deduplicates types and completely resolves inference variables within.
- field completion now deduplicates fields of the same name and only picks such field of the first type in the deref chain.
2023-06-12 12:53:53 +00:00
bors
dcd31550e2 Auto merge of #14932 - HKalbasi:dev, r=HKalbasi
Lower const params with a bad id

cc #7434

This PR adds an `InTypeConstId` which is a `DefWithBodyId` and lower const generic parameters into bodies using it, and evaluate them with the mir interpreter. I think this is the last unimplemented const generic feature relative to rustc stable.

But there is a problem: The id used in the `InTypeConstId` is the raw `FileAstId`, which changes frequently. So these ids and their bodies will be invalidated very frequently, which is bad for incremental analysis.

Due this problem, I disabled lowering for local crates (in library crate the id is stable since files won't be changed). This might be overreacting (const generic expressions are usually small, maybe it would be better enabled with bad performance than disabled) but it makes motivation for doing it in the correct way, and it splits the potential panic and breakages that usually comes with const generic PRs in two steps.

Other than the id, I think (at least I hope) other parts are in the right direction.
2023-06-12 08:49:02 +00:00
hkalbasi
a4695788ca Add a bunch of fixme comments 2023-06-12 00:37:11 +03:30
Lukas Wirth
179b8d7efc
Formatting
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2023-06-11 20:11:26 +02:00
Lukas Wirth
52bb94d697 internal: Give rustfmt jobs a separate thread 2023-06-11 19:56:24 +02:00
Ryo Yoshida
42eab5e100
Deduplicate field names for completion 2023-06-11 19:34:27 +09:00
Ryo Yoshida
b4795507e3
autoderef: completely resolve and deduplicate types 2023-06-11 19:34:22 +09:00
Ryo Yoshida
ed8c58a3b1
Remove commented out conflicts 2023-06-11 17:14:36 +09:00
Ryo Yoshida
d091991491
fix(completion): derive source scope from syntax node to be transformed 2023-06-11 15:25:43 +09:00
Ryo Yoshida
008f5065d1
fix(assist): derive source scope from syntax node to be transformed 2023-06-11 15:25:36 +09:00
hkalbasi
e83b56739f Flatten the TypeOwnerId 2023-06-11 01:36:32 +03:30
hkalbasi
f8594f78bb Use ConstArg instead of Expr for AstId of InTypeConstId 2023-06-11 00:39:28 +03:30
hkalbasi
d9136df9e5 Handle return types for in type const bodies 2023-06-11 00:39:28 +03:30
hkalbasi
a481e004b0 Lower const params with a bad id 2023-06-11 00:39:28 +03:30
bors
68bdf609f3 Auto merge of #14974 - max-heller:issue-14958, r=lowr
Properly format documentation for `SignatureHelpRequest`s

Properly formats function documentation instead of returning it raw when responding to `SignatureHelpRequest`s.

I added a test in `crates/rust-analyzer/tests/slow-tests/main.rs` -- not sure if this is the best location given the relevant code is in `crates/rust-analyzer` or if it's possible to test in a less heavyweight manner.

Closes #14958
2023-06-10 14:15:37 +00:00
max-heller
78fab7d5d5 format documentation for SignatureHelpRequests 2023-06-10 09:54:34 -04:00
bors
95228d23bb Auto merge of #14875 - ponyii:fix/implement-missing-members-do-not-transform-lifetimes, r=Veykril
fix: implemeted lifetime transformation fot assits

A part of https://github.com/rust-lang/rust-analyzer/issues/13363
I expect to implement transformation of const params in a separate PR

Other assists and a completion affected:
- `generate_function` currently just ignores lifetimes and, consequently, is not affected
- `inline_call` and `replace_derive_with...` don't seem to need lifetime transformation
- `trait_impl` (a completion) is fixed and tested
2023-06-10 13:22:50 +00:00
bors
489eeab978 Auto merge of #14960 - jneem:group-delim-span, r=Veykril
Add span to group.

This appears to fix #14959, but I've never contributed to rust-analyzer before and there were some things that confused me:

- I had to add the `fn byte_range` method to get it to build. This was added to rust in [April](https://github.com/rust-lang/rust/pull/109002), so I don't understand why it wasn't needed until now
- When testing, I ran into the fact that rust recently updated its `METADATA_VERSION`, so I had to test this with nightly-2023-05-20. But then I noticed that rust has its own copy of `rust-analyzer`, and the metadata version bump has already been [handled there](60e95e76d0). So I guess I don't really understand the relationship between the code there and the code here.
2023-06-10 11:15:16 +00:00
bors
49b4f15973 Auto merge of #15022 - HKalbasi:nightly-mir-eval-panic, r=HKalbasi
Fix panic in displaying unsized structs
2023-06-10 08:06:56 +00:00
hkalbasi
1dd76e8a9d Fix panic in displaying unsized structs 2023-06-10 11:32:37 +03:30
Lukas Wirth
ccce893577 Count query entries in memory usage command 2023-06-10 01:49:32 +02:00
Lukas Wirth
b6fb35f20c Shrink hir_expand::attr::AttrInput by boxing a variant 2023-06-10 01:21:52 +02:00
bors
993299ee3f Auto merge of #15019 - HKalbasi:nightly-mir-eval-panic, r=HKalbasi
Fix panic in displaying const trait objects

I hope this fixes the panic on recent nightly stdlib, but I didn't test it locally.
2023-06-09 22:43:58 +00:00
hkalbasi
6fbf6ef514 Fix panic in displaying const trait objects 2023-06-10 02:10:52 +03:30
bors
60d952e902 Auto merge of #14979 - DropDemBits:structure-snippets-migrate-1, r=Veykril
internal: Migrate some assists to use the structured snippet API

Migrates the following assists:

- `add_missing_impl_members`
- `extract_type_alias`

As an additional requirement, these assists are also migrated to use the mutable AST API, since otherwise there would be overlapping `Indel` spans
2023-06-09 19:26:01 +00:00
Lukas Wirth
a02b9b279e internal: Lazy eager macros 2023-06-09 13:02:13 +02:00
bors
9973b11218 Auto merge of #15012 - lowr:patch/generate-fn-async-ret-ty, r=HKalbasi
Infer return type for async function in `generate_function`

Part of #10122

In `generate_function` assist, when we infer the return type of async function we're generating, we should retrieve the type of parent await expression rather than the call expression itself.
2023-06-09 09:00:45 +00:00
bors
9c03aa1ac2 Auto merge of #14997 - lnicola:fix-warning, r=Veykril
internal: Fix dependency warning

Hope this doesn't break #14984 again.
2023-06-08 15:48:58 +00:00
Ryo Yoshida
32768fe310
Infer return type for async function in generate_function 2023-06-09 00:32:52 +09:00
hkalbasi
30e16e20d0 Fix unwrap on None in expanding format args 2023-06-08 00:17:22 +03:30
beyarkay
dac660dc1d Fix typo in reload.rs 2023-06-07 20:57:27 +02:00
Joe Neeman
ad2a0d1093 Add configurable proc-macro-srv path for diagnostics 2023-06-07 08:48:19 -05:00
Joe Neeman
cdab3507eb Add span to group. 2023-06-07 08:48:19 -05:00
Ryo Yoshida
4f0c6fac17
fix: only generate trait bound for associated types in field types 2023-06-07 20:52:49 +09:00
Laurențiu Nicola
08ef169435 Fix dependency warning 2023-06-07 12:34:38 +03:00
Lukas Wirth
a6bef7808f fix: Fix proc-macro slow test 2023-06-07 07:03:27 +02:00
Viktor Lott
eef716d5f2 fix: use render_eval instead of inlined expr 2023-06-06 12:08:11 +02:00
Viktor Lott
2d4cb780b6 fix: Use render_eval for all builtins 2023-06-06 00:34:00 +02:00
Viktor Lott
8103a10a78 update assist to include more literals 2023-06-06 00:34:00 +02:00
Viktor Lott
094c1e7b86 feat: inline const expr as static str 2023-06-06 00:34:00 +02:00
Laurențiu Nicola
768a6c5931 Add back sysroot-abi feature gate to rust-analyzer 2023-06-05 14:43:31 +03:00
Laurențiu Nicola
c3dbe7c717 Merge remote-tracking branch 'upstream/master' into sync-from-rust 2023-06-05 11:07:47 +03:00
bors
c6a3fe051a Auto merge of #14978 - HKalbasi:lifetime-display, r=HKalbasi
Emit `'_` for lifetime generics in `HirDisplay`

This makes the generated code not linted by `rust_2018_idioms` lint. But that is an allow by default lint, so should we do this? Maybe we should only do this for `DisplayTarget::SourceCode`?
2023-06-05 07:26:30 +00:00
hkalbasi
5531d46c95 Emit '_ for lifetime generics in HirDisplay 2023-06-05 10:55:47 +03:30
DropDemBits
dd5f05590e
Migrate extract_type_alias to mutable ast 2023-06-05 00:24:12 -04:00
DropDemBits
e6e72bf9d5
Migrate add_missing_impl_members to mutable ast
`replace_derive_with_manual_impl` was slightly since it used
`add_trait_assoc_items_to_impl`
(which was also used by `add_missing_impl_members`)
2023-06-05 00:23:10 -04:00
bors
2f1b7cedcf Auto merge of #14971 - lowr:fix/captured-item-ty-outer-binder, r=HKalbasi
fix: consider outer binders when folding captured items' type

Fixes #14966

Basically, the crash is caused by us producing a broken type and passing it to chalk: `&dyn for<type> [for<> Implemented(^1.0: A<^0.0>)]` (notice the innermost bound var `^0.0` has no corresponding binder). It's created in `CapturedItemWithoutTy::with_ty()`, which didn't consider outer binders when folding types to replace placeholders with bound variables.

The fix is one-liner, but I've also refactored the surrounding code a little.
2023-06-04 18:25:23 +00:00
bors
5545961df2 Auto merge of #14976 - HKalbasi:mir-fix, r=HKalbasi
Fix missing terminator for slice pattern
2023-06-04 17:30:16 +00:00
hkalbasi
b4907a531f Fix missing terminator for slice pattern 2023-06-04 20:59:27 +03:30
bors
17426835d8 Auto merge of #14972 - HKalbasi:mir-fix, r=HKalbasi
Fix `unused-mut` false positive for `Box`
2023-06-04 12:26:39 +00:00
hkalbasi
0408af6453 Fix unused-mut false positive for Box 2023-06-04 15:56:01 +03:30
Ryo Yoshida
f549cacc1d
Destructure InferenceResult in resolve_all()
so that whenever new fields are added we don't forget to handle them.
2023-06-04 20:38:40 +09:00
Ryo Yoshida
a3789eabc9
Minor refactorings
- use `DefWithBodyId::as_generic_def_id()`
- add comments on `InferenceResult` invariant
- move local helper function to bottom to comply with style guide
2023-06-04 19:39:49 +09:00
Ryo Yoshida
275afd6e79
fix: consider outer binders when folding captured items' type 2023-06-04 19:38:47 +09:00
bors
9d5c34a80e Auto merge of #14970 - HKalbasi:mir-fix, r=HKalbasi
Detect "bound more than once" error and suppress `need-mut` for it.

Fix the `need-mut` false positive for `izip!`
2023-06-04 09:33:53 +00:00
hkalbasi
71f3e4b08c Detect "bound more than once" error and suppress need-mut for it. 2023-06-04 12:39:36 +03:30
Lukas Wirth
f9a9e40c0a Update builtin attribute list 2023-06-04 10:02:11 +02:00
Lukas Wirth
a1af9eb1f8
Revert "Add mandatory panic contexts to all threadpool tasks" 2023-06-04 09:30:21 +02:00
Lukas Wirth
2d0510e226 Add mandatory panic contexts to all threadpool tasks 2023-06-04 09:09:25 +02:00
bors
4fb1df6b7a Auto merge of #14961 - HKalbasi:mir-fix, r=HKalbasi
Fix drop scopes problems in mir

Fix false positives of `need-mut` emerged from #14955

There are still 5 `need-mut` false positives on self, all related to `izip!` macro hygenic issue. I will try to do something about that before monday release.
2023-06-03 21:40:09 +00:00
hkalbasi
08f89193b5 Fix drop scopes in mir 2023-06-04 01:03:32 +03:30
ponyii
7f45cccda4 lifetime transformation: refactoring & a new test 2023-06-03 21:34:31 +04:00
ponyii
fe8f862757 made the add_missing_impl_members and add_missing_default_members assists transform lifetimes 2023-06-03 21:12:11 +04:00
bors
e5c56cd9a0 Auto merge of #14955 - HKalbasi:mir-fix, r=HKalbasi
Remove unnecessary `StorageDead`

I hope this reduces MIR memory usage.
2023-06-03 13:55:40 +00:00
hkalbasi
f44fc271d4 Remove unnecessary StorageDead 2023-06-03 17:24:10 +03:30
bors
dd0c29c934 Auto merge of #14952 - lowr:fix/assignments-are-right-associative, r=HKalbasi
fix: assignment operators are right associative

Fixes #14944

Assignment operators, be they simple or complex, are right associative in Rust ([reference]). We need to consider that fact when computing [binding power][bp] of infix operators.

The changes in `0072_destructuring_assignment.{rs,rast}` are unexpected, but I'm pretty sure it's a typo and fixed the `.rs` file accordingly.

[reference]: https://doc.rust-lang.org/reference/expressions.html#expression-precedence
[bp]: https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html
2023-06-03 12:01:09 +00:00
Ryo Yoshida
f9c1a7dcd9
fix: assignment operators are right associative 2023-06-03 19:58:35 +09:00
hkalbasi
aab7589c40 Fix string pattern matching in mir interpreter 2023-06-02 23:45:29 +03:30
bors
dfaca9398a Auto merge of #14950 - HKalbasi:render-const, r=HKalbasi
Support floating point intrinsics in const eval
2023-06-02 13:59:47 +00:00
hkalbasi
a6a27a7ff8 Support floating point intrinsics in const eval 2023-06-02 17:29:17 +03:30
bors
7738ff4927 Auto merge of #14945 - justahero:gh-14626, r=Veykril
Fix Assist "replace named generic type with impl trait"

This is a follow-up PR to fix the assist "replace named generic type with impl trait" described in #14626 to filter invalid param types. It integrates the feedback given in PR #14816 .

The change updates the logic to determine when a function parameter is safe to replace a type param with its trait implementation. Some parameter definitions are invalid & should not be replaced by their traits, therefore skipping the assist completely.

First, all usages of the generic type under the cursor are determined. These usage references are checked to see if they occur outside the function parameter list. If an outside reference is found, e.g. in body, return type or where clause, the assist is skipped. All remaining usages need to appear only in the function param list. For each usage the param type is further inspected to see if it's valid. The logic to determine if a function parameter is valid, follows a heuristic and may not cover all possible parameter definitions.

With this change the following param types (as given in [this comment](https://github.com/rust-lang/rust-analyzer/pull/14816#discussion_r1206834603)) are not replaced & therefore skip the assist.

```rust
fn foo<P: Trait>(
    _: <P as Trait>::Assoc,          // within path type qualifier
    _: <() as OtherTrait<P>>::Assoc, // same as above
    _: P::Assoc,                     // associated type shorthand
    _: impl OtherTrait<P>            // generic arg in impl trait (note that associated type bindings are fine)
    _: &dyn Fn(P)                    // param type and/or return type for Fn* traits
) {}
```
2023-06-02 13:09:31 +00:00
Sebastian Ziebell
c0e9b57371 Improve assist to filter invalid params
The change updates the logic to determine if a function parameter is
valid for replacing the type param with the trait implementation.

First all usages are determined, to check if they are used outside the function
parameter list. If an outside reference is found, e.g. in body, return type or
where clause, the assist is skipped. All remaining usages only appear in the
function param list. For each usage the param type is checked to see if
it's valid.

**Please note** the logic currently follows a heuristic and may not cover
all existing parameter declarations.

* determine valid usage references by checking ancestors (on AST level)
* split test into separate ones
2023-06-02 12:46:01 +02:00
bors
0677c204ca Auto merge of #14947 - HKalbasi:render-const, r=HKalbasi
Add enum, reference, array and slice to `render_const_scalar`
2023-06-02 10:18:36 +00:00
hkalbasi
f9e3b180b7 Add enum, reference, array and slice to render_const_scalar 2023-06-02 13:47:02 +03:30
bors
0b4c09b1d2 Auto merge of #14941 - Veykril:def-map, r=Veykril
Shrink `DefMap`, share crate level items with block def maps
2023-06-01 16:42:12 +00:00
Lukas Wirth
11b937177b Skip extern prelude path resolution in block def maps 2023-06-01 17:58:08 +02:00
bors
4458e7f190 Auto merge of #14942 - HKalbasi:for-loop-label, r=HKalbasi
fix bug in labeled for loop desugaring

fix https://github.com/rust-lang/rust-analyzer/pull/14892#discussion_r1213091393
2023-06-01 14:54:47 +00:00
hkalbasi
f4c52b40bd fix bug in labeled for loop desugaring 2023-06-01 17:51:53 +03:30
Lukas Wirth
54e3ef658a Rename nameres::CrateData to DefMapCrateData 2023-06-01 15:50:19 +02:00
Lukas Wirth
1e6406e223 Move extern prelude into CrateData 2023-06-01 15:49:05 +02:00
Lukas Wirth
bdca349573 Arc DefMap::data so the block def maps can share it 2023-06-01 15:27:05 +02:00
Lukas Wirth
5c466ccc2b Refactor out some crate wide data in DefMap into nested struct 2023-06-01 15:04:38 +02:00
Lukas Wirth
dc7c6d43c7 Slightly shrink DefMap 2023-06-01 14:46:36 +02:00
bors
117f9b7752 Auto merge of #14939 - Veykril:nav-focus-ranges, r=Veykril
fix: Fix nav target calculation discarding file ids from differing macro upmapping

Fixes https://github.com/rust-lang/rust-analyzer/issues/14792

Turns out there was the assumption that upmapping from a macro will always end in the same root file, which is no longer the case thanks to `include!`
2023-06-01 09:19:24 +00:00
Lukas Wirth
a7d604d46f fix: Fix nav target calculation discarding file ids from differing macro upmapping 2023-06-01 11:05:03 +02:00
bors
7f2ac29e28 Auto merge of #14938 - Veykril:sig-help, r=Veykril
Add signature help for tuple patterns and expressions

~~These are somewhat wonky since their signature changes as you type depending on context but they help out nevertheless.~~ should be less wonky now with added parser and lowering recoveries
2023-06-01 07:07:23 +00:00
Lukas Wirth
0e28202832 Insert missing expr/pat for leading comma tuples 2023-06-01 08:56:40 +02:00
Lukas Wirth
7d1bf7023d Recover from leading comma in tuple pat and expr 2023-06-01 08:40:50 +02:00
Lukas Wirth
42450d2511 Add signature help for tuple patterns and expressions 2023-06-01 07:45:55 +02:00
bors
bafa6c4ee5 Auto merge of #14935 - Veykril:sysroot-dedup, r=Veykril
fix: Don't duplicate sysroot crates in rustc workspace

Since we handle `library` as the sysroot source directly in the rustc workspace, we now duplicate the crates there, once as sysroot and once as just plain workspace crate. This causes a variety of issues for `vec!` macros and similar that emit `$crate` tokens across crates.
2023-05-31 13:50:53 +00:00
Lukas Wirth
ecb8616870 fix: Don't duplicate sysroot crates in rustc workspace 2023-05-31 15:37:35 +02:00
Oli Scherer
1570299af4 Remove const eval limit and implement an exponential backoff lint instead 2023-05-31 10:24:17 +00:00
bors
526507fe22 Auto merge of #14888 - lunacookies:multi-qos, r=Veykril
Prioritize threads affected by user typing

To this end I’ve introduced a new custom thread pool type which can spawn threads using each QoS class. This way we can run latency-sensitive requests under one QoS class and everything else under another QoS class. The implementation is very similar to that of the `threadpool` crate (which is currently used by rust-analyzer) but with unused functionality stripped out.

I’ll have to rebase on master once #14859 is merged but I think everything else is alright :D
2023-05-31 10:23:19 +00:00
bors
d2b3caa5b5 Auto merge of #14929 - Veykril:hover-hex, r=Veykril
Add render configs for memory layout hovers

Closes https://github.com/rust-lang/rust-analyzer/issues/14918
2023-05-30 16:47:41 +00:00
Lukas Wirth
3c862507b9 Add render configs for memory layout hovers 2023-05-30 18:36:06 +02:00
bors
e33c0b4b5e Auto merge of #14842 - alibektas:internal/ast-make-improve, r=Veykril
Improve ast::make

Add `ty_alias` and make `impl_trait` , `fn` and `impl_` have more coverage.
2023-05-30 16:09:46 +00:00
bors
76d86502f7 Auto merge of #14912 - Veykril:cargo-alltargets, r=Veykril
Don't add --all-targets to runnables for no-std crates

Fixes https://github.com/rust-lang/rust-analyzer/issues/14155
2023-05-30 12:34:28 +00:00
bors
be446c6fd7 Auto merge of #14905 - Veykril:hover-hex, r=Veykril
feat: Render niches on hover
2023-05-30 12:19:51 +00:00
bors
e8dbb8e2e0 Auto merge of #14911 - Veykril:config-cfg, r=Veykril
Allow setting cfgs

Fixes https://github.com/rust-lang/rust-analyzer/issues/14365
2023-05-30 12:00:14 +00:00
Lukas Wirth
1275adc200 Don't leak rustc Layout in hir layer 2023-05-30 13:54:30 +02:00
Lukas Wirth
3514f2f2ab Render niches on hover 2023-05-30 13:49:43 +02:00
bors
51c3ab5b85 Auto merge of #14920 - lowr:fix/overhaul-named-struct-to-tuple-struct, r=Veykril
Fix edits for `convert_named_struct_to_tuple_struct`

Two fixes:
- When replacing syntax nodes, macro files weren't taken into account. Edits were simply made for `node.syntax().text_range()`, which would be wrong range when `node` is inside a macro file.
- We do ancestor node traversal for every struct name reference to find record expressions/patterns to edit, but we didn't verify that expressions/patterns do actually refer to the struct we're operating on.

Best reviewed one commit at a time.

Fixes #13780
Fixes #14927
2023-05-30 11:45:22 +00:00
Ryo Yoshida
033e6ac57a
Verify name references more rigidly
Previously we didn't verify that record expressions/patterns that were
found did actually point to the struct we're operating on. Moreover,
when that record expressions/patterns had missing child nodes, we would
continue traversing their ancestor nodes.
2023-05-29 20:10:54 +09:00
Ryo Yoshida
ab9347542c
Consider macro files when replacing nodes 2023-05-29 19:52:31 +09:00
hkalbasi
51368793b4 MIR episode 6 2023-05-28 23:25:15 +03:30
Lukas Wirth
8bc826dd53 Add diagnostic for _ expressions (typed holes) 2023-05-28 14:55:28 +02:00
Lukas Wirth
bbd9e41606 Don't add --all-targets to runnables for no-std crates 2023-05-28 14:18:44 +02:00
Luna Razzaghipour
6b46095980
Make formatting a latency-sensitive request 2023-05-28 22:10:24 +10:00
Lukas Wirth
cea84427e0 Allow setting cfgs 2023-05-28 13:43:21 +02:00
Ryo Yoshida
0d4d1d7e3b
Implement ${count()} metavariable expression 2023-05-28 19:54:36 +09:00
Ryo Yoshida
9ebaa85d37
Split test module for metavariable expressions 2023-05-28 19:54:23 +09:00
Luna Razzaghipour
74bc2a47e0
Wrap platform-specific QoS in r-a-specific “thread intent” 2023-05-28 20:37:38 +10:00
Luna Razzaghipour
d0b001eed2
Use appropriate QoS classes throughout the codebase 2023-05-28 20:37:37 +10:00
Luna Razzaghipour
2924fd2213
Implement custom QoS-aware thread pool
This code replaces the thread pool implementation we were using
previously (from the `threadpool` crate). By making the thread pool
aware of QoS, each job spawned on the thread pool can have a different
QoS class.

This commit also replaces every QoS class used previously with Default
as a temporary measure so that each usage can be chosen deliberately.
2023-05-28 20:37:35 +10:00
bors
1b5523a8cd Auto merge of #14913 - HKalbasi:fix14844, r=HKalbasi
Evaluate `UnevalutedConst` before trait solving

cc #14844
2023-05-26 21:01:20 +00:00
hkalbasi
cd4bffdd69 Evaluate UnevalutedConst before trait solving 2023-05-27 00:28:11 +03:30
Lukas Wirth
35b208aaa7 Filter out unused cargo features from config 2023-05-26 22:16:34 +02:00
Lukas Wirth
ee8c18cb6e Fix out_dirs_check test on stable 2023-05-26 20:54:58 +02:00
jyn
aa65395c49 Update proc-macro-api for the new rustc metadata format 2023-05-26 11:59:25 -05:00
bors
6bca9f2aac Auto merge of #14859 - lunacookies:qos, r=lunacookies
Specify thread types using Quality of Service API

<details>
<summary>Some background (in case you haven’t heard of QoS before)</summary>

Heterogenous multi-core CPUs are increasingly found in laptops and desktops (e.g. Alder Lake, Snapdragon 8cx Gen 3, M1). To maximize efficiency on this kind of hardware, it is important to provide the operating system with more information so threads can be scheduled on different core types appropriately.

The approach that XNU (the kernel of macOS, iOS, etc) and Windows have taken is to provide a high-level semantic API – quality of service, or QoS – which informs the OS of the program’s intent. For instance, you might specify that a thread is running a render loop for a game. This makes the OS provide this thread with as large a share of the system’s resources as possible. Specifying a thread is running an unimportant background task, on the other hand, is cause for it to be scheduled exclusively on high-efficiency cores instead of high-performance cores.

QoS APIs allows for easy configuration of many different parameters at once; for instance, setting QoS on XNU affects scheduling, timer latency, I/O priorities, and of course what core type the thread in question should run on. I don’t know any details on how QoS works on Windows, but I would guess it’s similar.

Hypothetically, taking advantage of these APIs would improve power consumption, thermals, battery life if applicable, etc.

</details>

# Relevance to rust-analyzer

From what I can tell the philosophy behind both the XNU and Windows QoS APIs is that _user interfaces should never stutter under any circumstances._ You can see this in the array of QoS classes which are available: the highest QoS class in both APIs is one intended explicitly for UI render loops.

Imagine rust-analyzer is performing CPU-intensive background work – maybe you just invoked Find Usages on `usize` or opened a large project – in this scenario the editor’s render loop should absolutely get higher priority than rust-analyzer, no matter what. You could view it in terms of “realtime-ness”: flight control software is hard realtime, audio software is soft realtime, GUIs are softer realtime, and rust-analyzer is not realtime at all. Of course, maximizing responsiveness is important, but respecting the rest of the system is more important.

# Implementation

I’ve tried my best to unify thread creation in `stdx`, where the new API I’ve introduced _requires_ specifying a QoS class. Different points along the performance/efficiency curve can make a great difference; the M1’s e-cores use around three times less power than the p-cores, so putting in this effort is worthwhile IMO.

It’s worth mentioning that Linux does not [yet](https://youtu.be/RfgPWpTwTQo) have a QoS API. Maybe translating QoS into regular thread priorities would be acceptable? From what I can tell the only scheduling-related code in rust-analyzer is Windows-specific, so ignoring QoS entirely on Linux shouldn’t cause any new issues. Also, I haven’t implemented support for the Windows QoS APIs because I don’t have a Windows machine to test on, and because I’m completely unfamiliar with Windows APIs :)

I noticed that rust-analyzer handles some requests on the main thread (using `.on_sync()`) and others on a threadpool (using `.on()`). I think it would make sense to run the main thread at the User Initiated QoS and the threadpool at Utility, but only if all requests that are caused by typing use `.on_sync()` and all that don’t use `.on()`. I don’t understand how the `.on_sync()`/`.on()` split that’s currently present was chosen, so I’ve let this code be for the moment. Let me know if changing this to what I proposed makes any sense.

To avoid having to change everything back in case I’ve misunderstood something, I’ve left all threads at the Utility QoS for now. Of course, this isn’t what I hope the code will look like in the end, but I figured I have to start somewhere :P

# References

<ul>

<li><a href="https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/PrioritizeWorkAtTheTaskLevel.html">Apple documentation related to QoS</a></li>
<li><a href="67e155c940/include/pthread/qos.h">pthread API for setting QoS on XNU</a></li>
<li><a href="https://learn.microsoft.com/en-us/windows/win32/procthread/quality-of-service">Windows’s QoS classes</a></li>
<li>
<details>
<summary>Full documentation of XNU QoS classes. This documentation is only available as a huge not-very-readable comment in a header file, so I’ve reformatted it and put it here for reference.</summary>
<ul>
<li><p><strong><code>QOS_CLASS_USER_INTERACTIVE</code>: A QOS class which indicates work performed by this thread is interactive with the user.</strong></p><p>Such work is requested to run at high priority relative to other work on the system. Specifying this QOS class is a request to run with nearly all available system CPU and I/O bandwidth even under contention. This is not an energy-efficient QOS class to use for large tasks. The use of this QOS class should be limited to critical interaction with the user such as handling events on the main event loop, view drawing, animation, etc.</p></li>
<li><p><strong><code>QOS_CLASS_USER_INITIATED</code>: A QOS class which indicates work performed by this thread was initiated by the user and that the user is likely waiting for the results.</strong></p><p>Such work is requested to run at a priority below critical user-interactive work, but relatively higher than other work on the system. This is not an energy-efficient QOS class to use for large tasks. Its use should be limited to operations of short enough duration that the user is unlikely to switch tasks while waiting for the results. Typical user-initiated work will have progress indicated by the display of placeholder content or modal user interface.</p></li>
<li><p><strong><code>QOS_CLASS_DEFAULT</code>: A default QOS class used by the system in cases where more specific QOS class information is not available.</strong></p><p>Such work is requested to run at a priority below critical user-interactive and user-initiated work, but relatively higher than utility and background tasks. Threads created by <code>pthread_create()</code> without an attribute specifying a QOS class will default to <code>QOS_CLASS_DEFAULT</code>. This QOS class value is not intended to be used as a work classification, it should only be set when propagating or restoring QOS class values provided by the system.</p></li>
<li><p><strong><code>QOS_CLASS_UTILITY</code>: A QOS class which indicates work performed by this thread may or may not be initiated by the user and that the user is unlikely to be immediately waiting for the results.</strong></p><p>Such work is requested to run at a priority below critical user-interactive and user-initiated work, but relatively higher than low-level system maintenance tasks. The use of this QOS class indicates the work should be run in an energy and thermally-efficient manner. The progress of utility work may or may not be indicated to the user, but the effect of such work is user-visible.</p></li>
<li><p><strong><code>QOS_CLASS_BACKGROUND</code>: A QOS class which indicates work performed by this thread was not initiated by the user and that the user may be unaware of the results.</strong></p><p>Such work is requested to run at a priority below other work. The use of this QOS class indicates the work should be run in the most energy and thermally-efficient manner.</p></li>
<li><p><strong><code>QOS_CLASS_UNSPECIFIED</code>: A QOS class value which indicates the absence or removal of QOS class information.</strong></p><p>As an API return value, may indicate that threads or pthread attributes were configured with legacy API incompatible or in conflict with the QOS class system.</p></li>
</ul>
</details>
</li>

</ul>
2023-05-26 15:48:22 +00:00
Lukas Wirth
be9cc0baae Render size, align and offset hover values in hex 2023-05-26 16:41:45 +02:00
Lukas Wirth
f876adf617 Report flycheck errors via status 2023-05-26 15:37:41 +02:00
Lukas Wirth
a2b59b110f Report config errors via status 2023-05-26 15:26:03 +02:00
Lukas Wirth
79fe11ced3 Shuffle some things around 2023-05-26 15:09:19 +02:00
bors
e963846656 Auto merge of #14816 - justahero:gh-14626, r=Veykril
feat: Assist to replace generic with impl trait

This adds a new assist named "Replace named generic with impl". It is the inverse operation to the existing "Replace impl trait with generic" assist.

It allows to refactor the following statement:

```rust
//      👇 cursor
fn new<T$0: ToString>(input: T) -> Self {}
```

to be transformed into:

```rust
fn new(input: impl ToString) -> Self {}
```

* adds new helper function `impl_trait_type` to create AST node
* add method to remove an existing generic param type from param list

Closes #14626
2023-05-26 12:03:44 +00:00
Sebastian Ziebell
e78df83e2f Integrate feedback
* pass in existing `Semantics` object to function
* pass in `Definition` for param type
* refactor iterator to use `flatten`
2023-05-26 13:43:12 +02:00
bors
8589a2d843 Auto merge of #14849 - alibektas:14557n, r=Veykril
enhancement : using doc aliases to search workspace symbols  ( fixes #14557 )

Doc aliases are now visible among symbols and can be used for searching.
2023-05-26 11:30:40 +00:00
Ali Bektas
d49924dc6e Choose & over ref, make nav target's name more intuitive. 2023-05-26 13:24:44 +02:00
Sebastian Ziebell
ce1c85317f Check param is not referenced in function
This checks the type param is referenced neither in the function body
nor as a return type.

* add tests
2023-05-26 13:24:29 +02:00
Sebastian Ziebell
95f59668e6 Fix removal of generic param from list
This removes an existing generic param from the `GenericParamList`. It
also considers to remove the extra colon & whitespace to the previous
sibling.

* change order to get all param types first and mark them as mutable
  before the first edit happens
* add helper function to remove a generic parameter
* fix test output
2023-05-26 13:13:15 +02:00
Sebastian Ziebell
59f8827a6f Implement assist to replace named generic with impl
This adds a new assist named "replace named generic with impl" to move
the generic param type from the generic param list into the function
signature.

```rust
fn new<T: ToString>(input: T) -> Self {}
```

becomes

```rust
fn new(input: impl ToString) -> Self {}
```

The first step is to determine if the assist can be applied, there has
to be a match between generic trait param & function paramter types.

* replace function parameter type(s) with impl
* add new `impl_trait_type` function to generate the new trait bounds with `impl` keyword  for use in the
  function signature
2023-05-26 13:13:11 +02:00
bors
2fd9260472 Auto merge of #14897 - HKalbasi:dev, r=HKalbasi
Insert type vars in function arguments

follow up #14891
2023-05-26 10:56:39 +00:00
hkalbasi
c21d09f3cc insert type vars in function arguments 2023-05-26 14:26:13 +03:30
Ryo Yoshida
397c8e5148
fix: don't try determining type of token inside macro calls 2023-05-26 16:46:45 +09:00
Wilfred Hughes
5b0e170683 Allow users to override the .scip output file path
Previously, rust-analyzer would write to the file index.scip
unconditionally.
2023-05-25 16:54:31 -07:00
hkalbasi
780349bdaf fix need-mut false positive in closure capture of match scrutinee 2023-05-26 02:08:37 +03:30
hkalbasi
7ef185d65e evaluate UnevaluatedConst in unify 2023-05-25 19:37:20 +03:30
bors
efd3094aba Auto merge of #14890 - HKalbasi:dev, r=HKalbasi
use `::core` instead of `$crate` in `option_env!`

fix #14885
2023-05-25 15:19:18 +00:00
hkalbasi
b0f17668f7 use ::core instead of $crate in option_env! 2023-05-25 18:46:34 +03:30
Lukas Wirth
e3dfcf2eb2 Add context to overly long loop message 2023-05-25 16:20:28 +02:00
bors
21e5dc2af9 Auto merge of #14881 - Veykril:name-display, r=Veykril
internal: Replace Display impl for Name

This allows us to plug in interner for `Name`s that live inside the database.
2023-05-25 12:04:16 +00:00
alibektas
1222869b3e Fix #14557. Docs aliases can now be detected and used in searching for workspace symbols 2023-05-24 23:57:24 +02:00
bors
a512774fd9 Auto merge of #14752 - ponyii:fix/generate_derive_breaks_indentation, r=Veykril
fix: assists no longer break indentation

Fixes https://github.com/rust-lang/rust-analyzer/issues/14674

These are _ad hoc_ patches for a number of assists that can produce incorrectly indented code, namely:
- generate_derive
- add_missing_impl_members
- add_missing_default_members

Some general solution is required in future, as the same problem arises in many other assists, e.g.
- replace_derive_with...
- generate_default_from_enum...
- generate_default_from_new
- generate_delegate_methods
(the list is incomplete)
2023-05-24 18:58:07 +00:00
Lukas Wirth
c7ef6c25b7 internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
bors
2f840c2236 Auto merge of #14874 - Veykril:crate-cfg, r=Veykril
expand: Change how `#![cfg(FALSE)]` behaves on crate root

Closes https://github.com/rust-lang/rust-analyzer/issues/14769
2023-05-24 16:06:09 +00:00
Luna Razzaghipour
430bdd3509
Run the main thread under the User Interactive QoS class 2023-05-25 00:22:14 +10:00
Luna Razzaghipour
578d99477a
Move on-type formatting request handler onto the main thread 2023-05-25 00:16:52 +10:00
bors
2df56cadcb Auto merge of #14755 - poliorcetics:clippy-fixes, r=Veykril
Fix: a TODO and some clippy fixes

- fix(todo): implement IntoIterator for ArenaMap<IDX, V>
- chore: remove unused method
- fix: remove useless `return`s
- fix: various clippy lints
- fix: simplify boolean test to a single negation
2023-05-24 11:13:52 +00:00
Lukas Wirth
74d6826858 expand: Change how #![cfg(FALSE)] behaves on crate root 2023-05-24 13:02:38 +02:00
bors
1d1a1195f3 Auto merge of #14880 - Veykril:intern-double, r=Veykril
Remove double lookups from Interned
2023-05-24 10:58:46 +00:00
Lukas Wirth
12d4355c60 Remove double lookups from Interned 2023-05-24 12:54:25 +02:00
alibektas
51ec2ced69 Improve ast::make
Add `ty_alias` and make `impl_trait` , `fn` and `impl_` have more coverage.
2023-05-23 03:12:57 +02:00
bors
2120c913c2 Auto merge of #14872 - lowr:fix/ref-pat-with-type-var, r=HKalbasi
fix: introduce new type var when expectation for ref pat is not ref

Fixes #14840

When we infer the type of ref patterns, its expected type may not be reference type: 1) expected type is an unresolved inference variable, or 2) expected type is erroneously other kind of type. In either case, we should produce a reference type with a new type variable rather than an error type so that we can continue inferring the inner patterns without further errors because of the (possible) type mismatch of this pattern.
2023-05-22 19:53:39 +00:00
Ryo Yoshida
01f42d2405
fix: introduce new type var when expectation for ref pat is not ref 2023-05-22 23:13:41 +09:00
bors
7ac161ce77 Auto merge of #14863 - lowr:fix/extract-fn-nested-tt, r=lnicola
fix: consider all tokens in macro expr when analyzing locals

Fixes #14687

2 fixes for `extract_function` assist (related closely enough that I squashed into one commit):

- Locals in macro expressions have been analyzed only when they are in the top-level token tree the macro call wraps. We should consider all descendant tokens.
- `self` in macro expressions haven't been analyzed.
2023-05-21 12:40:29 +00:00
Ryo Yoshida
7b70988d48
fix: consider all tokens in macro expr when analyzing locals
Also consider `self` token along with ordinary identifiers.
2023-05-21 20:07:36 +09:00
bors
a04d8456be Auto merge of #14855 - HKalbasi:mir, r=HKalbasi
Consider block impls in `lookup_impl_assoc_item_for_trait_ref`

fix #14782
2023-05-20 20:55:22 +00:00
Luna Razzaghipour
a416248296
Extract platform-specific QoS code into module 2023-05-21 02:48:30 +10:00
Luna Razzaghipour
bb02ae7532
Add doc comments for QoSClass 2023-05-21 02:02:30 +10:00
Luna Razzaghipour
91f4fbe596
Improve comments 2023-05-21 02:02:21 +10:00
Luna Razzaghipour
ca6461c143
Add proof-of-concept QoS implementation 2023-05-20 22:29:32 +10:00
bors
4de8c0980e Auto merge of #14857 - Veykril:perf, r=Veykril
internal: Shrink ProcMacroExpander from 8 to 4 bytes
2023-05-20 10:00:43 +00:00
Lukas Wirth
14dc1ac3bf internal: Shrink ProcMacroExpander from 8 to 4 bytes 2023-05-20 11:31:28 +02:00
hkalbasi
92d6670f72 Consider block impls in lookup_impl_assoc_item_for_trait_ref 2023-05-20 01:11:17 +03:30
bors
bb78059be4 Auto merge of #14847 - HKalbasi:layout, r=HKalbasi
Reduce MIR memory usage
2023-05-19 12:06:11 +00:00
hkalbasi
60379dabfb resolve types in closure capture copy detection 2023-05-19 14:54:57 +03:30
hkalbasi
c5ea2d7adc handle match scrutinee in closure captures 2023-05-19 12:04:12 +03:30
bors
e8ae2d3976 Auto merge of #14848 - bm-w:fix/highlight-let-else-return, r=Veykril
Fix `preorder_expr` skipping the `else` block of let-else statements

Fixes exit/yield points not getting highlighted in such blocks for `highlight_related` (#14813; and possibly other bugs in features that use `preorder_expr`).
2023-05-19 07:41:46 +00:00
Lukas Wirth
c0519daf3b
Update crates/ide-db/src/syntax_helpers/node_ext.rs
Co-authored-by: Bastiaan Marinus van de Weerd <id@bm-w.eu>
2023-05-19 09:33:57 +02:00
Bastiaan Marinus van de Weerd
5857836047
Fix preorder_expr skipping the else block of let-else statements
Fixes exit/yield points not getting highlighted in such blocks for `highlight_related` (#14813; and possibly other bugs in features that use `preorder_expr`).
2023-05-18 18:30:27 -04:00
hkalbasi
23ce228d54 Reduce MIR memory usage 2023-05-19 00:16:52 +03:30
hkalbasi
cae9660a1d Add layout info for enum variant and locals 2023-05-18 21:03:03 +03:30
hkalbasi
b55fbd3ad7 Add moved-out-of-ref diagnostic 2023-05-18 19:17:06 +03:30
hkalbasi
4adfbbfbad partially support panic message in MirEvalError 2023-05-18 18:30:49 +03:30
bors
9ce95674e8 Auto merge of #14837 - Veykril:rustc-lexer, r=Veykril
Support c string literals
2023-05-18 11:55:38 +00:00
Lukas Wirth
3e528b85f9 Fix cstring literals construct &CStr not &str 2023-05-18 12:03:15 +02:00
bors
034d7c8537 Auto merge of #14787 - HKalbasi:mir2, r=HKalbasi
MIR episode 5

This PR inits drop support (it is very broken at this stage, some things are dropped multiple time, drop scopes are wrong, ...) and adds stdout support (`println!` doesn't work since its expansion is dummy, but `stdout().write(b"hello world\n")` works if you use `RA_SYSROOT_HACK`) for interpreting. There is no useful unit test that it can interpret yet, but it is a good sign that it didn't hit a major road block yet.

In MIR lowering, it adds support for slice pattern and anonymous const blocks, and some fixes so that we can evaluate `SmolStr::new_inline` in const eval. With these changes, 57 failed mir body remains.
2023-05-18 09:44:26 +00:00
Lukas Wirth
eab295cc73 Fix mir CString lowering not respecting the extra 0 byte for length calc 2023-05-18 11:29:19 +02:00