Commit graph

476 commits

Author SHA1 Message Date
Shoyu Vanilla
db24cf5a48 fix: Missing non-exhaustive let diagnostics inside async or unsafe block 2024-08-12 23:19:03 +09: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
Lukas Wirth
ded3e21fdd fix: Correctly support #[rustc_deprecated_safe_2024] 2024-08-12 10:56:59 +02:00
Lukas Wirth
e3e31ce199 Fix unconfigured diagnostic being attached to the wrong file for modules 2024-08-07 15:07:09 +02:00
Vincent Esche
7dec7e92ea Replace [package.repository] = "…" of published crates with [package.repository.workspace] = true 2024-08-06 00:26:42 +02:00
Vincent Esche
624f2ead7b Unify package descriptions by adding references to "rust-analyzer"
With the lack of a README on the individually published library crates and the somewhat cryptic `ra_ap_` prefix it is hard to figure out where those crates belong to, so mentioning "rust-analyzer" feels like auseful hint there.
2024-08-06 00:25:02 +02:00
Vincent Esche
6f329e6d5b Add repository URL for published crates' missing [package.repository] fields 2024-08-06 00:25:02 +02:00
Vincent Esche
b5b0f4bc5a Replace "TBD" with more helpful desciptions in published crates' [package.description] fields 2024-08-06 00:25:02 +02:00
Lukas Wirth
deddbbfa60 Surpress type mismatches in calls with mismatched arg counts 2024-08-05 16:15:28 +02:00
bors
25d9e05c03 Auto merge of #17791 - ShoyuVanilla:await-outside-of-async, r=Veykril
feat: Implement diagnostic for `await` outside of `async`

Closes #17781
2024-08-05 13:53:21 +00:00
bors
f62d7b9f11 Auto merge of #17775 - ShoyuVanilla:segregate-diags, r=Veykril
perf: Segregate syntax and semantic diagnostics

Closes #17731
2024-08-05 13:39:30 +00:00
Shoyu Vanilla
eea1e9b21f perf: Segregate syntax and semantic diagnostics 2024-08-05 22:12:47 +09:00
Shoyu Vanilla
8a51419a2d feat: Implement diagnostic for await outside of async 2024-08-05 21:47:57 +09:00
Lukas Wirth
fcb88832de Simplify FileDelegate 2024-08-05 13:03:03 +02:00
Shoyu Vanilla
3121a91e0a fix: Insert a tail Ok(()) for expr block instead of wrapping with Ok 2024-08-01 21:24:28 +09:00
bors
a021b85be5 Auto merge of #17707 - Veykril:proc-macro-err-cleanup, r=Veykril
feat: Use spans for builtin and declarative macro expansion errors

This should generally improve some error reporting for macro expansion errors. Especially for `compile_error!` within proc-macros
2024-07-29 14:07:33 +00:00
Lukas Wirth
d46060b168 Fix error spans for include! and compile_error! 2024-07-29 15:57:01 +02:00
Lukas Wirth
ae9c553902 Make basic use of spans for macro expansion errors 2024-07-29 14:52:40 +02:00
Ali Bektas
480db310b6 early exit if unresolved field is an index 2024-07-26 22:44:47 +02:00
Lukas Wirth
7beac14cba Internal: Cleanup proc-macro error handling 2024-07-26 14:38:19 +02:00
bors
6f3030f316 Auto merge of #17586 - ShoyuVanilla:tuple-arg-macro-rest, r=Veykril
Allow macro expansions into `RestPat` in tuple args work as ellipsis like plain `RestPat`

Fixes #17292

Currently, Rust Analyzer lowers `ast::Pat::RestPat` into `Pat::Missing` in general cases on the following lines;

ffbc5ad993/crates/hir-def/src/body/lower.rs (L1359-L1367)

And in some proper positions such as `TupleStruct(..)`, it is specially handed on the following lines;

ffbc5ad993/crates/hir-def/src/body/lower.rs (L1429-L1437)

This behavior is reasonable because rustc does similar things in
62c068feea/compiler/rustc_ast_lowering/src/pat.rs (L108-L111)
and
62c068feea/compiler/rustc_ast_lowering/src/pat.rs (L123-L142)

