Commit Graph

330 Commits

Author SHA1 Message Date
cui fliter
6dca7948f7 remove repetitive words
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-02-23 18:45:03 +08:00
Lukas Wirth
d93096ecc0 internal: Fetch toolchain and datalayout for DetachedFiles 2024-02-20 10:40:39 +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
Lukas Wirth
d2b27d09ea Don't populate rust_ir::AdtVariantDatum::fields for now due to perf 2024-02-19 17:38:03 +01:00
Rose Hudson
a492d9d164 feat: add unresolved-ident diagnostic 2024-02-19 14:12:18 +01:00
davidsemakula
f2218e7278 refactor: remove body parameter for "unnecessary else" diagnostic 2024-02-19 15:35:47 +03:00
davidsemakula
ff70310086 fix: only emit "unnecessary else" diagnostic for expr stmts 2024-02-19 15:24:45 +03:00
Shoyu Vanilla
21f4ff0351 Check for let expr ancestors instead of tail expr 2024-02-19 15:24:45 +03:00
Shoyu Vanilla
d14b22863b Handle cases for else if 2024-02-19 15:19:27 +03:00
Shoyu Vanilla
e9c80a9c25 fix: False positive diagnostic for necessary else 2024-02-19 15:19:27 +03:00
Rose Hudson
5390e4ce9b feat: add non-exhaustive-let diagnostic 2024-02-19 12:36:30 +01:00
Rose Hudson
69c25327f4 internal: reduce body lookups in expr diagnostics 2024-02-19 12:34:06 +01:00
bors
25d12673db Auto merge of #16586 - Veykril:crate-graph-side-table, r=Veykril
fix: Remove cargo knowledge from `CrateData`

Fixes https://github.com/rust-lang/rust-analyzer/issues/16170, Fixes https://github.com/rust-lang/rust-analyzer/issues/15656
2024-02-16 16:04:14 +00:00
Lukas Wirth
b1404d387a fix: Split toolchain and datalayout out of CrateData 2024-02-16 14:48:25 +01:00
Lukas Wirth
fd652ceb73 fix: Don't show type mismatches for {unknown} to non-{unknown} mismatches 2024-02-16 12:16:43 +01:00
davidsemakula
9ae0f924dd fix "needless return" for trailing item declarations 2024-02-15 20:07:58 +03:00
Maybe Waffle
e146139957 Add support for become expr/tail calls 2024-02-14 14:57:18 +00:00
Lukas Wirth
9d18e197bc Filter out {unknown} types in adt_datum_quqery 2024-02-14 14:10:54 +01:00
Lukas Wirth
0eca3ef93e Fix coerce_unsize_generic test 2024-02-14 13:50:44 +01:00
Ryo Yoshida
4829f591fb Add test for auto trait bounds 2024-02-14 13:50:44 +01:00
Ryo Yoshida
03340742ea Return ADT fields and phantom_data flag from adt_datum_query() 2024-02-14 13:50:44 +01:00
Ryo Yoshida
4940017716 Rename StructDatum -> AdtDatum 2024-02-14 13:50:44 +01:00
Ryo Yoshida
a52acccc58 Implement RustIrDatabase::impl_provided_for() for ChalkContext 2024-02-14 13:50:43 +01:00
bors
818c30c311 Auto merge of #16092 - kilpkonn:term_search_1, r=Veykril
feat: Introduce term search to rust-analyzer

# Introduce term search to `rust-analyzer`
_I've marked this as draft as there might be some shortcomings, please point them out so I can fix them. Otherwise I think it is kind of ready as I think I'll rather introduce extra functionality in follow up PRs._

Term search (or I guess expression search for rust) is a technique to generate code by basically making the types match.
Consider the following program
```rust
fn wrap(arg: i32) -> Option<i32> {
    todo!();
}
```
From the types of values in scope and constructors of `Option`, we can produce the expected result of wrapping the argument in `Option`

Dependently typed languages such as `Idris2` and `Agda` have similar tools to help with proofs, but this can be also used in everyday development as a "auto-complete".

# Demo videos

https://github.com/rust-lang/rust-analyzer/assets/19900308/7b68a1b7-7dba-4e31-9221-6c7485e77d88

https://github.com/rust-lang/rust-analyzer/assets/19900308/0fae530a-aabb-4b28-af71-e19f8d3d64b2

