Commit Graph

438 Commits

Author SHA1 Message Date
Lukas Wirth
95c4cb991f Handle new hir block kinds in scope calculations 2023-03-04 15:22:39 +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
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
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
Lukas Wirth
ec273c3d12 Split pattern inference into more functions 2023-03-03 10:42:46 +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
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
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
9942cc425b Fix 14142: Annotate lifetime paramaters in doctest runnables 2023-02-27 18:08:17 +01:00
shilangyu
44e47fe408 Add check for extra path segments after an angled one 2023-02-25 16:16:49 +01: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
Lukas Wirth
026a8c976d Simplify 2023-02-15 13:38:42 +01: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
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
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
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
Laurențiu Nicola
354b1aaa50 Merge branch 'master' into sync-from-rust 2023-02-14 08:40:55 +02:00
Laurențiu Nicola
bc45c7659a ⬆️ rust-analyzer 2023-02-13 13:55:14 +02:00
Lukas Wirth
1be24e0899 internal: Improve parser recovery a bunch 2023-02-11 20:28:36 +01: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
e59487de38 Add tests for float access macro call inputs 2023-02-07 17:12:24 +01:00
Lukas Wirth
c6e7917d6e Fix up token_tree_to_syntax_node float split handling 2023-02-07 15:21:37 +01:00
Lukas Wirth
41a46a78f2 Make tt generic over the span data 2023-01-31 14:58:16 +01: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
Maybe Waffle
249ea9502d Set "current" edition to 2021 2023-01-31 10:51:43 +00:00
Lukas Wirth
c65782e64a Parse macros allow_internal_unsafe attribute 2023-01-30 15:41:08 +01:00
Lukas Wirth
4a677e91aa minor: Remove unnecessary arg in LowerCtx::ast_id 2023-01-25 21:52:28 +01:00
Lukas Wirth
f8ed4d7ae4 Use lang item resolution instead of known paths 2023-01-21 19:03:36 +01:00
Lukas Wirth
1535881836 Replace SmolStr usage with lang item enum for lang items 2023-01-21 17:55:45 +01:00
Laurențiu Nicola
392a6ee422 Bump once_cell 2023-01-21 08:48:46 +02:00
bors
fa874627f0 Auto merge of #13969 - Veykril:workspace.dependencies, r=Veykril
Use workspace.dependencies to declare local dependencies
2023-01-17 10:29:27 +00:00
bors
62907858d5 Auto merge of #13964 - Veykril:workspace.package, r=Veykril
Specify authors, edition, license and rust-versian via workspace.package
2023-01-17 10:13:24 +00:00
Lukas Wirth
bed4db3c62 Use workspace.dependencies to declare local dependencies 2023-01-17 10:52:26 +01:00
hkalbasi
77efa0267d Don't compute layout if TargetDataLayout is not available 2023-01-16 22:43:27 +03:30
Lukas Wirth
e4858fe480 Specify authors, edition and license via workspace.package 2023-01-16 16:44:00 +01:00
Lukas Wirth
679df2adf1 Specify rust-version via workspace.package 2023-01-16 16:33:01 +01:00
bors
cdbe025232 Auto merge of #13922 - danieleades:loop-that-never-loops, r=lnicola
minor: loop-that-never-loops

closes #13921
2023-01-13 11:23:51 +00:00
Daniel Eades
7413a9954f interior-mutable types should be 'static' rather than 'const 2023-01-12 10:48:10 +00:00
daniel.eades
a3114c3697 move loop index inside iterator 2023-01-11 16:07:35 +00:00
Albert Larsan
3e0e51c108 Change src/test to tests in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00
Daniel Eades
95fc3ba41c fixup 2023-01-10 19:51:21 +00:00
Daniel Eades
ac3844a0bb a number of code simplifications 2023-01-10 18:48:51 +00:00
bors
c3b78f440e Auto merge of #13917 - Veykril:raw-attrs, r=Veykril
Split out hir-def attribute handling parts into hir-expand

This should help with `cfg_attr` handling for macro inputs
2023-01-10 17:35:37 +00:00
Daniel Eades
6153ea8dce loop-that-never-loops 2023-01-10 08:28:28 +00:00
Lukas Wirth
621e96bd6a Encode one level of cfg_attr in attr_id 2023-01-09 21:06:13 +01:00
arcnmx
25242fe93f ⬆️ rust-analyzer
Merge commit '368e0bb32f1178cf162c2ce5f7e10b7ae211eb26'
2023-01-09 10:36:22 -08:00
Lukas Wirth
68723043db Split out hir-def attribute handling parts into hir-expand 2023-01-09 19:29:28 +01:00
bors
e125bee055 Auto merge of #13890 - lowr:fix/unescape-inline-mod-name, r=Veykril
fix: unescape inline module names in module resolution

