summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/ide-diagnostics
AgeCommit message (Collapse)AuthorLines
2024-09-29Fix ambiguity with CamelCase diagnostic messagesMatthew Wilding-15/+15
2024-09-19Handle lint attributes that are under `#[cfg_attr]`Chayim Refael Friedman-9/+92
2024-09-19Remove check that text of `parse_expr_from_str()` matches the produced ↵Chayim Refael Friedman-0/+13
parsed tree This check is incorrect when we have comments and whitespace in the text. We can strip comments, but then we still have whitespace, which we cannot strip without changing meaning for the parser. So instead I opt to remove the check, and wrap the expression in parentheses (asserting what produced is a parenthesized expression) to strengthen verification.
2024-09-18Auto merge of #18128 - ChayimFriedman2:external-macros-lint, r=Veykrilbors-1/+62
fix: Handle errors and lints from external macros Some lints should not be reported if they originate from an external macro, and quickfixes should be disabled (or they'll change library code). Fixes #18122. Closes #18124.
2024-09-18Auto merge of #18136 - valadaptive:no-mangle-lints, r=Veykrilbors-0/+58
Don't lint names of #[no_mangle] extern fns [Rust doesn't run the `non_snake_case_name` lint on `extern fn`s with the `#[no_mangle]` attribute](https://github.com/rust-lang/rust/pull/44966). The conditions are: - The function must be `extern` and have a `#[no_mangle]` attribute. - The function's ABI must not be explicitly set to "Rust". This PR replicates that logic here.
2024-09-18Don't lint names of #[no_mangle] extern fnsvaladaptive-0/+58
2024-09-18Add diagnostics for `unsafe_op_in_unsafe_fn`Chayim Refael Friedman-3/+45
Turns out it's pretty easy, but I did have to add support for allowed-by-default lints.
2024-09-17Handle errors and lints from external macrosChayim Refael Friedman-1/+62
Some lints should not be reported if they originate from an external macro, and quickfixes should be disabled (or they'll change library code).
2024-09-12Auto merge of #18099 - ChayimFriedman2:diag-only-necessary, r=Veykrilbors-134/+310
Use more correct handling of lint attributes The previous analysis was top-down, and worked on a single file (expanding macros). The new analysis is bottom-up, starting from the diagnostics and climbing up the syntax and module tree. While this is more efficient (and in fact, efficiency was the motivating reason to work on this), unfortunately the code was already fast enough. But luckily, it also fixes a correctness problem: outline parent modules' attributes were not respected for the previous analysis. Case lints specifically did their own analysis to accommodate that, but it was limited to only them. The new analysis works on all kinds of lints, present and future. It was basically impossible to fix the old analysis without rewriting it because navigating the module hierarchy must come bottom-up, and if we already have a bottom-up analysis (including syntax analysis because modules can be nested in other syntax elements, including macros), it makes sense to use only this kind of analysis. Few other bugs (not fundamental to the previous analysis) are also fixed, e.g. overwriting of lint levels (i.e. `#[allow(lint)] mod foo { #[warn(lint)] mod bar; }`. After this PR is merged I intend to work on an editor command that does workspace-wide diagnostics analysis (that is, `rust-analyzer diagnostics` but from your editor and without having to spawn a new process, which will have to analyze the workspace from scratch). This can be useful to users who do not want to enable check on save because of its overhead, but want to see workspace wide diagnostics from r-a (or to maintainers of rust-analyzer). Closes #18086. Closes #18081. Fixes #18056.
2024-09-12Use more correct handling of lint attributesChayim Refael Friedman-134/+310
The previous analysis was top-down, and worked on a single file (expanding macros). The new analysis is bottom-up, starting from the diagnostics and climbing up the syntax and module tree. While this is more efficient (and in fact, efficiency was the motivating reason to work on this), unfortunately the code was already fast enough. But luckily, it also fixes a correctness problem: outline parent modules' attributes were not respected for the previous analysis. Case lints specifically did their own analysis to accommodate that, but it was limited to only them. The new analysis works on all kinds of lints, present and future. It was basically impossible to fix the old analysis without rewriting it because navigating the module hierarchy must come bottom-up, and if we already have a bottom-up analysis (including syntax analysis because modules can be nested in other syntax elements, including macros), it makes sense to use only this kind of analysis. Few other bugs (not fundamental ti the previous analysis) are also fixed, e.g. overwriting of lint levels (i.e. `#[allow(lint)] mod foo { #[warn(lint)] mod bar; }`.
2024-09-12Auto merge of #18106 - Veykril:push-yzsqoykyowts, r=Veykrilbors-0/+22
fix: Don't report typed hole error in asm! out ops Fixes https://github.com/rust-lang/rust-analyzer/issues/18103
2024-09-12fix: Don't report typed hole error in asm! out opsLukas Wirth-0/+22
2024-09-12Fix inference of literals when the expectation is CastableChayim Refael Friedman-3/+14
I followed the compiler: https://github.com/rust-lang/rust/blob/5bce6d48ff09dcb2613278ec93013795718478ef/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs#L1560-L1579.
2024-09-11Skip checks for cast to dyn traitsShoyu Vanilla-0/+96
2024-09-06fix: Properly prevent mir building with unknown types presentLukas Wirth-1/+1
2024-09-06fix: Always explicitly set trait ref self types when loweringLukas Wirth-1/+1
2024-09-03feat: Implement cast typechecksShoyu Vanilla-7/+1034
2024-08-29Do not report missing unsafe on `addr_of[_mut]!(EXTERN_OR_MUT_STATIC)`Chayim Refael Friedman-0/+25
The compiler no longer does as well; see https://github.com/rust-lang/rust/pull/125834.
2024-08-29Add diagnostic for accessing an `extern` staticChayim Refael Friedman-0/+25
2024-08-29feat: Implement object safetyShoyu Vanilla-1/+1
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