Commit Graph

15635 Commits

Author SHA1 Message Date
Amos Wenger
fd1b64ec71 Return result directly
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-07-25 15:19:57 +02:00
Amos Wenger
fba6adfae4 Add doc comment to pass tidy check 2022-07-25 15:19:57 +02:00
Amos Wenger
5f54ec0e85 Add a proc-macro-srv-cli crate 2022-07-25 15:19:57 +02:00
Amos Wenger
dc94050815 revert nightly rustfmt formatting that accidentally slipped in
cf. https://github.com/rust-lang/rust/pull/99603
cf. https://github.com/rust-lang/rust-analyzer/pull/12871#discussion_r928816339
2022-07-25 14:18:30 +02:00
Amos Wenger
0d04e63627 Merge remote-tracking branch 'origin/master' into sync-from-rust-2 2022-07-25 14:07:07 +02:00
bors
ac86b8edff Auto merge of #12856 - Veykril:multi-proc-srv, r=Veykril
feat: Spawn a proc-macro-srv instance per workspace

cc https://github.com/rust-lang/rust-analyzer/issues/12855

The idea is to have each server be spawned with the appropriate toolchain, that way workspaces with differing toolchains shouldn't suffer from proc-macro abi mismatches.
2022-07-25 10:41:05 +00:00
Ryo Yoshida
71225c35bf
Replace debug_assert! with stdx::always! 2022-07-25 18:41:10 +09:00
Amos Wenger
dfe84494c1 Make macros test order-resistant 2022-07-24 16:48:06 +02:00
bors
7e2b983fd4 Auto merge of #12861 - DorianListens:dscheidt/complete-field, r=DorianListens
fix: Autocomplete for struct fields includes receiver

fixes #12857
2022-07-24 14:11:35 +00:00
Amos Wenger
56c369db48 Sort when iterating through CrateGraph 2022-07-24 16:11:05 +02:00
Dorian Scheidt
77acb5c162 fix: Autocomplete for struct fields includes receiver
fixes #12857
2022-07-24 09:07:43 -05:00
Amos Wenger
d8c0d88e4f Sort in DefMap::dump, since HashMap iteration order isn't defined 2022-07-24 16:04:20 +02:00
bors
537cc1eec5 Auto merge of #12863 - lowr:fix/missing-fields-on-destructuring-assignment, r=Veykril
Fix missing fields check on destructuring assignment

Fixes #12838

When checking if the record literal in question is an assignee expression or not, the new fn `is_assignee_record_literal` iterates over its ancestors until it is sure. This isn't super efficient, as we don't cache anything and does the iteration for every record literal during missing fields check. Alternatively, we may want to have a field like `assignee` on `hir_def::Expr::{RecordLit, Array, Tuple, Call}` to tell if it's an assignee expression, which would be O(1) when checking later but have some memory overhead for the field.
2022-07-24 13:57:14 +00:00
Amos Wenger
ff317858c1 hir-def tests: sort results before comparing, since FxHashSet iteration order isn't guaranteed
(And, in fact, it failed on i686)
2022-07-24 15:55:26 +02:00
Ryo Yoshida
805ac666ca
fix: consider assignee expressions in record fields exhaustiveness check 2022-07-24 22:40:04 +09:00
Ryo Yoshida
64758bd481
Add info whether it's assignee expr to relevant HIR Expr variants 2022-07-24 22:40:00 +09:00
bors
894d6a232c Auto merge of #12832 - lowr:fix/impl-default-members-no-codegen, r=Veykril
fix: don't replace default members' body

cc #12779, #12821
addresses https://github.com/rust-lang/rust-analyzer/pull/12821#issuecomment-1190157506

`gen_trait_fn_body()` only attempts to implement required trait member functions, so we shouldn't call it for `Implement default members` assist.

This patch also documents the precondition of `gen_trait_fn_body()` and inserts `debug_assert!`, but I'm not entirely sure if the assertions are appropriate.
2022-07-24 12:46:08 +00:00
Amos Wenger
74998e46e9 Fix .gitattributes for test_data 2022-07-24 14:05:35 +02:00
Joshua Nelson
20eb2ddb2e Small fixups
- use `path` instead of `paths`
- don't mark rust-analyzer as an optional tool
- print the cargo command that's run in the proc-macro-test build script

  this originally was part of a change to fix `test --stage 0 rust-analyzer`,
  but I'm going to leave that for a separate PR so it's easier to review.