# What does it currently do
- It works well with locals, free functions, type constructors and non-static impl methods that take items by value.
- Works with functions/methods that take shared references, but not with unique references (very conservative).
- Can handle projections to struct fields (eg. `foo.bar.baz`) but this might me more conservative than it has to be to avoid conflicting with borrow checker
- Should create only valid programs (no type / borrow checking errors). Tested with `rust-analyzer analysis-stats /path/to/ripgrep/Cargo.toml --run-term-search --validate-term-search` (basically running `cargo check` on all of the generated programs and only error seems to be due to type inference which is more of issue of testing method.

# Performace / fitness
```txt
ripgrep (latest)
Tail Expr syntactic hits: 130/1692 (7%)
Tail Exprs found: 523/1692 (30%)
Term search avg time: 9ms
Term search:         15.64s, 97ginstr, 8mb

rust-analyzer (on this branch)
Tail Expr syntactic hits: 804/13860 (5%)
Tail Exprs found: 6757/13860 (48%)
Term search avg time: 78ms
Term search:         1088.23s, 6765ginstr, 98mb
```
Highly generic code seems to blow up the search space so currently the amount of generics allowed is functions/methods is limited down to 0 (1 didn't give much improvement and 2 is already like 0.5+s search time)

# Plans for the future (not in this PR)
- ``~~Add impl methods that do not take `self` type (should be quite straight forward)~~ Done
- Be smarter (aka less restrictive) about borrow checking - this seems quite hard but since the current approach is rather naive I think some easy improvement is available.
- ``~~See if it works as a autocomplete while typing~~ Done

_Feel free to ask questions / point of shortcoming either here or on Zulip, I'll be happy to address them. I'm doing this as part of my MSc thesis so I'll be working on it till summer anyway 😄_
2024-02-12 14:47:12 +00:00
bors
5e1b09bb76 Auto merge of #16537 - Veykril:sysroot-tools, r=Veykril
internal: tool discovery prefers sysroot tools

Fixes https://github.com/rust-lang/rust-analyzer/issues/15927, Fixes https://github.com/rust-lang/rust-analyzer/issues/16523

After this PR we will look for `cargo` and `rustc` in the sysroot if it was succesfully loaded instead of using the current lookup scheme. This should be more correct than the current approach as that relies on the working directory of the server binary or loade workspace, meaning it can behave a bit odd wrt overrides.

Additionally, rust-project.json projects now get the target data layout set so there should be better const eval support now.
2024-02-12 11:26:53 +00:00
Lukas Wirth
8f3209ba27 internal: tool discovery prefers sysroot tools 2024-02-12 12:08:18 +01:00
Nadrieril
43caf8323a Prefer debug! to never! and add regression test 2024-02-11 23:46:05 +01:00
Nadrieril
b04e0df1ce pattern_analysis doesn't need an arena anymore 2024-02-11 22:30:14 +01:00
Nadrieril
3356ebd255 Update to latest rustc_pattern_analysis 2024-02-11 22:30:14 +01:00
Tavo Annus
125791386d Cleanup term search related changes 2024-02-11 14:35:54 +02:00
Tavo Annus
0b838e3e23 Expand target for autocompletion 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
Tetsuharu Ohzeki
d580b2c7bc hir-ty: Fix warnings about clippy str_to_string rule 2024-02-10 01:00:40 +09:00
Tetsuharu Ohzeki
c6637f39c0 clippy: Enable borrowed_box rule 2024-02-10 00:14:17 +09:00
Tetsuharu Ohzeki
3365e50180 clippy: Enable forget_non_drop rule 2024-02-09 23:10:43 +09:00
davidsemakula
98e6f43a2f remove trailing return in trailing match expression 2024-02-08 19:32:53 +03:00
davidsemakula
cad222ff1b remove trailing return in trailing if 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
5812b693c3 Auto merge of #16484 - Austaras:master, r=Veykril
fix: preserve where clause when builtin derive

Closes #16432.
2024-02-08 15:03:55 +00:00
austaras
dad0fdb13f fix: preserve where clause when builtin derive 2024-02-08 22:44:39 +08: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
545382db25 Fix warnings 2024-02-08 14:54:52 +01:00
davidsemakula
62cc4f9c46 add unnecessary else diagnostic 2024-02-06 19:00:10 +03:00
Nadrieril
d2d4119d24 Don't need an arena for types anymore 2024-02-06 05:09:30 +01:00
Nadrieril
ba7b12e062 Update rustc_pattern_analysis dependency 2024-02-06 05:08:19 +01:00
Nadrieril
c2d21242aa Tweak variant_id_for_adt 2024-02-06 05:01:05 +01:00