Fixes #13884
2023-01-09 15:07:06 +00:00
Ryo Yoshida
21ea0048cd
fix: unescape inline module names in module resolution 2023-01-04 18:22:01 +09:00
Daniel Eades
4f8ffd0ba4 remove unnecessary lifetimes that can be elided 2023-01-02 15:02:54 +00:00
Daniel Eades
efd2c20e96 remove useless conversions 2023-01-02 15:02:54 +00:00
Daniel Eades
cc80c5bd07 remove unnecessary lazy evaluations 2023-01-02 15:02:54 +00:00
Daniel Eades
ed128872eb remove needless borrows 2023-01-02 14:52:32 +00:00
Daniel Eades
77051679d7 use inline format args 2023-01-02 14:52:32 +00:00
bors
790759fb11 Auto merge of #13854 - lowr:fix/mbe-glue-punct, r=Veykril
Support multi-character punct tokens in MBE

Fixes #11497

In the context of MBE, consecutive puncts are parsed as multi-character punct tokens whenever possible. For example, `:::` is parsed as ``[Punct(`::`), Punct(`:`)]`` and shouldn't get matched to patterns like `: : :` or `: ::`.

We have implemented this behavior only for when we match puncts against `tt` fragments, but not when we match puncts literally. This PR extracts the multi-character punct handling procedure into a separate method and extends its support for literal matching.

For good measure, this PR adds support for `<-` token, which is still [considered as one token in rustc](e396186407/compiler/rustc_ast/src/token.rs (L249)) despite the placement syntax having been removed.
2023-01-02 13:07:42 +00:00
Ryo Yoshida
cf2fa14db5
fix: prefix prelude items whose name collides in current scope 2023-01-02 20:50:45 +09:00
Lukas Wirth
eee7de0225 Diagnose private assoc item accesses 2023-01-01 13:24:48 +01:00
bors
0d76b94c90 Auto merge of #13866 - Nilstrieb:rustc_safe_intrinsic, r=Veykril
Use `rustc_safe_intrinsic` attribute to check for intrinsic safety

Instead of maintaining a list that is poorly kept in sync we can just use the attribute.

This will make new RA versions unusable with old toolchains that don't have the attribute yet. Should we keep maintaining the list as a fallback or just don't care?
2022-12-30 22:14:31 +00:00
Nilstrieb
72afcf2cad Use rustc_safe_intrinsic attribute to check for intrinsic safety
Instead of maintaining a list that is poorly kept in sync we can just
use the attribute.
2022-12-30 20:29:37 +01:00
Maybe Waffle
346bf5fb5b Implement do yeet expression 2022-12-28 23:17:13 +00:00
Ryo Yoshida
ec7148b091
mbe: split Op::Leaf and handle multi-character puncts 2022-12-27 18:23:01 +09:00
Yuri Astrakhan
e16c76e3c3 Inline all format arguments where possible
This makes code more readale and concise,
moving all format arguments like `format!("{}", foo)`
into the more compact `format!("{foo}")` form.

The change was automatically created with, so there are far less change
of an accidental typo.