2022-07-24 10:38:42 +02:00
Amos Wenger
b351e115d6 Move cfg attrs up to the mod definitions to disable sourcegen 2022-07-24 10:38:34 +02:00
Amos Wenger
0bffdf2627 Disable all source-gen tests at compile time 2022-07-24 10:38:28 +02:00
Amos Wenger
5f3f4284dd Don't run slow tests in Rust CI, only RA CI 2022-07-24 10:38:19 +02:00
Ryo Yoshida
fb063d360c
Add ellipsis to HIR RecordLit 2022-07-24 17:10:31 +09:00
Aleksey Kladov
5bd84432dd internal: extract common code for adjusting diagnostic range 2022-07-23 22:24:44 +01:00
Aleksey Kladov
a436be44b2 feat: don't highlight the whole fn on return-type mismatch 2022-07-23 21:16:59 +01:00
Lukas Wirth
50b27e57ba Better error messages when the proc-macro-server fails to start 2022-07-23 20:24:01 +02:00
Lukas Wirth
aeb07745d5 Spawn a proc-macro-srv instance per workspace 2022-07-23 20:10:10 +02:00
bors
2be00623e4 Auto merge of #12851 - DorianListens:dscheidt/if-completion-match-guard, r=Veykril
fix: Don't add braces to 'if' completion in match guard position

fixes #12823

Is this what you were thinking of here, `@Veykril` ? I haven't done any work on completions before, so I could definitely be misunderstanding the issue.
2022-07-23 17:42:59 +00:00
Dorian Scheidt
13c83f90ac fix: Don't add braces to 'if' completion in match guard position
When the cursor is in a match arm, but before the fat arrow (=>) token, don't
add braces when autocompleting "if".

fixes #12823
2022-07-23 12:25:02 -05:00
Ralf Jung
ff041bfa68 fix generate_new doc 2022-07-23 11:09:01 -04:00
bors
0b131bc78e Auto merge of #12849 - Veykril:no-parse, r=Veykril
internal: Don't parse files unnecessarily in scope_for_offset
2022-07-22 23:00:35 +00:00
Lukas Wirth
cb6703fe06 internal: Don't parse files unnecessarily in scope_for_offset 2022-07-23 00:50:59 +02:00
bors
d469e0de9a Auto merge of #12840 - Veykril:be-lazy, r=Veykril
internal: Use ItemTree for variant, field and module attribute collection in attrs_query

Less parsing = very good, should speed up lang item collection as that basically probes attributes of all enum variants which currently triggers parsing

Not fond of how this is searching for the correct index, ideally we'd map between HIR and item tree Id here but I am not sure how, storing the item tree ids in the HIR version doesn't work due to the usage of `Trace`...
2022-07-22 20:35:31 +00:00
Lukas Wirth
0081ef3834 Use ItemTree for modules in attrs_query 2022-07-22 22:17:13 +02:00
bors
7e30ca1f2a Auto merge of #12844 - Veykril:highlight-attr, r=Veykril
fix: Improve syntax highlighting in attributes

Fixes https://github.com/rust-lang/rust-analyzer/issues/12842
2022-07-22 15:31:32 +00:00
Lukas Wirth
1ab862a628 fix: Improve syntax highlighting in attributes 2022-07-22 17:29:03 +02:00
bors
cb8a3be2a1 Auto merge of #12835 - fasterthanlime:sysroot-abi, r=fasterthanlime
Introduce proc-macro-srv/sysroot-abi

Still a WIP.

This change is tracked by:

  * https://github.com/rust-lang/rust-analyzer/issues/12818
2022-07-22 12:28:27 +00:00
Amos Wenger
e591ff3269 Add comment about replacing crossbeam with std scoped threads when they land 2022-07-22 14:23:36 +02:00
Amos Wenger
39db9cdb7d Use std::panic::resume_unwind 2022-07-21 21:35:15 +02:00
Amos Wenger
48bcc229bf Move interner methods to Symbol, return SmolStr directly since it's ref-counted 2022-07-21 21:32:46 +02:00
Amos Wenger
246947b779 Fix raw ident handling (a little) 2022-07-21 19:13:44 +02:00
Amos Wenger
941416a1d6 Add test for idents incl. raw idents 2022-07-21 18:48:19 +02:00
Amos Wenger
9cf99a9c71 Stringify literals create client-side properly 2022-07-21 18:44:41 +02:00
Amos Wenger
36d825fd5d Add test for literals created client-side 2022-07-21 18:29:28 +02:00
Amos Wenger
32ee097580 Run proc macro expansion in a separate thread (for the thread-local interner) 2022-07-21 18:11:50 +02:00
Amos Wenger
05d8f5fee7 Use a thread-local for the symbol interner (1/2) 2022-07-21 14:57:09 +02:00
Amos Wenger
30769598a4 Move version string to RustcInfo, read '.rustc' section only once 2022-07-21 13:57:36 +02:00
Amos Wenger
bbaf4daca0 Pass tidy checks 2022-07-21 13:37:41 +02:00
Amos Wenger
fdddd83224 Assert that sysroot ABI version matches exactly
Otherwise, fall back to the multi ABI scheme, except in testing, where
it becomes a hard error.

