Commit Graph

15857 Commits

Author SHA1 Message Date
bors
306687b640 Auto merge of #13014 - Veykril:simplify, r=Veykril
minor: Simplify `GlobalState::handle_event`
2022-08-13 18:03:56 +00:00
Lukas Wirth
038c36a1f5 Simplify GlobalState::handle_event 2022-08-13 20:03:06 +02:00
Lukas Wirth
72ae308c73 Do not unconditionally succeed RUSTC_WRAPPER checks when run by build scripts
rust-analyzer's RUSTC_WRAPPER unconditionally succeeds `cargo check`
invocations tripping up build scripts using `cargo check` to probe for
successful compilations. To prevent this from happening the RUSTC_WRAPPER
now checks if it's run from a build script by looking for the
`CARGO_CFG_TARGET_ARCH` env var that cargo sets only when running build
scripts.
2022-08-13 12:13:48 +02:00
bors
cee1e157d7 Auto merge of #12993 - lowr:patch/swap-name-and-escaped-name, r=Veykril
Make `Name` hold escaped name

Resolves #12787
Resolves rust-lang/rust#99361

This PR effectively swaps `Name` and `EscapedName` in hir. In other words, it makes `Name` hold and print escaped raw identifiers and introduces another struct `UnescapedName` for cases where you need to print names without "r#" prefix.

My rationale is that it makes it easier for us to format an escaped name into string, which is what we want when we serialize names in general. This is because we format a name into string usually when we are presenting it to the users and arguably they expect its escaped form as that's what they see and write in the source code.

I split the change for `Name` into 3 commits to make it easier to follow but it also made some tests fail in the intermediate commits. I can squash them into a commit after the review if desired. I've also made similar changes for `ModPath` and `EscapedModPath` as it makes them consistent with `Name`.

For reference, there was a brief discussion on this in [a zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/escaping.20.60Name.60s).
2022-08-12 14:53:45 +00:00
bors
696bee3246 Auto merge of #12997 - Veykril:no-such-field, r=Veykril
fix: Fix panic in `no_such_field` when using tuple fields on record structs
2022-08-11 08:42:04 +00:00
Lukas Wirth
1bb58205f0 Fix panic in no_such_field when using tuple fields on record structs 2022-08-11 10:41:30 +02:00
Ryo Yoshida
ba6db3e9b0
Add test for runnables with raw identifiers 2022-08-11 03:41:23 +09:00
Ryo Yoshida
018266a7ff
Make ModPath display escaped path 2022-08-11 03:41:10 +09:00
Ryo Yoshida
8fe73a2240
Make tests pass 2022-08-11 01:16:35 +09:00
Ryo Yoshida
4322cf7f5b
Remove EscapedName 2022-08-11 01:11:18 +09:00
Ryo Yoshida
53ec791dc6
Add UnescapedName and make Name hold escaped name 2022-08-11 01:03:08 +09:00
bors
3eb340fa4d Auto merge of #12989 - lnicola:rm-1-64-abi, r=Veykril
internal: Remove incomplete 1.64 ABI

This no longer works for current nightlies and should not be needed any more, since we can use the toolchain's proc macro server instead.
2022-08-10 14:53:21 +00:00
bors
b1e9bcddc2 Auto merge of #12984 - Veykril:keep-going, r=Veykril
Use `--keep-going` cargo flag when building build scripts

See https://github.com/rust-lang/rust-analyzer/issues/12973#issuecomment-1209159426
2022-08-10 14:43:23 +00:00
bors
e70681f208 Auto merge of #12992 - lowr:fix/type-inference-for-byte-string-pat, r=Veykril
fix: infer byte string pattern as `&[u8]` when matched against slices

Fixes #12630

c.f. [rustc_typeck](1603a70f82/compiler/rustc_typeck/src/check/pat.rs (L388-L404))
2022-08-10 11:05:02 +00:00
Ryo Yoshida
ffc6b42901
fix: infer byte string pattern as &[u8] when matched against slices 2022-08-10 19:17:13 +09:00
Edwin Cheng
c47914c6cf Fixes tests 2022-08-10 16:29:23 +08:00
Edwin Cheng
23e17cd581 Improve insert whitespace in mbe 2022-08-10 16:28:56 +08:00
Lukas Wirth
25d4fbe9da Re-try build script building with --keep-going 2022-08-10 10:23:46 +02:00
Laurențiu Nicola
f4f70c0e0d Remove incomplete 1.64 ABI 2022-08-10 10:49:49 +03:00
Justin Ridgewell
dc3219bb11 Suggest .await when type impls IntoFuture 2022-08-09 16:39:14 -04:00
Lukas Wirth
49d24f639f Recover from missing ellipsis in record literals for path expressions 2022-08-09 18:23:25 +02:00
Lukas Wirth
b3ac58dfb8 Add some more cov_marks 2022-08-09 18:08:05 +02:00
Lukas Wirth
8c9359b072 Fix pattern field completions not working for unions 2022-08-09 17:53:16 +02:00
Lukas Wirth
950de7c3c3 Use --keep-going cargo flag when building build scripts 2022-08-09 14:31:17 +02:00
Justin Ridgewell
5810c8188a Implement IntoFuture type inference 2022-08-08 21:05:56 -04:00
KaDiWa
232176b46a
remove imports that are also in edition 2021's prelude 2022-08-09 01:16:32 +02:00
bors
554f7f889e Auto merge of #12974 - fprasx:master, r=lnicola
Corrected order of printing op and `=`

