Commit graph

1569 commits

Author SHA1 Message Date
Tavo Annus
3825d8bd0f Increase search depth to account for more granual steps 2024-06-22 15:06:07 +03:00
Tavo Annus
b4f3eb48db Simplify impl_method tactic 2024-06-22 14:22:56 +03:00
Tavo Annus
23d3ac70e9 Simplify impl_static_method tactic 2024-06-22 14:14:42 +03:00
Tavo Annus
a3315fe028 Remove remove not-very-helpful optimizations 2024-06-22 10:17:33 +03:00
Tavo Annus
957325a5fe Run data_constructor tactic only backwards 2024-06-21 22:01:06 +03:00
roife
d5bb2f0cba fix: use ItemInNs::Macros to convert ModuleItem to ItemInNs 2024-06-21 21:05:14 +08:00
bors
e08f7953f4 Auto merge of #17462 - Veykril:sema-attr-macro-res, r=Veykril
fix: Fix IDE features breaking in some attr macros

Fixes https://github.com/rust-lang/rust-analyzer/issues/17453, Fixes https://github.com/rust-lang/rust-analyzer/issues/17458
2024-06-20 09:11:44 +00:00
Lukas Wirth
ee8a3458ee fix: Fix IDE features breaking in some attr macros 2024-06-20 11:00:19 +02:00
bors
6738f81b12 Auto merge of #17419 - ishanjain28:filter_builtin_macro_expansion, r=Veykril
Filter builtin macro expansion

This PR adds a filter on the types of built in macros that are allowed to be expanded.

Currently, This list of allowed macros contains, `stringify, cfg, core_panic, std_panic, concat, concat_bytes, include, include_str, include_bytes, env` and `option_env`.

Fixes #14177
2024-06-20 08:39:17 +00:00
Lukas Wirth
bf9a7264d1 Invert matching on builtin macros in expand_allowed_builtins 2024-06-20 10:31:20 +02:00
Ishan Jain
19d9bb808d
removed format_args from allowed expansions 2024-06-19 16:58:48 +05:30
Tavo Annus
c87609fef1 Add tactic for associated item constants 2024-06-18 22:08:44 +03:00
Ishan Jain
020537cd06
Created expand_allowed_builtins, updated expand_macro to call this function 2024-06-15 15:20:46 +05:30
Ishan Jain
2df806a3a5
allow format_args! expansion 2024-06-14 10:13:41 +05:30
Ishan Jain
0adb0e114f
fixed tests 2024-06-14 09:52:46 +05:30
Wilfred Hughes
d68e549205 internal: Fix rustdoc warnings
`cargo doc` generates a bunch of warnings on rust-analyzer. Fix all the
bare URL and empty code block warnings.
2024-06-13 17:29:10 -07:00
Ishan Jain
5d5f68af3f
hir/semantics: Only allow expansion of specific built in macros 2024-06-13 10:45:11 +05:30
bors
22648b2655 Auto merge of #17405 - Veykril:modpath-clone, r=Veykril
internal: Don't unnecessarily clone ModPaths in early name res
2024-06-12 09:27:49 +00:00
Lukas Wirth
855282fa53 internal: Don't unnecessarily clone ModPaths in early name res 2024-06-12 11:25:19 +02:00
roife
224d0dd36e refactor: move the logic that displays container type bounds to function fmt 2024-06-11 21:02:13 +08:00
roife
ab7c7d4501 fix: skip container header if no generics params 2024-06-11 21:02:13 +08:00
roife
9f70f87d35 internal: simplify and rename display_xxx to write_xxx for consistency 2024-06-11 21:02:13 +08:00
roife
78118f98f6 feat: add hover config for showing container bounds 2024-06-11 21:02:13 +08:00
roife
184ddc6f5b feat: show type bounds from containers for functions 2024-06-11 21:02:13 +08:00
roife
af1291bbf3 internal: simplify and refactor write_where_clause 2024-06-11 21:02:13 +08:00
Lukas Wirth
30c04d5aa9 Remove extra parse cache from Semantics again 2024-06-10 12:04:35 +02:00
Lukas Wirth
8520a0c585 Thread more HasSource::source calls through Semantics for caching 2024-06-10 10:33:07 +02:00
Lukas Wirth
d4dc3ca83b Register virtual workspace Cargo.toml files in the VFS 2024-06-09 12:54:50 +02:00
Wilfred Hughes
27182bb96b chore: Prefer tracing span shorthand macros 2024-06-06 16:52:25 -07:00
Vincent Esche
78f31696da Resolve #17344 by using .get(…) instead of […] in TypeOrConstParam::source(…)
(… and `LifetimeParam::source(…)`)
2024-06-05 11:03:56 +02:00
Lukas Wirth
9349045e09 Use dyn cache for Semantics macro resolution 2024-06-04 16:25:38 +02:00
Lukas Wirth
7d40763c88 Cache parse trees in Semantics 2024-06-04 15:29:24 +02:00
Lukas Wirth
c12f093716 Cache file_to_def in SourceToDefCtx 2024-06-04 15:23:02 +02:00
Lukas Wirth
97b58f2846 Try caching macro calls more aggressively 2024-06-04 15:23:00 +02:00
Lukas Wirth
6f0207d594 Cleanup some inert attribute stuff 2024-06-04 12:38:20 +02:00
Lukas Wirth
60fa981df1 Simplify 2024-06-03 19:06:58 +02:00
bors
cb6b808185 Auto merge of #17315 - hamirmahal:style/simplify-string-interpolation, r=Veykril
style: simplify string interpolation
2024-06-03 12:29:27 +00:00
bors
9edc30a42b Auto merge of #17312 - regexident:function-fn-ptr-type, r=Veykril
Add `Function::fn_ptr_type(…)` for obtaining name-erased function type

