Commit graph

17052 commits

Author SHA1 Message Date
Lukas Wirth
b6e7cf3201 Highlight unresolved derives as being unresolved 2023-03-08 13:51:14 +01:00
bors
6ebbd48ac0 Auto merge of #14283 - Veykril:error-notifs, r=Veykril
Load proc-macros for rustc_private crates

If the client support our server status notification there is no need to show the pop up for workspace fetching failures since that's already going to be shown in the status.
cc https://github.com/rust-lang/rust-analyzer/issues/14193
2023-03-08 12:22:10 +00:00
Lukas Wirth
b4bd27be90 Don't send error notifications for workspace failures if server status is supported 2023-03-08 13:18:44 +01:00
bors
aff6cb0080 Auto merge of #14282 - Veykril:rustc_private-proc-macro, r=Veykril
fix: Load proc-macros for rustc_private crates

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

Verified that this makes things work in the clippy repo (like resolving `sym` things for example)
2023-03-08 12:02:38 +00:00
bors
a9d97b6449 Auto merge of #14248 - XFFXFF:let_else_right_curly_brace, r=Veykril
fix: show diagnostic for } token followed by else in let else statement

fix #14221

My thinking is to check if the `expr` after `=` is block like when parse `let ... lese` , and if so, emit error.
2023-03-08 11:47:52 +00:00
Lukas Wirth
c9786484c5 Load proc-macros for rustc_private crates 2023-03-08 12:41:38 +01:00
bors
ecc32c2f85 Auto merge of #14271 - Veykril:ty-diag-err, r=Veykril
Don't trigger unresolved method/field diagnostics on types containing errors
2023-03-07 14:25:20 +00:00
Lukas Wirth
d45708fabe Don't trigger unresolved method/field diagnostics on types containing errors 2023-03-07 15:24:43 +01:00
bors
44ff3c407a Auto merge of #14232 - HKalbasi:mir, r=Veykril
MIR episode 2

This PR adds:
1. `need-mut` and `unused-mut` diagnostics
2. `View mir` command which shows MIR for the body under cursor, useful for debugging
3. MIR lowering for or-patterns and for-loops
2023-03-07 09:49:49 +00:00
XFFXFF
6e97527eae add is_blocklike func on BlockLike 2023-03-07 17:27:52 +08:00
hkalbasi
bcd7ecb242 Add profiling to mir lower and borrowck query 2023-03-07 12:42:52 +03:30
XFFXFF
98990affe5 add more tests 2023-03-07 08:24:25 +08:00
XFFXFF
995aacfce8 show diagnostic for } token followed by else in let else statement 2023-03-07 08:24:25 +08:00
bors
31c12ec282 Auto merge of #14266 - Veykril:generalize-eager-lazy, r=Veykril
feature: Make replace_or_with_or_else assists more generally applicable
2023-03-06 21:41:46 +00:00
Lukas Wirth
0ce06088f8 Fix inlay-hint tests 2023-03-06 22:39:42 +01:00
Lukas Wirth
34a3187ee8 internal: Mark unresolved field, unresolved method and expected function diagnostics experimental 2023-03-06 22:24:38 +01:00
Lukas Wirth
199bc82ce8 feature: Make replace_or_with_or_else assists more generally applicable 2023-03-06 22:17:30 +01:00
hkalbasi
2cce9dc3e9 Make unused_mut diagnostic experimental 2023-03-06 21:09:09 +03:30
hkalbasi
af90ec8096 Partially support "overloaded deref" MIR lowering 2023-03-06 21:09:09 +03:30
hkalbasi
bf0f99f15d Fix overloaded deref unused mut false positive 2023-03-06 21:09:09 +03:30
hkalbasi
6377d50bd1 Support "for loop" MIR lowering 2023-03-06 21:09:09 +03:30
hkalbasi
ac04bfd7a7 Add View Mir command and fix some bugs 2023-03-06 21:09:09 +03:30
hkalbasi
a25710b0c0 Add need-mut and unused-mut diagnostics 2023-03-06 21:09:08 +03:30
hkalbasi
c0a0664d12 Support "or patterns" MIR lowering 2023-03-06 21:09:08 +03:30
hkalbasi
61ad6a96ad Add BindingId 2023-03-06 21:09:08 +03:30
bors
a360fab9a3 Auto merge of #14261 - Veykril:ty-perf, r=Veykril
internal: Re-use the resolver in `InferenceContext` instead of rebuilding it whenever needed

This reduced inference time on my local build by roughly ~1 sec (out of like 60)
2023-03-06 10:54:27 +00:00
bors
900efbefdd Auto merge of #14260 - Veykril:if-let-match-adjust, r=Veykril
fix: Adjust `replace_match_with_if_let` applicability range

It currently trigger in the entirety of match which is less than ideal
2023-03-06 10:36:26 +00:00
Lukas Wirth
7be48ac32c Adjust replace_match_with_if_let applicability range 2023-03-05 16:52:07 +01:00
Lukas Wirth
d8b1ec6a25 Remove unnecessary option wrapping 2023-03-05 15:43:02 +01:00
Lukas Wirth
27fad2ad75 Lift segment check out of the loop in resolve_path_in_value_ns 2023-03-05 15:42:40 +01:00
Lukas Wirth
a51267c5e0 Allocate traits in scope upfront when type checking instead of recollecting them everytime 2023-03-05 15:04:46 +01:00
Lukas Wirth
a8606e5363 Re-use the resolver in InferenceContext instead of rebuilding it on every expression change 2023-03-05 14:37:44 +01:00
hkalbasi
ae8ce99d97 Bring back the hex in const hover 2023-03-05 13:53:49 +03:30
bors
e6ba791dce Auto merge of #14252 - Veykril:field-mcall-fallback, r=Veykril
internal: Handle fields called as method calls as the fields they resolve to

