657 Commits

Author SHA1 Message Date
Lukas Wirth
97ac158aaa
Merge pull request #20193 from ChayimFriedman2/setting-rename-conflict
feat: Provide a setting to disable showing rename conflicts
2025-12-26 09:08:49 +00:00
Chayim Refael Friedman
5813fe7ff6 Stabilize type mismatch diagnostic 🎉 2025-12-26 09:35:55 +02:00
Jesung Yang
7f6858fd09 feat: introduce crate_attrs field in rust-project.json
Since the commit 50384460c68f
("Rewrite method resolution to follow rustc more closely"), the method
resolution logic has changed: rust-analyzer only looks up inherent
methods for primitive types in sysroot crates.

Unfortunately, this change broke at least one project that relies on
`rust-project.json`: Rust-for-Linux. Its auto-generated
`rust-project.json` directly embeds `core`, `alloc`, and `std` in the
`crates` list without defining `sysroot_src`. Consequently,
rust-analyzer fails to identify them as sysroot crates, breaking IDE
support for primitive methods (e.g., `0_i32.rotate_left(0)`).

However, specifying `sysroot_src` creates a new issue: it implicitly
adds `std` as a dependency to all kernel module crates, which are
actually compiled with `-Zcrate-attr=no_std`. Since rust-analyzer cannot
see compiler flags passed outside of the project definition, we need a
method to explicitly specify `#![no_std]` or, more generally,
crate-level attributes through the project configuration.

To resolve this, extend the `rust-project.json` format with a new
`crate_attrs` field. This allows users to specify crate-level attributes
such as `#![no_std]` directly into the configuration, enabling
rust-analyzer to respect them when analyzing crates.

References:
- The original Zulip discussion:
  https://rust-lang.zulipchat.com/#narrow/channel/185405-t-compiler.2Frust-analyzer/topic/Primitive.20type.20inherent.20method.20lookup.20fails/with/562983853
2025-12-18 01:27:43 +00:00
The rustc-josh-sync Cronjob Bot
2d06e40dd0 Merge ref '0208ee09be46' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh.

Upstream ref: 0208ee09be465f69005a7a12c28d5eccac7d5f34
Filtered ref: 69b2702db74151cd410a028fb347c6e4e3f779dc
Upstream diff: dfe1b8c97b...0208ee09be

This merge was created using https://github.com/rust-lang/josh-sync.
2025-12-15 04:30:45 +00:00
Jesung Yang
2619bd2cec fix: respect rustc's lint attribute application order
Reverse the order of returned lint attributes for a `SyntaxNode` to
match rustc's behavior.

When multiple lint attributes are present, rustc overrides earlier ones
with the last defined attribute. The previous iteration order was
incorrect, causing earlier attributes to override the later ones.
2025-12-14 06:30:09 +00:00
Jieyou Xu
acb575c6ab
rust-analyzer: prep crates for testing against in-tree rustc_private 2025-12-11 20:22:49 +08:00
Chayim Refael Friedman
fc265a27da #[rustc_deprecated_safe_2024] can also come as #[rustc_deprecated_safe_2024(audit_that = "reason")] 2025-12-10 22:45:20 +02:00
Shoyu Vanilla (Flint)
25278ada1a
Merge pull request #21209 from ChayimFriedman2/stale-expr
internal: Do not create stale expressions in body lowering
2025-12-08 16:28:46 +00:00
Shoyu Vanilla (Flint)
a50c1ccc9c
Merge pull request #21221 from A4-Tacks/no-pub-in-variant-field
Fix pub in enum variant field for no_such_field
2025-12-08 07:18:53 +00:00
A4-Tacks
fcc307ae04
Fix pub in enum variant field for no_such_field
Example
---
```rust
//- /main.rs
mod foo;

fn main() {
    foo::Foo::Variant { bar: 3, $0baz: false};
}
//- /foo.rs
pub enum Foo {
    Variant {
        bar: i32
    }
}
```

**Before this PR**

```rust
pub enum Foo {
    Variant {
        bar: i32,
        pub(crate) baz: bool
    }
}
```

**After this PR**

```rust
pub enum Foo {
    Variant {
        bar: i32,
        baz: bool
    }
}
```
2025-12-07 20:49:22 +08:00
Lukas Wirth
30550d917b Make ModuleId a tracked struct
optimize some stuff

Optimize `pub(crate)` visibility resolution