But this sometimes works differently because Rust Analyzer expands macros while ast lowering;

ffbc5ad993/crates/hir-def/src/body/lower.rs (L1386-L1398)
ffbc5ad993/crates/hir-def/src/body/lower.rs (L941-L963)
but rustc uses expanded ast in the corresponding tuple-handling process, so it does not have macro patterns there.
62c068feea/compiler/rustc_ast_lowering/src/pat.rs (L114)

So, if a macro expansion in a tuple arg results in `..`, rustc permits it like plain `..` pattern, but Rust Analyzer rejects it.
This is the root cause of #17292 and this PR allows macros expanded into `..` in a tuple arg position work as ellipsis like that.
2024-07-22 09:08:12 +00:00
bors
4afe0d5393 Auto merge of #17657 - Veykril:cfg-slim, r=lnicola
internal: Make `CfgExpr` slimmer
2024-07-21 15:50:31 +00:00
Lukas Wirth
1141c35a4b Make CfgExpr slimmer 2024-07-21 14:50:44 +02:00
Shoyu Vanilla
6e728df43a fix: Panic in debug profile for tuple deconstruct with arity mismatch 2024-07-21 02:37:37 +09:00
Yuri Astrakhan
cc1aded86c Avoid ref when using format! in compiler
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.
2024-07-19 14:41:59 -04:00
Lukas Wirth
5264f86242 Encode edition within FileId in the hir layer 2024-07-18 08:49:10 +02:00
Lukas Wirth
2346a80ab4 Remove Name::to_smol_str 2024-07-16 12:43:58 +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
f2d51073d2 Use statics + clone instead of const until const can access statics 2024-07-14 17:52:59 +02: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
3fe815b0f3 Use Symbol in Name 2024-07-12 16:06:44 +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
4420e7148f Diagnose unresolved self value in path expression 2024-07-06 15:44:12 +02: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
Shohei Wada
3725ab3146 squash. 2024-07-02 01:52:34 +09: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
21a3d01875 Remove inline rust_2018_idioms, unused_lifetimes lint warn, Cargo.toml already enforces this 2024-06-30 15:23:54 +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
Lukas Wirth
5374ebbf36 Simplify 2024-06-30 14:00:55 +02:00
Tavo Annus
1389312871 Make borrow checking configurable for term search 2024-06-29 12:24:08 +03: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
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
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
Tavo Annus
957325a5fe Run data_constructor tactic only backwards 2024-06-21 22:01:06 +03: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
Wilfred Hughes
495c0cb1ea fix: Only show unlinked-file diagnostic on first line during startup
This partially reverts #17350, based on the feedback in #17397.

If we don't have an autofix, it's more annoying to highlight the whole line.
This heuristic fixes the diagnostic overwhelming the user during startup.
2024-06-13 11:52:34 -07:00
DropDemBits
4e6d908382
internal: Expose snippet capability to diagnostic quickfixes 2024-06-07 21:29:48 -04:00
Wilfred Hughes
27182bb96b chore: Prefer tracing span shorthand macros 2024-06-06 16:52:25 -07:00
Wilfred Hughes
fcecbc5467 fix: Highlight unlinked files consistently with inactive files
Currently, rust-analyzer highlights the entire region when a `cfg` is
inactive (e.g. `#[cfg(windows)]` on a Linux machine). However,
unlinked files only highlight the first three characters of the file.

