Commit graph

31254 commits

Author SHA1 Message Date
Shoyu Vanilla
d7431ecdfa fix: Wrong BoundVar index when lowering impl trait parameter of parent generics 2024-08-17 22:33:27 +09:00
bors
e4edf6ca94 Auto merge of #17917 - ShoyuVanilla:pin-rowan, r=lnicola
Pin `rowan` to `0.15.15`

To prevent #17914, I think that it would be safer pinning this before we fix it correctly
2024-08-17 12:40:17 +00:00
Shoyu Vanilla
95470c250a Pin rowan to 0.15.15 2024-08-17 21:35:07 +09:00
bors
07659783fd Auto merge of #17909 - darichey:remove-discoverProjectRunner, r=lnicola
Remove rust-analyzer.workspace.discoverProjectRunner

The functionality for this vscode config option was removed in #17395, so it doesn't do anything anymore.
2024-08-16 14:58:43 +00:00
David Richey
ac6a3f82cd Remove rust-analyzer.workspace.discoverProjectRunner 2024-08-16 09:50:45 -05:00
bors
7f77e09fbe Auto merge of #17900 - darichey:exclude-vendored-libraries, r=davidbarsky
Add scip/lsif flag to exclude vendored libaries

#17809 changed StaticIndex to include vendored libraries. This PR adds a flag to disable that behavior.

At work, our monorepo has too many rust targets to index all at once, so we split them up into several shards. Since all of our libraries are vendored, if rust-analyzer includes them, sharding no longer has much benefit, because every shard will have to index the entire transitive dependency graphs of all of its targets. We get around the issue presented in #17809 because some other shard will index the libraries directly.
2024-08-16 14:25:36 +00:00
bors
c9ee892263 Auto merge of #17905 - ChayimFriedman2:edition-dependent-raw-keyword, r=Veykril
fix: Properly account for editions in names

This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now.

The rules of thumb are:

 - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code.
 - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn).
 - For debugging tools (helper methods and logs), I used `Edition::LATEST`.

Reviewing notes:

This is a really big PR but most of it is mechanical translation. I changed `Name` displayers to require an edition, and followed the compiler errors. Most methods just propagate the edition requirement. The interesting cases are mostly in `ide-assists`, as sometimes the correct crate to fetch the edition from requires awareness (there may be two). `ide-completions` and `ide-diagnostics` were solved pretty easily by introducing an edition field to their context. `ide` contains many features, for most of them it was propagated to the top level function and there the edition was fetched based on the file.

I also fixed all FIXMEs from #17896. Some required introducing an edition parameter (usually not for many methods after the changes to `Name`), some were changed to a new method `is_any_identifier()` because they really want any possible keyword.

Fixes #17895.
Fixes #17774.
2024-08-16 13:49:32 +00:00
Chayim Refael Friedman
9d3368f2c2 Properly account for editions in names
This PR touches a lot of parts. But the main changes are changing
`hir_expand::Name` to be raw edition-dependently and only when necessary
(unrelated to how the user originally wrote the identifier),
and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware
(this was done in #17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly
escape (or not escape) identifiers now.

The rules of thumb are:

 - If we show the identifier to the user, its rawness should be determined
   by the edition of the edited crate. This is nice for IDE features,
   but really important for changes we insert to the source code.
 - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update
   tests when an edition becomes stable, to avoid churn).
 - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
2024-08-16 16:46:24 +03:00
bors
ed5c260fc6 Auto merge of #17595 - dfireBird:infer-lt, r=flodiebold
Implement lifetime inferring
2024-08-16 12:09:18 +00:00
dfireBird
8a4261aca8
implement basic inferring of lifetimes 2024-08-16 16:40:32 +05:30
bors
4cd8dcf287 Auto merge of #17903 - tmandry:graceful-exit, r=Veykril
Allow flycheck process to exit gracefully

Assuming it isn't cancelled. Closes #17902.

The only place CommandHandle::join() is used is when the flycheck command
finishes, so this commit changes the behavior of the method itself.