Confusing PR title tbf but this makes it so `bar` in `foo.bar()` resolves to the field if it exists and no method with the same name exists. Improves UX slightly when incorrectly calling a field.
2023-03-04 19:35:03 +00:00
Lukas Wirth
5a91f015b4 internal: Handle fields called as method calls as the fields they resolve to 2023-03-04 20:33:28 +01:00
bors
94dc7a3eb0 Auto merge of #14251 - Veykril:ty-expr-stmt, r=Veykril
internal: Set expectation for no-semi expression statements to unit
2023-03-04 19:01:47 +00:00
Lukas Wirth
b85e2af898 Correctly handle non-semi statement expressions for never coercions 2023-03-04 19:48:03 +01:00
Lukas Wirth
95c4cb991f Handle new hir block kinds in scope calculations 2023-03-04 15:22:39 +01:00
Lukas Wirth
b8276481e7 Fix extract_variable test 2023-03-04 14:58:58 +01:00
Lukas Wirth
1b5bc83118 Remove weird nesting of effect blocks in hir 2023-03-04 14:45:57 +01:00
Lukas Wirth
24ba1bed04 Set expectation for no-semi expression statements to unit 2023-03-04 12:48:57 +01:00
bors
5efcfe5ca9 Auto merge of #14244 - Veykril:metrics, r=lnicola
internal: Report type metrics for patterns

```
❯ cargo run --release -p rust-analyzer -q analysis-stats --memory-usage .
Database loaded:     2.09s, 218mb (metadata 275.07ms, 21mb; build 1.29s, 504kb)
  crates: 44, mods: 916, decls: 19582, fns: 14631
Item Collection:     14.33s, 472mb
  exprs: 420422, ??ty: 68 (0%), ?ty: 141 (0%), !ty: 1
  pats: 82968, ??ty: 11 (0%), ?ty: 10 (0%), !ty: 178
Inference:           47.84s, 745mb
Total:               62.16s, 1217mb
```
We currently have 178 mismatches on r-a itself
2023-03-04 08:31:20 +00:00
Lukas Wirth
800ab650ac split expression and pattern metrics 2023-03-04 09:21:17 +01:00
Pascal Kuthe
2e465d18f2
generate correct completion edits for missing macro arguments
rust-analyzer used the token at the cursor after macro expansion
to decide whether to replace the token at the cursor before macro
expansion. In most cases these two are the same but in some cases these
can mismatch which can lead to incorrect replacements.

For example if an ident/expr macro argument is missing rust-analyzer
generates a "missing" identifier as a placeholder, there is only a
brace at the cursor. Therefore, rust-analyzer will incorrectly replace
the macro brace with the completion in that case leading to #14246.

Using the expanded token type was intentional. However, this doesn't
seem to ever be desirable (this is supported by the fact that there
were no tests that relied on this behavior) since the type of edit to
perform should always be determined by the token it's actually applied
to.
2023-03-04 02:05:09 +01:00
Lukas Wirth
29150c2315 Disable pattern type mismatches again 2023-03-03 22:41:41 +01:00
Lukas Wirth
c12fac698f Report type metrics for patterns 2023-03-03 21:08:45 +01:00
Lukas Wirth
e7485a0416 Diagnose unresolved method calls 2023-03-03 20:43:13 +01:00
Lukas Wirth
78b2dd813a Diagnose unresolved field accesses 2023-03-03 20:43:10 +01:00
Lukas Wirth
3c7a0aa00e Diagnose call expression on non-callable things 2023-03-03 20:43:05 +01:00
bors
3ba876a4a6 Auto merge of #14240 - Veykril:coerce-many, r=Veykril
Diagnose value breaks in incorrect breakables
2023-03-03 17:03:39 +00:00
Lukas Wirth
41f234df09 Diagnose value breaks in incorrect breakables 2023-03-03 17:28:57 +01:00
Lukas Wirth
02eb2d758e Distinguish between expected and final type in CoerceMany 2023-03-03 16:52:09 +01:00
bors
6756294aa0 Auto merge of #14184 - lowr:feat/trait-alias-def, r=Veykril
Handle trait alias definitions

Part of #2773

This PR adds a bunch of structs and enum variants for trait aliases. Trait aliases should be handled as an independent item because they are semantically distinct from traits.

I basically started by adding `TraitAlias{Id, Loc}` to `hir_def::item_tree` and iterated adding necessary stuffs until compiler stopped complaining what's missing. Let me know if there's still anything I need to add.

