about summary refs log tree commit diff
path: root/src/tools/rust-analyzer
AgeCommit message (Collapse)AuthorLines
2024-09-20analysis-stats: respect --disable-proc-macros flagDavid Barsky-1/+5
2024-09-20Auto merge of #18132 - ChayimFriedman2:fix-closure-semi, r=Veykrilbors-32/+100
fix: Don't complete `;` when in closure return expression Completing it will break syntax. Fixes #18130.
2024-09-20Auto merge of #18151 - ChayimFriedman2:metavar-concat, r=Veykrilbors-5/+304
feat: Support the `${concat(...)}` metavariable expression I didn't follow rustc precisely, because I think it does some things wrongly (or they are FIXME), but I only allowed more code, not less. So we're all fine. Closes #18145.
2024-09-20Auto merge of #18108 - ChayimFriedman2:lint-level-cfg, r=Veykrilbors-16/+120
fix: Handle lint attributes that are under `#[cfg_attr]` I forgot `cfg_attr` while working on #18099. Although the original code also didn't handle that (although case lints specifically were correct, by virtue of using hir attrs).
2024-09-19When checking for forbidden expr kind matches, account for rawnessChayim Refael Friedman-1/+25
An expression starting with `r#const` etc. should be accepted even in edition <=2021.
2024-09-19feat: Highlight exit points of async blocksChristopher Serr-71/+93
Async blocks act similar to async functions in that the await keywords are related, but also act like functions where the exit points are related.
2024-09-19Handle lint attributes that are under `#[cfg_attr]`Chayim Refael Friedman-16/+120
2024-09-19Support the `${concat(...)}` metavariable expressionChayim Refael Friedman-5/+304
I didn't follow rustc precisely, because I think it does some things wrongly (or they are FIXME), but I only allowed more code, not less. So we're all fine.
2024-09-19Auto merge of #18146 - ChayimFriedman2:allow-comment, r=Veykrilbors-6/+24
fix: Remove check that text of `parse_expr_from_str()` matches the produced 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. Fixes #18144.
2024-09-19Remove check that text of `parse_expr_from_str()` matches the produced ↵Chayim Refael Friedman-6/+24
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 #18131 - ChayimFriedman2:macro-expand-dollar-crate, r=Veykrilbors-64/+396
fix: Get rid of `$crate` in expansions shown to the user Be it "Expand Macro Recursively", "Inline macro" or few other things. We replace it with the crate name, as should've always been. Probably fixes some issues, but I don't know what they are.
2024-09-18Auto merge of #18139 - ShoyuVanilla:issue-18109, r=Veykrilbors-4/+81
fix: Extend `type_variable_table` when modifying index is larger than the table size Fixes #18109 Whenever we create an inference variable in r-a, we extend `type_variable_table` to matching size here; https://github.com/rust-lang/rust-analyzer/blob/f4aca78c92e03354327c8f6c7fefaef9f45ab166/crates/hir-ty/src/infer/unify.rs#L378-L381 But sometimes, an inference variable is [created from chalk](https://github.com/rust-lang/chalk/blob/ab710e0c9b455403b138ef72a2fb90967a58eff3/chalk-solve/src/infer/unify.rs#L743) and passed to r-a as a type of an expression or a pattern. If r-a set diverging flag to this before the table is extended to a sufficient size, it panics here; https://github.com/rust-lang/rust-analyzer/blob/f4aca78c92e03354327c8f6c7fefaef9f45ab166/crates/hir-ty/src/infer/unify.rs#L275-L277 I think that extending table when setting diverging flag is reasonable becase we are already doing such extending to a size that covers the inference vars created from chalk and this change only covers the order-dependent random cases that this might fail
2024-09-18Get rid of `$crate` in expansions shown to the userChayim Refael Friedman-64/+396
Be it "Expand Macro Recursively", "Inline macro" or few other things. We replace it with the crate name, as should've always been.
2024-09-19fix: Extend `type_variable_table` when modifying index is larger than table sizeShoyu Vanilla-4/+81
2024-09-18Extract logic to decide how to complete semicolon for unit-returning ↵Chayim Refael Friedman-39/+73
function into `CompletionContext` So that we don't recompute it for every item.
2024-09-18Don't complete `;` when in closure return expressionChayim Refael Friedman-24/+58
Completing it will break syntax.
2024-09-18Auto merge of #18117 - ChayimFriedman2:issue-18089, r=Veykrilbors-48/+166
fix: Always cache macro expansions' root node in Semantics Previously some expansions were not cached, but were cached in the expansion cache, which caused panics when later queries tried to lookup the node from the expansion cache. Fixes #18089.
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-6/+73
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-18Auto merge of #18135 - ChayimFriedman2:unsafe-op-in-unsafe-fn, r=Veykrilbors-10/+55
feat: Add diagnostics for `unsafe_op_in_unsafe_fn` Turns out it's pretty easy, but I did have to add support for allowed-by-default lints.
2024-09-18Auto merge of #18137 - ShoyuVanilla:expr-2021, r=Veykrilbors-21/+192
feat: Implement `expr_2021` Resolves #18062
2024-09-18feat: Implement `expr_2021`Shoyu Vanilla-21/+192
2024-09-18Don't lint names of #[no_mangle] extern fnsvaladaptive-6/+73
2024-09-18Add diagnostics for `unsafe_op_in_unsafe_fn`Chayim Refael Friedman-10/+55
Turns out it's pretty easy, but I did have to add support for allowed-by-default lints.
2024-09-17Use `SyntaxEditor` in `extract_type_alias`DropDemBits-13/+15
2024-09-17internal: Extend `SourceChangeBuilder` to make make working with ↵DropDemBits-1/+95
`SyntaxEditor`s easier
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-16fix: fix ambigious package name in flycheckJake-1/+1
2024-09-17assert that unexpectedly unsized fields are sized in the param envLukas Markeffsky-3/+3
2024-09-17Always cache macro expansions' root node in SemanticsChayim Refael Friedman-48/+166
Previously some expansions were not cached, but were cached in the expansion cache, which caused panics when later queries tried to lookup the node from the expansion cache.
2024-09-16layout computation: eagerly error for unexpected unsized fieldsLukas Markeffsky-38/+40
2024-09-16Fix printing of constants greater than `i128::MAX`Chayim Refael Friedman-3/+27
2024-09-13Auto merge of #18073 - alibektas:immutable_tree_panics, r=lnicolabors-2/+41
fix: Immutable tree panic in `generate_delegate_trait` fixes #17835
2024-09-12fix: Immutable tree panic in `generate_delegate_trait`Ali Bektas-2/+41
2024-09-12Auto merge of #18099 - ChayimFriedman2:diag-only-necessary, r=Veykrilbors-279/+403
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-279/+403
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 #18038 - roife:fix-issue-18034, r=Veykrilbors-105/+298
feat: generate names for tuple-struct in add-missing-match-arms fix #18034. This PR includes the following enhancement: - Introduced a `NameGenerator` in `suggest_name`, which implements an automatic renaming algorithm to avoid name conflicts. Here are a few examples: ```rust let mut generator = NameGenerator::new(); assert_eq!(generator.suggest_name("a"), "a"); assert_eq!(generator.suggest_name("a"), "a1"); assert_eq!(generator.suggest_name("a"), "a2"); assert_eq!(generator.suggest_name("b"), "b"); assert_eq!(generator.suggest_name("b"), "b1"); assert_eq!(generator.suggest_name("b2"), "b2"); assert_eq!(generator.suggest_name("b"), "b3"); assert_eq!(generator.suggest_name("b"), "b4"); assert_eq!(generator.suggest_name("b3"), "b5"); ``` - Updated existing testcases in ide-assists for the new `NameGenerator` (only modified generated names). - Generate names for tuple structs instead of using wildcard patterns in `add-missing-match-arms`.
2024-09-12Auto merge of #18107 - Veykril:push-oopkquknxqxs, r=Veykrilbors-38/+24
fix: Don't emit empty inlay hint parts
2024-09-12fix: Don't emit empty inlay hint partsLukas Wirth-38/+24
2024-09-12Auto merge of #18106 - Veykril:push-yzsqoykyowts, r=Veykrilbors-29/+70
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-29/+70
2024-09-12Auto merge of #18105 - Veykril:push-rquxwznuuwpu, r=Veykrilbors-28/+24
fix: Faulty notifications should not bring down the server Fixes https://github.com/rust-lang/rust-analyzer/issues/18055, if a client sends us an unregistered document path in a did save notification it would force us to exit the thread. That is obviously not great behavior, we should be more fallible here
2024-09-12fix: Faulty notifications should not bring down the serverLukas Wirth-28/+24
2024-09-12Fix inference of literals when the expectation is CastableChayim Refael Friedman-9/+51
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-11Auto merge of #18075 - roife:fix-issue-17858, r=Veykrilbors-24/+303
feat: render patterns in params for hovering Fix #17858 This PR introduces an option to [hir-def/src/body/pretty.rs](https://github.com/rust-lang/rust-analyzer/blob/08c7bbc2dbe4dcc8968484f1a0e1e6fe7a1d4f6d/crates/hir-def/src/body/pretty.rs) to render the result as a single line, which is then reused for rendering patterns in parameters for hovering.
2024-09-11Auto merge of #18080 - Veykril:dedup, r=Veykrilbors-19760/+133
Remove crate graph deduplication logic Fixes https://github.com/rust-lang/rust-analyzer/issues/17748
2024-09-11Auto merge of #18078 - cuishuang:master, r=Veykrilbors-3/+5
Remove unnecessary symbols and add missing symbols
2024-09-11Auto merge of #18057 - alibektas:better_ratoml_testing, r=Veykrilbors-103/+228
internal: Better testing infra for ratoml This PR makes some improvements on how we test configs that come from `rust-analyzer.toml` files. It was primarily used to solve #18021 but along the way I could not really determine the cause of the said issue which makes me think that it may not be related to the changes that I made earlier to the ratoml infra. In either way `custom_snippets` are now made `global` because we still don't have a tree that maps a `SourceRootId` to a set of `Snippet`s.
2024-09-11Auto merge of #18052 - Coekjan:fix-inline-const, r=Veykrilbors-4/+14
fix: Fix `inline_const_as_literal` error when the number >= 10 ## Description ### The Bug This PR fixes a small bug in the IDE assistence (`inline_const_as_literal`). When the being-inlined constant is a number and it is greater than or equal to 10, the assistence inserts unexpected string `(0x...)` after the number itself. A simple example is followed: Current `inline_const_as_literal` changes ```rs const A: usize = 16; fn f() -> usize { A // inline the constant } ``` into ```rs const A: usize = 16; fn f() -> usize { 16 (0x10) } ``` The bug originates from #14925 & #15306 . #14925 added some unittests, but it just tested the number-inlining behavior when the number is `0`. https://github.com/rust-lang/rust-analyzer/blob/50882fbfa204027c84753e6d51a1a12884dc1b19/crates/ide-assists/src/handlers/inline_const_as_literal.rs#L124-L138 And #15306 modified the behavior of `Const::render_eval` and added the `(0x...)` part after the number (if the number >= `10`). Because of insufficient unittests in #14925, changes about `Const::render_eval` in #15306 introduced this bug with no CI failure. ### The Fix I think `Const::render_eval` is intended for user-facing value displaying (e.g. hover) and not designed for `inline_const_as_literal`. To fix the bug, I defined a new function named `Const::eval`, which evaluates the value itself faithfully and simply and does nothing else. ## Thanks Thanks `@roife` for your kind help. Your guidance helped me better understand the code.
2024-09-11Auto merge of #18018 - ChayimFriedman2:unit-ret-complete-semi, r=Veykrilbors-40/+217
feat: Automatically add semicolon when completing unit-returning functions But provide a config to suppress that. I didn't check whether we are in statement expression position, because this is hard in completion (due to the natural incompleteness of source code when completion is invoked), and anyway using function returning unit as an argument to something seems... dubious. Fixes #17263.