This should make it possible to use a rustup-provided rust-analyzer with
proc macro dylibs compiled by older rustcs, and it'll also catch changes
to the format of `rustc --version` or the `.rustc` section that would
make them impossible to compare for equality.
2022-07-21 13:13:25 +02:00
bors
84a6fac37a Auto merge of #12841 - Veykril:query-fix, r=Veykril
fix: Fix `trait_impls_in_deps_query` being called directly instead of as a query

Fixes the inlay hint performance regression introdcuced by https://github.com/rust-analyzer/rust-analyzer/issues/12549
2022-07-21 08:23:19 +00:00
Lukas Wirth
cfad882745 fix: Fix trait_impls_in_deps_query being called directly instead of as a query 2022-07-21 10:23:07 +02:00
Lukas Wirth
5f9a5825e0 Use ItemTree for crate root attr_query collection 2022-07-21 09:23:30 +02:00
Lukas Wirth
1aadd9da92 internal: Use itemtree for variant and field attribute collection 2022-07-21 08:48:13 +02:00
Lukas Wirth
10c7ee7068 Simplify 2022-07-21 08:48:09 +02:00
bors
2f6c39005c Auto merge of #12827 - Veykril:be-lazy, r=Veykril
internal: Construct fewer `AstIdMap`s in lowering
2022-07-21 00:11:18 +00:00
Lukas Wirth
7bd2e305d6 Simplify 2022-07-21 02:06:26 +02:00
Lukas Wirth
c83f14a44a Remove AstIdMap from Expander as it is seldom needed 2022-07-21 02:01:07 +02:00
Amos Wenger
480f555334 implement literal_from_str (poorly) 2022-07-20 19:23:25 +02:00
Amos Wenger
d25b61030e Add literal/ident conversion, tests pass 2022-07-20 19:18:39 +02:00
Amos Wenger
191db9fed4 stub missing APIs 2022-07-20 19:18:39 +02:00
Amos Wenger
00bc060ba3 Fix imports, delete removed interfaces 2022-07-20 19:18:39 +02:00
Amos Wenger
e009cdc8d9 Move token_stream to separate module 2022-07-20 19:18:39 +02:00
Amos Wenger
315b0a7254 Add sysroot-abi feature, copy 1.64 ABI fo rnow 2022-07-20 19:18:39 +02:00
bors
fa883cb647 Auto merge of #12834 - fasterthanlime:proc-macro-test-toolchain, r=Veykril
Add PROC_MACRO_TEST_TOOLCHAIN environment variable

This allows overriding the toolchain used to run `proc-macro-srv` tests.

---

Sample usage.

Testing the current ABI (variable unset/empty):

```shell
amos@tails ~/bearcove/rust-analyzer/crates/proc-macro-srv proc-macro-test-toolchain*
❯ PROC_MACRO_TEST_TOOLCHAIN="" cargo test --quiet

running 16 tests
................
test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
```

Testing an older ABI:

```shell
amos@tails ~/bearcove/rust-analyzer/crates/proc-macro-srv proc-macro-test-toolchain*
❯ PROC_MACRO_TEST_TOOLCHAIN="1.58" cargo test --quiet

running 16 tests
................
test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
```

Testing current nightly ABI:

```shell
❯ rustc +nightly --version
rustc 1.64.0-nightly (f8588549c 2022-07-18)

❯ PROC_MACRO_TEST_TOOLCHAIN="nightly" cargo test --quiet

running 16 tests
................
test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
```

Testing future ABI (`rust-lang/rust` master):