I'm opening up this PR for early review and stuff. I'm planning to add tests for IDE functionalities in this PR, but not type-related support, for which I put FIXME notes.
2023-03-03 15:45:18 +00:00
Ryo Yoshida
f8eac19b33
Support trait aliases in IDE where type support isn't needed 2023-03-04 00:24:08 +09:00
Ryo Yoshida
29c957f973
Lower and handle trait aliases in HIR 2023-03-04 00:24:07 +09:00
Ryo Yoshida
e2ec3a6561
Refactor generic parameter lowering
Since we moved impl trait handling to other place, there are only two
cases now: those that introduce implicit `Self` parameter and those that
don't.
2023-03-04 00:24:05 +09:00
Ryo Yoshida
356d12eae4
refactor: leverage HasAttrs for code brevity 2023-03-04 00:24:03 +09:00
Ryo Yoshida
2e7d2c2d04
Parse trait alias as a distinct AST type 2023-03-04 00:23:56 +09:00
bors
a8d3c46082 Auto merge of #14239 - Veykril:sysroot-cli, r=Veykril
fix: Load the sysroot in all CLI commands
2023-03-03 10:51:15 +00:00
bors
c229a836e8 Auto merge of #14222 - Veykril:pat-mismatch-diags, r=Veykril
Show pattern mismatch diagnostics
2023-03-03 10:33:54 +00:00
Lukas Wirth
80ddfb89a2 fix: Load the sysroot in all CLI commands 2023-03-03 11:21:27 +01:00
Lukas Wirth
522823f610 Fix text fixtures of missing_match_arms diagnostics 2023-03-03 11:13:06 +01:00
Lukas Wirth
44e2c6ea92 Don't emit two type mismatches for literal pattern mismatches 2023-03-03 10:42:49 +01:00
Lukas Wirth
ec273c3d12 Split pattern inference into more functions 2023-03-03 10:42:46 +01:00
Lukas Wirth
fc2b395e00 Show pattern mismatch diagnostics 2023-03-03 10:41:44 +01:00
Ryo Yoshida
bda2af71c6
feat: allow generate_function to generate in different local crate 2023-03-03 18:40:13 +09:00
Ryo Yoshida
943de55214
Fix typo 2023-03-03 01:12:39 +09:00
Lukas Wirth
88f2abb8f7 Don't drop rustc crates in the rustc workspace 2023-03-02 12:55:41 +01:00
bors
32424d0aba Auto merge of #14176 - lowr:fix/assoc-func-vis-in-local-impl, r=Veykril
Fix associated item visibility in block-local impls

Fixes #14046

When we're resolving visibility of block-local items...

> `self` normally refers to the containing non-block module, and `super` to its parent (etc.). However, visibilities must only refer to a module in the DefMap they're written in, so we restrict them when that happens. ([link])

 ...unless we're resolving visibility of associated items in block-local impls, because that impl is semantically "hoisted" to the nearest (non-block) module. With this PR, we skip the adjustment for such items.

Since visibility representation of those items is modified, this PR also adjusts visibility rendering in `HirDisplay`.

[link]: a6603fc21d/crates/hir-def/src/nameres/path_resolution.rs (L101-L103)
2023-03-01 12:40:55 +00:00
bors
ef9d5db857 Auto merge of #14223 - HKalbasi:mir, r=HKalbasi
Add tuple to render_const_scalar

cc `@lowr`
2023-03-01 12:23:52 +00:00
Ryo Yoshida
de4a8961dc
Support removing nested dbg!()s in remove_dbg 2023-03-01 19:06:05 +09:00
hkalbasi
f64fe66c2a Add tuple to render_const_scalar 2023-02-28 23:12:30 +03:30
Ryo Yoshida
b5a1ddf77c
Don't use unstable pointer link 2023-02-28 21:22:20 +09:00
bors
1d07c5bc25 Auto merge of #14218 - Veykril:root-dedup, r=Veykril
Deduplicate source roots that have overlapping include paths

Fixes flycheck not working for the rustc workspace when using `linkedProjects`
2023-02-28 11:09:27 +00:00
Lukas Wirth
47a567b833 Deduplicate source roots that have overlapping include paths 2023-02-28 12:08:23 +01:00
bors
c386316fe0 Auto merge of #14185 - anergictcell:fix_14142, r=HKalbasi
Fix: Run doctests for structs with lifetime parameters from IDE

Fixes #14142: Doctests can't be triggered for structs with lifetimes

This MR adds lifetime parameters to the structs path for runnables so that they can be triggered from an IDE as well.

This is my first MR for rust-analyzer, please let me know if I should change something, either in code or the description here.
2023-02-28 09:52:03 +00:00
Jonas Marcello
af79491ae6 Rename method to generic_parameters 2023-02-28 10:32:42 +01:00
bors
a0be16b0b2 Auto merge of #14040 - HKalbasi:mir, r=HKalbasi
Beginning of MIR

This pull request introduces the initial implementation of MIR lowering and interpreting in Rust Analyzer.

The implementation of MIR has potential to bring several benefits:
- Executing a unit test without compiling it: This is my main goal. It can be useful for quickly testing code changes and print-debugging unit tests without the need for a full compilation (ideally in almost zero time, similar to languages like python and js). There is a probability that it goes nowhere, it might become slower than rustc, or it might need some unreasonable amount of memory, or we may fail to support a common pattern/function that make it unusable for most of the codes.
- Constant evaluation: MIR allows for easier and more correct constant evaluation, on par with rustc. If r-a wants to fully support the type system, it needs full const eval, which means arbitrary code execution, which needs MIR or something similar.
- Supporting more diagnostics: MIR can be used to detect errors, most famously borrow checker and lifetime errors,  but also mutability errors and uninitialized variables, which can be difficult/impossible to detect in HIR.
- Lowering closures: With MIR we can find out closure capture modes, which is useful in detecting if a closure implements the `FnMut` or `Fn` traits, and calculating its size and data layout.

But the current PR implements no diagnostics and doesn't support closures. About const eval, I removed the old const eval code and it now uses the mir interpreter. Everything that is supported in stable rustc is either implemented or is super easy to implement. About interpreting unit tests, I added an experimental config, disabled by default, that shows a `pass` or `fail` on hover of unit tests (ideally it should be a button similar to `Run test` button, but I didn't figured out how to add them). Currently, no real world test works, due to missing features including closures, heap allocation, `dyn Trait` and ... so at this point it is only useful for me selecting what to implement next.

