Commit graph

20398 commits

Author SHA1 Message Date
roife
d94dcfa841 fix: ensure that highlight_related works for macro_expr 2024-07-20 01:42:52 +08:00
roife
ae6e8d56d4 use token_ancestors_with_macros to simplify goto-def on kw 2024-07-20 01:42:52 +08:00
roife
22c5924080 fix: navigate to label directly when perform 'goto-def' on control-flow kw
See https://github.com/rust-lang/rust-analyzer/pull/17542#discussion_r1667656190
2024-07-20 01:42:52 +08:00
roife
07570bac66 feat: find references on control-flow kws 2024-07-20 01:42:52 +08:00
roife
3650b40714 fix: keyword highlighting in macro expansion 2024-07-20 01:42:52 +08:00
roife
1bca00d1bc fix: incorrect highlighting of try blocks with control flow kws 2024-07-20 01:42:51 +08:00
roife
a93a7c2403 fix: ensure that goto-def works on fn/try/async kw 2024-07-20 01:41:01 +08:00
roife
37085d9dcd feat: goto-def on keywords 2024-07-20 01:41:00 +08:00
Lukas Wirth
a324e46b0b Drop an unnecessary Arc::clone 2024-07-19 18:53:52 +02:00
Lukas Wirth
89bcc79b5d Regenerate files 2024-07-19 18:39:42 +02:00
Lukas Wirth
6d4989b3c7 Make LRU opt-in 2024-07-19 18:38:08 +02:00
Lukas Wirth
7fcac48023 Remove duplicate information from interned::Slot 2024-07-19 17:52:49 +02:00
bors
9fd6c695da Auto merge of #17638 - Veykril:salsa-perf, r=Veykril
perf: Reduce memory usage of salsa slots by 8 bytes
2024-07-19 15:48:57 +00:00
Lukas Wirth
8e3133f118 Reduce maximum LRU size to 2^16 entries, reducing memory footprint of LRU entries 2024-07-19 17:48:12 +02:00
Lukas Wirth
4691ca97f1 perf: Reduce memory usage of salsa slots by 8 bytes 2024-07-19 17:34:48 +02:00
bors
aa4768f7be Auto merge of #17622 - roife:fix-issue-17602, r=Veykril
fix: handle synonymous imports with different renaming in 'merge imports'

fix #17602
2024-07-19 15:16:02 +00:00
bors
fa3dd33c27 Auto merge of #17620 - Veykril:edition-aware-parser, r=Veykril
Edition aware parser

Fixes https://github.com/rust-lang/rust-analyzer/issues/16324 by allowing us to properly thread through the edition to the parser
2024-07-19 14:56:56 +00:00
Lukas Wirth
546eb6b530 Test macros doing edition dependent parsing 2024-07-19 16:43:58 +02:00
Lukas Wirth
2c32ee7cfa Prevent generated runner module from being format checked 2024-07-19 16:01:47 +02:00
Lukas Wirth
d235d09bf9 Parse try as a keyword only in edition 2018 and up 2024-07-19 15:43:20 +02:00
Lukas Wirth
713c47f25b Add basic edition inline parser test support 2024-07-19 15:19:43 +02:00
bors
52143a5ac0 Auto merge of #17246 - davidbarsky:david/move-rust-project-generation-to-server, r=Veykril
feature: teach rust-analyzer to discover `linked_projects`

This PR's been a long-time coming, but like the title says, it introduces server-side project discovery and removes the extension hooks I previously introduced. I don't think this PR is ready to land, but here are the things I'm feeling squishy about:
- I don't think I like the idea of introducing the `cargo-metadata` command-but-for-everything-else in the `flycheck` module, but the progress reporting infrastructure was too convenient to pass up. Happy to move it elsewhere.

Here are the things I _know_ I need to change:
- For progress reporting, I'm extracting from a `serde_json::Value` that corresponds to `tracing_subsciber::fmt::Layer`'s JSON output. I'd like to make this a bit more structured/documented than the current nonsense I wrote.
- The progress reporting currently hardcodes "Buck"; it should be deriving that from the previously mentioned more-structured-output.
- This doesn't handle *reloading* when a corresponding buildfile is changed. It should be doing that.

<details>
<summary>Anyway, here's a video of rust-analyzer discovering a Buck target.</summary>

https://github.com/rust-lang/rust-analyzer/assets/2067774/be6cd9b9-2c9a-402d-847f-05f860a91df1
</details>
2024-07-18 16:15:31 +00:00
David Barsky
db43a5a6e9 feature: move linked_projects discovery to the rust-analyzer server 2024-07-18 12:01:27 -04:00
Lukas Wirth
7a5bf92b89 Rewrite inline parser test infra to generated proper rust test cases 2024-07-18 10:03:19 +02:00
Lukas Wirth
ef462ca88e Update test fixtures 2024-07-18 09:09:31 +02:00
Lukas Wirth
5264f86242 Encode edition within FileId in the hir layer 2024-07-18 08:49:10 +02:00
roife
87a3ab4658 fix: handle synonymous imports in 'merge imports' 2024-07-18 05:01:58 +08:00
bors
a62ea0a59e Auto merge of #17618 - Veykril:rustc_skip_during_method_dispatch, r=Veykril
Support rustc_skip_during_method_dispatch