The only reason I can see for the existing behavior is if the command is somehow holding onto a build lock longer than it should, this would force it to be released. But it would be a pretty heavy-handed way to solve that issue. I'm not aware of this occurring in practice.
2024-08-16 07:35:16 +00:00
bors
28b6838a0e Auto merge of #17908 - ChayimFriedman2:usages-word-boundaries, r=Veykril
Test for word boundary in `FindUsages`

This speeds up short identifiers search significantly, while unlikely to have an effect on long identifiers (the analysis takes much longer than some character comparison).

Tested by finding all references to `eq()` (from `PartialEq`) in the rust-analyzer repo. Total time went down from 100s to 10s (a 10x reduction!).

Feel free to close this if you consider this a non-issue, as most short identifiers are local.
2024-08-16 07:20:23 +00:00
bors
fc36e0ca16 Auto merge of #17907 - ChayimFriedman2:no-once_cell, r=Veykril
internal: Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/Lock

This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-16 07:05:59 +00:00
Chayim Refael Friedman
1a31fe299b Test for word boundary in FindUsages
This speeds up short identifiers search significantly, while unlikely to have an effect on long identifiers (the analysis takes much longer than some character comparison).

Tested by finding all references to `eq()` (from `PartialEq`) in the rust-analyzer repo. Total time went down from 100s to 10s (a 10x reduction!).
2024-08-16 10:02:36 +03:00
Chayim Refael Friedman
955e609867 Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/Lock
This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-16 09:53:37 +03:00
Tyler Mandry
da34676104 Allow flycheck process to exit gracefully
Assuming it isn't cancelled. Closes #17902.

The only place CommandHandle::join is used is when the flycheck command
finishes, so this commit changes the behavior of the method itself.
2024-08-15 15:18:15 -07:00
David Richey
e257b9880f Add scip/lsif flag to exclude vendored libaries 2024-08-15 17:00:31 -05:00
bors
91aa3f46b3 Auto merge of #17896 - Veykril:editioned-syntax-kinds, r=Veykril
internal: Properly check the edition for edition dependent syntax kinds

This puts the current edition in a bunch of places, most of which I annoted with FIXMEs asside from the ones in ide-assists because I couldnt bother with those
2024-08-15 14:11:09 +00:00
Lukas Wirth
f90bdfc13d internal: Properly check the edition for edition dependent syntax kinds 2024-08-15 15:57:47 +02:00
bors
2b86639018 Auto merge of #17893 - ShoyuVanilla:issue-17871, r=flodiebold
fix: Panic while hovering associated function with type annotation on generic param that not inherited from its container type

Fixes #17871

We call `generic_args_sans_defaults` here;

64a140527b/crates/hir-ty/src/display.rs (L1021-L1034)

but the following substitution inside that function panic in #17871;

64a140527b/crates/hir-ty/src/display.rs (L1468)

it's because the `Binders.binder` inside `default_parameters` has a same length with the generics of the function we are hovering on, but the generics of it is split into two, `fn_params` and `parent_params`.
Because of this, it may panic if the function has one or more default parameters and both `fn_params` and `parent_params` are non-empty, like the case in the title of this PR.

So, we must call `generic_args_sans_default` first and then split it into `fn_params` and `parent_params`
2024-08-15 07:05:47 +00:00
Shoyu Vanilla
f4b7e8100c fix: Panic while displaying associated function with a type annotation 2024-08-15 09:37:49 +09:00
bors
64a140527b Auto merge of #17882 - ShoyuVanilla:issue-17866, r=lnicola
fix: Panic while canonicalizing erroneous projection type

Fixes #17866

The root cause of #17866 is quite horrifyng 😨

```rust
trait T {
    type A;
}

type Foo = <S as T>::A; // note that S isn't defined

fn main() {
    Foo {}
}
```

While inferencing alias type `Foo = <S as T>::A`;

78c2bdce86/crates/hir-ty/src/infer.rs (L1388-L1398)

the error type `S` in it is substituted by inference var in L1396 above as below;

78c2bdce86/crates/hir-ty/src/infer/unify.rs (L866-L869)

This new inference var's index is `1`, as the type inferecing procedure here previously inserted another inference var into same `InferenceTable`.