The implementation of MIR is based on the design of rustc, the data structures are almost copy paste (so it should be easy to migrate it to a possible future stable-mir), but the lowering and interpreting code is from me.
2023-02-28 09:12:19 +00:00
hkalbasi
cd67589f63 beginning of MIR 2023-02-27 23:45:54 +03:30
Jonas Marcello
f494d1199d Remove empty line 2023-02-27 18:10:20 +01:00
Jonas Marcello
7abcc7d862 Add const to doctest runnable definition
Refactor method to get type parameters to add const parameters
Remove unused methods
2023-02-27 18:08:20 +01:00
Jonas Marcello
4ee2e469a2 Rename the method that returns struct paramaters 2023-02-27 18:08:20 +01:00
Jonas Marcello
9957bb361d Add const generics to doctest names for structt 2023-02-27 18:08:20 +01:00
Jonas Marcello
8bc75c4c28 return Iterator instead of Vec for combined lifetime and argument parameters 2023-02-27 18:08:20 +01:00
Jonas Marcello
9942cc425b Fix 14142: Annotate lifetime paramaters in doctest runnables 2023-02-27 18:08:17 +01:00
Lukas Wirth
29a4453d55 Merge the two autoref vecs into one in autoderef_method_receiver 2023-02-27 16:01:16 +01:00
Lukas Wirth
9e5fa74279 Simplify 2023-02-27 15:51:45 +01:00
bors
b38fcde3ba Auto merge of #14213 - swarnimarun:raw-ptr-ty, r=Veykril
add: clean api to get `raw_ptr` type

There doesn't seem to be an API to fetch the type of `raw_ptr`, which is helpful for a project I work on.

Notes:

- I am unsure about the function name, do let me know if I should use something else.
- Also unsure about where to add tests, for hir changes. Will fix it as needed.
2023-02-27 10:45:29 +00:00
Swarnim Arun
832f8bfe2b
rename: as_raw_ptr_ty to remove_raw_ptr 2023-02-27 15:57:26 +05:30
bors
2e479158bb Auto merge of #14208 - Kohei316:master, r=Veykril
fix:add a case in which remainig is None in resolveing types when resolving hir path.

fix #14030 The variable type is being determined incorrectly
This PR fixed a problem in which `go to definition` is jumping to the incorrect position because it was failing to resolve the type in case it defined in the module when resolving hir.
In addition, I added a test for this issue and refactored the related code.
This is my first PR and I am using a translation tool to write this text. Let me know if you have any problems.
2023-02-27 08:40:39 +00:00
Swarnim Arun
9a481d1ecf
add: clean api to get raw_ptr type 2023-02-27 10:59:20 +05:30
morine0122
aa877645a6 Fix resolving types when resolving HIR and add a related test 2023-02-26 21:50:39 +09:00
Tomoki Nakagawa
e4b184a776 Respect $CARGO_HOME when looking up toolchains. 2023-02-26 15:37:04 +09:00
shilangyu
44e47fe408 Add check for extra path segments after an angled one 2023-02-25 16:16:49 +01:00
Ryo Yoshida
cf0c8fe000
minor: import Either from either 2023-02-25 21:55:11 +09:00
bors
f5401f6206 Auto merge of #14175 - jmviz:openDocs-context-menu, r=lnicola
add openDocs command to context menu in VS Code extension

This adds the `openDocs` command to the VS Code context menu. I believe there are probably many user who are unaware of this command existing in the rust analyzer extension, and that this should enhance the discoverability of the command. Additionally, even if people are aware of this capability, it's helpful to have this in the context menu anyway; for example, one might forget the name of the command, or the keybinding they have assigned to it. I think that opening docs is a common enough action to warrant the extra line added to the context menu.

This makes a few other small changes as well. There are two minor style changes to increase style consistency. First, it changes the titles of the two commands that the rust analyzer extension will contribute to the context menu to title case. All standard VS Code commands that appear in the context menu are in title case. Second, it shortens the title of the `openDocs` command from `Open docs under cursor` to `Open Docs`. The implicit assumption in the standard VS Code context menu command titles is that the action applies to the symbol under the cursor: `Go to Definition`, `Find All References`, etc. Note that since these are changes to the command titles, rather than the command names themselves, these changes will not break any users' existing keybindings for these commands.

Second, this adds further restrictions to the `where` clauses of the two commands that the rust analyzer extension will contribute to the context menu, so that the two commands will appear in the context menu only when in a Rust project **and** within a Rust file. Say you have a Python or bash script inside your Rust project. Having these commands appear in the context menu when you right click a symbol in such a non-Rust file is extraneous and potentially confusing.