Optimize private visibility resolution
2025-12-07 09:31:19 +01:00
Chayim Refael Friedman
c72df45cdc Do not create stale expressions in body lowering 2025-12-05 12:53:10 +02:00
Chayim Refael Friedman
753449bdae Handle lint attributes via hir-expand attr handling
This avoids code duplication.
2025-12-05 07:04:18 +02:00
Chayim Refael Friedman
f4bc77484c Support multiple enable in #[target_feature] 2025-11-29 21:23:04 +02:00
Chayim Refael Friedman
b92767700a Make Semantics::attach_first_edition() not return Option
And instead call `EditionedFileId::current_edition_guess_origin`, as most callers do it anyway.
2025-11-29 18:52:18 +02:00
Chayim Refael Friedman
f0e372c3b6 Rewrite attribute handling
Basically, we switch to expanding cfg_attr in AST form, filter irrelevant attributes from the item tree, and move hir-def attributes (non-item-tree) to be flag-based.

The main motivation is memory usage, although this also simplifies the code, and fixes some bugs around handling of `cfg_attr`s.
2025-11-29 18:52:18 +02:00
Asuka Minato
94e8a22a1a add test 2025-11-20 23:12:20 +09:00
Chayim Refael Friedman
e8e02d5515
Merge pull request #20974 from ChayimFriedman2/ns4
fix: Rewrite method resolution to follow rustc more closely
2025-11-18 23:20:04 +00:00
Chayim Refael Friedman
d0fbd88f41
Merge pull request #21018 from Natural-selection1/visibility
fix: make visibility diagnostics for fields to correct location
2025-11-18 14:13:19 +00:00
Hegui Dai
cc66e1d7dc Add visibility diagnostics for private fields to the correct location 2025-11-18 22:03:20 +08:00
A4-Tacks
3bbd8f1e70
Fix hit incorrect_case on no_mangle static items
Example
---
```rust
#[no_mangle]
static lower_case: () = ();
```

**Before this PR**

```text
non_upper_case_globals
```

**After this PR**

No diagnostics
2025-11-17 18:34:22 +08:00
Chayim Refael Friedman
50384460c6 Rewrite method resolution to follow rustc more closely
It cannot be exactly the same, because we have needs rustc doesn't have (namely, accurate enumeration of all methods, not just with a specific name, for completions etc., while rustc also needs a best-effort implementation for diagnostics) but it is closer than the previous impl.

In addition we rewrite the closely related handling of operator inference and impl collection.

This in turn necessitate changing some other parts of inference in order to retain behavior. As a result, the behavior more closely matches rustc and is also more correct.

This fixes 2 type mismatches on self (1 remains) and 4 diagnostics (1 remains), plus some unknown types.
2025-11-05 18:43:36 +02:00
Chayim Refael Friedman
dc91c0a9f3 Provide a setting to disable showing rename conflicts 2025-10-27 18:04:33 +02:00
Shoyu Vanilla
c6e605388f Add regression tests for some fixed A-ty issues 2025-10-27 02:18:52 +09:00
Shoyu Vanilla
71ddc8dced fix: Fix a bug on inhabitedness checks for arrays 2025-10-24 22:35:09 +09:00
Chayim Refael Friedman
7a7ab993bb
Revert "internal: Rewrite attribute handling" 2025-10-22 19:19:13 +03:00
Chayim Refael Friedman
455ca02f17 Rewrite attribute handling
Basically, we switch to expanding cfg_attr in AST form, filter irrelevant attributes from the item tree, and move hir-def attributes (non-item-tree) to be flag-based.

The main motivation is memory usage, although this also simplifies the code, and fixes some bugs around handling of `cfg_attr`s.
2025-10-22 11:47:01 +03:00
Chayim Refael Friedman
81e621af0b Improve fixture support
Support more features beside highlighting, and support items from minicore.
2025-10-16 22:06:16 +03:00
Shoyu Vanilla (Flint)
87ccc2b7c9
Merge pull request #20801 from ChayimFriedman2/fix-insert-use
minor: Small fixes for import insertion
2025-10-10 08:28:42 +00:00
David Barsky
7e9be347cc
Merge pull request #20796 from ChayimFriedman2/bump-salsa
internal: Bump Salsa
2025-10-06 16:23:20 +00:00
Chayim Refael Friedman
f0b496cbc7
Merge pull request #20802 from ChayimFriedman2/regression20662
minor: Add regression test for need-mut diagnostic
2025-10-05 19:06:18 +00:00
Chayim Refael Friedman
8121727283 Add regression test for need-mut diagnostic 2025-10-05 21:57:22 +03:00
Chayim Refael Friedman
10db7ac7a4 Deprecate preserve import granularity option
It didn't do anything (behaved like `item`), as with `enforceGranularity = false` (which is the default), the style of the current file is always preferred, regardless of the setting.

We could make it fail when the setting is `preserve` and the current file's style could not be detected, but that makes little sense.