Fixes https://github.com/rust-lang/rust-analyzer/issues/17256
2024-07-17 09:48:18 +00:00
Lukas Wirth
92268627a8 Support rustc_skip_during_method_dispatch 2024-07-17 11:46:36 +02:00
bors
b78cc87b1b Auto merge of #17617 - Veykril:grammar-kind-gen, r=Veykril
Derive kinds information from ungrammar file

This reduces the need to touch more files when adding a new grammar rule
2024-07-17 09:27:03 +00:00
Lukas Wirth
b8cac1bb6b string is not a keyword 2024-07-17 11:11:57 +02:00
Lukas Wirth
7011094685 Add always disabled gen parse support 2024-07-17 10:49:12 +02:00
Lukas Wirth
983c9c122e Derive kinds information from ungrammar file 2024-07-17 10:04:45 +02:00
bors
3fa78e113b Auto merge of #17616 - Veykril:config-param-hints, r=Veykril
Fix incorrect generic parameter hint defaults

Missed this in the review but we should show const param hints, not lifetime param hints by default
2024-07-17 06:54:06 +00:00
Lukas Wirth
8f044d9681 Fix incorrect generic parameter hint defaults 2024-07-17 08:52:23 +02:00
Laurențiu Nicola
f0c3cb3738 Add --keep-going to rust-analyzer.cargo.buildScripts.overrideCommand docs 2024-07-17 08:42:39 +03:00
bors
26747bd1e5 Auto merge of #17611 - Veykril:macro-arg-no-call, r=Veykril
fix: Don't call macro_arg directly in `ExpandDatabase::syntax_context`
2024-07-16 20:12:14 +00:00
Lukas Wirth
e75dbe52a1 Don't call macro_arg directly in ExpandDatabase::syntax_context 2024-07-16 22:10:42 +02:00
bors
cf156a7a43 Auto merge of #17609 - lnicola:sync-from-rust, r=lnicola
minor: Sync from downstream
2024-07-16 13:38:39 +00:00
Laurențiu Nicola
6a121d177d Merge from rust-lang/rust 2024-07-16 16:23:47 +03:00
Lukas Wirth
33ce9a4211 Set RUSTC_SYSROOT for runnables 2024-07-16 13:48:14 +02:00
bors
f5efae854c Auto merge of #127617 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer`

r? `@ghost`
2024-07-16 10:54:30 +00:00
Lukas Wirth
2346a80ab4 Remove Name::to_smol_str 2024-07-16 12:43:58 +02:00
Lukas Wirth
df5f1777b8 More symbol usage 2024-07-16 12:05:16 +02:00
Lukas Wirth
c30bdfcc84 Use symbol in cfg 2024-07-16 10:41:42 +02:00
Lukas Wirth
93024ad411 Switch token trees to use Symbols 2024-07-16 10:11:59 +02:00
Laurențiu Nicola
5f9ce1dcd4 Use re-exported Idx and IndexVec in pat_analysis 2024-07-16 10:41:13 +03:00
Lukas Wirth
05ce57efd5 Fix incorrect encoding of literals in the proc-macro-api on version 4 2024-07-15 14:51:01 +02:00
bors
f913901399 Auto merge of #17559 - Veykril:tokentree, r=Veykril
Encode ident rawness and literal kind separately in tt::Leaf
2024-07-15 11:25:51 +00:00
Lukas Wirth
dcfda55c82 Escape fetched env vars in env! expansion 2024-07-15 13:08:29 +02:00
Lukas Wirth
c0136070a7 Add cargo xtask install proc-macro-server 2024-07-15 12:41:02 +02:00
Lukas Wirth
e846c04fbe Encode ident rawness and literal kind separately in tt::Leaf 2024-07-15 12:24:40 +02:00
bors
5ece16cf17 Auto merge of #17588 - CamWass:more-rename, r=Veykril
feat: Add incorrect case diagnostics for enum variant fields and all variables/params

Updates the incorrect case diagnostic to check:

1. Fields of enum variants. Example:
```rust
enum Foo {
    Variant { nonSnake: u8 }
}
```
2. All variable bindings, instead of just let bindings and certain match arm patters. Examples:
```rust
match 1 { nonSnake => () }
match 1 { nonSnake @ 1 => () }
match 1 { nonSnake1 @ nonSnake2 => () } // slightly cursed, but these both introduce new
                                        // bindings that are bound to the same value.

const ONE: i32 = 1;
match 1 { nonSnake @ ONE } //  ONE is ignored since it is not a binding

match Some(1) { Some(nonSnake) => () }

struct Foo { field: u8 }
match (Foo { field: 1 } ) {
    Foo { field: nonSnake } => ();
}

struct Foo { nonSnake: u8 } // diagnostic here, at definition
match (Foo { nonSnake: 1 } ) { // no diagnostic here...
    Foo { nonSnake } => ();    // ...or here, since these are not where the name is introduced
}

for nonSnake in [] {}

struct Foo(u8);
for Foo(nonSnake) in [] {}
```
3. All parameter bindings, instead of just top-level binding identifiers. Examples:
```rust
fn func(nonSnake: u8) {} // worked before

struct Foo { field: u8 }
fn func(Foo { field: nonSnake }: Foo) {} // now get diagnostic for nonSnake
```

This is accomplished by changing the way binding identifier patterns are filtered:
- Previously, all binding idents were skipped, except a few classes of "good" binding locations that were checked.
- Now, all binding idents are checked, except field shorthands which are skipped.

Moving from a whitelist to a blacklist potentially makes the analysis more brittle:
If new pattern types are added in the future where ident pats don't introduce new names, then they may incorrectly create diagnostics.

