Commit graph

18462 commits

Author SHA1 Message Date
Lukas Wirth
d6b908ec41 Fix import preference config keys 2023-11-12 17:48:40 +01:00
Laurențiu Nicola
bad3d9e766 Include toml files in the vfs 2023-11-12 16:45:47 +02:00
bors
1152f593b3 Auto merge of #15870 - lnicola:expand-macro, r=lnicola
minor: Make "Expand macro" command title more explicit

Closes [#15856](https://github.com/rust-lang/rust-analyzer/issues/15856).

I opted for "caret", since it's the better term (cursor is the mouse), but I'm not sure how popular it is these days.
2023-11-12 13:48:43 +00:00
Laurențiu Nicola
cace36cade Make Expand macro command title more explicit 2023-11-12 11:43:46 +02:00
Young-Flash
23fde40fed fix PathSegment grammar 2023-11-12 11:20:14 +08:00
DropDemBits
4aaa592a9a
Migrate destructure_tuple_binding to mutable ast
Due to the way the current tree mutation api works, we need to collect
changes before we can apply them to the real syntax tree, and also can only
switch to a file once.

`destructure_tuple_binding_in_sub_pattern` also gets migrated even
though can't be used.
2023-11-11 21:07:19 -05:00
DropDemBits
f3dcc67dfa
Migrate add_type_ascription 2023-11-11 21:05:27 -05:00
DropDemBits
5fc8cc52e2
Add LetStmt::set_ty
Way for setting and removing the type ascription of a let stmt
2023-11-11 21:05:27 -05:00
DropDemBits
92422f7488
Use syntax's version of SyntaxElement 2023-11-11 21:05:27 -05:00
DropDemBits
cc4e06f04b
Migrate add_turbo_fish to mutable ast
`add_type_ascription` is still left as-is since it's a different assist
2023-11-11 21:05:26 -05:00
DropDemBits
02c7b8b9ba
Add MethodCallExpr::get_or_create_generic_arg_list
Mirrors `PathSegment's` version, except that it always generates a
turbofish
2023-11-11 21:05:26 -05:00
Lukas Wirth
74e5444f15 Fix some FIXMEs 2023-11-11 15:49:57 +01:00
Lukas Wirth
ba61766217 Add config for preferring / ignoring prelude modules in find_path 2023-11-11 14:56:38 +01:00
Lukas Wirth
801a887954 Record all import paths per item in ImportMap 2023-11-11 14:48:44 +01:00
Lukas Wirth
2339ba4440 Prepare ImportMap for supportin multiple import paths per item 2023-11-11 14:04:24 +01:00
Pascal Kuthe
0647b645cd
ensure renames happen after edit 2023-11-10 17:39:32 +01:00
Laurențiu Nicola
9826717550 Improve check for include macro 2023-11-10 16:53:08 +02:00
bors
7cca4e5816 Auto merge of #15854 - alibektas:15782/relax_hidden_attr, r=lnicola
fix: Ignore doc(hidden) attr if no body is present

fixes #15782
2023-11-10 13:30:52 +00:00
bors
5afaf680b8 Auto merge of #15864 - Young-Flash:find_self, r=lnicola
fix: find `Self` reference

took a lot of time to debug to find the problem, here should compare the actual `Adt` type

close https://github.com/rust-lang/rust-analyzer/issues/12693
2023-11-10 13:13:14 +00:00
Young-Flash
e0276dc5dd fix: find Self reference 2023-11-10 19:54:43 +08:00
bors
76633199f4 Auto merge of #15860 - HKalbasi:fix-capture-raw-pointer, r=HKalbasi
Truncate closure capture place for raw pointer

fix https://github.com/rust-lang/rust-analyzer/issues/15670#issuecomment-1804070623
2023-11-09 17:53:52 +00:00
bors
ebb9ed90d1 Auto merge of #15853 - Kangaxx-0:gaxx/update-parser-event-comment, r=lnicola
Try to update parser/event doc

`TokenSource` and `TreeSink` has been refactored as part of #10765, they no longer exist in code repo. This pr tries to remove them from event module level comment to prevent confusion.
2023-11-09 17:39:58 +00:00
hkalbasi
3bcdb7d886 Truncate closure capture place for raw pointer 2023-11-09 20:59:17 +03:30
Young-Flash
be62e0bf08 fix: remove parenthesis should ensure space 2023-11-09 18:33:49 +08:00
Ali Bektas
b0101da116 Ignore doc(hidden) attr if no body is present 2023-11-09 02:12:53 +01:00
Gaxx
fa7a91844a Try to update parser doc 2023-11-08 16:29:21 -08:00
bors
7059ae2fc2 Auto merge of #15847 - wasd96040501:feat/preview_adt, r=lnicola
feat: preview adt field when hover

Closes #13977
![20231108194345_rec_](https://github.com/rust-lang/rust-analyzer/assets/14040068/95894c4b-de6e-4ca4-98b3-6ab4559d0950)
2023-11-08 13:48:19 +00:00
YangzeLuo
41bcd542e2 feat: preview adt field when hover 2023-11-08 21:45:32 +08:00
Laurențiu Nicola
d1d111d09e Merge commit '3b7c7f97e4a7bb253a8d398ee4f8346f6cf2817b' into sync-from-ra 2023-11-08 08:15:03 +02:00
hkalbasi
1086b294c2 update rustc dependencies 2023-11-08 01:16:47 +03:30
roife
13249b7dd9 fix: correct a typo in a comment in base-db/lib.rs 2023-11-07 14:51:34 +08:00
Young-Flash
b84940b199 make generate_mut_trait_impl assist trigged for std trait only 2023-11-05 12:27:10 +08:00
Young-Flash
8d8d12120d feat: add generate_mut_trait_impl assist 2023-11-05 12:27:10 +08:00
Laurențiu Nicola
19bf0da9d7 Fix docs path for derive macros 2023-11-04 13:33:19 +02:00
Nicholas Nethercote
6eaf3f8bb2 Remove support for compiler plugins.
They've been deprecated for four years.

This commit includes the following changes.
- It eliminates the `rustc_plugin_impl` crate.
- It changes the language used for lints in
  `compiler/rustc_driver_impl/src/lib.rs` and
  `compiler/rustc_lint/src/context.rs`. External lints are now called
  "loaded" lints, rather than "plugins" to avoid confusion with the old
  plugins. This only has a tiny effect on the output of `-W help`.
- E0457 and E0498 are no longer used.
- E0463 is narrowed, now only relating to unfound crates, not plugins.
- The `plugin` feature was moved from "active" to "removed".
- It removes the entire plugins chapter from the unstable book.
- It removes quite a few tests, mostly all of those in
  `tests/ui-fulldeps/plugin/`.

Closes #29597.
2023-11-04 08:50:46 +11:00
bors
11a263d5ee Auto merge of #15819 - wasd96040501:feat/skip_tt_count_limit, r=lnicola
feat: skip checking token tree count for include! macro call

fix #15335 #15648
2023-11-02 10:48:51 +00:00
luoyangze.ptrl
b76f2c8ee0 fix: using name(include) instead of str 2023-11-02 10:14:54 +08:00
luoyangze.ptrl
740a864b7c feat: skip checking tt count for include macro call 2023-11-02 00:27:11 +08:00
bors
99e94d2938 Auto merge of #15788 - Young-Flash:import_anonymously, r=lnicola
feat: import trait with alias

![import_trait_with_alias](https://github.com/rust-lang/rust-analyzer/assets/71162630/81601160-fe55-46e3-ab8d-b2705e1aa696)

cc `@Veykril`

close https://github.com/rust-lang/rust-analyzer/issues/15684
2023-10-31 14:33:00 +00:00
Young-Flash
929544ef28 use check_assist_by_label to pick assist 2023-10-31 22:13:07 +08:00
Young-Flash
a723acf346 simplify the code 2023-10-31 21:03:26 +08:00
cui fliter
9c99afe3aa Fix some typos
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-10-30 10:31:50 +08:00
bors
f493207744 Auto merge of #15809 - Young-Flash:extract_variable_in_place, r=HKalbasi
feat: make extract_variable assist in place

![extract_variable_without_select](https://github.com/rust-lang/rust-analyzer/assets/71162630/96be2de4-42c9-4b24-b3e1-8b3e3a2da1d9)

close https://github.com/rust-lang/rust-analyzer/issues/15796
2023-10-28 06:20:35 +00:00
Young-Flash
7186a28717 chore: add unapplicable test for extract_variable without select 2023-10-28 10:06:09 +08:00
Young-Flash
00cdbe6c96 feat: make extract_variable assist in place 2023-10-27 21:16:34 +08:00
Roberto Bampi
99ec3aa8a3 scip: update crate to version 0.3.1.
While the git repo has been updated constantly, crates.io has only now
been updated after more than a year of activity.
2023-10-26 16:20:06 +02:00
bors
2f6961aaaf Auto merge of #15780 - Young-Flash:auto_import, r=lnicola
fix: import trait if needed for `unqualify_method_call` assist

before:

![before](https://github.com/rust-lang/rust-analyzer/assets/71162630/66fda67d-afcb-453f-91a9-7e85993c3d2a)

after:

![after](https://github.com/rust-lang/rust-analyzer/assets/71162630/72ffbda4-1615-4413-836e-480eb52e9728)

follow up https://github.com/rust-lang/rust-analyzer/pull/13825
2023-10-23 16:56:22 +00:00
Young-Flash
45ee88f9cb fix: remove unwrap 2023-10-23 23:12:07 +08:00
hkalbasi
8b82ea4f51 Store binding mode for each instance independently 2023-10-22 23:35:33 +03:30
Young-Flash
4f5f7e2800 feat: import trait with alias 2023-10-22 21:39:00 +08:00
bohan
d20471334f use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
Laurențiu Nicola
094cecd3bd Fix VS Code detection for Insiders version 2023-10-21 19:08:41 +03:00
bors
954fb1d673 Auto merge of #15727 - DaniPopes:lintgen-unstable-book, r=HKalbasi
feat: generate descriptors for all unstable features

Most unstable features don't have their own chapter in the unstable book, so a rustc helper tool (`src/tools/unstable-book-gen`) generates shims to fill the gaps.
Run this tool to generate the full unstable-book source before parsing it.
2023-10-20 16:42:23 +00:00
bors
bd38871a98 Auto merge of #15736 - rmehri01:15678_module_incorrect_case_diagnostics, r=HKalbasi
fix: add incorrect case diagnostics for module names

Adds diagnostics for checking both inline and file module names are snake case.

Closes #15678
2023-10-20 16:20:40 +00:00
Young-Flash
a7f77d89a9 fix: auto import trait if needed 2023-10-19 17:34:17 +08:00
bors
7f1e6fdfee Auto merge of #15775 - Young-Flash:refactor, r=Veykril
refactor: change generated variable name

change generated variable name in `replace_is_some_with_if_let_some` assist

close https://github.com/rust-lang/rust-analyzer/issues/15765
2023-10-18 06:39:34 +00:00
Young-Flash
1a0fe58d81 refactor: change generated variable name 2023-10-17 17:34:11 +08:00
bors
d6afb4fa23 Auto merge of #15746 - pvalletbo:string-literals-diagnose, r=Veykril
String literals diagnose

Continues the work from #15744 to add diagnosis errors to Str, ByteStr, and CStr literal kinds.

Also replaces `unescape_char` for `unescape_byte` to use the correct method for Byte literals.
2023-10-16 18:23:22 +00:00
Lukas Wirth
40acc5250f Update rustc_abi dependency 2023-10-15 18:57:40 +02:00
bors
65532e417d Auto merge of #15755 - Young-Flash:cursor_selection, r=lnicola
fix: make cursor select at _tmp

Here make cursor select at `_tmp` atuomatically after the assist apply. Refer to [vscode snippet placeholder](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_placeholders).

![cursor_selection](https://github.com/rust-lang/rust-analyzer/assets/71162630/a7866efe-2d54-488b-903e-9df039f34a7e)

following https://github.com/rust-lang/rust-analyzer/pull/15752
2023-10-15 07:41:29 +00:00
Christian Schott
8217ff9c16
make ProjectionStore-impls pub-accessible 2023-10-14 19:20:11 +02:00
bors
16ac6c284c Auto merge of #15756 - harpsword:fix_typo_in_mbe_lib, r=lnicola
fix typo in mbe/lib.rs comment

fix typo in mbe/lib.rs comment
2023-10-14 06:23:12 +00:00
harpsword
3f4368a090 fix: fix typo in mbe/lib.rs comment 2023-10-14 14:13:24 +08:00
Young-Flash
bc34e8f1ad feat: make cursor select at _tmp 2023-10-14 11:05:38 +08:00
bors
862693ff95 Auto merge of #15752 - Young-Flash:replace_is_method_with_if_let_method, r=HKalbasi
feat: add replace_is_ok_with_if_let_ok assist

following https://github.com/rust-lang/rust-analyzer/pull/15743
2023-10-13 07:32:55 +00:00
Young-Flash
5bbca22720 update mod order to adapt alphabetically sorted 2023-10-13 00:09:13 +08:00
Young-Flash
506b1e515b feat: add replace_is_ok_with_if_let_ok assist 2023-10-12 23:26:42 +08:00
bors
84e1d27343 Auto merge of #15743 - Young-Flash:replace_is_some_with_if_let_some, r=HKalbasi
add replace_is_some_with_if_let_some assist

This is a basic impl, if it is ok, `if my_result.is_ok()`-> `if let Ok(_x) = my_result ​`will be add next.

close https://github.com/rust-lang/rust-analyzer/issues/12977
2023-10-12 08:20:08 +00:00
Young-Flash
3605bb38ff fix CI: generate doctest 2023-10-12 11:50:44 +08:00
Pol Valletbó
6845c80a2f fix: format 2023-10-11 15:52:22 +02:00
Pol Valletbó
4b281ffdf2 chore: format imports 2023-10-11 15:52:05 +02:00
Pol Valletbó
b769f34f63 chore: move common code to function 2023-10-11 15:45:45 +02:00
Pol Valletbó
e1aeb7fa79 fix: handle errors for string byte string and c_string 2023-10-11 15:25:52 +02:00
Pol Valletbó
677e6f3439 fix: use unescape_byte function for Byte literals 2023-10-11 13:09:15 +02:00
Pol Valletbó
f58a8250dc fix: cargo fmt 2023-10-11 12:36:53 +02:00
Pol Valletbó
1fe6ac87e9 add diagnosis messages for chars and byte literal errors 2023-10-11 12:19:00 +02:00
Young-Flash
a7fada4650 add replace_is_some_with_if_let_some assist 2023-10-11 17:44:27 +08:00
Ryan Mehri
36eac9abee fix: add incorrect case diagnostics for module names 2023-10-09 13:36:39 -07:00
bors
aaa1e8e1b8 Auto merge of #15618 - shogo-nakano-desu:internal/port-anymap, r=Veykril
internal: port anymap

## Description
- The anymap crate has been ported. During this process, unnecessary features for rust-analyzer have been removed.
- From the tests that were checking the existing licenses, the anymap license (`BlueOak-1.0.0 OR MIT OR Apache-2.0`) has been removed.

## Requests
- While porting the code this time, I have tried to respect the original author's intentions and have kept the comments/codes as much as possible. Please don't hesitate to tell me if you think the comments/codes also need to be appropriately modified.
- If there are any necessary changes regarding the licensing or anything else, please let me know so I can fix them.

## Issue
https://github.com/rust-lang/rust-analyzer/issues/15500
2023-10-09 08:40:54 +00:00
bors
ab62c0186f Auto merge of #15696 - rmehri01:14293_tuple_return_type_to_struct, r=Veykril
feat: implement tuple return type to tuple struct assist

This PR implements the `convert_tuple_return_type_to_struct` assist, for converting the return type of a function or method from a tuple to a tuple struct. Additionally, it moves the `to_camel_case` and `char_has_case` functions from `case_conv` to `stdx` so that they can be used similar to `to_lower_snake_case`.

[tuple_return_type_to_tuple_struct.webm](https://github.com/rust-lang/rust-analyzer/assets/52933714/2803ff58-fde3-4144-9495-7c7c7e139075)

Currently, the assist puts the struct definition above the function, or above the nearest `impl` or `trait` if applicable and only rewrites literal tuples that are returned in the body of the function. Additionally, it only attempts to rewrite simple tuple pattern usages with the corresponding tuple struct pattern but does so across files and modules.

I think that this is sufficient for the majority of use cases but I could be wrong. One thing I'm still not sure how to approach is handling `Self` and generics/lifetimes in the tuple type to be extracted. I was thinking of either manually figuring out what lifetimes and generics are in scope and using them (sort of similar to the `generate_function` assist) or maybe using `ctx.sema.resolve_type` and `generic_params` on `hir::Type` but this seems to not deal with lifetimes.

Closes #14293
2023-10-09 08:14:42 +00:00
bors
dca63d1b21 Auto merge of #15713 - Veykril:flyimport-completions-short, r=Veykril
Do flyimport completions by prefix search for short paths

Fixes https://github.com/rust-lang/rust-analyzer/issues/15711
2023-10-09 07:56:02 +00:00
DaniPopes
0c4be03456
feat: generate descriptors for all unstable features 2023-10-09 09:36:47 +02:00
Victor Song
a39d2076db Addressed PR style comments 2023-10-09 02:15:05 -05:00
Victor Song
9771e1e18f Don't pass any target directory options to custom flycheck 2023-10-09 02:15:05 -05:00
Victor Song
2290cc3cf3 Pass target directory as flag instead of env variable 2023-10-09 02:15:05 -05:00
Victor Song
3682c3791b Set CARGO_TARGET_DIR when using Flycheck custom command 2023-10-09 02:15:05 -05:00
Victor Song
ef0b3bbef1 Clarify documentation on new parameter 2023-10-09 02:15:05 -05:00
Victor Song
53b6700594 Add dedicated target_dir field to CargoConfig and FlycheckConfig
Add dedicated field for `target_dir` in the configurations for Cargo
and Flycheck. Also change the directory to be a `PathBuf` as opposed to
a `String` to be more appropriate to the operating system.
2023-10-09 02:15:05 -05:00
Victor Song
aeef7b644b Add config option to use rust-analyzer specific target dir
Adds a Rust Analyzer configuration option to set a custom
target directory for builds. This is a workaround for Rust Analyzer
blocking debug builds while running `cargo check`. This change
should close #6007
2023-10-09 02:15:05 -05:00
DaniPopes
c5d9bfaa52
internal: fix automatic rustc/rustdoc lint generation 2023-10-07 23:24:55 +02:00
bors
b1f89a84ab Auto merge of #15600 - davidbarsky:davidbarsky/broken-rustfmt-in-ra, r=Veykril
fix: ensure `rustfmt` runs when configured with `./`

(Hopefully) resolves https://github.com/rust-lang/rust-analyzer/issues/15595. This change kinda approaches canonicalization—which I am not a fan of—but only in service of making `./`-configured commands run correctly.

Longer-term, I feel like this code should be removed once `rustfmt` supports recursive searches of configuration files or interpolation of values like `${workspace_folder}` lands in rust-analyzer.

## Testing

I cloned `rustc`, setup rust-analyzer as suggested in the [`rustc` dev guide](https://rustc-dev-guide.rust-lang.org/building/suggested.html#configuring-rust-analyzer-for-rustc), saved and formatted files in `src/tools/miri` and `compiler`, and saw `rustfmt` (seemingly) correctly.
2023-10-06 11:33:52 +00:00
Lukas Wirth
b3ebc9ab6a Check for both path separators on windows 2023-10-06 13:26:36 +02:00
Lukas Wirth
88a00bf49d Shrink PatPtr by swapping its AstPtr and Either wrap order 2023-10-06 12:32:37 +02:00
Tobias Berger
114f8a07e9
Fix typos exec_intrinsic 2023-10-06 09:24:28 +02:00
bors
fd39a30b6c Auto merge of #15712 - cuishuang:master, r=lnicola
minor: Remove repetitive words
2023-10-05 22:29:45 +00:00
cui fliter
58239f2990 Remove repetitive words
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-10-05 19:40:41 +08:00
Lukas Wirth
4af730eb26 Do flyimport completions by prefix search for short paths 2023-10-05 13:21:12 +02:00
bors
695c612489 Auto merge of #15641 - alibektas:15598/fix_into_to_from, r=Veykril
fix: preceding QualifiedPathType for into_to_from assist

fixes #15598
2023-10-05 08:25:58 +00:00
Ryan Mehri
9ba8dbc902 style: clean up magic number for finding pattern usages 2023-10-04 08:04:59 -07:00
bors
7e9da40078 Auto merge of #15700 - rmehri01:15694_iterator_demorgan, r=Veykril
feat: add assist for applying De Morgan's law to `Iterator::all` and `Iterator::any`

This PR adds an assist for transforming expressions of the form `!iter.any(|x| predicate(x))` into `iter.all(|x| !predicate(x))` and vice versa.

[IteratorDeMorgans.webm](https://github.com/rust-lang/rust-analyzer/assets/52933714/aad1a299-6620-432b-9106-aafd2a7fa9f5)

Closes #15694
2023-10-04 11:08:44 +00:00
Lukas Wirth
c266387e13
Replace unwrap with expect 2023-10-04 13:06:23 +02:00
Lukas Wirth
fe398163b6 Recognize custom main function as binary entrypoint for runnables 2023-10-04 12:07:41 +02:00
David Barsky
a8ec77dc7e address PR feedback. 2023-10-03 16:44:09 -04:00
Laurențiu Nicola
7c113ee77c Add mock description to rustc-dependencies 2023-10-03 17:32:57 +03:00
bors
4c9d2c75b5 Auto merge of #15698 - rmehri01:15695_make_guarded_return_more_lenient, r=Veykril
fix: allow more kinds of if let patterns in guarded return assist

Removes the checks that require the pattern to be a tuple struct with exactly 1 field that is unqualified and has an identifier pattern in it. I'm not sure if there should be more checks in place but they seem unnecessary now?

Closes #15695
2023-10-02 09:23:49 +00:00
Laurențiu Nicola
084ee934b8 Strip base prefix in layout_scalar_valid_range 2023-10-02 10:47:18 +03:00
Ryan Mehri
34d3490198 feat: add assist for applying De Morgan's law to iterators 2023-10-01 21:30:10 -07:00
Ryan Mehri
146a7cc490 fix: allow more kinds of if let patterns in guarded return assist 2023-10-01 11:48:10 -07:00
Ryan Mehri
2611fbf623 implement basic version of convert_tuple_return_type_to_struct assist 2023-09-30 17:07:01 -07:00
Ryan Mehri
40f80e29a5 move to_camel_case and char_has_case from case_conv to stdx 2023-09-30 08:04:04 -07:00
hkalbasi
af28458643 Downgrade unused_variables to experimental 2023-09-30 08:38:55 +03:30
bors
4791a5de21 Auto merge of #15692 - Veykril:underscore-completions, r=Veykril
fix: Typing underscore should not trigger completions in types or patterns
2023-09-29 19:08:15 +00:00
Lukas Wirth
ae5d74dffb typing underscore should not trigger completions in types or patterns 2023-09-29 21:06:47 +02:00
bors
547bcf8bbf Auto merge of #15688 - Veykril:rustc_layout_scalar_valid_range, r=Veykril
Make rustc_layout_scalar_valid_range attributes work for non-decimal literals

Closes https://github.com/rust-lang/rust-analyzer/issues/15687
2023-09-29 13:32:09 +00:00
Lukas Wirth
a943b19e08 Make rustc_layout_scalar_valid_range attributes work for non-decimal literals 2023-09-29 15:30:47 +02:00
bors
e478db717e Auto merge of #15680 - DaniPopes:regenerate-lints, r=Veykril
internal: re-generate lints.rs

Looks like this hasn't been run in a while
2023-09-29 12:44:24 +00:00
DaniPopes
53f5c1c13f
internal: re-generate lints.rs 2023-09-29 14:20:17 +02:00
bors
50678e0da0 Auto merge of #15682 - Veykril:param-list-recov, r=Veykril
Recover better on missing parameter in param list

We should do the same for argument lists, but that is more tricky to fix.
2023-09-29 11:14:02 +00:00
Lukas Wirth
a382e649ca Recover better on missing parameter in param list 2023-09-29 12:50:16 +02:00
bors
87e2c310f9 Auto merge of #15667 - rmehri01:bool_to_enum_top_level, r=Veykril
fix: make bool_to_enum assist create enum at top-level

This pr makes the `bool_to_enum` assist create the `enum` at the next closest module block or at top-level, which fixes a few tricky cases such as with an associated `const` in a trait or module:

```rust
trait Foo {
    const $0BOOL: bool;
}

impl Foo for usize {
    const BOOL: bool = true;
}

fn main() {
    if <usize as Foo>::BOOL {
        println!("foo");
    }
}
```

Which now properly produces:

```rust
#[derive(PartialEq, Eq)]
enum Bool { True, False }

trait Foo {
    const BOOL: Bool;
}

impl Foo for usize {
    const BOOL: Bool = Bool::True;
}

fn main() {
    if <usize as Foo>::BOOL == Bool::True {
        println!("foo");
    }
}
```

I also think it's a bit nicer, especially for local variables, but didn't really know to do it in the first PR :)
2023-09-29 10:20:11 +00:00
Ryan Mehri
1b3e5b2105 style: simplify node_to_insert_before 2023-09-28 10:09:13 -07:00
Emilio Cobos Álvarez
791e6c8b1b
scip: Allow customizing cargo config.
Re-use the LSP config json for simplicity.
2023-09-28 17:22:19 +02:00
Lukas Wirth
2b9dde14ab Allocate ast ids for parameters 2023-09-28 13:16:11 +02:00
bors
3b1b58c225 Auto merge of #15662 - rmehri01:fix_panic_with_return_in_match, r=Veykril
fix: panic with wrapping/unwrapping result return type assists

With the `wrap_return_type_in_result` assist, the following code results in a panic (note the lack of a semicolon):

```rust
fn foo(num: i32) -> $0i32 {
    return num
}

=>

thread 'handlers::wrap_return_type_in_result::tests::wrap_return_in_tail_position' panicked at crates/syntax/src/ted.rs:137:41:
called `Option::unwrap()` on a `None` value
```

I think this is because it first walks the body expression to change any `return` expressions and then walks all tail expressions, resulting in the `return num` being changed twice since it is both a `return` and in tail position. This can also happen when a `match` is in tail position and `return` is used in a branch for example. Not really sure how big of an issue this is in practice though since this seems to be the only case that is impacted and can be reduced to just `num` instead of `return num`.

This also occurs with the `unwrap_result_return_type` assist but panics with the following instead:

```
thread 'handlers::unwrap_result_return_type::tests::wrap_return_in_tail_position' panicked at /rustc/3223b0b5e8dadda3f76c3fd1a8d6c5addc09599e/library/alloc/src/string.rs:1766:29:
assertion failed: self.is_char_boundary(n)
```
2023-09-26 14:18:33 +00:00
Lukas Wirth
0dbde71159 Simplify 2023-09-26 12:25:59 +02:00
Ryan Mehri
73150c3f36 fix: wrap method call exprs in parens 2023-09-25 21:44:16 -07:00
Ryan Mehri
bce4be9478 fix: make bool_to_enum assist create enum at top-level 2023-09-25 21:01:54 -07:00
Milo
85ead6ec27 remove other unwraps 2023-09-25 11:48:23 +00:00
Milo
f64eecd2e2 fix one 2023-09-25 11:30:21 +00:00
bors
972a19f4cb Auto merge of #15659 - HKalbasi:unused-var, r=HKalbasi
Add `unused_variables` native diagnostic
2023-09-25 06:38:14 +00:00
Ryan Mehri
7306504b82 fix panic with wrapping/unwrapping result return type assists 2023-09-24 16:00:55 -07:00
DaniPopes
588c7d9182
minor: hover_simple refactor 2023-09-24 22:47:29 +02:00
hkalbasi
ab52ba2de7 Fix unused_variables in tests 2023-09-24 23:45:36 +03:30
hkalbasi
7834b8fadb Add unused_variables native diagnostic 2023-09-24 21:29:15 +03:30
bors
e5e937ae5e Auto merge of #15582 - vxpm:master, r=HKalbasi
add option to show full function signatures in completion docs

implements #15538

with `"rust-analyzer.completion.fullFunctionSignatures.enable": false`:
![image](https://github.com/rust-lang/rust-analyzer/assets/59714841/ff739ad1-9975-461f-a62d-22c7823e7b71)

with `"rust-analyzer.completion.fullFunctionSignatures.enable": true`:
![image](https://github.com/rust-lang/rust-analyzer/assets/59714841/9bc98300-cef6-44ef-a353-dcf35cd36fce)
2023-09-24 07:38:38 +00:00
vxpm
10fae62820 split detail function 2023-09-23 19:43:19 -03:00
vxpm
9f3d627681 add tests for full signatures 2023-09-23 19:39:42 -03:00
Ali Bektas
fc258de5a3 Make QualPathTy case readable 2023-09-22 21:23:03 +02:00
bors
2b580a1f3c Auto merge of #15492 - RalfJung:invocation, r=Veykril
extend check.overrideCommand and buildScripts.overrideCommand docs

Extend check.overrideCommand and buildScripts.overrideCommand docs regarding invocation strategy and location.

However something still seems a bit odd -- the docs for `invocationStrategy`/`invocationLocation` talk about "workspaces", but the setting that controls which workspaces are considered is called `linkedProjects`. Is a project the same as a workspace here or is there some subtle difference?
2023-09-22 16:09:01 +00:00
bors
8139e8e072 Auto merge of #15425 - alibektas:deunwrap/convert_comment_block, r=Veykril
minor : Deunwrap convert_comment_block and desugar_doc_comment

Closes subtask 13 of #15398 . I still don't know a more idiomatic way for the for loops I added, any suggestion would make me happy.
2023-09-22 15:47:55 +00:00
bors
59bcbafc95 Auto merge of #15594 - alibektas:deunwrap/add_missing_match_arms, r=Veykril
Deunwrap add_missing_match_arms

Last subtask of #15398
2023-09-22 15:31:30 +00:00
Ali Bektas
132a6ce8fc Omit QualPathTy when possible 2023-09-22 14:04:17 +02:00
Ali Bektas
622e1a8d88 Add a test case to add_missing_match_arms
Although it doesn't panic now, further changes to how we recover from incomplete syntax
may cause this assist to panic. To mitigate this a test case has been added.
2023-09-22 13:51:19 +02:00
Ali Bektas
0a91a54794 v4 2023-09-22 13:32:20 +02:00
bors
4a8622c8fa Auto merge of #15652 - Veykril:format_to, r=lnicola
minor: Various small fixes
2023-09-22 09:06:06 +00:00
Ali Bektas
695a1349fa Fix doctest 2023-09-22 10:46:21 +02:00
Ali Bektas
8ad536f2d1 Make path start with a QualifiedPathType 2023-09-22 10:46:21 +02:00
Lukas Wirth
556f0c6704 Various small fixes 2023-09-22 10:13:51 +02:00
bors
5855bd8579 Auto merge of #15587 - dfireBird:fix-15128, r=Veykril
Fix autoimport does nothing when importing trait that is as _ imports

Potentially fixes #15128

There are two cases of imports:
1. With simple path
2. With use tree list (or say complex path).

On deeper inspection, the [`recursive_merge`](994df3d6a3/crates/ide-db/src/imports/merge_imports.rs (L87)) function (called by [`try_merge_trees_mut`)](994df3d6a3/crates/ide-db/src/imports/merge_imports.rs (L69)) is meaningful only in the case of complex path (i.e when the UseTree contains a UseTreeList).

The [`recursive_merge`](994df3d6a3/crates/ide-db/src/imports/merge_imports.rs (L87)) function has [match with `Ok` arm](994df3d6a3/crates/ide-db/src/imports/merge_imports.rs (L106)), that is only executed when both LHS and RHS has `PathSegment` with same `NameRef`. The removal of underscore is implemented in this arm in the case of complex path.

For simple paths, the underscore is removed by checking if both LHS and RHS are simple paths and if their `Path` is same (the check is done [here](994df3d6a3/crates/ide-db/src/imports/merge_imports.rs (L74))) and remove the underscore if one is found (I made an assumption here that RHS will always be what rust-analyzer suggests to import, because at this point I'm not sure how to remove underscore with help of `ted::replace`).
2023-09-22 07:39:11 +00:00
bors
df75809a85 Auto merge of #15484 - rmehri01:14779_bool_to_enum_assist, r=Veykril
feat: Bool to enum assist

This adds the `bool_to_enum` assist, which converts the type of boolean local variables, fields, constants and statics to a new `enum` type, making it easier to distinguish the meaning of `true` and `false` by renaming the variants.

Closes #14779
2023-09-22 07:19:12 +00:00