It is a bit weird that the default is `crate` but `preserve` falls back to `item`, however that was the previous behavior.
2025-10-05 15:19:52 +03:00
Chayim Refael Friedman
c6ef51e550 Switch to home-made db attaching infrastructure
Instead of using Salsa's, as we can no longer can a `dyn HirDatabase` from the `dyn salsa::Database` Salsa provides.
2025-10-05 09:55:50 +03:00
Chayim Refael Friedman
940e1308f2
Merge pull request #20793 from A4-Tacks/diag-paren-missing-unsafe
Fix missing parentheses for missing_unsafe
2025-10-05 06:52:31 +00:00
A4-Tacks
a068ef86e3
Fix parentheses for missing_unsafe
I seem unable to use `Expr::needs_parens*` to complete it

Example
---
```rust
static mut STATIC_MUT: u8 = 0;

fn foo() -> u8 {
    STATIC_MUT$0 * 2
}
```

**Before this PR**:

```rust
static mut STATIC_MUT: u8 = 0;

fn foo() -> u8 {
    unsafe { STATIC_MUT } * 2
}
```

**After this PR**:

```rust
static mut STATIC_MUT: u8 = 0;

fn foo() -> u8 {
    (unsafe { STATIC_MUT }) * 2
}
```
2025-10-05 14:02:49 +08:00
Chayim Refael Friedman
797ba9c7cb Fix erroneous diagnostic incorrect_generics_len when there are generics on enum variant used through type alias 2025-10-03 06:54:32 +03:00
Shoyu Vanilla (Flint)
3706595ad2
Merge pull request #20770 from ChayimFriedman2/unsafe-impl-unresolved
fix: Ignore impl trait safety errors when the trait is unresolved
2025-10-02 03:29:55 +00:00
Chayim Refael Friedman
572e703df0 Ignore impl trait safety errors when the trait is unresolved 2025-09-30 18:48:54 +03:00
Chayim Refael Friedman
d1288f6353 Migrate inference to next solver 2025-09-30 13:10:59 +03:00
Lukas Wirth
5c0b555a65
Merge pull request #19867 from Kivooeo/unsafegate
Allow `&raw [mut | const]` for union field
2025-09-28 11:54:24 +00:00
A4-Tacks
4353624cc0
Fix fixes for unused raw variables
Example
---
```
fn main() {
    let $0r#type = 2;
}
```

**Before this PR**:

```rust
fn main() {
    let _r#type = 2;
}
```

**After this PR**:

```rust
fn main() {
    let _type = 2;
}
```
2025-09-25 19:58:45 +08:00
Chayim Refael Friedman
ad9422da1a Fix lifetime elision handling for Fn-style trait bounds
Two fixes were needed:

 1. Previously, we enabled elision for the generic args of `Fn` itself, instead of for generic args of paths within it.
 2. In lowering in the new solver the `Output` parameter did not have elision set correctly, I don't know why. In the old lowering it was done correctly.
2025-09-22 16:53:20 +03:00
Kivooeo
285bb607e0 allow take union field addresses in safe rust 2025-09-20 08:42:51 -07:00
A4-Tacks
a41ca500b0
Fix unused_variables fixes shorthand record field
Example
---

```rust
struct S { field : u32 }
fn main() {
    let s = S { field : 2 };
    let S { $0field } = s
}
```

**Before this PR**:

```rust
struct S { field : u32 }
fn main() {
    let s = S { field : 2 };
    let S { _field } = s
}
```

**After this PR**:

```rust
struct S { field : u32 }
fn main() {
    let s = S { field : 2 };
    let S { field: _field } = s
}
```
2025-09-20 18:25:28 +08:00
Chayim Refael Friedman
cd31e11f94
Merge pull request #20664 from ChayimFriedman2/coerce-ns
fix: Port a bunch of stuff from rustc and fix a bunch of type mismatches/diagnostics
2025-09-18 00:19:30 +00:00
Lukas Wirth
aecb756876
Merge pull request #20517 from Veykril/veykril/push-wrurmtqppzus
fix: Only compute unstable paths on nightly toolchains for IDE features
2025-09-16 07:28:47 +00:00
Lukas Wirth
685f156fa6 fix: Only compute unstable paths on nightly toolchains for IDE features 2025-09-16 09:17:16 +02:00
Chayim Refael Friedman
7d1860807e Port a bunch of stuff from rustc and fix a bunch of type mismatches/diagnostics
This started from porting coercion, but ended with porting much more.
2025-09-15 18:56:17 +03:00
Shoyu Vanilla (Flint)
db0420c278
Merge pull request #20642 from ChayimFriedman2/wasm-safe
fix: Make `#[target_feature]` always safe on WASM
2025-09-11 05:09:26 +00:00