```
cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2022-12-24 14:36:10 -05:00
Yuri Astrakhan
e341e996f7 Clippy-fix explicit auto-deref
Seems like these can be safely fixed. With one, I was particularly
surprised -- `Some(pats) => &**pats,` in body.rs?

```
cargo clippy --fix -- -A clippy::all -D clippy::explicit_auto_deref
```
2022-12-23 02:52:14 -05:00
Yuri Astrakhan
1d59c7b667 Remove non-needed clones
I am not certain if this will improve performance,
but it seems having a .clone() without any need should be removed.

This was done with clippy, and manually reviewed:

```
cargo clippy --fix -- -A clippy::all -D clippy::redundant_clone
```
2022-12-23 02:20:03 -05:00
bors
113f17be6e Auto merge of #13818 - Veykril:layout, r=Veykril
Simplify
2022-12-21 20:38:57 +00:00
Lukas Wirth
8f8200eb14 Simplify 2022-12-21 21:34:01 +01:00
bors
c2840c809a Auto merge of #13814 - Veykril:layout, r=Veykril
Calculate the TargetDataLayout correctly for the selected target

This fails the tests still since those don't call into rustc yet
2022-12-21 19:38:51 +00:00
Lukas Wirth
33591cd3f4 Calculate the TargetDataLayout correctly for the selected target 2022-12-21 15:11:24 +01:00
Ryo Yoshida
e027ac0fbf
fix: don't let mbe expr fragments match let exprs and inline consts 2022-12-20 20:31:47 +09:00
bors
6e8a54d0f6 Auto merge of #13490 - HKalbasi:layout, r=jonas-schievink
Compute data layout of types

cc #4091

Things that aren't working:
* Closures
* Generators (so no support for `Future` I think)
* Opaque types
* Type alias and associated types which may need normalization

Things that show wrong result:
* ~Enums with explicit discriminant~
* SIMD types
* ~`NonZero*` and similar standard library items which control layout with special attributes~

At the user level, I didn't put much work, since I wasn't confident about what is the best way to present this information. Currently it shows size and align for ADTs, and size, align, offset for struct fields, in the hover, similar to clangd. I used it some days and I feel I liked it, but we may consider it too noisy and move it to an assist or command.
2022-12-07 15:22:03 +00:00
hkalbasi
05906da0ec use rustc crates instead of copy paste 2022-12-07 01:59:38 +03:30
Ryo Yoshida
051c6598be
Resolve macro2's derive helpers in IDE layer
Macro2's generally don't have derive helpers, but currently builtin
derive macros are declared with macro2 syntax, which can have derive
helpers.
2022-12-06 16:01:20 +09:00
Ryo Yoshida
cf54b8c3a4
Parse and collect derive helpers for builtin derive macros 2022-12-06 16:00:46 +09:00
Lukas Wirth
ca1389ef9f Support rustc_has_incoherent_inherent_impls 2022-12-04 20:37:17 +01:00
hkalbasi
86b5b609f1 Compute data layout of types 2022-12-04 00:29:34 +03:30
bors
b651646510 Auto merge of #13676 - fasterthanlime:subtree-fix, r=Veykril
Mega-sync from `rust-lang/rust`

This essentially implements `@oli-obk's` suggestion here https://github.com/rust-lang/rust-analyzer/pull/13459#issuecomment-1297285607, with `@eddyb's` help.

This PR is equivalent to 14 syncs (back and forth) between `rust-lang/rust` and `rust-lang/rust-analyzer`.

Working from this list (from bottom to top):

```
(x) a2a1d9954 ⬆️ rust-analyzer
(x) 79923c382 ⬆️ rust-analyzer
(x) c60b1f641 ⬆️ rust-analyzer
(x) 8807fc4cc ⬆️ rust-analyzer
(x) a99a48e78 ⬆️ rust-analyzer
(x) 4f55ebbd4 ⬆️ rust-analyzer
(x) f5fde4df4 ⬆️ rust-analyzer
(x) 459bbb422 ⬆️ rust-analyzer
(x) 65e1dc4d9 ⬆️ rust-analyzer
(x) 3e358a682 ⬆️ rust-analyzer
(x) 31519bb39 ⬆️ rust-analyzer
(x) 8231fee46 ⬆️ rust-analyzer
(x) 22c8c9c40 ⬆️ rust-analyzer
(x) 9d2cb42a4 ⬆️ rust-analyzer
```

(This listed was assembled by doing a `git subtree push`, which made a branch, and looking at the new commits in that branch, picking only those that were `⬆️ rust-analyzer` commits)

We used the following commands to simulate merges in both directions:

```shell
TO_MERGE=22c8c9c40 # taken from the list above, bottom to top
git merge --no-edit --no-ff $TO_MERGE
git merge --no-edit --no-ff $(git -C ../rust log --pretty=format:'%cN | %s | %ad => %P' | rg -m1 -F "$(git show --no-patch --pretty=format:%ad $TO_MERGE)" | tee /dev/stderr | rg '.* => \S+ (\S+)$' --replace '$1')
```

We encountered no merge conflicts that Git wasn't able to solve by doing it this way.

Here's what the commit graph looks like (as shown in the Git Lens VSCode extension):

<img width="1345" alt="image" src="https://user-images.githubusercontent.com/7998310/203984523-7c1a690a-8224-416c-8015-ed6e49667066.png">

This PR closes #13459

## Does this unbreak `rust->ra` syncs?

Yes, here's how we tried:

In `rust-analyzer`:

  * check out `subtree-fix` (this PR's branch)
  * make a new branch off of it: `git checkout -b subtree-fix-merge-test`
  * simulate this PR getting merged with `git merge master`

In `rust`:

  * pull latest master
  * make a new branch: `git checkout -b test-change`
  * mess with rust-analyzer (I added a comment to `src/tools/rust-analyzer/Cargo.toml`)
  * commit
  * run `git subtree push -P src/tools/rust-analyzer ra-local final-sync` (this follows the [Clippy sync guide](https://doc.rust-lang.org/nightly/clippy/development/infrastructure/sync.html))

This created a `final-sync` branch in `rust-analyzer`.

In `rust-analyzer`:

  * `git merge --no-ff final-sync` (this follows the [Clippy sync guide](https://doc.rust-lang.org/nightly/clippy/development/infrastructure/sync.html))

Now `git log` in `rust-analyzer` shows this:

```
commit 460128387e46ddfc2b95921b2d7f6e913a3d2b9f (HEAD -> subtree-fix-merge-test)
Merge: 0513fc02a 9ce6a734f
Author: Amos Wenger <amoswenger@gmail.com>
Date:   Fri Nov 25 13:28:24 2022 +0100

    Merge branch 'final-sync' into subtree-fix-merge-test

