Commit graph

30591 commits

Author SHA1 Message Date
Lukas Wirth
4420e7148f Diagnose unresolved self value in path expression 2024-07-06 15:44:12 +02:00
bors
f2afcb874e Auto merge of #17541 - ShoyuVanilla:nested-impl-traits, r=Veykril
Disallow nested impl traits

Fixes #17498

The above issue is due to formatting self referencing, recursive bound like `Implemented(^0.0: TraitId(0)<[?0 := ^0.0]>)` on the codes like;

```rust
trait Foo<T> {}

trait Bar {}

fn test(foo: impl Foo<impl Bar>) { ... }
```

When lowering predicate `impl Foo<impl Bar>` in `trait_environment_query`, the outer `impl Foo<...>` is treated as predicates, so the first `TypeRef` that passes the following code is `impl Bar`;

cae997e338/crates/hir-ty/src/lower.rs (L376-L400)

and thus the `idx` is `0` in the above context.

But the following code sets `self_ty` as the `BoundVar` with `idx = 0` because the target param id for predicate  `impl Foo<...>` is `0` since `impl Foo` is the first generic-like parameter of `fn test`;

cae997e338/crates/hir-ty/src/lower.rs (L998-L1025)

For the codes like;

```rust
trait Foo {
    type Assoc;
}

trait Bar {}

fn test(foo: impl Foo<Assoc = impl Bar>) { ... }
```

similar recursive bound doesn't happen because the following codes ***"count the number of `impl Trait` things that appear before the target of our `bound`."***

cae997e338/crates/hir-ty/src/lower.rs (L1168-L1199)

Instead of doing similar thing like nested `impl Foo<impl Bar>` thing, this PR lowers such nested impl traits into error types in the similar manner as the rustc does in the following lines (and of course, allows lowering and inferencing nested impl traits for the cases that rustc permits);

- e2cf31a614/compiler/rustc_ast_passes/src/ast_validation.rs (L802-L813)
- 7b21c18fe4/compiler/rustc_ast_passes/src/ast_validation.rs (L1299-L1314)

(Though rustc emits [E0666😈](https://doc.rust-lang.org/error_codes/E0666.html), I skipped diagnostics since gathering diagnostics in `hir-def` has no conventions so far 😅)
2024-07-05 10:28:30 +00:00
Shoyu Vanilla
4bb623decb Disallow nested impl traits 2024-07-04 23:31:55 +09: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
bors
39e6a8ea36 Auto merge of #17535 - Veykril:macro-def-syn, r=Veykril
fix: Fix up the syntax tree for macro 2.0

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

This change is trivial now that we don't have a token map anymore
2024-07-03 08:46:16 +00:00
Lukas Wirth
013b6a883f Fix up the syntax tree for macro 2.0 2024-07-03 10:41:19 +02:00
bors
848e0c4040 Auto merge of #17534 - Veykril:skip-unknown-match-check, r=Veykril
fix: Skip match exhaustiveness checking if pattern type contains errors

Should fix https://github.com/rust-lang/rust-analyzer/issues/17509, checking when errors are involved is generally a bad idea as the algorithm doesn't really expect error types in the first place I believe
2024-07-03 06:34:39 +00:00
Lukas Wirth
26c7bfd0b4 Skip match exhaustiveness checking if pattern type contains errors 2024-07-03 08:31:40 +02:00
bors
4981f00bb6 Auto merge of #17530 - Veykril:lifetime-order, r=Veykril
Move lifetimes in front of type and const params but after self
2024-07-02 12:20:54 +00: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
bors
73c97e3fe0 Auto merge of #17529 - Veykril:fix-17065, r=Veykril
fix: Fix lifetime parameters moving parameter defaults

Fixes https://github.com/rust-lang/rust-analyzer/issues/17075, https://github.com/rust-lang/rust-analyzer/issues/17515

We were incorrectly filling the default params due to our odd order of lifetime parameters vs type/const params. So this needs some special handling so that we don't shift the defaults around.
2024-07-02 10:35:44 +00:00
Lukas Wirth
1a929d6485 Fix lifetime parameters moving paramter defaults 2024-07-02 12:34:32 +02:00
bors
1b283db47f Auto merge of #17526 - Veykril:proc-server-errors, r=Veykril
internal: Improve error message when the proc-macro server unexpectedly exits
2024-07-01 13:57:24 +00:00
Lukas Wirth
c6709ffe05 Improve error message when the proc-macro server unexpectedly exits 2024-07-01 14:30:21 +02:00
bors
e6fd485683 Auto merge of #17495 - listochkin:pass-cargo-extra-args-for-debugger, r=Veykril
pass cargo extra args when debugging

fixes #17128
2024-07-01 10:34:09 +00: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
bors
9463d9eea4 Auto merge of #17505 - ShoyuVanilla:issue-17199, r=Veykril
Use proper `ImplTraits` in `insert_inference_vars_for_impl_trait`

Fixes #17199 and fixes #17403

In the previous implementation, I passed `rpits` as a function parameter and used `idx` of `ImplTraitId` for indexing `ImplTrait`.

4e836c622a/crates/hir-ty/src/infer.rs (L881-L887)

But that `idx` is rather a "local" one, so in the cases like mentioned issues, the async function that can be expanded roughly as

```rust
type TypeAlias = impl Something;
fn expanded_async() -> impl Future<Output = TypeAlias> { ... }
```

there are two bundles of `ImplTraits`; one for the `impl Future` and the other one for `TypeAlias`.
So using `idx` with `rpits` returns `ImplTrait` for `impl Future` even if we are asking for `TypeAlias` and this caused a stack overflow.

This PR is a fix for that implementation miss 😅
2024-06-28 12:08:55 +00: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