Commit graph

20199 commits

Author SHA1 Message Date
Lukas Wirth
93024ad411 Switch token trees to use Symbols 2024-07-16 10:11:59 +02: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
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
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
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