![demonstration](https://user-images.githubusercontent.com/6609145/219976062-b46ab21b-5753-48f5-a1da-562566cae71c.gif)
2023-02-24 06:55:02 +00:00
Nicholas Nethercote
888c18d3f3 Rename many interner functions.
(This is a large commit. The changes to
`compiler/rustc_middle/src/ty/context.rs` are the most important ones.)

The current naming scheme is a mess, with a mix of `_intern_`, `intern_`
and `mk_` prefixes, with little consistency. In particular, in many
cases it's easy to use an iterator interner when a (preferable) slice
interner is available.

The guiding principles of the new naming system:
- No `_intern_` prefixes.
- The `intern_` prefix is for internal operations.
- The `mk_` prefix is for external operations.
- For cases where there is a slice interner and an iterator interner,
  the former is `mk_foo` and the latter is `mk_foo_from_iter`.

Also, `slice_interners!` and `direct_interners!` can now be `pub` or
non-`pub`, which helps enforce the internal/external operations
division.

It's not perfect, but I think it's a clear improvement.

The following lists show everything that was renamed.

slice_interners
- const_list
  - mk_const_list -> mk_const_list_from_iter
  - intern_const_list -> mk_const_list
- substs
  - mk_substs -> mk_substs_from_iter
  - intern_substs -> mk_substs
  - check_substs -> check_and_mk_substs (this is a weird one)
- canonical_var_infos
  - intern_canonical_var_infos -> mk_canonical_var_infos
- poly_existential_predicates
  - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter
  - intern_poly_existential_predicates -> mk_poly_existential_predicates
  - _intern_poly_existential_predicates -> intern_poly_existential_predicates
- predicates
  - mk_predicates -> mk_predicates_from_iter
  - intern_predicates -> mk_predicates
  - _intern_predicates -> intern_predicates
- projs
  - intern_projs -> mk_projs
- place_elems
  - mk_place_elems -> mk_place_elems_from_iter
  - intern_place_elems -> mk_place_elems
- bound_variable_kinds
  - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter
  - intern_bound_variable_kinds -> mk_bound_variable_kinds

direct_interners
- region
  - intern_region (unchanged)
- const
  - mk_const_internal -> intern_const
- const_allocation
  - intern_const_alloc -> mk_const_alloc
- layout
  - intern_layout -> mk_layout
- adt_def
  - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid)
  - alloc_adt_def(!) -> mk_adt_def
- external_constraints
  - intern_external_constraints -> mk_external_constraints

Other
- type_list
  - mk_type_list -> mk_type_list_from_iter
  - intern_type_list -> mk_type_list
- tup
  - mk_tup -> mk_tup_from_iter
  - intern_tup -> mk_tup
2023-02-24 07:32:24 +11:00
Laurențiu Nicola
563bd9c24a Try to improve the rustfmt.overrideCommand docs 2023-02-21 12:43:22 +02:00
Laurențiu Nicola
f40526b949 Remove file added by mistake 2023-02-21 09:05:19 +02:00
jmviz
dd92e4a507 add to manual 2023-02-20 11:38:33 -05:00
Laurențiu Nicola
7e711da2f0 ⬆️ rust-analyzer 2023-02-20 10:14:12 +02:00
Ryo Yoshida
d4166234ef
Adjust block-local impl item visibility rendering 2023-02-20 00:44:51 +09:00
Ryo Yoshida
83e24fec98
Fix associated item visibility in block-local impls 2023-02-19 23:55:55 +09:00
Ryo Yoshida
443801755c
Refactor
- Remove unnecessary references and derefs
- Manual formatting
2023-02-19 23:55:49 +09:00
bors
b881deb66a Auto merge of #14165 - Veykril:completion-item, r=Veykril
internal: Make CompletionItem more POD-like
2023-02-16 08:30:56 +00:00
Lukas Wirth
404a51f26a internal: Make CompletionItem more POD-like 2023-02-16 09:29:55 +01:00
Azriel Hoh
a6f54d6c5f Conditionally add snippet marker. 2023-02-16 10:50:27 +13:00
bors
1f2d33fb40 Auto merge of #14160 - Veykril:hover-call, r=Veykril
fix: Bring back hovering call parens for return type info
2023-02-15 17:59:31 +00:00
Lukas Wirth
e550e553e0 fix: Bring back hovering call parens for return type info 2023-02-15 18:58:59 +01:00
bors
dd582dac67 Auto merge of #14157 - Veykril:inlay, r=Veykril
Adjust binding mode inlay hints to render better with @ patterns
2023-02-15 13:47:29 +00:00
Lukas Wirth
5859190066 Adjust binding mode inlay hints to render better with @ patterns 2023-02-15 14:47:02 +01:00
bors
a04054ac39 Auto merge of #14156 - Veykril:completion-pod, r=Veykril
internal: Don't reconstruct ref match completion in to_proto manually

cc https://github.com/rust-lang/rust-analyzer/issues/12571
2023-02-15 13:17:27 +00:00
Lukas Wirth
23fc596e40 Don't reconstruct ref match completion in to_proto manually 2023-02-15 14:15:22 +01:00
Lukas Wirth
026a8c976d Simplify 2023-02-15 13:38:42 +01:00
Laurențiu Nicola
6e5ec0b3ce Fix a pair of typos 2023-02-15 14:11:11 +02:00
Rune Tynan
853f047245
Cargo fmt 2023-02-14 14:45:05 -05:00
Rune Tynan
bc81d582c9
Add v7 support to rust-analyzer 2023-02-14 12:29:33 -05:00
bors
37608f306c Auto merge of #14152 - Veykril:path-opt, r=Veykril
Replace some often empty `Vec`s with boxed slices
2023-02-14 16:58:58 +00:00
bors
523fea8f25 Auto merge of #14149 - Veykril:completion, r=Veykril
Trigger call info for more completions of signature having things
2023-02-14 16:42:30 +00:00
Lukas Wirth
4aee911ce4 Slim down GenericArgs by one usize once more 2023-02-14 17:41:16 +01:00
Lukas Wirth
853ae1927d Slim down GenericArgs by one usize 2023-02-14 17:40:24 +01:00
Lukas Wirth
4c2aef650a Slim down AssociatedTypeBinding by one usize 2023-02-14 17:40:24 +01:00
bors
41db8c2b59 Auto merge of #14151 - Veykril:smallvec, r=Veykril
internal: Enable smallvec's `union` feature
2023-02-14 16:24:21 +00:00
Lukas Wirth
cade9f7020 Trigger call info for more completions of signature having things 2023-02-14 17:05:07 +01:00
bors
9548388534 Auto merge of #14150 - Veykril:path, r=Veykril
internal: Don't allocate the generic_args vec in `hir_def::Path` if it consists only of `None` args