commit 0513fc02a08ea9de952983624bd0a00e98044b36
Merge: 38c98d1ff 6918009fe
Author: Amos Wenger <amoswenger@gmail.com>
Date:   Fri Nov 25 13:28:02 2022 +0100

    Merge branch 'master' into subtree-fix-merge-test

commit 9ce6a734f37ef8e53689f1c6f427a9efafe846bd (final-sync)
Author: Amos Wenger <amoswenger@gmail.com>
Date:   Fri Nov 25 13:26:26 2022 +0100

    Mess with rust-analyzer just for fun
```

And `git diff 0513fc02a08ea9de952983624bd0a00e98044b36` shows this:

```patch
diff --git a/Cargo.toml b/Cargo.toml
index 286ef1e7d..c9e24cd19 100644
--- a/Cargo.toml
+++ b/Cargo.toml
`@@` -32,3 +32,5 `@@` debug = 0
 # ungrammar = { path = "../ungrammar" }

 # salsa = { path = "../salsa" }
+
+# lol, hi
```

## Does this unbreak `ra->rust` syncs?

Yes, here's how we tried.

From `rust`:

  * `git checkout -b sync-from-ra`
  * `git subtree pull -P src/tools/rust-analyzer ra-local subtree-fix-merge-test` (this is adapted from the [Clippy sync guide](https://doc.rust-lang.org/nightly/clippy/development/infrastructure/sync.html#performing-the-sync-from-clippy-to-rust-langrust), you would normally use `ra-upstream master` but we're simulating things here)

A commit editor pops up, there was no merge conflicts.

## How do we prevent this from happening again?

Like `@bjorn3` said in https://github.com/rust-lang/rust-analyzer/pull/13459#issuecomment-1293587848

> Whenever syncing from rust-analyzer -> rust you have to immediately sync the merge commit from rust -> rust-analyzer to prevent merge conflicts in the future.

But if we get it wrong again, at least now we have a not-so-painful way to fix it.
2022-11-25 21:27:46 +00:00
Amos Wenger
e96c0b1d53 Merge commit 'a2a1d9954' into HEAD 2022-11-25 13:06:31 +01:00
Amos Wenger
ae43043aab Merge commit '79923c382' into HEAD 2022-11-25 13:06:01 +01:00
Amos Wenger
e070dc5129 Merge commit 'c60b1f641' into HEAD 2022-11-25 13:05:26 +01:00
Amos Wenger
2f65294569 Merge commit '8807fc4cc' into HEAD 2022-11-25 13:04:50 +01:00
Amos Wenger
251b18ac6c Merge commit 'a99a48e78' into HEAD 2022-11-25 13:03:59 +01:00
Amos Wenger
e6540cff74 Merge commit '4f55ebbd4' into HEAD 2022-11-25 13:03:10 +01:00
Amos Wenger
969e25033b Merge commit 'f5fde4df4' into HEAD 2022-11-25 13:02:44 +01:00
Amos Wenger
318fdacaf8 Merge commit '65e1dc4d9' into HEAD 2022-11-25 12:58:18 +01:00
Amos Wenger
ff2b468b55 Merge commit '3e358a682' into HEAD 2022-11-25 12:58:00 +01:00
Amos Wenger
6ac43ecf17 Merge commit '31519bb39' into HEAD 2022-11-25 12:57:38 +01:00
Amos Wenger
2374c0b368 Merge commit '8231fee46' into HEAD 2022-11-25 12:55:08 +01:00
Amos Wenger
db84a00d03 Merge commit '22c8c9c40' into HEAD 2022-11-25 12:13:34 +01:00
Amos Wenger
2566e06da1 Merge commit '8e38833c3674c1be7d81c6069c62e6ed52b18b27' into HEAD 2022-11-25 12:01:49 +01:00
Laurențiu Nicola
a2a1d99545 ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
Jake Heinz
427b63b676 hir-expand: fix compile_error! expansion not unquoting strings 2022-11-20 08:48:27 +00:00
Lukas Wirth
6674bd898e fix: Add trait alias grammar to rust.ungram 2022-11-11 15:25:15 +01:00
bors
57cc2a6e27 Auto merge of #13602 - lowr:fix/nameres-transitive-visibility, r=Veykril
fix: check visibility of each path segment

Upon path resolution, we have not been checking if every def pointed to by each segment of the path is visible from the original module. This leads to incorrect import resolutions, in particular when one uses glob imports and names collide.

There is decent amount of changes in this PR because:
- some of our tests were not correct in terms of visibility
  - I left several basic nameres tests as-is (with expect test updated) since I thought it would be nice to ensure we don't resolve defs that are not visible.
- `fix_visibility` assist relied on `Semantics::resolve_path()`, which uses the name resolution procedure I'm fixing and wouldn't be able to "see through" the items with strict visibility with this patch

The first commit is the gist of the fix itself.

Fixes #10991
Fixes #11473
Fixes #13252
2022-11-11 12:32:21 +00:00
bors
6f313cef8e Auto merge of #13548 - lowr:fix/tt-punct-spacing, r=Veykril
Fix `tt::Punct`'s spacing calculation

Fixes #13499

We currently set a `tt::Punct`'s spacing to `Spacing::Joint` unless its next token is a trivia (i.e. whitespaces or comment). As I understand it, rustc only [sets `Spacing::Joint` if the next token is an operator](5b3e909075/compiler/rustc_parse/src/lexer/tokentrees.rs (L77-L78)) and we should follow it to guarantee the consistent behavior of proc macros.
2022-11-11 12:19:30 +00:00
Ryo Yoshida
19306c070d
Fix tests that depended on loose visibility restriction 2022-11-11 20:31:46 +09:00
Ryo Yoshida
dea49d0826
fix: check visibility of each segment in path resolution 2022-11-11 20:31:37 +09:00
Laurențiu Nicola
79923c382a ⬆️ rust-analyzer 2022-11-09 21:49:10 +02:00
Lukas Wirth
ffd7bf8bf9 Bump Cargo rust-version fields to latest stable 2022-11-07 12:59:51 +01:00
Ryo Yoshida
41b0c54c07
Fix tt::Punct's spacing calculation 2022-11-05 19:42:09 +09:00
Lukas Wirth
6f09c72b1b Lower unsafety of fn pointer and fn item types 2022-11-04 21:07:15 +01:00
Laurențiu Nicola
c60b1f6414 ⬆️ rust-analyzer 2022-11-01 11:31:31 +02:00
Ryo Yoshida
63cba43b48
Collect generic arguments in associated type bindings 2022-10-27 19:18:59 +09:00
Laurențiu Nicola
8807fc4cc3 ⬆️ rust-analyzer 2022-10-26 17:40:41 +03:00
Ryo Yoshida
6459d7f817
Support const generics for builtin derive macro 2022-10-23 00:05:22 +09:00
Laurențiu Nicola
a99a48e786 ⬆️ rust-analyzer 2022-10-18 09:12:49 +03:00
bors
855cd5c280 Auto merge of #13418 - lnicola:bump-deps, r=lnicola
Bump deps
2022-10-15 11:27:12 +00:00
Laurențiu Nicola
3a5f6a705e Bump dashmap 2022-10-15 12:54:25 +03:00
Laurențiu Nicola
50f990c46f Bump smallvec 2022-10-15 12:52:34 +03:00
Laurențiu Nicola
cbce0cda08 Bump anyhow, arbitrary, itertools, semver, serde 2022-10-15 12:52:34 +03:00
Ralf Jung
8536eb016c rename rustc_allocator_nounwind to rustc_nounwind 2022-10-11 22:47:31 +02:00
Laurențiu Nicola
4f55ebbd4f ⬆️ rust-analyzer 2022-10-11 10:37:35 +03:00
bors
21319d135f Auto merge of #13329 - Veykril:rustc-proc-macro, r=Veykril
Use $crate instead of std for panic builtin_fn_macro

This should be closer to the expected output and gets rid of a few type mismatches in rustc/library
2022-10-10 21:35:07 +00:00
Lukas Wirth
1574fe0d54 Use $crate instead of std for panic builtin_fn_macro
This should be closer to the expected output and gets rid of a few
type mismatches in rustc/library
2022-10-10 10:33:49 +02:00
Lukas Wirth
63ed71bd30 Honor cfg attributes on params when lowering their patterns 2022-10-10 09:47:09 +02:00
Laurențiu Nicola
df7d39b2ed Bump once_cell 2022-10-08 21:25:11 +03:00
bors
b01cdd89d5 Auto merge of #13189 - unexge:unconfigured-diagnostics-for-fields, r=Veykril
Emit unconfigured code diagnostics for enum variants and struct/union fields

Fixes https://github.com/rust-lang/rust-analyzer/issues/12664
2022-09-27 12:59:45 +00:00
bors
8c7e37697f Auto merge of #13275 - Veykril:find-path, r=Veykril
Fix find_path using the wrong module for visibility calculations
2022-09-27 01:14:02 +00:00
unexge
3a8d84b4a3 Use Arc<[DefDiagnostic]> instead of Arc<Vec<DefDiagnostic>> 2022-09-26 19:16:02 +01:00
unexge
b21bf25a07 Collect diagnostics in queries instead of nameres 2022-09-26 19:06:29 +01:00
unexge
89107d5469 Emit unconfigured code diagnostics for fields 2022-09-26 19:04:57 +01:00
bors
1f929659ac Auto merge of #13209 - lowr:feat/inference-for-generator, r=Veykril
feat: type inference for generators

This PR implements basic type inference for generator and yield expressions.

Things not included in this PR:
- Generator upvars and generator witnesses are not implemented. They are only used to determine auto trait impls, so basic type inference should be fine without them, but method resolutions with auto trait bounds may not be resolved correctly.

Open questions:
- I haven't (yet) implemented `HirDisplay` for `TyKind::Generator`, so generator types are just shown as "{{generator}}" (in tests, inlay hints, hovers, etc.), which is not really nice. How should we show them?
- I added moderate amount of stuffs to minicore. I especially didn't want to add `impl<T> Deref for &T` and `impl<T> Deref for &mut T` exclusively for tests for generators; should I move them into the test fixtures or can they be placed in minicore?

cc #4309
2022-09-26 09:28:41 +00:00
Lukas Wirth
7ec9ffa325 Properly support IDE functionality in enum variants 2022-09-24 02:33:59 +02:00
Lukas Wirth
729a9eb5d0 Fix find_path using the wrong module for visibility calculations 2022-09-22 17:56:58 +02:00
Lukas Wirth
9bf386f4c0 Fix default enum representation not being isize 2022-09-20 17:50:13 +02:00
Lukas Wirth
2119c1f351 Fix using incorrect type for variants in DefWithBody::body_type 2022-09-20 17:29:35 +02:00
Lukas Wirth
9f233cd5d2 Parse more repr options 2022-09-20 17:12:27 +02:00
Laurențiu Nicola
f5fde4df43 ⬆️ rust-analyzer 2022-09-20 17:39:17 +03:00
bors
817a6a8609 Auto merge of #12966 - OleStrohm:master, r=Veykril
feat: Display the value of enum variant on hover

fixes #12955

This PR adds const eval support for enums, as well as showing their value on hover, just as consts currently have.

I developed these two things at the same time, but I've realized now that they are separate. However since the hover is just a 10 line change (not including tests), I figured I may as well put them in the same PR. Though if you want them split up into "enum const eval support"  and "show enum variant value on hover", I think that's reasonable too.

Since this adds const eval support for enums this also allows consts that reference enums to have their values computed now too.

The const evaluation itself is quite rudimentary, it doesn't keep track of the actual type of the enum, but it turns out that Rust doesn't actually either, and `E::A as u8` is valid regardless of the `repr` on `E`.

It also doesn't really care about what expression the enum variant contains, it could for example be a string, despite that not being allowed, but I guess it's up to the `cargo check` diagnostics to inform of such issues anyway?
2022-09-20 14:01:16 +00:00
bors
39eaf7864c Auto merge of #13253 - Veykril:simplify, r=Veykril
Simplify
2022-09-18 17:52:21 +00:00
Lukas Wirth
0d9f97166b Simplify 2022-09-18 19:44:38 +02:00
Lukas Wirth
a9f103e2fa Fix prelude injection 2022-09-15 12:12:22 +02:00
Lukas Wirth
a8ecaa1979 Restructure find_path into a separate functions for modules and non-module items
Also renames `prefer_core` imports config to `prefer_no_std` and changes the behavior of no_std path searching by preferring `core` paths `over` alloc
2022-09-13 15:15:27 +02:00
OleStrohm
177ec82a41 Rebased 2022-09-12 21:02:30 +01:00
OleStrohm
ad0a6bf1a3 Added consteval tests 2022-09-12 20:20:43 +01:00
OleStrohm
2f84b6e2e5 Almost there 2022-09-12 20:20:22 +01:00
OleStrohm
997fc46efa Implemented basic enum const eval 2022-09-12 20:19:13 +01:00
Lukas Wirth
7d19971666 Add config to unconditionally prefer core imports over std
Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-09 20:04:56 +02:00
Ryo Yoshida
ba64c93a44
Lower generator expression to HIR 2022-09-09 16:47:32 +09:00
Laurențiu Nicola
65e1dc4d9c ⬆️ rust-analyzer 2022-09-06 21:20:49 +03:00
Lukas Wirth
894aa0ed0d Clarify the state of (extern) preludes for block def maps 2022-09-02 17:43:20 +02:00
Lukas Wirth
8828049b23 Lift out the module scope into a field in the Resolver
A Resolver *always* has a module scope at the end of its scope stack,
instead of encoding this as an invariant we can just lift this scope
out into a field, allowing us to skip going through the scope vec
indirection entirely.
2022-09-02 17:02:12 +02:00
bors
2bb6635a85 Auto merge of #13173 - Veykril:synthetic, r=Veykril
Don't store SyntheticSyntax in the reverse maps in BodySourceMap

They are ZSTs which we can just create on missing access instead.
2022-09-02 13:17:16 +00:00
Lukas Wirth
fe0a106256 Don't store SyntheticSyntax in the reverse maps in BodySourceMap
They are ZSTs which we can just create on missing access instead.
2022-09-02 15:08:48 +02:00
bors
4f8153e4a5 Auto merge of #13167 - iDawer:exhaustive_patterns, r=Veykril
feat: Implement `feature(exhaustive_patterns)` from unstable Rust

Closes #12753

Recognize Rust's unstable `#![feature(exhaustive_patterns)]` (RFC 1872). Allow omitting visibly uninhabited variants from `match` expressions when the feature is on.