The use case of this function if being able to group functions by their function ptr type.

cc `@flodiebold`
2024-06-03 12:16:29 +00:00
Lukas Wirth
3116f76fba feat: Enable completions within derive helper attributes 2024-06-02 09:45:57 +02:00
Lukas Wirth
c0171bdd32 fix: Fix container search failing for tokens originating within derive attributes 2024-06-01 20:57:29 +02:00
Hamir Mahal
7c34eb3880
style: simplify string interpolation 2024-05-30 16:18:49 -07:00
Vincent Esche
7b75f1113c Add Function::fn_ptr_type(…) for obtaining name-erased function type 2024-05-29 19:41:55 +02:00
Tavo Annus
0f6842700f Fix data_constructor ignoring generics for struct 2024-05-25 13:09:26 +03:00
David Barsky
a0d3a81a19 fix: ensure implied bounds from associated types are considered in autocomplete 2024-05-22 16:16:20 -04:00
David Barsky
b75301cec8 internal: refactor prefer_no_std/prefer_prelude bools into a struct 2024-05-22 20:46:30 +02:00
bors
6a16749eb0 Auto merge of #17277 - Veykril:find-path-fixes, r=Veykril
fix: Various find path fixes

Fixes https://github.com/rust-lang/rust-analyzer/issues/17271
2024-05-22 18:22:32 +00: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
Lukas Wirth
7bd343e085 Show fn traits in signature info for trait implementors 2024-05-18 16:22:59 +02:00
Lukas Wirth
ff79903cf6 Render closure fn trait kind in siganture help 2024-05-18 15:01:37 +02:00
Lukas Wirth
7c6f31a45b Allow hir::Param to refer to other entity params aside from functions 2024-05-18 12:35:55 +02:00
Lukas Wirth
cd9e90cc71 Update builtin tool list 2024-05-18 10:52:05 +02:00
Lukas Wirth
aaa5426fec internal: Add StaticLifetime to hir API 2024-05-16 08:02:51 +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
bors
40ab5e5f8c Auto merge of #17220 - Veykril:hov-lit, r=Veykril
fix: Improve confusing literal hovers
2024-05-13 10:58:29 +00:00
Lukas Wirth
253929f6ae Fix literal hovers being confusing and wrong for floats 2024-05-13 12:26:45 +02:00
Tavo Annus
ab18604309 Make term search fuel configurable 2024-05-08 19:46:33 +03:00
Tavo Annus
9e1adc76e5 Use unit of work as fuel instead of time 2024-05-07 22:13:27 +03:00
Tavo Annus
d253617bba Add time based fuel to term search 2024-05-06 22:13:09 +03:00
Tavo Annus
c3ab435b54 Collapse term search exprs before Cartesian product to avoid OOM 2024-05-06 20:29:34 +03:00
Wilfred Hughes
c981ff0944 fix: Tracing span names should match function names
When viewing traces, it's slightly confusing when the span name doesn't
match the function name. Ensure the names are consistent.

(It might be worth moving most of these to use #[tracing::instrument]
so the name can never go stale. @davidbarsky suggested that is marginally
slower, so I've just done the simple change here.)
2024-04-30 11:22:47 -07:00
bors
84ef3cfa91 Auto merge of #17138 - Kohei316:generate-function-assist-for-new, r=Veykril
feature: Make generate function assist generate a function as a constructor if the generated function has the name "new" and is an asscociated function.

close #17050
This PR makes `generate function assist` generate a function as a constructor if the generated function has the name "new" and is an asscociated function.
If the asscociate type is a record struct, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        Self { field_1: todo!(), field_2: todo!() }
    }
}
```
If the asscociate type is a tuple struct, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        Self(todo!(), todo!())
    }
}
```
If the asscociate type is a unit struct, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        Self
    }
}
```
If the asscociate type is another adt, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        todo!()
    }
}
```
2024-04-30 12:09:34 +00:00
morine0122
ff2629d651 Make generate function assist generate a function as a constructor if the name of function is new 2024-04-30 17:02:48 +09:00
Lukas Wirth
18ca22a98e Show workspace info in the status bar 2024-04-26 11:28:33 +02:00
bors
65eda41e65 Auto merge of #17021 - roife:add-hover-limits-for-adts, r=Veykril
Support hovering limits for adts

