Commit graph

17018 commits

Author SHA1 Message Date
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
Ryo Yoshida
0ec2911857
fix: consider relative offset to fake ident token in expansion for completion 2023-02-05 22:27:52 +09:00
Lukas Wirth
9053bcc65c Make mbe compile with parser changes 2023-02-03 21:39:24 +01:00
Lukas Wirth
6fa6efe90f fix: Fix parsing of nested tuple field accesses in a cursed way 2023-02-03 17:18:48 +01:00
bors
3bc33c7e9f Auto merge of #14010 - silvergasp:ci, r=lnicola
fuzz: Fixes broken Cargo.toml for fuzz tests

Fixes broken Cargo.toml for fuzz tests and adds building of fuzz tests to the CI.
2023-02-03 11:15:54 +00:00
Lukas Wirth
dab685dd87 De-magic number parser::Output encoding 2023-02-03 11:47:33 +01:00
bors
6133e27b83 Auto merge of #14070 - Veykril:proc-macro-api, r=Veykril
Implement proc-macro-api versioning

So as it stands, we can't really change the proc-macro-api protocol at all without breaking all proc-macro servers again. To somewhat alleviate this we can move the supported ABI mess over to the proc-macro-api now by supporting multiple versions there (versions defined by us at least, not by rustc). Since the proc-macro-api protocol has no versioning scheme at the moment though, the best we can do here is add a new request to query the version from a server. Due to how the server currently works though, if it encounters an unknown request it will exit, meaning we can check if it is a server without support by checking if it exited after our version check request, that way we can support the current circulating server as well.

We need this since our span type will change from `TokenId` to something else at some point, but for that to work we need to comply with that the server expects. So knowing the version the server is using we can decide whether to send our new span data, or the tokenid (assuming we keep that information with our span data as well, alternatively we send irrelevant tokenids). That way we can keep old servers working while the user installations slowly migrate to newer servers that support the new spandata.
2023-02-03 09:41:24 +00:00
Lukas Wirth
8e998c4aa7 Fail spawning proc-macro servers when their api version is newer than r-a's 2023-02-03 10:38:38 +01:00
Ryo Yoshida
98c8077495
fix: support non-ascii characters in case conversion 2023-02-03 18:11:11 +09:00
bors
eeceba7480 Auto merge of #14065 - lowr:patch/generate-generic-function, r=Veykril
Support generic function in `generate_function` assist

Part of #3639

This PR adds support for generic function generation in `generate_function` assist. Now the assist looks for generic parameters and trait bounds in scope, filters out irrelevant ones, and generates new function with them.

See `fn_generic_params()` for the outline of the procedure, and see comments on `filter_unnecessary_bounds()` for criteria for filtering. I think it's good criteria for most cases, but I'm open to opinions and suggestions.

The diff is pretty big, but it should run in linear time w.r.t. the number of nodes we operate on and should be fast enough.

Some notes:
- When we generate function in an existing impl, generic parameters may cause name conflict. While we can detect the conflict and rename conflicting params, I didn't find it worthwhile mainly because it's really easy to resolve on IDE: use Rename functionality.
- I've implemented graph structure myself, because we don't have graph library as a dependency and we only need the simplest one.
  - Although `petgraph` is in our dependency graph and I was initially looking to use it, we don't actually depend on it AFAICT since it's only used in chalk's specialization graph handling, which we don't use. I'd be happy to replace my implementation with `petgraph` if it's okay to use it though.
- There are some caveats that I consider out of scope of this PR. See FIXME notes on added tests.
2023-02-02 09:06:22 +00:00
Ryo Yoshida
493cabbde7
Treat scope info retrieval failure as assist failure 2023-02-02 17:47:11 +09:00
bors
ccd142c616 Auto merge of #14058 - gftea:master, r=Veykril
fix negative trait bound in outline view (#14044)

try to fix and close #14044
2023-02-01 20:00:19 +00:00
Laurențiu Nicola
ff340f9c21 Bump zip 2023-02-01 19:24:32 +02:00
bors
7acc434f46 Auto merge of #14071 - Veykril:inlay-hints, r=Veykril
fix: Don't render fieldless discriminant inlay hints for datacarrying enums
2023-02-01 10:39:15 +00:00
Lukas Wirth
14f19c73e9 fix: Don't render fieldless discriminant inlay hints for datacarrying enums 2023-02-01 11:38:39 +01:00
bors
bfe82cda48 Auto merge of #14036 - Veykril:write-method-resolution, r=Veykril
Record method resolution for remaining operator expressions

This allows goto def and future substituted hover to work for the concrete impls.
2023-02-01 10:23:33 +00:00
Lukas Wirth
c40b0895f0 Implement proc-macro-api versioning 2023-02-01 11:04:20 +01:00
hkalbasi
0bf0d937b8 unsize cast array only on pointer type 2023-01-31 20:23:38 +03:30
Lukas Wirth
41a46a78f2 Make tt generic over the span data 2023-01-31 14:58:16 +01:00
Ryo Yoshida
3edde6fcc1
Support generic function in generate_function assist 2023-01-31 21:05:25 +09:00
Ryo Yoshida
32955c30cd
Add method to get generic parameters in a type 2023-01-31 21:05:23 +09:00
Ryo Yoshida
0df70d37fc
Minor refactoring 2023-01-31 21:05:04 +09:00
bors
577e839c0d Auto merge of #14063 - Veykril:proc-macro-abi-1-58, r=Veykril
feat: Remove support for 1.58 proc-macro abi

This seems old enough that we can drop the support for it now, the less ABIs we have the less work it is adjusting our span implementation.

Extracted from https://github.com/rust-lang/rust-analyzer/pull/14061, will rebase that over this once merged.
2023-01-31 11:17:29 +00:00
bors
06981d4b10 Auto merge of #14062 - WaffleLapkin:сurrent_edition, r=Veykril
internal: Set "current" edition to 2021

:p
2023-01-31 11:03:49 +00:00
Lukas Wirth
183f171263 Remove support for 1.58 proc-macro abi 2023-01-31 11:56:12 +01:00
Maybe Waffle
249ea9502d Set "current" edition to 2021 2023-01-31 10:51:43 +00:00
bors
b4832b3d00 Auto merge of #14056 - Veykril:allow_internal_unsafe, r=Veykril
Parse macros `allow_internal_unsafe` attribute

We don't use it for anything yet but it might become part of hygiene
2023-01-31 10:50:47 +00:00
bors
be76f357af Auto merge of #14034 - lnicola:tweak-change-collapsing, r=Veykril
internal: Tweak change collapsing

CC https://github.com/rust-lang/rust-analyzer/pull/14025#discussion_r1087946555.
2023-01-31 10:37:50 +00:00
gftea
fd1a9a93fe tidy by rustfmt 2023-01-30 20:34:07 +01:00
gftea
04a4ac1cff trim trailing whitespaces 2023-01-30 20:17:12 +01:00
gftea
5356a8b157 trim trailing whitespaces (#14044) 2023-01-30 20:03:50 +01:00
gftea
75676ebe86
Update crates/ide/src/file_structure.rs
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2023-01-30 19:17:48 +01:00
gftea
28b7460db1 fix negative trait bound in outline view (#14044) 2023-01-30 17:57:27 +01:00
Jonas Schievink
6321b25a21 Apply the assist to itself 2023-01-30 17:52:15 +01:00
Jonas Schievink
1f20804b6e Improve "match to let-else" assist 2023-01-30 17:50:02 +01:00