This adjusts match checking to the current implementation of the postponed RFC 1872 in rustc.
2022-09-02 12:32:36 +00:00
iDawer
8ae58b9fe4 Record enabled unstable features into DefMap 2022-09-02 16:31:15 +05:00
Lukas Wirth
ee02a4721b Remove unnecessary allocations 2022-08-31 18:05:52 +02:00
Lukas Wirth
192a79c235 Remove hir::Expr::MacroStmts
This hir expression isn't needed and only existed as it was simpler to
deal with at first as it gave us a direct mapping for the ast version of
the same construct. This PR removes it, properly handling the statements
that are introduced by macro call expressions.
2022-08-31 16:58:11 +02:00
Ryo Yoshida
662ab0cd8e
fix: unescape all occurrences of module name in module resolution 2022-08-31 03:51:37 +09:00
Laurențiu Nicola
3e358a6827 ⬆️ rust-analyzer 2022-08-30 14:51:24 +03:00
Lukas Wirth
d025c5d8d6 Make use of NoHash hashing for FileId and CrateId 2022-08-25 20:41:49 +02:00
Laurențiu Nicola
31519bb394 ⬆️ rust-analyzer 2022-08-23 10:05:52 +03:00
bors
dea163970a Auto merge of #12965 - DesmondWillowbrook:assoc-method-dimming, r=Veykril
feat: make trait assoc items become inactive due to cfg

