summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/ide-diagnostics
AgeCommit message (Collapse)AuthorLines
2024-12-18Taking a raw ref of a deref is always safeLukas Wirth-0/+16
2024-12-16Merge pull request #18700 from ChayimFriedman2/dyn-sendLukas Wirth-1/+18
fix: Fix a panic with a diagnostics fix when a keyword is used as a field
2024-12-16Fix a panic with a diagnostics fix when a keyword is used as a fieldChayim Refael Friedman-1/+18
I found it easiest to fix in the quickfix code, and not deeper (e.g. body lowering).
2024-12-16Report unresolved idents for implicit captures in `format_args!()`Chayim Refael Friedman-8/+8
And also a bit of cleanup by storing the capture's span with the open quote included.
2024-12-12Fix typo in error message for invalid castingPhilipp Hofer-1/+1
Corrected the spelling of "defererence" to "dereference" in the error message that informs users about invalid casting requirements.
2024-12-11Properly handle different defaults for severity of lintsChayim Refael Friedman-45/+103
Previously all lints were assumed to be `#[warn]`, and we had a hand-coded list of `#[allow]` exceptions. Now the severity is autogenerated from rustdoc output. Also support lints that change status between editions, and the `warnings` lint group.
2024-12-09minor: Migrate `remove_unnecessary_wrapper` to `SyntaxEditor`Giga Bowser-20/+43
2024-12-09Add diagnostic fix to remove unnecessary wrapper in type mismatchGiga Bowser-62/+375
I also reorganized the tests in a more logical order, and removed the redundant `test_` prefix from their names.
2024-12-09fix: Non-exhaustive structs may be emptyLukas Wirth-0/+19
2024-12-06Merge pull request #18594 from ChayimFriedman2/async-closuresLukas Wirth-0/+21
feat: Support `AsyncFnX` traits
2024-12-04Merge pull request #18611 from ChayimFriedman2/proc-macro-warnLukas Wirth-0/+6
fix: Do not report warnings from proc macros, ever
2024-12-04Do not report warnings from proc macros, everChayim Refael Friedman-0/+6
2024-12-04Complete diagnostics in ty lowering groundworkChayim Refael Friedman-0/+200
Implement diagnostics in all places left: generics (predicates, defaults, const params' types), fields, and type aliases. Unfortunately this results in a 20mb addition in `analysis-stats .` due to many type methods returning an addition diagnostics result now (even if it's `None` in most cases). I'm not sure if this can be improved. An alternative strategy that can prevent the memory usage growth is to never produce diagnostics in hir-ty methods. Instead, lower all types in the hir crate when computing diagnostics from scratch (with diagnostics this time). But this has two serious disadvantages: 1. This can cause code duplication (although it can probably be not that bad, it will still mean a lot more code). 2. I believe we eventually want to compute diagnostics for the *entire* workspace (either on-type or on-save or something alike), so users can know when they have diagnostics even in inactive files. Choosing this approach will mean we lose all precomputed salsa queries. For one file this is fine, for the whole workspace this will be very slow.
2024-12-04Lay the foundation for diagnostics in ty lowering, and implement a first ↵Chayim Refael Friedman-3/+247
diagnostic The diagnostic implemented is a simple one (E0109). It serves as a test for the new foundation. This commit only implements diagnostics for type in bodies and body-carrying signatures; the next commit will include diagnostics in the rest of the things. Also fix one weird bug that was detected when implementing this that caused `Fn::(A, B) -> C` (which is a valid, if bizarre, alternative syntax to `Fn(A, B) -> C` to lower incorrectly. And also fix a maybe-bug where parentheses were sneaked into a code string needlessly; this was not detected until now because the parentheses were removed (by the make-AST family API), but with a change in this commit they are now inserted. So fix that too.
2024-12-04Extend reported unsafe operationsChayim Refael Friedman-20/+134
We add union fields access (in both expressions and patterns) and inline assembly. That completes the unsafe check (there are some other unsafe things but they are unstable), and so also opens the door to reporting unused unsafe without annoying people about their not-unused unsafe blocks.
2024-12-03Support `AsyncFnX` traitsChayim Refael Friedman-0/+21
Only in calls, because to support them in bounds we need support from Chalk. However we don't yet report error from bounds anyway, so this is less severe. The returned future is shown in its name within inlay hints instead of as a nicer `impl Future`, but that can wait for another PR.
2024-10-31Move child_by_source from hir-def to hirLukas Wirth-1/+1
2024-10-28Merge pull request #18420 from ChayimFriedman2/cfg-true-falseLukas Wirth-0/+16
feat: Support `cfg(true)` and `cfg(false)`
2024-10-28Merge pull request #18421 from Veykril/push-uxxwvwnqvomrLukas Wirth-21/+19
Move text-edit into ide-db
2024-10-28ReformatLukas Wirth-14/+14
2024-10-28Move text-edit into ide-dbLukas Wirth-21/+19
2024-10-27Properly resolve prelude paths inside modules inside blocksChayim Refael Friedman-0/+25
I.e. the following situation: ``` fn foo() { mod bar { fn qux() { // Prelude path here (e.g. macro use prelude or extern prelude). } } } ``` Those were previously unresolved, because, in order to support `self` and `super` properly, since #15148 we do not ascend block paths when there is a module in between, but only crate def maps register preludes, not block def maps, and we can't change this because block def map prelude can always be overridden by another block. E.g. ``` fn foo() { struct WithTheSameNameAsPreludeItem; { WithTheSameNameAsPreludeItem } } ``` Here `WithTheSameNameAsPreludeItem` refer to the item from the top block, but if we would register prelude items in each block the child block would overwrite it incorrectly.
2024-10-27Support `cfg(true)` and `cfg(false)`Chayim Refael Friedman-0/+16
As per RFC 3695.
2024-10-27Split `macro-error` diagnostic so users can ignore only parts of itChayim Refael Friedman-4/+9
Split it into `macro-error`, `proc-macros-disabled` and `proc-macro-disabled`.
2024-10-22Correctly resolve variables and labels from before macro definition in macro ↵Chayim Refael Friedman-0/+30
expansion E.g.: ```rust let v; macro_rules! m { () => { v }; } ``` This was an existing bug, but it was less severe because unless the variable was shadowed it would be correctly resolved. With hygiene however, without this fix the variable is never resolved.
2024-10-22Merge pull request #18254 from ChayimFriedman2/fix-mutLukas Wirth-18/+45
fix: Nail destructuring assignment once and for all
2024-10-21fix: classify `safe` as a contextual kwroife-2/+2
2024-10-20Store patterns desugared from destructuring assignments in source mapChayim Refael Friedman-9/+29
And few more fixups. I was worried this will lead to more memory usage since `ExprOrPatId` is double the size of `ExprId`, but this does not regress `analysis-stats .`. If this turns out to be a problem, we can easily use the high bit to encode this information.
2024-10-20Handle destructuring assignments uniformlyChayim Refael Friedman-1/+16
Instead of lowering them to `<expr> = <expr>`, then hacking on-demand to resolve them, we lower them to `<pat> = <expr>`, and use the pattern infrastructure to handle them. It turns out, destructuring assignments are surprisingly similar to pattern bindings, and so only minor modifications are needed. This fixes few bugs that arose because of the non-uniform handling (for example, MIR lowering not handling slice and record patterns, and closure capture calculation not handling destructuring assignments at all), and furthermore, guarantees we won't have such bugs in the future, since the programmer will always have to explicitly handle `Expr::Assignment`. Tests don't pass yet; that's because the generated patterns do not exist in the source map. The next commit will fix that.
2024-10-20Remove now-incorrect codeChayim Refael Friedman-8/+0
Because our lint infra *can* handle allows from within macro expansions! (Also, what did this reason have to do with something that is a hard error and not a lint? I'm puzzled). I wonder how many such diagnostics we have... Maybe that also mean we can change `unused_mut` to no-longer-experimental? But this is a change I'm afraid to do without checking.
2024-10-20fix: do not emit unsafe diagnositcs for safe statics in extern blocksroife-0/+35
2024-10-20feat: initial support for safe_kw in extern blocksroife-2/+2
2024-10-15fix: autofix for missing wrapped unit in return exprroife-0/+38
2024-10-14Auto merge of #18252 - ShoyuVanilla:issue-15799, r=Veykrilbors-0/+25
fix: Do not consider mutable usage of deref to `*mut T` as deref_mut Fixes #15799 We are doing some heuristics for deciding whether the given deref is deref or deref_mut here; https://github.com/rust-lang/rust-analyzer/blob/5982d9c420d0dc90739171829f0d2e9c80d98979/crates/hir-ty/src/infer/mutability.rs#L182-L200 But this heuristic is erroneous if we are dereferencing to a mut ptr and normally those cases are filtered out here as builtin; https://github.com/rust-lang/rust-analyzer/blob/5982d9c420d0dc90739171829f0d2e9c80d98979/crates/hir-ty/src/mir/lower/as_place.rs#L165-L177 Howerver, this works not so well if the given dereferencing is double dereferencings like the case in the #15799. ```rust struct WrapPtr(*mut u32); impl core::ops::Deref for WrapPtr { type Target = *mut u32; fn deref(&self) -> &Self::Target { &self.0 } } fn main() { let mut x = 0u32; let wrap = WrapPtr(&mut x); unsafe { **wrap = 6; } } ``` Here are two - outer and inner - dereferences here, and the outer dereference is marked as deref_mut because there is an assignment operation. And this deref_mut marking is propagated into the inner dereferencing. In the later MIR lowering, the outer dereference is filtered out as it's expr type is `*mut u32`, but the expr type in the inner dereference is an ADT, so this false-mutablility is not filtered out. This PR cuts propagation of this false mutablilty chain if the expr type is mut ptr. Since this happens before the resolve_all, it may have some limitations when the expr type is determined as mut ptr at the very end of inferencing, but I couldn't find simple fix for it 🤔
2024-10-14Auto merge of #18217 - ChayimFriedman2:cast-unknown-ptr, r=Veykrilbors-18/+36
fix: Comment out cast checks for unknown ptr kind Just like we don't check for types containing unknown. Fixes #18214. See also https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Another.20case.20of.20.2318064.3F.
2024-10-07fix: Do not consider mutable usage of deref to `*mut T` as deref_mutShoyu Vanilla-0/+25
2024-09-30Comment out cast checks for unknown ptr kindChayim Refael Friedman-18/+36
Just like we don't check for types containing unknown.
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.