But the benefit of the blacklist approach is simplicity: I think a whitelist approach would need to recursively visit patterns to collect renaming candidates?
2024-07-15 10:07:37 +00:00
bors
e961b1aece Auto merge of #17587 - joshka:jm/edit-name-after-refactor, r=Veykril
Trigger VSCode to rename after extract variable assist is applied

When the user applies the "Extract Variable" assist, the cursor is
positioned at the newly inserted variable. This commit adds a command
to the assist that triggers the rename action in VSCode. This way, the
user can quickly rename the variable after applying the assist.

Fixes part of: #17579

https://github.com/user-attachments/assets/4cf38740-ab22-4b94-b0f1-eddd51c26c29

I haven't yet looked at the module or function extraction assists yet.
2024-07-15 09:53:39 +00:00
Lukas Wirth
cde0f69cae Fix stable iteration ordering for Map<Name, ...> usages 2024-07-15 11:25:46 +02:00
Lukas Wirth
f2d51073d2 Use statics + clone instead of const until const can access statics 2024-07-14 17:52:59 +02:00
Jubilee
312db81e07
Rollup merge of #127434 - onur-ozkan:use-bootstrap-instead-of-rustbuild, r=Mark-Simulacrum
use "bootstrap" instead of "rustbuild" in comments and docs

Let's stick with the single name "bootstrap" to refer to the bootstrap project to avoid confusion. This should make it clearer, especially for new contributors.
2024-07-13 20:19:45 -07:00
Josh McKinney
bfa6a5ca84
Address feedback from @DropDemBits
- move `edit.rename()` to the end of the function
- use a match statement to set `res.command`
2024-07-13 19:33:35 -07:00
Campbell
af30111b1c feat: Add incorrect case diagnostics for enum variant fields and all variables 2024-07-13 21:54:22 +12:00
bors
8efe8a8528
Trigger VSCode to rename after extract variable assist is applied
When the user applies the "Extract Variable" assist, the cursor is
positioned at the newly inserted variable. This commit adds a command
to the assist that triggers the rename action in VSCode. This way, the
user can quickly rename the variable after applying the assist.

Fixes part of: #17579
2024-07-12 19:06:19 -07:00
Shoyu Vanilla
b238855892 Allow macro expansions into RestPat in tuple args work as ellipsis like plain RestPat 2024-07-13 07:09:17 +09:00
Lukas Wirth
dd626e78c7 Fix cloning Symbols not increasing their ref count 2024-07-12 17:13:12 +02:00
Lukas Wirth
3fe815b0f3 Use Symbol in Name 2024-07-12 16:06:44 +02:00
Lukas Wirth
843806b79f Add missing docs 2024-07-12 16:01:47 +02:00
Lukas Wirth
6275eb140e Implement rough symbol interning infra 2024-07-12 16:01:47 +02:00
Laurențiu Nicola
bd6de0cb57 Merge from rust-lang/rust 2024-07-11 20:06:05 +03:00
bors
5577e4e3b1 Auto merge of #17571 - winstxnhdw:bool-to-enum-no-dupe, r=Veykril
feat: do not add new enum if it already exists

## Summary

This PR introduces a check for the existence of another enum within the current scope, and if it exist, we skip `add_enum_def`.

## Why?

Currently, when using the `bool_to_enum` assist more than once, it is possible to add multiple enum definitions. For example, the following snippet,

```rs
#[derive(PartialEq, Eq)]
enum Bool {
    True,
    False,
}

fn main() {
    let a = Bool::True;
    let b = true;
    println!("Hello, world!");
}
```

will be transformed into,

```rs
#[derive(PartialEq, Eq)]
enum Bool {
    True,
    False,
}

#[derive(PartialEq, Eq)]
enum Bool {
    True,
    False,
}

fn main() {
    let a = Bool::True;
    let b = Bool::True;
    println!("Hello, world!");
}
```

This can be annoying for users to clean up.
2024-07-11 08:55:34 +00:00
winstxnhdw
c4bcec214a refactor: search for enum semantically 2024-07-10 21:13:13 +01:00
bors
2bfab900dc Auto merge of #17572 - beetrees:f16-f128, r=Veykril
Add `f16` and `f128` support

Adds `f16` and `f128` support, using the `rustc_apfloat` library (also used by `rustc`) for parsing/arithmetic/displaying since the types aren't stable yet so can't be used by rust-analyzer itself.

Issue: #17451
2024-07-10 10:04:30 +00:00
bors
1c814f0259 Auto merge of #17544 - MikeWalrus:inlay-hint-generic-param-name, r=Veykril
feat: add inlay hints for generic parameters

fixes #11091

By default, only hints for const generic parameters are shown, and this can be configured through `rust-analyzer.inlayHints.genericParameterHints.enable`.

Probably needs more testing.
2024-07-10 09:50:40 +00:00
Lukas Wirth
5c7a52999a
Remove dead code in config.rs 2024-07-10 11:49:11 +02:00
beetrees
d5db933f9d
Add f16 and f128 support 2024-07-10 10:43:14 +01:00
winstxnhdw
120526ad68 style: prefer type inference
- unrelated to the PR but I wanted to change this in #17467
2024-07-09 22:30:00 +01:00
winstxnhdw
2b52bffaef feat: do not add new enum if it already exists 2024-07-09 22:17:07 +01:00
bors
da27b89ca5 Auto merge of #17558 - beetrees:fix-double-rounding, r=Veykril
fix: Fix double rounding of `f32` literals