fixes #12394
2022-08-22 07:20:56 +00:00
Kartavya Vashishtha
23c00ed50d
fix: formatting 2022-08-20 13:44:01 +05:30
Kartavya Vashishtha
8f87fcb179
remove push_diagnostic methods
weren't used in the end
2022-08-20 13:30:25 +05:30
Kartavya Vashishtha
87b779756c
make impl and trait inactive diagnostics work 2022-08-20 13:28:43 +05:30
Dezhi Wu
23747419ca fix: a bunch of typos
This PR will fix some typos detected by [typos].

There are also some other typos in the function names, variable names, and file
names, which I leave as they are. I'm more certain that typos in comments
should be fixed.

[typos]: https://github.com/crate-ci/typos
2022-08-17 21:44:58 +08:00
Laurențiu Nicola
8231fee466 ⬆️ rust-analyzer 2022-08-16 11:24:50 +03:00
bors
3903243192 Auto merge of #13027 - jonas-schievink:fix-mismatch-with-trailing-empty-macro, r=jonas-schievink
fix: Fix incorrect type mismatch with `cfg_if!` and other macros in expression position

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

This is a bit of a hack, ideally `MacroStmts` would not exist at all after HIR lowering, but that requires changing how the lowering code works.
2022-08-15 16:06:59 +00:00
Jonas Schievink
8c60813096 Fix lowering of empty macro expressions in trailing position 2022-08-15 18:01:58 +02:00
bors
3561433ef2 Auto merge of #13026 - Veykril:nameres, r=Veykril
internal: Make `resolve_name_in_module` a bit more lazy
2022-08-15 14:49:12 +00:00
Lukas Wirth
88b19cc39b Make resolve_name_in_module a bit more lazy 2022-08-15 16:41:51 +02:00
Jonas Schievink
dcbe892d7c Add an HIR pretty-printer 2022-08-15 13:51:45 +02:00
Ryo Yoshida
8fe73a2240
Make tests pass 2022-08-11 01:16:35 +09:00
Edwin Cheng
c47914c6cf Fixes tests 2022-08-10 16:29:23 +08:00
Laurențiu Nicola
22c8c9c401 ⬆️ rust-analyzer 2022-08-09 07:23:57 +03:00
bors
b569bbbacc Auto merge of #12942 - lowr:fix/concat-with-char, r=Veykril
fix: make `concat!` work with char