Saves roughly 5mb on self
2023-02-14 16:02:02 +00:00
Lukas Wirth
a18ebf40cb Don't allocate the generic_args vec in hir_def::Path if it consists only of None args 2023-02-14 17:01:38 +01:00
Lukas Wirth
3c0f20a7bd internal: Enable smallvec's union feature 2023-02-14 17:01:01 +01:00
Lukas Wirth
38144fd914 Bump lsp-types 2023-02-14 14:59:50 +01:00
Lukas Wirth
95fa278f30 Don't assume VSCode internal commands in the server 2023-02-14 14:45:48 +01:00
bors
44568007d1 Auto merge of #14128 - Veykril:parser, r=Veykril
internal: Improve parser recovery for delimited lists

Closes https://github.com/rust-lang/rust-analyzer/issues/11188, https://github.com/rust-lang/rust-analyzer/issues/10410, https://github.com/rust-lang/rust-analyzer/issues/10173

Should probably be merged after the stable release as this might get the parser stuck if I missed something
2023-02-14 12:59:39 +00:00
Lukas Wirth
4f6b5f41d4 Recover better for more delimited sequences 2023-02-14 13:52:15 +01:00
bors
88b3d9f6f4 Auto merge of #14144 - lowr:fix/find-occurrence-of-raw-ident, r=Veykril
fix: Search raw identifiers without prefix