Fixes #17556 by delaying parsing until the type is known. Also adds a test to check the issue is fixed.
2024-07-08 16:10:58 +00:00
beetrees
320022622c
fix: Fix double rounding of f32 literals 2024-07-08 16:31:32 +01:00
mo8it
8ecfdec3c3 Remove version check before using --keep-going 2024-07-08 16:41:12 +02:00
Matthias Krüger
4bd78b0a8d
Rollup merge of #120248 - WaffleLapkin:bonk-ptr-object-casts, r=compiler-errors,oli-obk,lnicola
Make casts of pointers to trait objects stricter

This is an attempt to `fix` https://github.com/rust-lang/rust/issues/120222 and https://github.com/rust-lang/rust/issues/120217.

This is done by adding restrictions on casting pointers to trait objects.

Before this PR the rules were as follows:

> When casting `*const X<dyn A>` -> `*const Y<dyn B>`, principal traits in `A` and `B` must refer to the same trait definition (or no trait).

With this PR the rules are changed to

> When casting `*const X<dyn Src>` -> `*const Y<dyn Dst>`
> - if `Dst` has a principal trait `DstP`,
>   - `Src` must have a principal trait `SrcP`
>   - `dyn SrcP` and `dyn DstP` must be the same type (modulo the trait object lifetime, `dyn T+'a` -> `dyn T+'b` is allowed)
>   - Auto traits in `Dst` must be a subset of auto traits in `Src`
>     - Not adhering to this is currently a FCW (warn-by-default + `FutureReleaseErrorReportInDeps`), instead of an error
> - if `Src` has a principal trait `Dst` must as well
>   - this restriction will be removed in a follow up PR