Fixes #12921

- I avoided making `unquote_str()` take char literals as well because it's depended on by another function `parse_string()` that's only supposed to take strings.
- Even with this patch, we don't output `\0` as `\u{0}` which #12921 pointed out ~~, but we're not actually responsible for serializing it but rowan is~~. They are functionally equivalent and I don't think it'd cause any confusion, but we *could* try escaping them before serialization (for reference, `rustc -Zunpretty=expanded`, which `cargo expand` uses under the hood, [makes use of `str::escape_default()`](3830ecaa8d/compiler/rustc_ast/src/util/literal.rs (L161)).
2022-08-08 11:28:42 +00:00
Kartavya Vashishtha
c1eae3d028
make diagnostic function public 2022-08-08 16:45:27 +05:30
Kartavya Vashishtha
196f389a70
try adding diagnostrics for AssocItems 2022-08-08 16:40:29 +05:30
oxalica
326ffee5b7 Returns the old value for la_arena::ArenaMap::insert 2022-08-07 04:53:23 +08:00
Ryo Yoshida
4d5873e92f
minor: align with rustc on escaping characters in macro expansion 2022-08-05 22:01:09 +09:00
Ryo Yoshida
859d467276
fix: make concat! work with char 2022-08-05 02:58:16 +09:00
Laurențiu Nicola
9d2cb42a41 ⬆️ rust-analyzer 2022-08-02 09:05:16 +03:00
Jonas Schievink
bd7dfac5eb Fix r-a spelling in some places 2022-08-01 13:47:09 +02:00
bors
af646621de Auto merge of #12916 - Veykril:nits, r=Veykril
minor: Properly cfg the `max` field of Limit
2022-07-31 17:42:10 +00:00
Lukas Wirth
3b2ecf44a0 Give variables more descriptive names 2022-07-31 19:27:34 +02:00
Lukas Wirth
618cfd792c fix: Fix ast-id up when merging raw attributes 2022-07-30 09:43:30 +02:00
Lukas Wirth
f867ddc621 fix: Order ItemScope::entries results 2022-07-28 19:28:56 +02:00
Amos Wenger
a1f1b95d00 Merge commit 'e36a20c24f35a4cee82bbdc600289104c9237c22' into ra-sync-and-pms-component 2022-07-26 11:53:50 +02:00
Lukas Wirth
ddad2847ab Allow name querying for derive helpers 2022-07-26 09:27:22 +02:00
Lukas Wirth
aa1491ecde Record derive helper attributes, resolve them in IDE layer 2022-07-26 09:26:51 +02:00
Lukas Wirth
4e60db2d07 feat: Downmap tokens inside derive helpers 2022-07-26 09:26:47 +02:00
Amos Wenger
dc94050815 revert nightly rustfmt formatting that accidentally slipped in
cf. https://github.com/rust-lang/rust/pull/99603
cf. https://github.com/rust-lang/rust-analyzer/pull/12871#discussion_r928816339
2022-07-25 14:18:30 +02:00
Amos Wenger
0d04e63627 Merge remote-tracking branch 'origin/master' into sync-from-rust-2 2022-07-25 14:07:07 +02:00
Amos Wenger
dfe84494c1 Make macros test order-resistant 2022-07-24 16:48:06 +02:00
Amos Wenger
56c369db48 Sort when iterating through CrateGraph 2022-07-24 16:11:05 +02:00
Amos Wenger
d8c0d88e4f Sort in DefMap::dump, since HashMap iteration order isn't defined 2022-07-24 16:04:20 +02:00
Amos Wenger
ff317858c1 hir-def tests: sort results before comparing, since FxHashSet iteration order isn't guaranteed
(And, in fact, it failed on i686)
2022-07-24 15:55:26 +02:00
Ryo Yoshida
64758bd481
Add info whether it's assignee expr to relevant HIR Expr variants 2022-07-24 22:40:00 +09:00
Ryo Yoshida
fb063d360c
Add ellipsis to HIR RecordLit 2022-07-24 17:10:31 +09:00