But after that, the projection type made from the above then passed to the following function;

78c2bdce86/crates/hir-ty/src/traits.rs (L88-L96)

here, a whole new `InferenceTable` is made, without any inference var and in the L94, this table calls;

78c2bdce86/crates/hir-ty/src/infer/unify.rs (L364-L370)

And while registering `AliasEq` `obligation`, this obligation contains inference var `?1` made from the previous table, but this table has only one inference var `?0` made at L365.
So, the chalk panics when we try to canonicalize that obligation to register it, because the obligation contains an inference var `?1` that the canonicalizing table doesn't have.

Currently, we are calling `InferenceTable::new()` to do some normalizing, unifying or coercing things to some targets that might contain inference var that the new table doesn't have.
I think that this is quite dangerous footgun because the inference var is just an index that does not contain the information which table does it made from, so sometimes this "foreign" index might cause panic like this case, or point at the wrong variable.

This PR mitigates such behaviour simply by inserting sufficient number of inference vars to new table to avoid such problem.
This strategy doesn't harm current r-a's intention because the inference vars that passed into new tables are just "unresolved" variables in current r-a, so this is just making sure that such "unresolved" variables exist in the new table
2024-08-14 15:12:03 +00:00
Shoyu Vanilla
e6d8970e07 fix: Panic while canonicalizing erroneous projection type 2024-08-14 23:17:48 +09:00
bors
36a071c04d Auto merge of #17891 - lnicola:binop-bad-lang-items, r=flodiebold
internal: Be more resilient to bad language item definitions in binop inference

Fixes #16287
Fixes #16286

There's one more in `write_fn_trait_method_resolution`, but I'm not sure if it won't cause further problems in `infer_closures`.
2024-08-14 12:06:50 +00:00
Laurențiu Nicola
e37df4cd24 Be more resilient to bad language item definitions in binop inference 2024-08-14 14:38:39 +03:00
bors
b6913c577a Auto merge of #17885 - Wilfred:op_queue_docs, r=lnicola
minor: Add a doc comment for OpQueue

Add an explanatory sentence and some sample code to help readers understand why this struct exists.
2024-08-14 05:13:44 +00:00
Wilfred Hughes
da907c2ec3 docs: Add a doc comment for OpQueue
Add an explanatory sentence and some sample code to help
readers understand why this struct exists.
2024-08-13 16:51:54 -07:00
bors
78c2bdce86 Auto merge of #17880 - lnicola:sync-from-rust, r=lnicola
minor: sync from downstream
2024-08-13 15:01:50 +00:00
Laurențiu Nicola
bd6fb363f0 Merge from rust-lang/rust 2024-08-13 17:58:52 +03:00
Laurențiu Nicola
30d5c86538 Preparing for merge from rust-lang/rust 2024-08-13 17:56:37 +03:00
bors
e25abba561 Auto merge of #17853 - ShoyuVanilla:min-exhaustive-pat, r=ShoyuVanilla
feat: `min-exhaustive-patterns`