This ensures that
1. Principal trait's generic arguments match (no `*const dyn Tr<A>` -> `*const dyn Tr<B>` casts, which are a problem for [#120222](https://github.com/rust-lang/rust/issues/120222))
2. Principal trait's lifetime arguments match (no `*const dyn Tr<'a>` -> `*const dyn Tr<'b>` casts, which are a problem for [#120217](https://github.com/rust-lang/rust/issues/120217))
3. No auto traits can be _added_ (this is a problem for arbitrary self types, see [this comment](https://github.com/rust-lang/rust/pull/120248#discussion_r1463835350))

Some notes:
 - We only care about the metadata/last field, so you can still cast `*const dyn T` to `*const WithHeader<dyn T>`, etc
- The lifetime of the trait object itself (`dyn A + 'lt`) is not checked, so you can still cast `*mut FnOnce() + '_` to `*mut FnOnce() + 'static`, etc
  - This feels fishy, but I couldn't come up with a reason it must be checked

The diagnostics are currently not great, to say the least, but as far as I can tell this correctly fixes the issues.

cc `@oli-obk` `@compiler-errors` `@lcnr`
2024-07-08 16:28:15 +02:00
Liao Junxuan
35b4957b80
feat: add inlay hints for generic parameters
fixes #11091

By default, only hints for const generic parameters are shown.
2024-07-08 19:11:41 +08:00
mo8it
9d01d7ce35 Add --keep-going to the check command 2024-07-07 18:37:02 +02:00
bors
a5b21ea0aa Auto merge of #17555 - Veykril:grammar-inline, r=Veykril
internal: Inline generated syntax methods
2024-07-07 09:21:04 +00:00
Lukas Wirth
35aa238020 Inline all the things 2024-07-07 11:18:40 +02:00
Lukas Wirth
c08d419fba HasGenericArgs syntax trait 2024-07-07 11:18:28 +02:00
bors
a494aaba87 Auto merge of #17523 - wada314:master, r=Veykril
Add an option to use "::" for the external crate prefix.

Fixes #11823 .
Hi I'm very new to rust-analyzer and not sure how the review process are. Can somebody take a look at this PR? thanks!
2024-07-07 08:32:46 +00:00
Lukas Wirth
6c8c49b01b fix: Fix callHierarchy LSP violation 2024-07-07 10:14:47 +02:00
Lukas Wirth
ce5046be50 Run codegen commands as tests if their results are commited 2024-07-07 09:14:50 +02:00
Lukas Wirth
866102cdaf Re-implement tidy as an xtask action 2024-07-07 09:12:16 +02:00
Lukas Wirth
210b748909 Drop sourcegen 2024-07-07 09:00:19 +02:00
Lukas Wirth
986b9cf022 Move feature-doc generation to xtask codegen 2024-07-07 09:00:18 +02:00
Lukas Wirth
09932d9cd4 Update hover test fixture 2024-07-07 08:55:10 +02:00
Lukas Wirth
5802643900 Move parser test generation to xtask 2024-07-07 08:51:19 +02:00
Lukas Wirth
b9c1c42959 Allow new clippy lint in test 2024-07-07 08:41:41 +02:00
Lukas Wirth
15973f1a55 Fix stop_watch on linux 2024-07-07 08:40:41 +02:00
Lukas Wirth
9b3e912d67 Update generated lint definitions 2024-07-07 08:35:18 +02:00
Lukas Wirth
90682c393d Drop unused profile things 2024-07-07 08:24:10 +02:00
Lukas Wirth
8f2704654c fix: Fix parameter completions using macro expanded source ranges 2024-07-07 08:11:16 +02:00
Lukas Wirth
e4604c69ba Move capability querying out of the config module 2024-07-07 07:42:12 +02:00
onur-ozkan
3d0d5424b9 use "bootstrap" instead of "rustbuild" in comments and docs
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-07-07 00:07:08 +03:00
bors
058c88da66 Auto merge of #17551 - Veykril:has-errors, r=Veykril
Also mark InferenceResult::has_errors flag when there are error types

Should work around https://github.com/rust-lang/rust-analyzer/issues/15090#issuecomment-2211647133
2024-07-06 18:56:23 +00:00
Lukas Wirth
e0105c473e Also mark InferenceResult::has_errors flag when there are error types 2024-07-06 20:45:23 +02:00
bors
35db3f5a03 Auto merge of #17547 - Veykril:runnables-env, r=Veykril
internal: Clean up runnable lsp extension

This feels like a natural addition to me, and also allows us to drop the expect-test hardcoding from the extension. Additionally, `cargoExtraArgs` is pointless, all the client will do is merge it with `cargoArgs` so the server can do that instead of delegating that to the client.
2024-07-06 15:02:41 +00:00
Lukas Wirth
8f69d98214 Don't emit current dir as cwd for runnables 2024-07-06 16:44:57 +02:00
Lukas Wirth
3d7ee9b4ea Flatten cargoExtraArgs away from the runnable lsp extension 2024-07-06 16:36:27 +02:00
Lukas Wirth
fcddcf2ee5 Add environment to runnable lsp extension 2024-07-06 16:20:25 +02:00
Lukas Wirth
4420e7148f Diagnose unresolved self value in path expression 2024-07-06 15:44:12 +02:00
Michael Goulet
68ea9f82cb
Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix
Improve dead code analysis

Fixes #120770

1. check impl items later if self ty is private although the trait method is public, cause we must use the ty firstly if it's private
2. mark the adt live if it appears in pattern, like generic argument, this implies the use of the adt
3. based on the above, we can handle the case that private adts impl Default, so that we don't need adding rustc_trivial_field_reads on Default, and the logic in should_ignore_item

r? ``@pnkfelix``
2024-07-05 20:49:31 -04:00
Maybe Lapkin
0cea755154 Delete CloneAny from rust-analyzer's fork of AnyMap
...because it's very sketchy and causes FCWs.
In this case it *is* actually sound, but still.

I should write a better fork of anymap...
2024-07-04 17:57:31 +02:00
Shoyu Vanilla
4bb623decb Disallow nested impl traits 2024-07-04 23:31:55 +09:00
mu001999
2ec3a7dd6a Improve dead code analysis 2024-07-04 22:05:00 +08:00
bors
cae997e338 Auto merge of #17536 - Veykril:syntax-diags, r=Veykril
fix: Don't emit semantic diagnostics in files with a lot of syntax errors

These will only add to the noise when something very unexpected breaks or where parser recovery fails to kick in.
2024-07-03 09:01:48 +00:00
Lukas Wirth
cbcb9779f5 fix: Don't emit semantic diagnostics in files with a lot of syntax errors 2024-07-03 10:59:46 +02:00
Lukas Wirth
013b6a883f Fix up the syntax tree for macro 2.0 2024-07-03 10:41:19 +02:00
Lukas Wirth
26c7bfd0b4 Skip match exhaustiveness checking if pattern type contains errors 2024-07-03 08:31:40 +02:00
Lukas Wirth
baa959fa99 Move lifetimes in front of type and const params but after self 2024-07-02 14:17:34 +02:00
Lukas Wirth
966798b7ba Make GenericParams::lifetimes private 2024-07-02 13:45:53 +02:00
Lukas Wirth
be1ea4028b Make GenericParams::where_predicates private 2024-07-02 13:45:50 +02:00
Lukas Wirth
372e2d22e6 Make GenericParams::type_or_consts private 2024-07-02 13:45:48 +02:00
Lukas Wirth
1a929d6485 Fix lifetime parameters moving paramter defaults 2024-07-02 12:34:32 +02:00
Shohei Wada
3725ab3146 squash. 2024-07-02 01:52:34 +09:00
Lukas Wirth
c6709ffe05 Improve error message when the proc-macro server unexpectedly exits 2024-07-01 14:30:21 +02:00
bors
becf5d31f7 Auto merge of #17494 - harrysarson:harry/keep-braces, r=Veykril
do not normalize `use foo::{self}` to `use foo`

It changes behaviour and can cause collisions. E.g. for the following snippet

```rs
mod foo {

    pub mod bar {}

    pub const bar: i32 = 8;
}

// transforming the below to `use foo::bar;` causes the error:
//
//   the name `bar` is defined multiple times
use foo::bar::{self};

const bar: u32 = 99;

fn main() {
    let local_bar = bar;
}
```

we still normalize

```rs
use foo::bar;
use foo::bar::{self};
```

to `use foo::bar;` because this cannot cause collisions.

See: https://github.com/rust-lang/rust-analyzer/pull/17140#issuecomment-2079189725
2024-07-01 10:20:01 +00:00
bors
72f278b5be Auto merge of #17522 - Veykril:comptimes, r=Veykril
internal: Cut compiletimes slightly
2024-07-01 08:43:11 +00:00
Lukas Wirth
d859e40db9 Bump rustc_pattern_analysis 2024-06-30 18:41:55 +02:00
Lukas Wirth
b60b27bd22 Remove serde flag from indexmap dependency 2024-06-30 18:14:53 +02:00
bors
ea7fdada6a Auto merge of #17520 - Veykril:slim-proc-macro-api, r=Veykril
internal: Cleanup proc-macro-srv some more
2024-06-30 15:12:50 +00:00
Lukas Wirth
956c8521a9 Arc proc-macro expander paths 2024-06-30 17:03:03 +02:00
Lukas Wirth
c236190b60 Abstract proc-macro-srv protocol format 2024-06-30 16:56:30 +02:00
Lukas Wirth
7c7c0cbffb Simplify 2024-06-30 16:43:22 +02:00
Lukas Wirth
9d09bc0619 Actual dummy server for the server cli 2024-06-30 16:34:06 +02:00
Lukas Wirth
b0c4bc4972 Fix proc-macro-test build script 2024-06-30 16:26:39 +02:00
Lukas Wirth
2fb38ceb66 Faster env snapshotting in proc-macro-srv 2024-06-30 16:10:20 +02:00
Lukas Wirth
678420e66a Move proc-macro-test test path fetching from include to env var 2024-06-30 15:37:00 +02:00
Lukas Wirth
0b88dfc8b1 Rename proc-macro-srv::server to server_impl 2024-06-30 15:36:46 +02:00
Lukas Wirth
23b043a622 Move proc-macro-srv RUSTC_VERSION fetching from include to env var 2024-06-30 15:28:31 +02:00
Lukas Wirth
21a3d01875 Remove inline rust_2018_idioms, unused_lifetimes lint warn, Cargo.toml already enforces this 2024-06-30 15:23:54 +02:00
Lukas Wirth
e92646962a Move interior mutability into ProcMacroSrvProcess 2024-06-30 15:22:39 +02:00
bors
cbd3a7a08a Auto merge of #17519 - Veykril:slim-proc-macro-api, r=Veykril
internal: Move dylib version stuff to proc-macro-srv

The client no longer reads the proc-macro versions, so this has no need to be in the api crate
2024-06-30 13:07:21 +00:00
Lukas Wirth
db15273d4d Move dylib version stuff to proc-macro-srv 2024-06-30 15:05:35 +02:00
bors
56ef2404b3 Auto merge of #17516 - kilpkonn:master, r=kilpkonn
Quality of life improvements to term search

Basically two things:
- Allow optionally disabling "borrow checking" restrictions on term search code assists. Sometimes it is better to get invalid suggestions and fix borrow checking issues later...
- Remove explicit generics in generated expressions. I find it quite rare that one writes `None::<T>` instead of `None`.
2024-06-30 12:41:22 +00:00
bors
7e8f9c82e1 Auto merge of #17467 - winstxnhdw:bool-to-enum, r=Veykril
feat: add bool_to_enum assist for parameters

## Summary

This PR adds parameter support for `bool_to_enum` assists. Essentially, the assist can now transform this:

```rs
fn function($0foo: bool) {
    if foo {
        println!("foo");
    }
}
```

To this,

```rs
#[derive(PartialEq, Eq)]
enum Bool { True, False }

fn function(foo: Bool) {
    if foo == Bool::True {
        println!("foo");
    }
}
```

Thanks to `@/davidbarsky`  for the test skeleton (:

Closes #17400
2024-06-30 12:26:07 +00:00
Tavo Annus
c19458270d Do not explicit generics to generated expressions 2024-06-30 15:19:19 +03:00
bors
098d6996ef Auto merge of #17518 - Veykril:expr-scopes-mac, r=Veykril
fix: Fix expression scope calculation when within macro expansions
2024-06-30 12:11:12 +00:00
Lukas Wirth
5374ebbf36 Simplify 2024-06-30 14:00:55 +02:00
Lukas Wirth
bfb187aacd Fix expression scope calculation when within macro expansions 2024-06-30 13:26:17 +02:00
Lukas Wirth
882ae7105d Simplify unresolved proc-macro handling 2024-06-30 13:26:13 +02:00
bors
b6422dcaf1 Auto merge of #17513 - roife:fix-issue-17500, r=Veykril
fix: completions after async kw

fix #17500

### Changes

1. fix completions after async kw
2. fix completions for `async` kw in trait
2024-06-30 11:10:59 +00:00
roife
278425919d fix: completions after async kw 2024-06-29 22:23:54 +08:00
Tavo Annus
1389312871 Make borrow checking configurable for term search 2024-06-29 12:24:08 +03:00
Shoyu Vanilla
7e9da2d67d Use proper ImplTraits in insert_inference_vars_for_impl_trait 2024-06-27 23:51:33 +09:00
Shoyu Vanilla
50b7678621 Add a regression test for issue 17199 that causes stack overflow 2024-06-27 23:48:15 +09:00
Nicholas Nethercote
cac0a0742b Remove the box_pointers lint.
As the comment says, this lint "is mostly historical, and not
particularly useful". It's not worth keeping it around.
2024-06-27 08:55:28 +10:00
Harry Sarson
23965e4512 do not normalize use foo::{self} to use foo
It changes behaviour and can cause collisions. E.g. for the following snippet

```rs
mod foo {

    pub mod bar {}

    pub const bar: i32 = 8;
}

// tranforming the below to `use foo::bar;` causes the error:
//
//   the name `bar` is defined multiple times
use foo::bar::{self};

const bar: u32 = 99;

fn main() {
    let local_bar = bar;
}
```

we still normalize

```rs
use foo::bar;
use foo::bar::{self};
```

to `use foo::bar;` because this cannot cause collisions.

See: https://github.com/rust-lang/rust-analyzer/pull/17140#issuecomment-2079189725
2024-06-26 08:58:13 +01:00
xFrednet
770b139a1a
RFC 2383: Stabilize lint_reasons 🎉 2024-06-25 17:22:22 +02:00
winstxnhdw
d468746075
feat: add bool_to_enum assist for parameters 2024-06-25 01:39:16 +08:00
winstxnhdw
21c63abec7
tests: add test for param transformation 2024-06-25 01:39:11 +08:00
bors
7b11fdeb68 Auto merge of #17489 - Veykril:tt-iter, r=Veykril
minro: move tt-iter into tt crate
2024-06-24 12:48:53 +00:00
Lukas Wirth
dc39e87b79 move tt-iter into tt crate 2024-06-24 14:47:21 +02:00
bors
a35422a750 Auto merge of #17488 - alibektas:17485/duplicate_snippets, r=alibektas
minor : Fix duplicate snippets showing up on hover.

With each `config::apply_change` duplicate configs were being added.
Now we first drain the vec that holds these and then start adding. This fixes #17485
2024-06-24 11:34:13 +00:00
Ali Bektas
443ba254f9 Apply minor changes 2024-06-24 13:15:33 +02:00
Ali Bektas
b68200ee6f minor : Fix duplicate snippets showing up on hover.
With each `config::apply_change` duplicate configs were being added.
Now we first drain the vec that holds these and then start adding.
2024-06-24 13:01:40 +02:00
bors
0cb22db658 Auto merge of #17487 - Veykril:ty-perf-stuff, r=Veykril
internal: Some more small memory optimizations

Not a big impact on metrics, though there are some more savings in queries mainly used by the IDE layer from this
2024-06-24 09:50:35 +00:00
Lukas Wirth
db056b4a69 Fix term_search filtering enum variant generics incorrectly 2024-06-24 10:31:21 +02:00
bors
e0a400edd4 Auto merge of #17471 - davidsemakula:fix-remove-parenthesis, r=Veykril
fix: don't remove parentheses for calls of function-like pointers that are members of a struct or union

Fixes #17111
2024-06-24 08:25:49 +00:00
bors
f998561964 Auto merge of #17411 - Wilfred:clearer_unlinked_file, r=Veykril
fix: Improve hover text in unlinked file diagnostics

Use full sentences, and mention how to disable the diagnostic if users are intentionally working on unowned files.

![Screenshot 2024-06-12 at 5 55 48 PM](https://github.com/rust-lang/rust-analyzer/assets/70800/c91ee1ed-1c72-495a-9ee3-9e360a5c6977)

(Full disclosure: I've tested a rust-analyzer build in VS Code, but the pop-up logic is currently disabled due to #17062, so I haven't tested that.)
2024-06-24 08:11:43 +00:00
Lukas Wirth
8df034d453 Shrink mbe's Op 2024-06-24 10:07:32 +02:00
Lukas Wirth
e052b3e9a6 Intern ModPath within RawVisibility 2024-06-24 10:07:32 +02:00
Lukas Wirth
5548aecdca Save a bit on empty item trees by deduplicating them 2024-06-24 10:07:32 +02:00
Lukas Wirth
3168ab5b99 Enum variants are not generic def ids 2024-06-24 10:07:31 +02:00
bors
f2cffbac85 Auto merge of #17466 - chenyukang:patch-1, r=Veykril
chore: Fix diagnostic name in macro_error.rs
2024-06-24 07:57:45 +00:00
bors
3432ef4414 Auto merge of #17481 - roife:fix-issue-17480, r=Veykril
fix: pattern completions in let-stmt

fix #17480.

We can write `let S { a, b } = s;` or `let Some(x) = a else {}`, so it is reasonable to allow pattern completions in `LetStmt`.
2024-06-24 07:34:08 +00:00
bors
db69df3216 Auto merge of #17478 - kilpkonn:master, r=Veykril
Simplify some term search tactics

Working on the paper `@phijor` found that "Data constructor" tactic could be simplified quite a bit by running it only in the backwards direction. With n+1 rounds it has same coverage as previous implementation in n rounds, however the tactic it self is more simple and also potentially faster as there is less to do.

In a nutshell the idea is to only work with types in the wish-list rather than with any types.

Turns out it is quite a bit faster:

Before:
```
ripgrep:
Tail Expr syntactic hits: 238/1692 (14%)
Tail Exprs found: 1223/1692 (72%)
Term search avg time: 15ms

nalgebra:
Tail Expr syntactic hits: 125/3001 (4%)
Tail Exprs found: 2143/3001 (71%)
Term search avg time: 849ms
```

After
````
ripgrep:
Tail Expr syntactic hits: 246/1692 (14%)
Tail Exprs found: 1209/1692 (71%)
Term search avg time: 8ms

nalgebra:
Tail Expr syntactic hits: 125/3001 (4%)
Tail Exprs found: 2028/3001 (67%)
Term search avg time: 305ms
````

_Also removed niche optimization of removing scope defs from the search space as this wasn't helping much anyway and made code a bit more complex._
2024-06-24 07:20:50 +00:00
roife
291e96a562 fix: pattern completions in let-stmt 2024-06-23 22:27:54 +08:00
Tavo Annus
51c3bd215a Fix suggestions of unstable constants 2024-06-22 21:33:58 +03:00
Tavo Annus
3825d8bd0f Increase search depth to account for more granual steps 2024-06-22 15:06:07 +03:00
Tavo Annus
b4f3eb48db Simplify impl_method tactic 2024-06-22 14:22:56 +03:00
Tavo Annus
23d3ac70e9 Simplify impl_static_method tactic 2024-06-22 14:14:42 +03:00
Tavo Annus
a3315fe028 Remove remove not-very-helpful optimizations 2024-06-22 10:17:33 +03:00
Tavo Annus
957325a5fe Run data_constructor tactic only backwards 2024-06-21 22:01:06 +03:00
bors
c4681ea2cc Auto merge of #17469 - roife:fix-issue-17425, r=Veykril
fix: use ItemInNs::Macros to convert ModuleItem to ItemInNs

fix #17425.

When converting `PathResolution` to `ItemInNs`, we should convert `ModuleDef::Macro` to `ItemInNs::Macros` to ensure that it can be found in `DefMap`.
2024-06-21 17:52:42 +00:00
Lukas Wirth
4c62e6b05f Prevent re-allocation in CallableSig::from_params_and_return 2024-06-21 19:26:08 +02:00
Lukas Wirth
34ba8db3ed Save allocations for empty generic_defaults query results 2024-06-21 19:21:27 +02:00
Lukas Wirth
2761b1e236 Don't attempt to compute implict sized clauses for empty generics 2024-06-21 19:10:57 +02:00
Lukas Wirth
4d709cc866 Save allocations for empty generic_predicates query results 2024-06-21 19:10:45 +02:00
Lukas Wirth
7a16e06009 Lazy generics 2024-06-21 18:38:37 +02:00
Lukas Wirth
c01f4cf902 Simplify 2024-06-21 18:27:05 +02:00
Lukas Wirth
480bfd5a7d There can only be one self param 2024-06-21 17:55:16 +02:00
Lukas Wirth
cf2b757a1a Light docs and privacy 2024-06-21 17:54:40 +02:00
davidsemakula
d6d45a23d3 fix: don't remove parentheses for calls of function-like pointers that are members of a struct or union 2024-06-21 17:57:53 +03:00
roife
d5bb2f0cba fix: use ItemInNs::Macros to convert ModuleItem to ItemInNs 2024-06-21 21:05:14 +08:00
Lukas Wirth
585cc9e014 Extract generics module 2024-06-21 10:55:05 +02:00
Wilfred Hughes
e62bc2d1f5 fix: Improve hover text in unlinked file diagnostics
Use full sentences, and mention how to disable the diagnostic
if users are intentionally working on unowned files.
2024-06-20 09:32:48 -07:00
Yukang
bfcdeb2a24
Fix diagnostic name in macro_error.rs 2024-06-21 00:13:34 +08:00
Wyatt Herkamp
f51b161568
Check that Expr is none before adding fixup 2024-06-20 08:55:05 -04:00
bors
e08f7953f4 Auto merge of #17462 - Veykril:sema-attr-macro-res, r=Veykril
fix: Fix IDE features breaking in some attr macros

Fixes https://github.com/rust-lang/rust-analyzer/issues/17453, Fixes https://github.com/rust-lang/rust-analyzer/issues/17458
2024-06-20 09:11:44 +00:00
Lukas Wirth
ee8a3458ee fix: Fix IDE features breaking in some attr macros 2024-06-20 11:00:19 +02:00
bors
180c2292f9 Auto merge of #17461 - Veykril:drop-flycheck-recv, r=Veykril
fix: Fix flycheck panicking when cancelled

Fixes https://github.com/rust-lang/rust-analyzer/issues/17445
2024-06-20 08:58:44 +00:00
bors
6738f81b12 Auto merge of #17419 - ishanjain28:filter_builtin_macro_expansion, r=Veykril
Filter builtin macro expansion

This PR adds a filter on the types of built in macros that are allowed to be expanded.

Currently, This list of allowed macros contains, `stringify, cfg, core_panic, std_panic, concat, concat_bytes, include, include_str, include_bytes, env` and `option_env`.

Fixes #14177
2024-06-20 08:39:17 +00:00
Lukas Wirth
bf9a7264d1 Invert matching on builtin macros in expand_allowed_builtins 2024-06-20 10:31:20 +02:00
Lukas Wirth
48cf13b598 fix: Fix flycheck panicking when cancelled 2024-06-20 10:21:58 +02:00
bors
501b1fa594 Auto merge of #17457 - roife:remove-circle, r=Veykril
fix: ensure there are no cycles in the source_root_parent_map

See #17409

We can view the connections between roots as a graph. The problem is that this graph may contain cycles, so when adding edges, it is necessary to check whether it will lead to a cycle.

Since we ensure that each node has at most one outgoing edge (because each SourceRoot can have only one parent), we can use a disjoint-set to maintain the connectivity between nodes. If an edge’s two nodes belong to the same set, they are already connected.

Additionally, this PR includes the following three changes:

1. Removed the workaround from #17409.
2. Added an optimization: If `map.contains_key(&SourceRootId(*root_id as u32))`, we can skip the current loop iteration since we have already found its parent.
3. Modified the inner loop to iterate in reverse order with `roots[..idx].iter().rev()` at line 319. This ensures that if we are looking for the parent of `a/b/c`, and both `a` and `a/b` meet the criteria, we will choose the longer match (`a/b`).
2024-06-20 07:53:57 +00:00