summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/ide-diagnostics
AgeCommit message (Collapse)AuthorLines
2024-08-25fix: Fix trait method completions not acknowledging Deref implsLukas Wirth-1/+1
2024-08-16Auto merge of #17905 - ChayimFriedman2:edition-dependent-raw-keyword, r=Veykrilbors-63/+114
fix: Properly account for editions in names This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here). It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now. The rules of thumb are: - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code. - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn). - For debugging tools (helper methods and logs), I used `Edition::LATEST`. Reviewing notes: This is a really big PR but most of it is mechanical translation. I changed `Name` displayers to require an edition, and followed the compiler errors. Most methods just propagate the edition requirement. The interesting cases are mostly in `ide-assists`, as sometimes the correct crate to fetch the edition from requires awareness (there may be two). `ide-completions` and `ide-diagnostics` were solved pretty easily by introducing an edition field to their context. `ide` contains many features, for most of them it was propagated to the top level function and there the edition was fetched based on the file. I also fixed all FIXMEs from #17896. Some required introducing an edition parameter (usually not for many methods after the changes to `Name`), some were changed to a new method `is_any_identifier()` because they really want any possible keyword. Fixes #17895. Fixes #17774.
2024-08-16Properly account for editions in namesChayim Refael Friedman-63/+114
This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here). It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now. The rules of thumb are: - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code. - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn). - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
2024-08-16Auto merge of #17907 - ChayimFriedman2:no-once_cell, r=Veykrilbors-6/+6
internal: Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/Lock This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-16Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/LockChayim Refael Friedman-6/+6
This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-13Temporarily remove non-working test caseShoyu Vanilla-12/+2
2024-08-13feat: `min-exhaustive-patternsShoyu Vanilla-0/+70
2024-08-12fix: Missing non-exhaustive let diagnostics inside async or unsafe blockShoyu Vanilla-0/+39
2024-08-12Auto merge of #17863 - Veykril:include-diags, r=Veykrilbors-5/+19
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-12Resolve included files to their calling modules in IDE layerLukas Wirth-5/+19
2024-08-12fix: Correctly support `#[rustc_deprecated_safe_2024]`Lukas Wirth-0/+24
2024-08-07Fix unconfigured diagnostic being attached to the wrong file for modulesLukas Wirth-1/+25
2024-08-06Replace `[package.repository] = "…"` of published crates with ↵Vincent Esche-1/+1
`[package.repository.workspace] = true`
2024-08-06Unify package descriptions by adding references to "rust-analyzer"Vincent Esche-1/+1
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-06Add repository URL for published crates' missing `[package.repository]` fieldsVincent Esche-0/+1
2024-08-06Replace `"TBD"` with more helpful desciptions in published crates' ↵Vincent Esche-1/+1
`[package.description]` fields
2024-08-05Surpress type mismatches in calls with mismatched arg countsLukas Wirth-0/+14
2024-08-05Auto merge of #17791 - ShoyuVanilla:await-outside-of-async, r=Veykrilbors-0/+103
feat: Implement diagnostic for `await` outside of `async` Closes #17781
2024-08-05Auto merge of #17775 - ShoyuVanilla:segregate-diags, r=Veykrilbors-86/+138
perf: Segregate syntax and semantic diagnostics Closes #17731
2024-08-05perf: Segregate syntax and semantic diagnosticsShoyu Vanilla-86/+138
2024-08-05feat: Implement diagnostic for `await` outside of `async`Shoyu Vanilla-0/+103
2024-08-05Simplify FileDelegateLukas Wirth-3/+3
2024-08-01fix: Insert a tail `Ok(())` for expr block instead of wrapping with `Ok`Shoyu Vanilla-2/+68
2024-07-29Auto merge of #17707 - Veykril:proc-macro-err-cleanup, r=Veykrilbors-55/+16
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-29Fix error spans for include! and compile_error!Lukas Wirth-7/+12
2024-07-29Make basic use of spans for macro expansion errorsLukas Wirth-2/+2
2024-07-26early exit if unresolved field is an indexAli Bektas-3/+45
2024-07-26Internal: Cleanup proc-macro error handlingLukas Wirth-48/+4
2024-07-22Auto merge of #17586 - ShoyuVanilla:tuple-arg-macro-rest, r=Veykrilbors-0/+69
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; https://github.com/rust-lang/rust-analyzer/blob/ffbc5ad993d5cd2f3b8bcf9a511165470944ab91/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; https://github.com/rust-lang/rust-analyzer/blob/ffbc5ad993d5cd2f3b8bcf9a511165470944ab91/crates/hir-def/src/body/lower.rs#L1429-L1437 This behavior is reasonable because rustc does similar things in https://github.com/rust-lang/rust/blob/62c068feeafd1f4abbf87243d69cf8862e4dd277/compiler/rustc_ast_lowering/src/pat.rs#L108-L111 and https://github.com/rust-lang/rust/blob/62c068feeafd1f4abbf87243d69cf8862e4dd277/compiler/rustc_ast_lowering/src/pat.rs#L123-L142 But this sometimes works differently because Rust Analyzer expands macros while ast lowering; https://github.com/rust-lang/rust-analyzer/blob/ffbc5ad993d5cd2f3b8bcf9a511165470944ab91/crates/hir-def/src/body/lower.rs#L1386-L1398 https://github.com/rust-lang/rust-analyzer/blob/ffbc5ad993d5cd2f3b8bcf9a511165470944ab91/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. https://github.com/rust-lang/rust/blob/62c068feeafd1f4abbf87243d69cf8862e4dd277/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-21Auto merge of #17657 - Veykril:cfg-slim, r=lnicolabors-1/+1
internal: Make `CfgExpr` slimmer
2024-07-21Make `CfgExpr` slimmerLukas Wirth-1/+1
2024-07-21fix: Panic in debug profile for tuple deconstruct with arity mismatchShoyu Vanilla-0/+12
2024-07-19Avoid ref when using format! in compilerYuri Astrakhan-1/+1
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-18Encode edition within FileId in the hir layerLukas Wirth-111/+125
2024-07-16Remove Name::to_smol_strLukas Wirth-11/+22
2024-07-15Auto merge of #17588 - CamWass:more-rename, r=Veykrilbors-21/+111
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-15Auto merge of #17587 - joshka:jm/edit-name-after-refactor, r=Veykrilbors-10/+10
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-14Use statics + clone instead of const until const can access staticsLukas Wirth-1/+1
2024-07-13feat: Add incorrect case diagnostics for enum variant fields and all variablesCampbell-21/+111
2024-07-12Trigger VSCode to rename after extract variable assist is appliedbors-10/+10
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-13Allow macro expansions into `RestPat` in tuple args work as ellipsis like ↵Shoyu Vanilla-0/+69
plain `RestPat`
2024-07-12Use Symbol in NameLukas Wirth-3/+3
2024-07-07Auto merge of #17523 - wada314:master, r=Veykrilbors-0/+5
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-06Diagnose unresolved self value in path expressionLukas Wirth-0/+16
2024-07-03fix: Don't emit semantic diagnostics in files with a lot of syntax errorsLukas Wirth-1/+8
2024-07-02squash.Shohei Wada-0/+5
2024-06-30Auto merge of #17520 - Veykril:slim-proc-macro-api, r=Veykrilbors-2/+0
internal: Cleanup proc-macro-srv some more
2024-06-30Remove inline `rust_2018_idioms, unused_lifetimes` lint warn, Cargo.toml ↵Lukas Wirth-2/+0
already enforces this
2024-06-30Auto merge of #17516 - kilpkonn:master, r=kilpkonnbors-1/+8
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-30SimplifyLukas Wirth-12/+3