Fix #17009

1. Currently, r-a supports limiting the number of struct fields displayed when hovering. This PR extends it to support enum variants and union fields. Since the display of these three (ADTs) is similar, this PR extends 'hover_show_structFields' to 'hover_show_adtFieldsOrVariants'.
2. This PR also resolved the problem that the layout of ADT was not restricted by display limitations when hovering on the Self type.
3. Additionally, this PR changes the default value of display limitations to `10` (instead of the original `null`), which helps users discover this feature.
2024-04-25 07:23:27 +00:00
Bao Zhiyuan
5c88e98419 different error code based on variant 2024-04-23 20:54:03 +08:00
Lukas Wirth
a2ed6837bc Allow rust files to be used linkedProjects 2024-04-21 16:26:55 +02:00
Laurențiu Nicola
4c94e69115 Add in-rust-tree feature to hir-expand 2024-04-20 18:44:27 +03:00
roife
aa1f1344cc fix: remove space within {} when no fields in struct 2024-04-20 10:07:33 +08:00
roife
43576989a1 Add hovering limitations support for variants 2024-04-20 09:14:00 +08:00
roife
e0e28ec856 fix: add a separate setting for enum variants 2024-04-19 21:45:56 +08:00
Lukas Wirth
6bfdd38c69 Render matched macro arm on hover of macro calls 2024-04-18 10:51:58 +02:00
bors
46702ffc1a Auto merge of #17087 - davidbarsky:david/fix-some-tracing-spans, r=Veykril
chore: fix a few spans without `.entered()`
2024-04-17 16:59:33 +00:00
Lukas Wirth
011c2127c8 Update per_query_memory_usage query listing 2024-04-17 18:44:50 +02:00
David Barsky
5ba37f3f8e chore: fix a few spans without .entered() 2024-04-17 12:44:49 -04:00
roife
01c3559bf3 Update tests and docs for hover_show_adtFieldsOrVariants 2024-04-16 16:27:56 +08:00
roife
21da6c6164 Add config hover_show_adtFieldsOrVariants to handle hovering limitation for ADTs 2024-04-16 16:26:23 +08:00
Lukas Wirth
531a270d91 Generally optimize diagnostics performance 2024-04-15 22:15:41 +02:00
Lukas Wirth
1915980031 fix: Fix impl Trait<Self> causing stackoverflows 2024-04-15 15:41:20 +02:00
Lukas Wirth
a82e028e30 Cleanup util::Generics method names 2024-04-06 14:29:40 +02:00
Lukas Wirth
f3567bb604 Arc CrateData::cfg_options 2024-04-06 13:55:10 +02:00
Lukas Wirth
5957835cdf Consider exported_name="main" functions in test modules as tests 2024-04-04 14:51:10 +02:00
Lukas Wirth
86967032f7 Consider ADT generic parameter defaults for unsubstituted layout calculations 2024-04-03 09:01:27 +02:00
bors
c3b8c2a254 Auto merge of #16996 - Veykril:lt-err, r=Veykril
internal: Lower outlive goals, respect them in display impls
2024-04-02 14:13:22 +00:00
Lukas Wirth
707be6b99c Adjust display impls to respect lifetime bounds 2024-04-02 14:51:08 +02:00
Lukas Wirth
0927f86247 Replace static_lifetime usages with error_lifetime, lower outlives goals 2024-04-02 14:51:06 +02:00
bors
23dd54b010 Auto merge of #16968 - roife:fix-issue-16801, r=Veykril
fix: silence mismatches involving unresolved projections

fix #16801
2024-04-01 20:05:33 +00:00
roife
3d373fec8c tests: add tests for mismatches with unresolved projections 2024-04-02 01:32:43 +08:00
roife
8d6b65c544 fix: silence mismatches involving unresolved projections 2024-04-02 01:27:22 +08:00
dfireBird
69c4ac6304
implement len and is_empty method in generic_params 2024-03-29 18:26:46 +05:30
dfireBird
34a8cd6a7a
fix ADT hover considering only type or const len not lifetimes 2024-03-28 21:53:22 +05:30
bors
0583aaa555 Auto merge of #16805 - dfireBird:lifetime_lowering, r=Veykril
feat: Implement resolving and lowering of Lifetimes (no inference yet)
2024-03-26 07:58:43 +00:00
Young-Flash
ba8c9810aa review update 2024-03-25 19:55:19 +08:00
Young-Flash
1c85234bcd limit struct field hover display nums 2024-03-25 19:55:19 +08:00
Lukas Wirth
8e324e98a1 Rename ProcMacroKind::FuncLike to Bang 2024-03-22 11:20:56 +01:00
bors
16c8deeb86 Auto merge of #16835 - wyatt-herkamp:use_one_tt_for_a_derive, r=Veykril
Have Derive Attribute share a token tree with it's proc macros.