```shell
amos@tails ~/bearcove/rust-analyzer/crates/proc-macro-srv proc-macro-test-toolchain
❯ PROC_MACRO_TEST_TOOLCHAIN="stage1" cargo test --quiet

running 16 tests
..........thread '<unnamed>' panicked at 'range end index 216221164920373249 out of range for slice of length 18', library/core/src/slice/index.rs:73:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
....F.
failures:

---- tests::test_fn_like_macro2 stdout ----
thread 'tests::test_fn_like_macro2' panicked at 'called `Result::unwrap()` on an `Err` value: "range end index 216221164920373249 out of range for slice of length 18"', crates/proc-macro-srv/src/tests/utils.rs:38:83
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    tests::test_fn_like_macro2

test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass '--lib
```

---

Tagging `@jonas-schievink:` this might be helpful when updating versioned ABIs later on.
2022-07-20 16:04:23 +00:00
Amos Wenger
dcd52ec327 Add PROC_MACRO_TEST_TOOLCHAIN environment variable
This allows overriding the toolchain used to run `proc-macro-srv` tests.
2022-07-20 17:43:45 +02:00
bors
cd2c2406c0 Auto merge of #12833 - fasterthanlime:literal-tests, r=Veykril
Add proc-macro-srv integration test that clones literals

This exercises some of the upcoming proc_macro bridge changes. It should also pass for all supported ABIs, with the older-style bridge.

This changed is tracked in:

  * https://github.com/rust-lang/rust-analyzer/issues/12818
2022-07-20 15:33:19 +00:00
Amos Wenger
844aa8b53e
Update crates/proc-macro-test/build.rs
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2022-07-20 16:56:30 +02:00
Amos Wenger
9a8efe235f
Update crates/proc-macro-test/build.rs
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2022-07-20 16:56:25 +02:00
Amos Wenger
f5042947ce Add proc-macro-srv integration test that clones literals
This exercises some of the upcoming proc_macro bridge changes. It
should also pass for all supported ABIs, with the older-style bridge.
2022-07-20 16:43:40 +02:00
Amos Wenger
898898df89 Don't copy the Cargo.lock 2022-07-20 16:30:08 +02:00
Amos Wenger
4375cf365e proc-macro-test build script: wipe before, be more verbose 2022-07-20 16:22:48 +02:00
Amos Wenger
a88e088fa7 Build proc-macro-test-impl out-of-tree
Building it in-place fails in rust CI because the source directory
is read-only. This changes `proc-macro-test`'s build script to first
copy `imp` under `OUT_DIR` (which is read-write).

It also prints stdout/stderr for the nested cargo invocation, should
it fail. (I've seen failures in rust CI that I couldn't explain, and
when they take 25 minutes to reproduce, you want to have that info)
2022-07-20 16:16:29 +02:00
bors
bd4439fafa Auto merge of #12829 - fasterthanlime:in-rust-tree-feature, r=Veykril
Remove `check_merge_commits` test

Due to the way "git subtree" works, the `check_merge_commits` test _will_ find merge commits and fail, so we simply skip it.

This changed is tracked in:

  * https://github.com/rust-lang/rust-analyzer/issues/12818

Maintainer impact: none
2022-07-20 14:02:49 +00:00
Amos Wenger
244f29b1e7 Remove in-rust-tree feature
Since it's unused for now -it'll be re-introduced along with the
upcoming `proc-macro-srv/sysroot` feature.
2022-07-20 15:58:57 +02:00
Amos Wenger
d5b1ae66c2 Remove check_merge_commits test altogether
Rationale: Merge commits will probably end up in
`rust-lang/rust-analyzer` when doing "rust=>ra" syncs anyway.

It could be changed to only check for merge commits in non-sync PRs,
but it's "probably not worth the hassle"
2022-07-20 15:57:14 +02:00
Amos Wenger
c520408731 Allow merge commits when 'in-rust-tree' feature is enabled
This adds an `in-rust-tree` feature that will be enabled when
rust-analyzer is built from `rust-lang/rust`. Due to the way
"git subtree" works, that test _will_ find merge commits and
fail, so we simply skip it.
2022-07-20 15:49:40 +02:00
Amos Wenger
ade31ad757 Rename proc macro server from 'Rustc' to 'RustAnalyzer' 2022-07-20 15:40:23 +02:00
Ryo Yoshida
7e0bd377c2
fix: don't replace default members' body 2022-07-20 22:30:16 +09:00
Lukas Wirth
e507807837 internal: Don't eagerly construct AstIdMaps 2022-07-20 15:12:00 +02:00
Amos Wenger
7e285e1ef5 Run cargo fmt 2022-07-20 15:06:15 +02:00
Amos Wenger
8318035726 Fix last few warnings manually 2022-07-20 15:05:02 +02:00
Amos Wenger
816f7fe12a Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
Amos Wenger
23d25a3094 Enable extra warnings required by rust-lang/rust 2022-07-20 15:00:17 +02:00
bors
0ded8e734f Auto merge of #12825 - Veykril:trait-assoc-search, r=Veykril
fix: Fix search for associated trait items being inconsistent
2022-07-20 12:00:14 +00:00
Lukas Wirth
bb4bfae422 fix: Fix search for associated trait items being inconsistent 2022-07-20 13:59:31 +02:00
bors
f3e9b38e26 Auto merge of #12646 - lowr:fix/11897, r=lowr
fix: escape receiver texts in completion