This was introduced in #8444, but users have repeatedly found
themselves with no rust-analyzer support for a file and unsure
why (see e.g. #13226 and the intentionally prominent pop-up added in
PR #14366).

(Anecdotally, we see this issue bite our users regularly, particularly
people new to Rust.)

Instead, highlight the entire inactive file, but mark it as all as
unused. This allows users to hover and run the quickfix from any line.

Whilst this is marginally more prominent, it's less invasive than a
pop-up, and users do want to know why they're getting no rust-analyzer
support in certain files.
2024-06-05 17:44:07 -07:00
Lukas Wirth
6f0207d594 Cleanup some inert attribute stuff 2024-06-04 12:38:20 +02:00
bors
89218cf29c Auto merge of #17329 - Nilstrieb:rustc_deprecated_safe_2024, r=Veykril
Don't mark `#[rustc_deprecated_safe_2024]` functions as unsafe

`std::env::set_var` will be unsafe in edition 2024, but not before it. I couldn't quite figure out how to check for the span properly, so for now we just turn the false positives into false negatives, which are less bad.
2024-06-03 12:44:21 +00:00
Nilstrieb
0e1353bebd Don't mark #[rustc_deprecated_safe_2024] functions as unsafe
`std::env::set_var` will be unsafe in edition 2024, but not before it.
I couldn't quite figure out how to check for the span properly, so for now
we just turn the false positives into false negatives, which are less bad.
2024-06-02 15:04:26 +02:00
Hamir Mahal
7fa555f8ba
fix: formatting in handlers/unresolved_method.rs 2024-05-30 16:39:41 -07:00
Hamir Mahal
7c34eb3880
style: simplify string interpolation 2024-05-30 16:18:49 -07:00
David Barsky
b75301cec8 internal: refactor prefer_no_std/prefer_prelude bools into a struct 2024-05-22 20:46:30 +02:00
Lukas Wirth
760ad445e2 Update assists test fixtures 2024-05-22 14:46:33 +02:00
Lukas Wirth
c88b421853 fix: Fix general find-path inconsistencies 2024-05-22 14:05:24 +02:00
bors
b98690ba74 Auto merge of #17221 - Veykril:lazier-validation, r=Veykril
internal: Lazier macro parse tree validation
2024-05-13 15:16:46 +00:00
Lukas Wirth
caddcccea5 parse_macro_expansion_error almost never contains values so Option it 2024-05-13 17:02:08 +02:00
Lukas Wirth
56552f4839 Push macro-parsing error calculation out of fundamental queries 2024-05-13 16:56:26 +02:00
Tavo Annus
ab18604309 Make term search fuel configurable 2024-05-08 19:46:33 +03:00
Tavo Annus
c3ab435b54 Collapse term search exprs before Cartesian product to avoid OOM 2024-05-06 20:29:34 +03:00
Bao Zhiyuan
5c88e98419 different error code based on variant 2024-04-23 20:54:03 +08:00
bors
4c08e2d32f Auto merge of #16938 - Nilstrieb:dont-panic-tests, r=Veykril
Implement `BeginPanic` handling in const eval

for #16935, needs some figuring out of how to write these tests correctly
2024-04-21 16:22:02 +00:00
Lukas Wirth
3b9a2af21f Peek for panic message in test output 2024-04-21 08:50:25 +02:00
Lev Iskandarov
029c7108e0 add test with multiple names 2024-04-20 21:04:53 +03:00
Lev Iskandarov
ce18438cfd try to generate more meaningful names 2024-04-20 20:50:47 +03:00
bors
91b8441b3a Auto merge of #17055 - wyatt-herkamp:fix_panic_at_unused_variable, r=Veykril
fix: Replace Just the variable name in Unused Variable Diagnostic Fix

Changes Unused Variable diagnostic to just look at the variable name, not the entire syntax range.

Also added a test for an unused variable in an array destructure.

Closes #17053
2024-04-17 10:11:03 +00:00
Lukas Wirth
0eb7b6c7b5 Don't show unused_variables fixes if the name comes from a macro definition 2024-04-17 12:05:35 +02:00
Lukas Wirth
531a270d91 Generally optimize diagnostics performance 2024-04-15 22:15:41 +02:00
Wyatt Herkamp
701068daf2 Verify we are not in a macro attempt 2 2024-04-15 14:11:45 -04:00
Wyatt Herkamp
0faa2940c7 Use the text range for the name. Not the entire syntax in Unused Variable Diagnostic. 2024-04-15 10:46:21 -04:00
Lukas Wirth
1915980031 fix: Fix impl Trait<Self> causing stackoverflows 2024-04-15 15:41:20 +02:00
Lukas Wirth
0036762b9d Make use of ThinArc in RawAttrs 2024-03-21 11:49:09 +01:00
bors
4e54b4bd6c Auto merge of #16889 - Veykril:utf8-path, r=Veykril
internal: Enforce utf8 paths

Cargo already requires this, and I highly doubt r-a works with non-utf8 paths generally either. This just makes dealing with paths a lot easier.
2024-03-19 14:57:18 +00:00
bors
a2f73d3142 Auto merge of #16879 - Nadrieril:fuel, r=Veykril
Add fuel to match checking

Exhaustiveness checking is NP-hard hence can take extremely long to check some specific matches. This PR makes ehxaustiveness bail after a set number of steps. I chose a bound that takes ~100ms on my machine, which should be more than enough for normal matches.

I'd like someone with less recent hardware to run the test to see if that limit is low enough for them. Also curious if the r-a team thinks this is a good ballpark or if we should go lower/higher. I don't have much data on how complex real-life matches get, but we can definitely go lower than `500 000` steps.

The second commit is a drive-by soundness fix which doesn't matter much today but will matter once `min_exhaustive_patterns` is stabilized.

Fixes https://github.com/rust-lang/rust-analyzer/issues/9528 cc `@matklad`
2024-03-19 14:44:05 +00:00
Lukas Wirth
399dbc074b internal: Enforce utf8 paths 2024-03-19 15:39:00 +01:00
Nadrieril
08a5f1e52a Skip the test when testing locally 2024-03-19 15:08:57 +01:00
Lukas Wirth
b38d5394bb internal: Move grammar codegen into xtask 2024-03-19 10:57:53 +01:00
Nadrieril
040f37a99d Avoid hanging on complex matches 2024-03-18 21:21:52 +01:00
bors
b6d1887bc4 Auto merge of #16861 - Veykril:macro-diag-exceptions, r=Veykril
fix: Ignore some warnings if they originate from within macro expansions

These tend to be annoying noise as we can't handle `allow`s for them properly for the time being.
2024-03-17 20:41:40 +00:00
Lukas Wirth
bb541c38d3 fix: Ignore some warnings if they originate from within macro expansions 2024-03-17 21:30:56 +01:00
Matthias Krüger
2a8edaa14d remove redundant clone()s 2024-03-17 14:06:21 +01:00
Lukas Wirth
9ba4493918 internal: Improve rooted upmapping 2024-03-12 13:46:58 +01:00
Lukas Wirth
fdc527f096 fix: Fix method resolution snapshotting receiver_ty too early 2024-03-11 15:35:06 +01:00
Young-Flash
562f4a2688 test: update test for unused_variables 2024-03-11 19:36:53 +08:00
Young-Flash
77136575da feat: add fix for unused_variables 2024-03-11 19:36:53 +08:00
bors
a58f574816 Auto merge of #16762 - wyatt-herkamp:master, r=Veykril
Added QuickFix for unresolved field.

Adds an AssistKind::QuickFix for unresolved field.

Currently, Snippets are not available for Diagnostics. So the type defaults to the Unit type if the type is not able to be inferred.

https://github.com/rust-lang/rust-analyzer/assets/11785959/bd4c67bd-f8cb-4254-9a87-641ae80a7a28

Closes https://github.com/rust-lang/rust-analyzer/issues/4563
2024-03-11 09:31:22 +00:00
Laurențiu Nicola
cd2347e132 Skip match diagnostics for partially unknown types 2024-03-07 19:11:23 +02:00
Wyatt Herkamp
4f0bc1a314 Typo 2024-03-06 11:51:45 -05:00
Wyatt Herkamp
255ba692aa Added tests, added Union Support, and code cleanup 2024-03-06 10:55:47 -05:00
Wyatt Herkamp
6027eae51e Fix Tests + Fix Warnings 2024-03-05 08:34:52 -05:00
Wyatt Herkamp
b45cfe15b5 Added quickfix for unresolved field. 2024-03-05 08:07:21 -05:00
Lukas Wirth
8844640c6f fix: Put style lints behind disabled-by-default config 2024-03-05 11:43:23 +01:00