The goal of this PR is to stop creating a token tree for each derive proc macro.

This is done by giving the derive proc macros an id to its parent derive element.

From running the analysis stat on the rust analyzer project I did see a small memory decrease.

```
Inference:           42.80s, 362ginstr, 591mb
MIR lowering:        8.67s, 67ginstr, 291mb
Mir failed bodies: 18 (0%)
Data layouts:        85.81ms, 609minstr, 8mb
Failed data layouts: 135 (6%)
Const evaluation:    440.57ms, 5235minstr, 13mb
Failed const evals: 1 (0%)
Total:               64.16s, 552ginstr, 1731mb
```
After Change
```
Inference:           40.32s, 340ginstr, 593mb
MIR lowering:        7.95s, 62ginstr, 292mb
Mir failed bodies: 18 (0%)
Data layouts:        87.97ms, 591minstr, 8mb
Failed data layouts: 135 (6%)
Const evaluation:    433.38ms, 5226minstr, 14mb
Failed const evals: 1 (0%)
Total:               60.49s, 523ginstr, 1680mb
```

Currently this breaks the expansion for the actual derive attribute.

## TODO
- [x] Pick a better name for the function `smart_macro_arg`
2024-03-21 18:04:38 +00:00
Wyatt Herkamp
262e06f1ef Remove MacroCallKind::DeriveAttr 2024-03-21 12:50:58 -04:00
Wyatt Herkamp
2c2bbe07fd Treat Derive Macro specially. 2024-03-21 08:07:54 -04:00
Wyatt Herkamp
15d183be79 Initial Attempt limiting number of token tree in macro expansion. 2024-03-21 08:06:43 -04:00
Lukas Wirth
928d847cc2 Keep the span for Attr::Literal 2024-03-21 10:28:25 +01:00
Lukas Wirth
255a8aef92 Move Edition into span crate 2024-03-21 10:21:44 +01:00
bors
dc2e0b35cc Auto merge of #16891 - goodmost:master, r=lnicola
chore: remove repetitive words
2024-03-21 06:29:33 +00:00
goodmost
d6b0aae019 chore: remove repetitive words
Signed-off-by: goodmost <zhaohaiyang@outlook.com>
2024-03-19 22:14:13 +08:00
Shoyu Vanilla
967a864d03 fix: Goto implementation to impls inside blocks 2024-03-19 22:04:48 +09:00
dfireBird
d6e3929841
include lifetime in ParamKind and in Generics::provenance_split 2024-03-18 17:18:08 +05:30
Matthias Krüger
2a8edaa14d remove redundant clone()s 2024-03-17 14:06:21 +01:00
Lukas Wirth
d69a81fddb fix: Fix wrong where clause rendering on hover 2024-03-16 17:49:59 +01:00
Lukas Wirth
0dd89d7ee7 Remove usages of SpanData where Span suffices 2024-03-15 13:02:40 +01:00
Lukas Wirth
d2f8eae2ec feat: Support macro calls in eager macros for IDE features 2024-03-14 15:40:35 +01:00
Lukas Wirth
9ba4493918 internal: Improve rooted upmapping 2024-03-12 13:46:58 +01:00
bors
2f872156fe Auto merge of #16808 - ShoyuVanilla:proc-macro-sem-token, r=Veykril
feat: Add proc macro semantic token type

Closes  #11529
2024-03-11 13:20:29 +00:00
Shoyu Vanilla
fc11216ad5 feat: Add proc macro semantic token type 2024-03-11 22:14:59 +09:00
bors
2320e12541 Auto merge of #16771 - Veykril:self-param-split, r=Veykril
internal: Don't desugar self param into a pattern

Small experiment to see if this simplifies things
2024-03-11 12:45:46 +00:00
bors
a5035f4931 Auto merge of #16749 - Veykril:on-demand-validation-err, r=Veykril
internal: Some method resolution cleanups
2024-03-11 09:18:24 +00:00
Lukas Wirth
458f4a2960 internal: Treat the self param as different from patterns when lowering 2024-03-11 09:46:28 +01:00
Lukas Wirth
558feeab61 internal: Remove synstructure const hack support 2024-03-11 09:44:40 +01:00
Lukas Wirth
c04c0dd5ba fix: Don't force draw a dependency edge to the real_span_map query 2024-03-07 14:14:59 +01:00
Lukas Wirth
a3b6e891ea Add tracing spans to macro generated database 2024-03-06 20:19:36 +01:00
Vincent Esche
bf141310f8 Add fn index() accessor for hir::Param 2024-03-05 16:02:22 +01:00
Vincent Esche
1afeea85ff Add fn parent_fn() accessors for hir::Param & hir::SelfParam 2024-03-05 16:01:01 +01:00
Lukas Wirth
d21f88883b Remove some unnecessary cloning in method_resolution 2024-03-05 12:39:27 +01:00
bors
676455f911 Auto merge of #16757 - Veykril:style-lints, r=Veykril
fix: Put style lints behind disabled-by-default config