Resolves #17851
2024-08-13 14:18:14 +00:00
Shoyu Vanilla
588fa2c6ef Bump rustc_pattern_analysis 2024-08-13 23:15:37 +09:00
Shoyu Vanilla
a7bc556a5e Temporarily remove non-working test case 2024-08-13 23:10:55 +09:00
Shoyu Vanilla
5316ba9158 feat: `min-exhaustive-patterns 2024-08-13 23:10:55 +09:00
bors
f3d9c9df90 Auto merge of #17876 - Veykril:semantics-include-simplify, r=Veykril
internal: Remove unreachable logic for include token mapping

Turns out https://github.com/rust-lang/rust-analyzer/pull/17863 made this obsolete 🎉
2024-08-13 07:48:55 +00:00
Lukas Wirth
bd4785a6f0 Remove unreachable logic for include token mapping 2024-08-13 09:44:13 +02:00
bors
1093803e38 Auto merge of #17867 - ShoyuVanilla:issue-17854, r=Veykril
fix: Trailing excess comma in "Convert to named struct" assist

Fixes #17854
2024-08-13 06:24:19 +00:00
bors
9a090a2870 Auto merge of #128742 - RalfJung:miri-vtable-uniqueness, r=saethlin
miri: make vtable addresses not globally unique

Miri currently gives vtables a unique global address. That's not actually matching reality though. So this PR enables Miri to generate different addresses for the same type-trait pair.

To avoid generating an unbounded number of `AllocId` (and consuming unbounded amounts of memory), we use the "salt" technique that we also already use for giving constants non-unique addresses: the cache is keyed on a "salt" value n top of the actually relevant key, and Miri picks a random salt (currently in the range `0..16`) each time it needs to choose an `AllocId` for one of these globals -- that means we'll get up to 16 different addresses for each vtable. The salt scheme is integrated into the global allocation deduplication logic in `tcx`, and also used for functions and string literals. (So this also fixes the problem that casting the same function to a fn ptr over and over will consume unbounded memory.)

r? `@saethlin`
Fixes https://github.com/rust-lang/miri/issues/3737
2024-08-13 04:32:34 +00:00
bors
95f691a4c5 Auto merge of #128868 - s7tya:port-rustc-perf-cmp-command, r=Kobzol
Port rustc perf cmp command

I've integrated bench_cmp and bench_local into the bootstrap.

r​? `@Kobzol`
2024-08-13 02:07:10 +00:00
Shoyu Vanilla
2191a4686b fix: Trailing excess comma in "Convert to named struct" assist 2024-08-12 23:36:28 +09:00
bors
32a86cb1da Auto merge of #17865 - ShoyuVanilla:exhaust-block, r=Veykril
fix: Missing non-exhaustive let diagnostics inside async or unsafe block

The reason that this test doesn't have a pointer deref case is because the following code;
```rust
fn test(ptr: *const Result<i32, !>) {
    unsafe {
        let Ok(_x) = *ptr;
    }
}
```
is getting a block with no stmts but tail one in here(thus, no diagnostic error),
0daeb5c0b0/crates/hir-ty/src/diagnostics/expr.rs (L256-L257)
while the following is getting a block with a single stmt without tail 🤔
```rust
fn test(x: Result<i32, &'static !>) {
    let Ok(_y) = x;
}
```
I'll make a more deep inspection and file this as a new issue

_Originally posted by `@ShoyuVanilla` in https://github.com/rust-lang/rust-analyzer/pull/17853#discussion_r1712993585_
2024-08-12 14:34:10 +00:00
Shoyu Vanilla
db24cf5a48 fix: Missing non-exhaustive let diagnostics inside async or unsafe block 2024-08-12 23:19:03 +09:00
bors
18414cdf64 Auto merge of #17864 - Veykril:lsif, r=Veykril
fix: Build and run build scripts in lsif command
2024-08-12 12:34:31 +00:00
Lukas Wirth
154a9a15db Build and run build scripts in lsif command 2024-08-12 14:33:11 +02:00
bors
518532426d Auto merge of #17863 - Veykril:include-diags, r=Veykril
fix: Resolve included files to their calling modules in IDE layer

Fixes https://github.com/rust-lang/rust-analyzer/issues/17390 at the expense of reporting duplicate diagnostics for modules that have includes in them when both the calling and called file are included.
2024-08-12 11:48:32 +00:00
Lukas Wirth
2362975137 Resolve included files to their calling modules in IDE layer 2024-08-12 13:45:33 +02:00
bors
9817294eca Auto merge of #17861 - Veykril:bump-lock, r=Veykril
minor: Bump lockfile
2024-08-12 11:05:08 +00:00
Lukas Wirth
80483e0622 Allow new license combination 2024-08-12 12:51:47 +02:00
bors
a13f330060 Auto merge of #17862 - lnicola:publish-libs-members, r=lnicola
Only keep lib/ in publish-libs

Follow-up to #17860, see https://github.com/rust-lang/rust-analyzer/actions/runs/10350212090/job/28646162590.
2024-08-12 10:50:59 +00:00
Laurențiu Nicola
c875467c6c Only keep lib/ in publish-libs 2024-08-12 13:45:38 +03:00