Fixes https://github.com/rust-lang/rust-analyzer/issues/12971 where `Display` impl for assignment operators does `=+` instead of `+=`
2022-08-08 15:13:20 +00:00
fprasx
e39918f553 Corrected order of printing op and = 2022-08-08 11:05:18 -04:00
bors
79c22d5fb1 Auto merge of #12962 - lowr:patch/parse-last-range-pattern, r=Veykril
Parse range patterns in struct and slice without trailing comma

Resolves #12935

This patch includes the support for range patterns in slices, which is unstable (tracked in https://github.com/rust-lang/rust/issues/67264). If it's not desired I can remove it.
2022-08-08 15:03:39 +00:00
Ryo Yoshida
b14062aaec
Parse range patterns in let statement with type annotation 2022-08-09 00:00:22 +09:00
bors
20d64412c0 Auto merge of #12951 - jonas-schievink:doc-cli-stability, r=Veykril
internal: Document CLI flag stability
2022-08-08 11:56:44 +00:00
bors
3805067bf5 Auto merge of #12905 - HKalbasi:master, r=Veykril
Generate rust type from json

fix #10118

Should this be a diagnostic? I made it a diagnostic because of issue label.
2022-08-08 11:46:22 +00:00
bors
b481b59be5 Auto merge of #12937 - fprasx:master, r=Veykril
Add fixups for incomplete in proc-macros

Partially implements https://github.com/rust-lang/rust-analyzer/issues/12777.

Added support for for loops and match statements.

I couldn't do paths like `crate::foo::` as I wasn't able to add `SyntheticTokens` to the end of `foo::`, they always ended up after `crate::`

This is my first contribution so please don't be shy about letting me know if I've done anything wrong!
2022-08-08 11:37:51 +00:00
bors
b569bbbacc Auto merge of #12942 - lowr:fix/concat-with-char, r=Veykril
fix: make `concat!` work with char

Fixes #12921

- I avoided making `unquote_str()` take char literals as well because it's depended on by another function `parse_string()` that's only supposed to take strings.
- Even with this patch, we don't output `\0` as `\u{0}` which #12921 pointed out ~~, but we're not actually responsible for serializing it but rowan is~~. They are functionally equivalent and I don't think it'd cause any confusion, but we *could* try escaping them before serialization (for reference, `rustc -Zunpretty=expanded`, which `cargo expand` uses under the hood, [makes use of `str::escape_default()`](3830ecaa8d/compiler/rustc_ast/src/util/literal.rs (L161)).
2022-08-08 11:28:42 +00:00
Kartavya Vashishtha
c1eae3d028
make diagnostic function public 2022-08-08 16:45:27 +05:30
Kartavya Vashishtha
196f389a70
try adding diagnostrics for AssocItems 2022-08-08 16:40:29 +05:30
Kartavya Vashishtha
1883d1f141
activate assoc item test 2022-08-07 20:39:11 +05:30
Kartavya Vashishtha
bcab4be938
regenerate files with new syntax 2022-08-07 17:38:20 +05:30
Kartavya Vashishtha
a3fc4dbb04
more matches! sites 2022-08-07 17:37:50 +05:30
Kartavya Vashishtha
70255029cf
clippy: make generated code nice to read
Feel free to close if this is too minor.
2022-08-07 17:09:36 +05:30
bors
634cfe3d72 Auto merge of #12956 - oxalica:feat/la-arena-apis, r=lnicola
More methods and traits for `la_arena::ArenaMap`

Continue of #12931. Seems that I forgot some methods in the previous PR :(

I also changed `ArenaMap::insert` to return the old value, to match the map-like collection API of std. **So this is a breaking change.**

r? `@lnicola`
2022-08-07 08:50:23 +00:00
Ryo Yoshida
a81c7a2974
Parse range patterns in struct and slice without trailing comma 2022-08-07 17:19:15 +09:00
Laurențiu Nicola
eca6f2e897 Fix test_rainbow_highlighting gate 2022-08-07 09:29:26 +03:00
oxalica
326ffee5b7 Returns the old value for la_arena::ArenaMap::insert 2022-08-07 04:53:23 +08:00
hkalbasi
851f6db7f7 Import serde derives on converting json to struct 2022-08-06 20:12:21 +04:30
Adrian Stanciu
e8a9bc09a3 run stable fmt through rustup 2022-08-06 17:25:02 +03:00
Jonas Schievink
fd00bd4d3b Document CLI flag stability 2022-08-05 15:28:53 +02:00
bors
3792720086 Auto merge of #12947 - Veykril:switch-workspace, r=Veykril
Don't switch workspace on vfs file changes from libraries

When r-a starts up, it starts switching the workspace before all vfs
events have been processed which causes us to switch workspace multiple
times until all vfs changes have been processed. This scales with the
size of the project and its dependencies. If workspace files from
dependencies as well as the sysroot get loaded, we shouldn't switch
the workspace as those have no impact on the project workspace.
2022-08-05 13:13:44 +00:00
bors
97038e55cf Auto merge of #12949 - Veykril:token-pick, r=Veykril
fix: Fix incorrect token pick rankings
2022-08-05 13:06:10 +00:00
Ryo Yoshida
4d5873e92f
minor: align with rustc on escaping characters in macro expansion 2022-08-05 22:01:09 +09:00
Lukas Wirth
6bf674c8e4 fix: Fix incorrect token pick rankings 2022-08-05 14:59:26 +02:00
Lukas Wirth
8aa50e08af Simplify 2022-08-05 14:54:14 +02:00
Lukas Wirth
352d3c6e50 Fix visibilities 2022-08-05 14:28:36 +02:00
Lukas Wirth
d6e78b04d0 feat: Handle operators like their trait functions in the IDE 2022-08-05 14:16:36 +02:00
Lukas Wirth
6a1737242b Don't switch workspace on vfs file changes from libraries
When r-a starts up, it starts switching the workspace before all vfs
events have been processed which causes us to switch workspace multiple
times until all vfs changes have been processed. This scales with the
size of the project and its dependencies. If workspace files from
dependencies as well as the sysroot get loaded, we shouldn't switch
the workspace as those have no impact on the project workspace.
2022-08-05 12:06:42 +02:00
Ryo Yoshida
859d467276
fix: make concat! work with char 2022-08-05 02:58:16 +09:00
fprasx
ab44a81150 Fixed up for loops, added fixme with problem
https://github.com/rust-lang/rust-analyzer/pull/12937#discussion_r937633695
2022-08-04 10:43:09 -04:00
fprasx
d6d8a1c18f Shortened fixup for match, added cases for for
Previously added a blank _ => {} for match statements
2022-08-04 09:28:25 -04:00
bors
0fe3bcfd35 Auto merge of #12808 - Veykril:check-workspace, r=Veykril
feat: Only flycheck workspace that belongs to saved file

Supercedes https://github.com/rust-lang/rust-analyzer/pull/11038

There is still the problem that all the diagnostics are cleared, only clearing diagnostics of the relevant workspace isn't easily doable though I think, will have to dig into that
2022-08-04 12:57:04 +00:00
Lukas Wirth
df7f755e3b Don't flycheck while the workspace is being loaded 2022-08-04 14:56:44 +02:00
Jean santos
5698e51027 tidy formatting 2022-08-04 09:28:34 -03:00
Lukas Wirth
df9d3db82f Trigger flycheck on all transitive dependencies as well 2022-08-04 13:22:15 +02:00
Jean santos
49dac4070c on hover fallback error, adds ast::type as possible node 2022-08-03 17:37:11 -03:00
fprasx
ef2eabbfa8 Tidy formatted 2022-08-03 16:27:43 -04:00
fprasx
d513b4c8ba Added fixup for for loops w/ missing parts 2022-08-03 15:59:17 -04:00
fprasx
5cb3e7a41b Added fixup for match statements w/ missing parts
Passes tests
2022-08-03 15:59:17 -04:00
bors
2bc9a2d9e0 Auto merge of #12933 - Veykril:proc-ignored, r=Veykril
Use an empty expander for ignored non-attribute proc-macros

Identity is the wrong behaviour for anything that's not an attribute here
2022-08-03 16:11:08 +00:00
Lukas Wirth
a8a6c160be Use an empty expander for ignored non-attribute proc-macros 2022-08-03 18:10:15 +02:00
Dorian Scheidt
1980c1192c Support PathPat paths in generate_enum_variant 2022-08-02 14:37:12 -04:00
Dorian Scheidt
111694d85b Be more strict about supported Paths in generate_enum_variant
PathType path parents don't support this assist
2022-08-02 14:37:12 -04:00
Dorian Scheidt
e4638def7a Support record fields in generate_enum_variant 2022-08-02 14:37:12 -04:00
Dorian Scheidt
15d8049fa9 Support tuple fields in generate_enum_variant 2022-08-02 14:37:12 -04:00
Dorian Scheidt
bea1fec7a2 convert generate_enum_variant to use add_variant 2022-08-02 14:37:12 -04:00
Dorian Scheidt
405dd77d30 Support adding variants via structural editing 2022-08-02 14:37:12 -04:00
bors
113f1dbc91 Auto merge of #12880 - palango:while-fixup, r=Veykril
Add syntax fixup for while loops

Part of https://github.com/rust-lang/rust-analyzer/issues/12777

This is a first iteration to gather some feedback. In particular I'm not sure if the curly braces should be added here, but I couldn't get the test to work without them. Any hints welcome!
2022-08-02 14:08:56 +00:00
Jonas Schievink
bd7dfac5eb Fix r-a spelling in some places 2022-08-01 13:47:09 +02:00
Ryo Yoshida
d40ab66186
fix: remove whitespaces from doctest names 2022-08-01 17:57:47 +09:00
bors
af646621de Auto merge of #12916 - Veykril:nits, r=Veykril
minor: Properly cfg the `max` field of Limit
2022-07-31 17:42:10 +00:00
Lukas Wirth
3b2ecf44a0 Give variables more descriptive names 2022-07-31 19:27:34 +02:00
Lukas Wirth
d31f3605ce Properly cfg the max field of Limit 2022-07-31 19:27:20 +02:00
bors
e0ff4befda Auto merge of #12913 - Veykril:attr-merge, r=Veykril
fix: Fix ast-id up when merging raw attributes

Fixes https://github.com/rust-lang/rust-analyzer/issues/12912
2022-07-30 07:53:48 +00:00
Lukas Wirth
618cfd792c fix: Fix ast-id up when merging raw attributes 2022-07-30 09:43:30 +02:00
hkalbasi
c1a175f61e Generate rust type from json 2022-07-29 20:06:01 +04:30
cynecx
902fd6ddcd fix: complete path of existing record expr 2022-07-29 17:24:05 +02:00
Laurențiu Nicola
11ef494b37 Be more explicit when filtering built-in completions 2022-07-28 21:45:47 +03:00
hkalbasi
61d1c3e138 add debug impl for AnyDiagnostic 2022-07-28 22:38:20 +04:30
Laurențiu Nicola
948c9afc73 Only run rainbow highlighting test on 64-bit Unix 2022-07-28 21:03:59 +03:00
bors
b8763fe224 Auto merge of #12902 - Veykril:item-scope, r=Veykril
fix: Order ItemScope::entries results
2022-07-28 17:38:59 +00:00
Lukas Wirth
f867ddc621 fix: Order ItemScope::entries results 2022-07-28 19:28:56 +02:00
bors
32e640e2ba Auto merge of #12901 - Veykril:completion-trait-expr, r=Veykril
fix: Don't complete marker traits in expression position

cc https://github.com/rust-lang/rust-analyzer/issues/12196
2022-07-28 15:51:30 +00:00
Lukas Wirth
ce7541260d fix: Don't complete marker traits in expression position 2022-07-28 17:50:49 +02:00
bors
5986d2190f Auto merge of #12899 - Veykril:compl-qualifier, r=Veykril
fix: Do completions in path qualifier position

Fixes https://github.com/rust-lang/rust-analyzer/issues/12566

Not too happy with the duplication needed for this, but it is what it is. Completions in path qualifiers will have to be filtered properly still, but its better to show too many completions for this than too few for now.
2022-07-28 15:11:24 +00:00
Lukas Wirth
74abd44a26 fix: Do completions in path qualifier position 2022-07-28 17:09:31 +02:00
bors
02c240ff81 Auto merge of #12898 - Veykril:compl-pat-brace, r=Veykril
fix: Fix pattern completions adding unnecessary braces

Fixes https://github.com/rust-lang/rust-analyzer/issues/12852
2022-07-28 13:48:12 +00:00
Lukas Wirth
7c59d7c75c fix: Fix pattern completions adding unnecessary braces 2022-07-28 15:47:46 +02:00
bors
02f9ec4be5 Auto merge of #12895 - Veykril:compl-anchor, r=Veykril
fix: Calculate completions after type anchors

Fixes https://github.com/rust-lang/rust-analyzer/issues/12892
2022-07-28 08:06:58 +00:00
Lukas Wirth
e782e59d3d fix: Calculate completions after type anchors 2022-07-28 10:06:36 +02:00
bors
40875353a5 Auto merge of #12891 - brennanvincent:expander_stack, r=lnicola
Use large stack on expander thread

I have verified that this fixes #12884 for me.

Hat tip to `@bjorn3` for identifying the cause of the issue.
2022-07-27 19:40:59 +00:00
Brennan Vincent
f83738e1d9 Use large stack on expander thread 2022-07-27 15:02:34 -04:00
Paul Lange
c16e4f260f Add syntax fixup for loop 2022-07-27 18:18:51 +02:00
Paul Lange
a969481952 Add syntax fixup for while loops 2022-07-27 18:16:58 +02:00
Lukas Wirth
bf893d59b5 internal: Assume condition/iterable is missing if there is only a BlockExpr 2022-07-27 17:29:51 +02:00
bors
b4d652aa40 Auto merge of #12830 - hi-rustin:rustin-patch-issue-12717-fix, r=Veykril
Find original ast node before compute ref match

ref https://github.com/rust-lang/rust-analyzer/issues/12717
2022-07-27 12:31:26 +00:00
hi-rustin
349dfc7e95 Find original ast node before compute ref match in fn render
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-07-27 20:18:00 +08:00
Lukas Wirth
1f8daa180f fix: Honor ref expressions for compute_ref_match completions 2022-07-27 13:48:26 +02:00
Lukas Wirth
6c379b9f4b fix: Fix Semantics::original_ast_node not caching the resulting file 2022-07-27 12:46:04 +02:00
bors
c2eebd7a50 Auto merge of #12877 - zachs18:inline-def-in-macro, r=zachs18
fix: Insert spaces when inlining a function defined in a macro.

(partially) fixes #12860.

This PR (only) addresses the whitespace issue when inlining functions defined in macros.

Additionally, the indentation/spacing is not ideal, but works, e.g.
```rs
macro_rules! define_function {
    () => { fn test_function_macro() {
        if let Some(3) = 3i32.checked_add(0) {
            println!("3 + 0 == 3");
        }
    } };
}
define_function!();
fn main() {
    test_function_macro();
}
// previously became
// ...
fn main() {
    ifletSome(3)=3i32.checked_add(0){println!("3 + 0 == 3");};
}
// now becomes
// ...
fn main() {
    if let Some(3) = 3i32.checked_add(0){
        println!("3 + 0 == 3");

      };
}
```

The `self` -> `this` problem[^this] is (probably?) a separate problem that I am also looking into.

[^this]: As mentioned in [my comment on the above issue](https://github.com/rust-lang/rust-analyzer/issues/12860#issuecomment-1193231766), inlining a method defined in a macro does not properly replace `self` with the new local `this`.
2022-07-26 16:14:51 +00:00
Zachary S
add33b65dd Remove FIXME comment for unreachable fallback. 2022-07-26 10:59:19 -05:00
Lukas Wirth
c8ff70e924 fix: Fix server panicking on project loading when proc-macros are disabled 2022-07-26 16:30:45 +02:00
Amos Wenger
b1e3daf14b Find standalone proc-macro-srv on windows too 2022-07-26 12:28:59 +02:00
Lukas Wirth
ddad2847ab Allow name querying for derive helpers 2022-07-26 09:27:22 +02:00
Lukas Wirth
aa1491ecde Record derive helper attributes, resolve them in IDE layer 2022-07-26 09:26:51 +02:00
Lukas Wirth
4e60db2d07 feat: Downmap tokens inside derive helpers 2022-07-26 09:26:47 +02:00
Zachary S
e45a250f8c fix: Insert spaces when inlining a function defined in a macro. 2022-07-25 15:45:17 -05:00
Amos Wenger
2c2520fbb4 Allow specifying sysroot OR sysroot_src 2022-07-25 17:52:38 +02:00
Amos Wenger
696775153d Fix mix up in comments 2022-07-25 16:59:10 +02:00
Amos Wenger
74a2fad5e6 Gate and rename binary, use it if it's in the sysroot 2022-07-25 16:22:39 +02:00
Amos Wenger
dadb83282d Remember the difference between 'sysroot root' and 'sysroot src root', start looking in there for a rust-analyzer-proc-macro-srv binary 2022-07-25 16:07:41 +02:00
Amos Wenger
4364531c2f Name the binary 'proc-macro-srv' 2022-07-25 15:19:57 +02:00
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