Fixes https://github.com/rust-lang/rust-analyzer/issues/16542
Fixes https://github.com/rust-lang/rust-analyzer/issues/16725
cc https://github.com/rust-lang/rust-analyzer/issues/16628

Our diagnostic infra is not yet setup for those kinds of diagnostics
2024-03-05 10:45:05 +00:00
Lukas Wirth
8844640c6f fix: Put style lints behind disabled-by-default config 2024-03-05 11:43:23 +01:00
Lukas Wirth
b20e467373 internal: Adjust a few things for trait assoc item hovers 2024-03-05 11:06:36 +01:00
bors
ce3216e0ae Auto merge of #15938 - Young-Flash:display_trait_item_when_hover, r=Veykril
feat: add hover display for trait assoc items

This PR enable preview assoc items when hover on `trait`

![image](https://github.com/rust-lang/rust-analyzer/assets/71162630/d9c3949c-33cf-4a32-aa97-3af46b28033a)

inspired by https://github.com/rust-lang/rust-analyzer/pull/15847
2024-03-05 08:26:53 +00:00
bors
99a1b8f7a8 Auto merge of #16747 - Veykril:cleanup, r=Veykril
internal: Clean some stuff up

Just a bunch of small refactorings, mainly from browsing through `hir-def`
2024-03-04 10:30:17 +00:00
Lukas Wirth
4303e741de Cleanup 2024-03-04 11:10:06 +01:00
bors
d8feb908be Auto merge of #16703 - regexident:sema-ast-to-hir, r=Veykril
Add more methods for resolving definitions from AST to their corresponding HIR types

In order to be able to add these methods with consistent naming I had to also rename two existing methods that would otherwise be conflicting/confusing:

`Semantics::to_module_def(&self, file: FileId) -> Option<Module>` (before)
`Semantics::file_to_module_def(&self, file: FileId) -> Option<Module>` (after)

`Semantics::to_module_defs(&self, file: FileId) -> impl Iterator<Item = Module>` (before)
`Semantics::file_to_module_defs(&self, file: FileId) -> impl Iterator<Item = Module>` (after)

(the PR is motivated by an outside use of the `ra_ap_hir` crate that would benefit from being able to walk a `hir::Function`'s AST, resolving its exprs/stmts/items to their HIR equivalents)
2024-03-04 09:02:32 +00:00
bors
4ef6a49b44 Auto merge of #16702 - Veykril:intra-doc-links-generic, r=Veykril
fix: Ignore generic arguments in intra doc link path resolution

Fixes https://github.com/rust-lang/rust-analyzer/issues/16699
2024-03-02 09:51:16 +00:00
Young-Flash
dba67b46a1 update for review 2024-03-02 10:01:04 +08:00
bors
9efa23c4da Auto merge of #16707 - regexident:pub-sema-impl, r=Veykril
Export `SemanticsImpl` from `ra_ap_hir` crate, since it's already exposed via `Semantics.deref()`

The `SemanticsImpl` type is already de-facto exposed via `<Semantics as Deref>::Target`.

By not being part of the public crate interface it however doesn't get included in the documentation, resulting in a massive blind spot when it comes to `ra_ap_hir`'s type resolution APIs.
2024-02-29 15:12:04 +00:00
bors
ecda4642ef Auto merge of #16705 - regexident:resolve-callable-exprs, r=Veykril
Add public function for resolving callable AST exprs to their HIR equivalents

(the PR is motivated by an outside use of the `ra_ap_hir` crate that would benefit from being able to walk a `hir::Function`'s AST, resolving callable exprs within to their HIR equivalents)
2024-02-29 14:46:21 +00:00
bors
a6606d1767 Auto merge of #16698 - regexident:param-derives, r=Veykril
Derive `PartialEq`, `Eq` & `Hash` for `hir::Param`

Since `hir::SelfParam`, as well as all members of `hir::Param` already implement `PartialEq`, `Eq` & `Hash` it seems reasonable to also make `hir::Param` implement those.

(the change is motivated by an outside use of the `ra_ap_hir` crate that would benefit from being able to collect params in a `HashSet`)
2024-02-29 14:33:37 +00:00
Shoyu Vanilla
bf23deecb3 Fix goto index_mut 2024-02-29 00:52:58 +09:00
Vincent Esche
ed3497883c Add public function for resolving ast::Expr to hir::Callable 2024-02-28 16:44:07 +01:00
Vincent Esche
74531e4d80 Export SemanticsImpl from ra_ap_hir crate, since it's already exposed via Semantics.deref() 2024-02-28 16:16:54 +01:00
Lukas Wirth
ab533d887d fix: Ignore generic arguments in intra doc link path resolution 2024-02-28 14:47:47 +01:00
Vincent Esche
fac8a14de8 Add a more methods for resolving definitions from AST to their corresponding HIR types 2024-02-28 10:27:28 +01:00
Vincent Esche
6112ddfabb Add prefix file_ to Semantics's to_module_defs()/to_module_def() methods 2024-02-28 10:27:28 +01:00
Vincent Esche
c061a9e84e Derive PartialEq, Eq & Hash for hir::Param 2024-02-27 20:53:29 +01:00
Shoyu Vanilla
612443111b Remove unused imports 2024-02-28 00:10:08 +09:00
Shoyu Vanilla
0f4e313028 Fix goto deref_mut 2024-02-27 23:55:19 +09:00
bors
6b250a22c4 Auto merge of #16687 - kilpkonn:master, r=Veykril
feat: Add "make tuple" tactic to term search

Follow up to https://github.com/rust-lang/rust-analyzer/pull/16092

Now term search also supports tuples.
```rust
let a: i32 = 1;
let b: f64 = 0.0;
let c: (i32, (f64, i32)) = todo!(); // Finds (a, (b, a))
```
In addition to new tactic that handles tuples I changed how the generics are handled.
Previously it tried all possible options from types we had in scope but now it only tries useful ones that help us directly towards the goal or at least towards calling some other function.
This changes O(2^n) to O(n^2) where n is amount of rounds which in practice allows using types that take generics for multiple rounds (previously limited to 1). Average case that also used to be exponential is now roughly linear.
This means that deeply nested generics also work.
````rust
// Finds all valid combos, including `Some(Some(Some(...)))`
let a: Option<Option<Option<bool>>> = todo!();
````

_Note that although the complexity is smaller allowing more types with generics the search overall slows down considerably. I hope it's fine tho as the autocomplete is disabled by default and for code actions it's not super slow. Might have to tweak the depth hyper parameter tho_

This resulted in a huge increase of results found (benchmarks on `ripgrep` crate):
Before
````
Tail Expr syntactic hits: 149/1692 (8%)
Tail Exprs found: 749/1692 (44%)
Term search avg time: 18ms
```
After
```
Tail Expr syntactic hits: 291/1692 (17%)
Tail Exprs found: 1253/1692 (74%)
Term search avg time: 139ms
````

Most changes are local to term search except some tuple related stuff on `hir::Type`.
2024-02-27 09:41:14 +00:00
Lukas Wirth
cc7fe32ba3 fix: Fix completions panicking with certain macro setups 2024-02-27 09:35:57 +01:00
Tavo Annus
be6f8e2648 Add make_tuple tactic 2024-02-26 20:17:09 +02:00
Tavo Annus
8bd30e9b3f Improve generics handling in term search 2024-02-26 20:17:09 +02:00
bors
5fead606bc Auto merge of #16555 - davidbarsky:david/speedup-completions-by-exploiting-orphan-rules, r=Veykril
performance: Speed up Method Completions By Taking Advantage of Orphan Rules

(Continues https://github.com/rust-lang/rust-analyzer/pull/16498)

This PR speeds up method completions by doing two things without regressing `analysis-stats`[^1]:
- Filter candidate traits prior to calling `iterate_path_candidates` by relying on orphan rules (see below for a slightly more in-depth explanation). When generating completions [on `slog::Logger`](5e9e59c312/common/src/ledger.rs (L78)) in `oxidecomputer/omicron` as a test, this PR halved my completion times—it's now 454ms cold and 281ms warm. Before this PR, it was 808ms cold and 579ms warm.
- Inline some of the method candidate checks into `is_valid_method_candidate` and remove some unnecessary visibility checks. This was suggested by `@Veykril` in [this comment](https://github.com/rust-lang/rust-analyzer/pull/16498#issuecomment-1929864427).

We filter candidate traits by taking advantage of orphan rules. For additional details, I'll rely on `@WaffleLapkin's` explanation  [from Zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Trait.20Checking/near/420942417):

> A type `A` can only implements traits which
> 1. Have a blanket implementation (`impl<T> Trait for T {}`)
> 2. Have implementation for `A` (`impl Trait for A {}`)
>
> Blanket implementation can only exist in `Trait`'s crate. Implementation for `A` can only exist in `A`'s or `Trait`'s crate.

Big thanks to Waffle for its keen observation!

---

I think some additional improvements are possible:
- `for_trait_and_self_ty` seemingly does not distinguish between `&T`, `&mut T`, or `T`, resulting in seemingly irrelevant traits like `tokio::io::AsyncWrite` being being included for, e.g., `&slog::Logger`. I don't know they're being considered due to the [autoref/autoderef behavior](a02a219773/crates/hir-ty/src/method_resolution.rs (L945-L962)), but I wonder if it'd make sense to filter by mutability earlier and not consider trait implementations that require `&mut T` when we only have a `&T`.
- The method completions [spend a _lot_ of time in unification](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Trait.20Checking/near/421072356), and while there might be low-hanging fruit there, it might make more sense to wait for the new trait solver in `rustc`. I dunno.

[^1]: The filtering occurs outside of typechecking, after all.
2024-02-26 18:05:52 +00:00
David Barsky
c246a93046 completions: speed up completions by filtering non-applicable traits 2024-02-26 12:49:11 -05:00
bors
1d3558bfe1 Auto merge of #16684 - Veykril:synthetic-fmt-args, r=Veykril
fix: Don't panic on synthetic syntax in inference diagnostics

Temporary fix for https://github.com/rust-lang/rust-analyzer/issues/16682

We ought to rethink how we attach diagnostics to things, as IDs don't work for `format_args` like that!
2024-02-26 16:47:57 +00:00
Lukas Wirth
3856648b52 fix: Don't panic on synthetic syntax in inference diagnostics 2024-02-26 17:46:03 +01:00
bors
40bf8bf757 Auto merge of #16679 - Veykril:block-mod, r=Veykril
fix: Fix modules in blocks not resolving in ide layer

Fixes https://github.com/rust-lang/rust-analyzer/issues/16511
2024-02-26 13:56:01 +00:00
Lukas Wirth
91554e0ae7 fix: Fix modules in blocks not resolving in ide layer 2024-02-26 14:54:47 +01:00
Shoyu Vanilla
a336bdc142 Merge BorrowKind::Unique into BorrowKind::Mut 2024-02-26 01:57:03 +09:00
Young-Flash
2e87f31fe9 add HoverDisplayConfig 2024-02-22 17:37:40 +08:00
Young-Flash
35ec5955eb add config item for hover display 2024-02-21 11:08:45 +08:00
Young-Flash
00358b1fe0 rebase on lastest master 2024-02-21 10:57:39 +08:00
Young-Flash
dba167592e feat: add hover display for trait assoc items 2024-02-21 10:57:39 +08:00
Lukas Wirth
85203d9721 Render assoc item owner in hover for items other than functions 2024-02-20 13:16:12 +01:00
bors
2223b4fa71 Auto merge of #13112 - lowr:patch/auto-trait-bounds, r=Veykril
Setup infra for handling auto trait bounds disabled due to perf problems

This patch updates some of the partially-implemented functions of `ChalkContext as RustIrDatabase`, namely `adt_datum()` and `impl_provided_for()`. With those, we can now correctly work with auto trait bounds and distinguish methods based on them.

Resolves #7856 (the second code; the first one is resolved by #13074)

**IMPORTANT**: I don't think we want to merge this until #7637 is resolved. Currently this patch introduces A LOT of unknown types and type mismtaches as shown below. This is because we cannot resolve items like `hashbrown::HashMap` in `std` modules, leading to auto trait bounds on them and their dependents unprovable.

|crate (from `rustc-perf@c52ee6` except for r-a)|e3dc5a588f07d6f1d3a0f33051d4af26190abe9e|HEAD of this branch|
|---|---|---|
|rust-analyzer @ e3dc5a588f |exprs: 417528, ??ty: 907 (0%), ?ty: 114 (0%), !ty: 1|exprs: 417528, ??ty: 1704 (0%), ?ty: 403 (0%), !ty: 20|
|ripgrep|exprs: 62120, ??ty: 2 (0%), ?ty: 0 (0%), !ty: 0|exprs: 62120, ??ty: 132 (0%), ?ty: 58 (0%), !ty: 11|
|webrender/webrender|exprs: 94355, ??ty: 49 (0%), ?ty: 16 (0%), !ty: 2|exprs: 94355, ??ty: 429 (0%), ?ty: 130 (0%), !ty: 7|
|diesel|exprs: 132591, ??ty: 401 (0%), ?ty: 5129 (3%), !ty: 31|exprs: 132591, ??ty: 401 (0%), ?ty: 5129 (3%), !ty: 31|
2024-02-19 16:45:59 +00:00
Rose Hudson
a492d9d164 feat: add unresolved-ident diagnostic 2024-02-19 14:12:18 +01:00
Rose Hudson
5390e4ce9b feat: add non-exhaustive-let diagnostic 2024-02-19 12:36:30 +01:00
Young-Flash
f3d84e86c8 minor: fix typo 2024-02-19 18:12:08 +08:00
Ryo Yoshida
4940017716 Rename StructDatum -> AdtDatum 2024-02-14 13:50:44 +01:00
Tavo Annus
125791386d Cleanup term search related changes 2024-02-11 14:35:54 +02:00
Tavo Annus
88964c0b6a Optionally disable term search for autocompletion 2024-02-11 13:33:29 +02:00
Tavo Annus
0b838e3e23 Expand target for autocompletion 2024-02-11 13:33:29 +02:00
Tavo Annus
a946970e2d Add quantified trees to reduce autocomplete options 2024-02-11 13:33:29 +02:00
Tavo Annus
bdbdd83ec1 Initial version of term_search for autocomplete 2024-02-11 13:33:29 +02:00
Tavo Annus
627255dd5a Add static method tactic 2024-02-11 13:33:29 +02:00
Tavo Annus
35eb0dbbc0 Add more documentation for term search 2024-02-11 13:33:29 +02:00
Tavo Annus
bb3c7cff60 Introduce term search to rust-analyzer 2024-02-11 13:33:29 +02:00
Lukas Wirth
5136705fad internal: Remove SELF_REF hack for self referential SyntaxContexts 2024-02-10 16:20:02 +01:00
bors
1ef7a2329b Auto merge of #16525 - Veykril:item-loc, r=Veykril
Abstract more over ItemTreeLoc-like structs

Allows reducing some code duplication by using functions generic over said structs. The diff isn't negative due to me adding some additional impls for completeness.
2024-02-10 10:47:37 +00:00
Lukas Wirth
00303c3b67 Abstract over ItemTreeLoc 2024-02-10 11:37:59 +01:00
Lukas Wirth
2ebf0c87c2 Deduplicate some code 2024-02-10 01:51:22 +01:00
Tetsuharu Ohzeki
eba1b13295 hir: Fix warnings about clippy str_to_string rule 2024-02-10 01:00:40 +09:00
Tetsuharu Ohzeki
7669619f9a clippy: Enable self_named_constructors rule 2024-02-09 22:31:21 +09:00
davidsemakula
602acfcb70 fix conflicting "unnecessary else" and "trailing return" diagnostics tests 2024-02-08 19:32:53 +03:00
davidsemakula
a250c2dde0 refactor remove trailing return diagnostic 2024-02-08 19:32:53 +03:00
davidsemakula
98e6f43a2f remove trailing return in trailing match expression 2024-02-08 19:32:53 +03:00
davidsemakula
2987fac76f diagnostic to remove trailing return 2024-02-08 19:32:53 +03:00
bors
0e5766b0d8 Auto merge of #16477 - davidsemakula:trait-incorrect-case-diagnostic, r=Veykril
feat: Add incorrect case diagnostics for traits and their associated items

Updates incorrect case diagnostic to:
- Check traits and their associated items
- Ignore trait implementations except for patterns in associated function bodies

Also cleans up `hir-ty::diagnostics::decl_check` a bit (mostly to make it a bit more DRY and easier to maintain)

Also fixes: #8675 and fixes: #8225
2024-02-08 14:40:16 +00:00
bors
e9d3565cd1 Auto merge of #16502 - davidsemakula:unnecessary-else-diagnostic, r=Veykril
feat: Add "unnecessary else" diagnostic and fix

Fixes #9457
2024-02-08 14:25:00 +00:00
Lukas Wirth
81ea48a573 fix: Fix tuple structs not rendering visibility in their fields 2024-02-08 10:05:28 +01:00
davidsemakula
62cc4f9c46 add unnecessary else diagnostic 2024-02-06 19:00:10 +03:00
bors
66cec4d11a Auto merge of #16470 - Veykril:clippy-disallow, r=lnicola
internal: Lint debug prints and disallowed types with clippy
2024-02-05 17:20:43 +00:00
bors
3e47532dd4 Auto merge of #16474 - davidbarsky:david/import-on-the-fly-improvements, r=lnicola
internal: even more `tracing`

As part of profiling completions, I added some additional spans and moved `TyBuilder::subst_for_def` closer to its usage site (the latter had a small impact on completion performance. Thanks for the tip, Lukas!)
2024-02-05 09:01:58 +00:00
davidsemakula
080d223dd4 incorrect case diagnostics for type aliases 2024-02-02 17:07:08 +03:00
davidsemakula
6d2d6323ac incorrect case diagnostics for trait assoc functions and consts 2024-02-02 17:07:08 +03:00
David Barsky
f9bef39d48 internal: add some more tracing spans inside of hir-ty 2024-02-01 16:10:32 -05:00
Lukas Wirth
9e8a0fae0c Lint debug prints and disallowed types with clippy 2024-02-01 17:57:27 +01:00
Johann Hemmann
b73ee2f50d useless_conversion 2024-01-31 19:06:18 +01:00
Johann Hemmann
c4302eaa56 unnecessary_lazy_evaluations 2024-01-31 19:06:18 +01:00
Johann Hemmann
de6f9561f2 unnecessary_cast 2024-01-31 19:06:18 +01:00
Johann Hemmann
daa20725c5 toplevel_ref_arg 2024-01-31 19:06:18 +01:00
Lukas Wirth
d252247ab7 internal: Remove unnecessary usages of ExpansionInfo 2024-01-31 09:57:17 +01:00
David Barsky
e1ea7c8844 internal: switch to tracing from log
This commit also adds `tracing` to NotificationDispatcher/RequestDispatcher,
bumps `rust-analyzer-salsa` to 0.17.0-pre.6, `always-assert` to 0.2, and
removes the homegrown `hprof` implementation in favor of a vendored
tracing-span-tree.
2024-01-30 12:27:31 -05:00
Johann Hemmann
43b1ae0446 cargo clippy --fix 2024-01-30 14:50:21 +01:00