When we find references/usages of a raw identifier, we should disregard `r#` prefix because there are keywords one can use without the prefix in earlier editions (see #13034; this bug is actually fallout from the PR). `name`, the text we're searching for, has already been stripped of the prefix, but the text of nodes we compare it to hasn't been.

The second commit is strictly refactoring, I can remove it if it's not much of value.
2023-02-14 11:15:55 +00:00
bors
31486a639d Auto merge of #14141 - matklad:utf-32, r=lnicola
Support UTF-32 position encoding

Looks like this is a native encoding for Emacs at least!
2023-02-14 10:53:35 +00:00
Ryo Yoshida
60fa8fefa6
refactor: reduce nesting 2023-02-14 17:34:19 +09:00
Ryo Yoshida
098d9d77b4
Search raw identifiers without prefix 2023-02-14 17:34:14 +09:00
Alex Kladov
9fdcf5787d
Update crates/ide-db/src/line_index.rs
Co-authored-by: Stig Brautaset <stig@brautaset.org>
2023-02-14 08:19:58 +00:00
bors
2a57b01980 Auto merge of #14122 - lowr:patch/abort-macro-expansion-on-overflow, r=Veykril
fix: Don't expand macros in the same expansion tree after overflow

This patch fixes 2 bugs:

- In `Expander::enter_expand_id()` (and in code paths it's called), we never check whether we've reached the recursion limit. Although it hasn't been reported as far as I'm aware, this may cause hangs or stack overflows if some malformed attribute macro is used on associated items.
- We keep expansion even when recursion limit is reached. Take the following for example:

  ```rust
  macro_rules! foo { () => {{ foo!(); foo!(); }} }
  fn main() { foo!(); }
  ```

  We keep expanding the first `foo!()` in each expansion and would reach the limit at some point, *after which* we would try expanding the second `foo!()` in each expansion until it hits the limit again. This will (by default) lead to ~2^128 expansions.

  This is essentially what's happening in #14074. Unlike rustc, we don't just stop expanding macros when we fail as long as it produces some tokens so that we can provide completions and other services in incomplete macro calls.

This patch provides a method that takes care of recursion depths (`Expander::within_limit()`) and stops macro expansions in the whole macro expansion tree once it detects recursion depth overflow. To be honest, I'm not really satisfied with this fix because it can still be used in unintended ways to bypass overflow checks, and I'm still seeking ways such that misuses are caught by the compiler by leveraging types or something.

Fixes #14074
2023-02-14 07:37:53 +00:00
bors
381295144e Auto merge of #14123 - dqkqd:discard-postfix-completion-for-indivisble-expr, r=Veykril
fix: Don't trigger postfix completion in `if` block which has an `else` block

Fix #14096
2023-02-14 07:24:47 +00:00
Laurențiu Nicola
354b1aaa50 Merge branch 'master' into sync-from-rust 2023-02-14 08:40:55 +02:00
Aleksey Kladov
0da27376cf Support UTF-32 position encoding
Looks like this is a native encoding for Emacs at least!
2023-02-14 01:09:50 +00:00
Laurențiu Nicola
bc45c7659a ⬆️ rust-analyzer 2023-02-13 13:55:14 +02:00
bors
c97aae38f2 Auto merge of #14138 - lowr:fix/rename-raw-ident-mod, r=Veykril
fix: don't include `r#` prefix in filesystem changes

Fixes #14131

In addition to fix for #14131, this PR adds raw ident validity checks in rename functionality that we've been missing.
2023-02-13 11:38:32 +00:00
Duong Quoc Khanh
0285acc5f7
Find next_non_trivia_token of name_ref. 2023-02-13 20:11:04 +09:00
bors
23871f9dd1 Auto merge of #14140 - Veykril:proc-macro-srv-fix, r=Veykril
fix: Fix proc-macro-server incorrectly stripping delimiters

🙄
2023-02-13 11:08:23 +00:00
Lukas Wirth
1c2292e5c6 fix: Fix proc-macro-server incorrectly stripping delimiters 2023-02-13 12:07:31 +01:00
Lukas Wirth
244a48d13d Cleanup signature help a bit 2023-02-13 11:25:45 +01:00
Ryo Yoshida
57f0e9c100
Disallow invalid raw ident names 2023-02-13 18:45:19 +09:00
Ryo Yoshida
9b0daf20c9
fix: don't include r# prefix in filesystem changes 2023-02-13 18:44:53 +09:00
Ryo Yoshida
92fdfb548e
Make is_raw_identifier() public util function 2023-02-13 18:43:59 +09:00
Lukas Wirth
9738f97f8c Fix active parameter analysis once more 2023-02-12 17:32:11 +01:00
Lukas Wirth
d2cf8c234a Make else autocompletion work in more places 2023-02-12 10:49:57 +01:00
Lukas Wirth
33cacde04b Fix active parameter analysis 2023-02-12 10:26:19 +01:00
Lukas Wirth
1be24e0899 internal: Improve parser recovery a bunch 2023-02-11 20:28:36 +01:00
Lukas Wirth
5fdf640fb3 fix: Fix bind pat inlay hints rendering for constant patterns 2023-02-11 16:29:54 +01:00
Duong Quoc Khanh
e1396bde73
Don't trigger postfix completion if block which has an else block
Discard postfix completion if the next_non_trivia_sibling of dot_token
is an ELSE_KW.
2023-02-11 21:26:00 +09:00
Ryo Yoshida
ae7e62c50f
Don't expand macros in the same expansion tree after overflow 2023-02-11 18:19:08 +09:00
Lukas Wirth
7677f41f41 Preallocate some vecs 2023-02-10 16:42:09 +01:00
Lukas Wirth
79492cb8ae internal: Revert castable expectation and simplify 2023-02-10 16:08:47 +01:00
Lukas Wirth
8f5deb4ff2 Remove a few allocations in hir-ty::utils 2023-02-10 14:57:03 +01:00
bors
f11cff8976 Auto merge of #14116 - Veykril:inlay-hints-disc, r=Veykril
Render discriminant inlay hints for mixed variants if at least one discriminant is specified
2023-02-10 08:59:17 +00:00
Lukas Wirth
557aa1e378 Render discriminant inlay hints for mixed variants if at least one discriminant is specified 2023-02-10 09:57:03 +01:00
lh123
626dc651ff fix: Insert spaces when inlining macros 2023-02-10 14:22:56 +08:00
bors
7e17b98d17 Auto merge of #14111 - lnicola:squash-proc-macro-server-warning, r=Veykril
fix: Hide proc macro server version detection errors

These are harmless, but users tend to blame other things on them.
2023-02-09 10:29:28 +00:00
Laurențiu Nicola
8828f3494e Hide proc macro server version detection errors 2023-02-09 10:46:36 +02:00
Duong Quoc Khanh
74cd8ecc7e
Add completion without body.
Add completion for Fn, Const, TypeAlias without body.
2023-02-09 17:37:11 +09:00
Duong Quoc Khanh
58136b01ba
Add more tests for completion without body.
Add tests for Fn, Const, TypeAlias without body inside Trait.
2023-02-09 17:32:55 +09:00
bors
eaed19c539 Auto merge of #14104 - Veykril:castable-expect, r=Veykril
fix: Implement Expactation::Castable and add a test case for it

Fixes https://github.com/rust-lang/rust-analyzer/issues/11571
2023-02-08 12:08:15 +00:00
Lukas Wirth
f8f1cb93e0 fix: Implement Expactation::Castable and add a test case for it 2023-02-08 13:07:59 +01:00
bors
5341a6fa7f Auto merge of #14103 - Veykril:typing-semi, r=Veykril
fix: Don't insert a semicolon when typing = if parse errors are encountered

Fixes https://github.com/rust-lang/rust-analyzer/issues/11005
2023-02-08 11:14:58 +00:00
Lukas Wirth
5e6208b1df fix: Don't insert a semicolon when typing = if parse errors are encountered 2023-02-08 12:06:35 +01:00
bors
885c1ad578 Auto merge of #14102 - Veykril:bump-lexer, r=Veykril
minor: Bump `rustc-ap-rustc_lexer`

Closes https://github.com/rust-lang/rust-analyzer/issues/9554
2023-02-08 11:01:32 +00:00
Lukas Wirth
4788c7a056 Bump rustc-ap-rustc_lexer 2023-02-08 11:42:14 +01:00
bors
512a93ac94 Auto merge of #14100 - Veykril:load_cargo-proc-macro-srv-config, r=Veykril
Allow specifying what proc-macro server to run in rust_analyzer::load_cargo API

Closes https://github.com/rust-lang/rust-analyzer/issues/10516
2023-02-08 10:12:31 +00:00
Lukas Wirth
f03fb262f7 Allow specifying what proc-macro server to run in rust_analyzer::load_cargo API 2023-02-08 11:05:34 +01:00
bors
6effb26062 Auto merge of #14095 - dqkqd:master, r=Veykril
Add postfix completion for `unsafe`.

Fix #13779.

Hi, this is my first PR. Please tell me if there is anything I should do.
2023-02-08 09:44:22 +00:00
bors
a05ce5a3e7 Auto merge of #13986 - MariaSolOs:limit-completions, r=Veykril
Add setting for limiting number of completions

For #13911.
2023-02-08 09:31:35 +00:00
bors
3c89945e78 Auto merge of #14098 - pascalkuthe:did_change_workspace_folder, r=Veykril
Support DidChangeWorkspaceFolders notifications

This PR enables the `WorkspaceFoldersServerCapabilities` capability for rust-analyzer and implemented support for the associated [`DidChangeWorkspaceFolders`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeWorkspaceFolders) notification to allow clients to update the list of `workspaceFolders` sent during initialization.

## Motivation

This allows clients which lazily autodiscover their workspace roots (like the [helix editor](https://github.com/helix-editor/helix) once [my PR](https://github.com/helix-editor/helix/pull/5748) lands) avoid spawning multiple instances of RA. Right now such clients are forced to either:

* greedily discover all LSP roots in the workspace (precludes the ability to respond to new workspace roots)
* spawn multiple instance of rust-analyzer (one for each root)
* restart rust-analyzer whenever a new workspace is added

Some example use-cases are shown [here](https://github.com/helix-editor/helix/pull/5748#issuecomment-1421012523).

This PR will also improve support for VSCode (and Atom) multi workspaces.

## Implementation

The implementation was fairly straightforward as `rust-analyzer` already supports dynamically reloading workspaces, for example on configuration changes. Furthermore, rust-analyzer also already supports auto-discovering internal workspace from the `workspaceFolders` key in the initialization request. Therefore, the necessary logic just needed to be moved to a central place and reused.
2023-02-08 09:14:01 +00:00
bors
b7836e44d3 Auto merge of #14099 - Veykril:inlay-hint-loc, r=Veykril
Properly use location links for type hints of impl Future and its assoc type
2023-02-08 08:43:10 +00:00
Maria José Solano
064fcfa016 Sort and truncate final response 2023-02-07 18:41:28 -08:00
Lukas Wirth
2b4a5374ee Properly use location links for type hints of impl Future and its assoc type 2023-02-07 22:42:03 +01:00
Pascal Kuthe
c7010eda1b
Support DidChangeWorkspaceFolders capability 2023-02-07 22:40:40 +01:00
Duong Quoc Khanh
2666e6eda8
Add test for LetElse case.
Postfix completion is not triggered.
2023-02-08 04:04:10 +09:00
Duong Quoc Khanh
8535f2bb1b
Handle edge cases.
Handle case when BlockExpr is child of IfExpr, WhileExpr, LoopExpr,
ForExpr.
An additional { } will be added when:
- It is not a BlockExpr
- It is a BlockExpr and a child of IfExpr, WhileExpr, LoopExpr, ForExpr.
2023-02-08 03:37:20 +09:00
bors
7f1234492e Auto merge of #14084 - Veykril:float-parse, r=Veykril
fix: Fix parsing of nested tuple field accesses in a cursed way

This is absolutely terrible but seems to work. Macro fragment parsing comes next.
2023-02-07 17:25:31 +00:00
bors
57ea9826b5 Auto merge of #13991 - vasilev-alex:add-braces-assist, r=Veykril
feat: add braces assist

This assist adds support for adding braces where it may be appropriate (e.g. lambda expressions)

![ex](https://user-images.githubusercontent.com/4973437/213783924-7c8a8ab5-6a52-4d80-837c-cf2a9b56f061.gif)
2023-02-07 17:12:01 +00:00
Lukas Wirth
a756c9ad08 Fixup comments 2023-02-07 18:08:05 +01:00
Duong Quoc Khanh
370ba94ca2
Add more tests.
Add tests for control flows and `let`.
2023-02-08 01:50:09 +09:00
Lukas Wirth
27cd509558 fix jointess for floats not being set properly 2023-02-07 17:41:16 +01:00
Lukas Wirth
e59487de38 Add tests for float access macro call inputs 2023-02-07 17:12:24 +01:00
Duong Quoc Khanh
a7df61f1d3
Add postfix completion for unsafe.
Wrap receiver_text with { } if it's not a BlockExpr.
2023-02-07 23:55:44 +09:00
Lukas Wirth
f6539b139e fix depth check for float split step 2023-02-07 15:44:00 +01:00
Lukas Wirth
c6e7917d6e Fix up token_tree_to_syntax_node float split handling 2023-02-07 15:21:37 +01:00
bors
1d32a7b7c6 Auto merge of #14094 - HKalbasi:layout, r=flodiebold
Reuse fetching target data layout from rustc function

fix https://github.com/rust-lang/rust-analyzer/pull/14087?notification_referrer_id=NT_kwDOArGpCLM1NTEyMDQ5MjU3OjQ1MTk3NTc2#discussion_r1097850915
2023-02-06 22:35:37 +00:00
hkalbasi
40cf8b45ac reuse fetching target data layout from rustc function 2023-02-06 23:48:20 +03:30
bors
e9ce02ce63 Auto merge of #14087 - HKalbasi:layout, r=Veykril
Support computing layout of RPIT

And some refactoring to make code more type safe.
2023-02-06 19:42:58 +00:00
hkalbasi
443bc7f193 Support layout of RPIT 2023-02-06 20:50:25 +03:30
bors
62523024d3 Auto merge of #14091 - Veykril:workspace-sysroot, r=Veykril
Support sysroot library source being defined inside the workspace

With this you can now specify `cargo.sysrootSrc`. This is required for the rust workspace such that the `library` folder inside the workspace can be used as the sysroot library sources. We now also recognize if these sources are inside the workspace, tagging the as workspace members.

This does duplicate the sysroot crates still, but I don't think that causes too many problems.
2023-02-06 14:24:51 +00:00
Lukas Wirth
c6305c5659 fix: Don't panic on broken syntax trees in adjustment inlay hints 2023-02-06 12:38:57 +01:00
Lukas Wirth
cb9a5b9549 Support sysroot library source being defined inside the workspace 2023-02-06 12:07:33 +01:00
Ryo Yoshida
a4d0b5c522
Add regression tests 2023-02-05 22:28:03 +09:00