This PR fixes #11897 by escaping '\\' and '$' in the text of the receiver position expression. See [here](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#snippet_syntax) for the specification of the snippet syntax (especially [this section](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#grammar) discusses escaping).

Although not all occurrences of '\\' and '$' have to be replaced, I chose to replace all as that's simpler and easier to understand. There *are* more clever ways to implement it, but I thought they were premature optimization for the time being (maybe I should put FIXME notes?).
2022-07-20 10:51:31 +00:00
Ryo Yoshida
cfc52adc65
Add comments 2022-07-20 19:11:14 +09:00
bors
84544134f6 Auto merge of #12811 - TopGunSnake:12790, r=Veykril
fix: Insert `pub(crate)` after doc comments and attribute macros

Fixes #12790

Original behavior was to insert `pub(crate)` at the `first_child_or_token`, which for an item with a comment or attribute macro, would put the visibility marker before the comment or macro, instead of after.

This merge request alters the call to find the node with appropriate `SyntaxKind` in the `children_or_tokens`. It also adds a test case to the module to verify the behavior. Test case verifies function, module, records, enum, impl, trait, and type cases.
2022-07-20 06:29:06 +00:00
Michael Chisolm
1c32fcfeb4
Fix generated PartialEq::ne 2022-07-20 00:26:50 -04:00
bors
0e7135615f Auto merge of #12800 - hi-rustin:rustin-patch-issue-12717, r=hi-rustin
Find original as node before compute ref match

part of https://github.com/rust-lang/rust-analyzer/issues/12717
2022-07-20 00:17:09 +00:00
TopGunSnake
6df414faa2 Inverted the match logic to skip comments, attribute macros, and whitespace before the appropriate keywords. 2022-07-19 18:08:05 -05:00
bors
30c4db10ab Auto merge of #12789 - DorianListens:dscheidt/unused-param-overlapping, r=DorianListens
fix: Prevent panic in Remove Unused Parameter assist

Instead of calling `builder.delete` for every text range we find with
`process_usage`, we now ensure that the ranges do not overlap before removing
them. If a range is fully contained by a prior one, it is dropped.

fixes #12784
2022-07-19 22:36:08 +00:00
Amos Wenger
1b416473a3 Upgrade to expect-test@1.4.0
cf. https://github.com/rust-analyzer/expect-test/issues/33
cf. https://github.com/rust-lang/rust/pull/99444#issuecomment-1188844202
2022-07-19 13:00:45 +02:00
bors
88515b981d Auto merge of #12809 - lnicola:empty-diagnostics, r=lnicola
fix: Work around Code bug with empty diagnostics

Closes #11404
2022-07-19 05:08:47 +00:00
Laurențiu Nicola
474f5eafc7 Work around Code bug with empty diagnostics 2022-07-19 07:45:31 +03:00
TopGunSnake
09da74a35d Added case for const 2022-07-18 20:48:01 -05:00
TopGunSnake
3cb78ffa82 Cleaned up trailing whitespace for tidy::files_are_tidy 2022-07-18 20:29:13 -05:00
TopGunSnake
3203cb124e Added coverage for trait, mod, impl, and enum cases. 2022-07-18 20:17:42 -05:00
TopGunSnake
27b65ec91d Add test case and token finder to address 12790 2022-07-18 19:55:33 -05:00
bors
567a5e9ef7 Auto merge of #12796 - mmirate:patch-1, r=Veykril
chore: change str_ref_to_string to str_ref_to_owned

`ToString` is implemented by many different types than `&str`, and represents a serialization into string data. The fact that said data is returned as owned, is an implementation detail resulting from the lack of a parameter for a pre-allocated buffer.

If merely copying borrowed string data to owned string data is all that is desired, `ToOwned` is a much better choice, because if the user later refactors the code such that the input is no longer an `&str`, then they will get a compiler error instead of a mysterious runtime-behavioral change.
2022-07-18 22:19:52 +00:00