Commit graph

1548 commits

Author SHA1 Message Date
bors
77e1969c15 Auto merge of #18052 - Coekjan:fix-inline-const, r=Veykril
fix: Fix `inline_const_as_literal` error when the number >= 10

## Description

### The Bug

This PR fixes a small bug in the IDE assistence (`inline_const_as_literal`). When the being-inlined constant is a number and it is greater than or equal to 10, the assistence inserts unexpected string `(0x...)` after the number itself. A simple example is followed:

Current `inline_const_as_literal` changes

```rs
const A: usize = 16;

fn f() -> usize {
    A  // inline the constant
}
```

into

```rs
const A: usize = 16;

fn f() -> usize {
    16 (0x10)
}
```

The bug originates from #14925 & #15306 . #14925 added some unittests, but it just tested the number-inlining behavior when the number is `0`.

50882fbfa2/crates/ide-assists/src/handlers/inline_const_as_literal.rs (L124-L138)

And #15306 modified the behavior of `Const::render_eval` and added the `(0x...)` part after the number (if the number >= `10`). Because of insufficient unittests in #14925, changes about `Const::render_eval` in #15306 introduced this bug with no CI failure.

### The Fix

I think `Const::render_eval` is intended for user-facing value displaying (e.g. hover) and not designed for `inline_const_as_literal`. To fix the bug, I defined a new function named `Const::eval`, which evaluates the value itself faithfully and simply and does nothing else.

## Thanks

Thanks `@roife` for your kind help. Your guidance helped me better understand the code.
2024-09-11 10:48:32 +00:00
roife
5caa56e18a fix: use pretty_print_pat for params in fn 2024-09-09 20:59:23 +08:00
Lukas Wirth
f74a0c8801 asm! parsing and lowering fixes 2024-09-05 15:08:16 +02:00
Lukas Wirth
c075a9980e Fix name fetching being incorrect for asm operands 2024-09-05 13:41:03 +02:00
Lukas Wirth
95d8d8e697 Support more IDE features for asm operands 2024-09-05 13:19:02 +02:00
Lukas Wirth
811905fce8 Give InlineAsmOperand a HIR representation 2024-09-05 12:40:48 +02:00
Lukas Wirth
3b11ff8c4d Lower asm expressions 2024-09-05 09:59:08 +02:00
coekjan
0b9d2725ae
fix: Fix inline_const_as_literal error when the number >= 10 2024-09-05 14:26:21 +08:00
Shoyu Vanilla
d186bdc617 feat: Implement cast typechecks 2024-09-03 04:11:36 +09:00
bors
d534cc63d3 Auto merge of #18016 - IvarWithoutBones:wrap-return-ty-local-result, r=Veykril
fix: use Result type aliases in "Wrap return type in Result" assist

This commit makes the "Wrap return type in Result" assist prefer type aliases of standard library type when the are in scope, use at least one generic parameter, and have the name `Result`.

The last restriction was made in an attempt to avoid false assumptions about which type the user is referring to, but that might be overly strict. We could also do something like this, in order of priority:
* Use the alias named "Result".
* Use any alias if only a single one is in scope, otherwise:
* Use the standard library type.

This is easy to add if others feel differently that is appropriate, just let me know.

Fixes #17796
2024-09-02 11:33:44 +00:00
cuishuang
680de15ec3 chore: fix some comments
Signed-off-by: cuishuang <imcusg@gmail.com>
2024-09-02 18:33:23 +08:00
Ivar Scholten
4e9d17b96d fix: use Result type aliases in "Wrap return type in Result" assist
This commit makes the "Wrap return type in Result" assist prefer type aliases of standard library
type when the are in scope, use at least one generic parameter, and have the name "Result".

The last restriction was made in an attempt to avoid false assumptions about which type the
user is referring to, but that might be overly strict. We could also do something like this, in
order of priority:

* Use the alias named "Result".
* Use any alias if only a single one is in scope, otherwise:
* Use the standard library type.

This is easy to add if others feel differently that is appropriate, just let me know.
2024-09-02 02:00:19 +02:00
bors
779d9eee2e Auto merge of #17967 - Veykril:mbe-tests, r=Veykril
internal: Lay basic ground work for standalone mbe tests

Most of our mbe hir-def tests don't actually do anything name res relevant, we can (and should) move those down the stack into `mbe/hir-expand`.
2024-09-01 11:44:58 +00:00
Lukas Wirth
4502a602a7 internal: Lay basic ground work for standalone mbe tests 2024-09-01 12:42:44 +02:00
Lukas Wirth
eb64cc8c35 Complete desugared and resugared async fn in trait impls 2024-09-01 11:22:50 +02:00
Yunfei
18feb726be feat(ide-completion): extra sugar auto-completion async fn ... in impl trait for async fn in trait that's defined in desugar form 2024-09-01 10:08:25 +02:00
bors
0ae42bd425 Auto merge of #17814 - ShoyuVanilla:object-safety, r=Veykril
feat: Implement object safety and its hovering hint

Resolves #17779

- [x] Fill missing implementations
- [x] Hover rendering
- [x] Implement object safety's own test suite, like layout
- [x] Add test cases (from rustc maybe)
- [x] Clean up ugly codes
- [x] Add doc string
2024-08-29 13:24:54 +00:00
Shoyu Vanilla
6520a43ca3 feat: Implement object safety 2024-08-29 22:22:21 +09:00
bors
07a66c475c Auto merge of #17940 - ChayimFriedman2:closure-to-fn, r=Veykril
feat: Create an assist to convert closure to freestanding fn

The assist converts all captures to parameters.

Closes #17920.

This was more work than I though, since it has to handle a bunch of edge cases...

Based on #17941. Needs to merge it first.
2024-08-29 07:21:46 +00:00
Chayim Refael Friedman
0e4f4d3f9c Create an assist to convert closure to freestanding fn
The assist converts all captures to parameters.
2024-08-27 17:07:55 +03:00
Lukas Wirth
fa48bc216c
Revert "feat: Implement module_path macro" 2024-08-27 08:19:09 +02:00
bors
0ad26e6025 Auto merge of #17941 - ChayimFriedman2:pre-closure-to-fn, r=Veykril
Preliminary work for #17940

I split the PR as requested, and made small commits.
2024-08-26 08:09:15 +00:00
Chayim Refael Friedman
e6d59e65ec Add helper methods to retrieve Future::Output and Iterator::Item 2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
da931e7398 Fix few bugs in closure capture computation, and add tests
Also create a test infrastructure for capture computation.
2024-08-24 22:35:49 +03:00
bors
33c1f57a1a Auto merge of #17936 - Veykril:module_path, r=Veykril
feat: Implement `module_path` macro

Turns out this is a pain to implement because of our hir-def hir-expand split :)
2024-08-23 09:32:27 +00:00
Chayim Refael Friedman
2fa0d4e2a8 When descending into macros in search, first check if there is a need to - i.e. if we are inside a macro call
This avoids the need to analyze the file when we are not inside a macro call.

This is especially important for the optimization in the next commit(s), as there the common case will be to descent into macros but then not analyze.
2024-08-22 20:52:51 +03:00
Lukas Wirth
c2a07e21f5 Thread file id through descension API for semantic highlighting 2024-08-22 16:45:37 +02:00
Lukas Wirth
354ab7a9e8 Rename macro descension functions 2024-08-22 16:24:01 +02:00
Lukas Wirth
64064907ce Fully remove old macro descension API 2024-08-22 16:18:01 +02:00
Lukas Wirth
495118015e Remove DescendPreference::SameKind 2024-08-22 16:00:57 +02:00
Lukas Wirth
ce8f32022b Drop MacroInputKind 2024-08-22 12:39:53 +02:00
Lukas Wirth
f979667fb5 Remove DescendPreference::SameText 2024-08-22 12:34:20 +02:00
Lukas Wirth
d44a3ab30c internal: Implement module_path macro 2024-08-21 13:50:05 +02:00
bors
c9ee892263 Auto merge of #17905 - ChayimFriedman2:edition-dependent-raw-keyword, r=Veykril
fix: Properly account for editions in names

This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now.

The rules of thumb are:

 - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code.
 - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn).
 - For debugging tools (helper methods and logs), I used `Edition::LATEST`.

Reviewing notes:

This is a really big PR but most of it is mechanical translation. I changed `Name` displayers to require an edition, and followed the compiler errors. Most methods just propagate the edition requirement. The interesting cases are mostly in `ide-assists`, as sometimes the correct crate to fetch the edition from requires awareness (there may be two). `ide-completions` and `ide-diagnostics` were solved pretty easily by introducing an edition field to their context. `ide` contains many features, for most of them it was propagated to the top level function and there the edition was fetched based on the file.

I also fixed all FIXMEs from #17896. Some required introducing an edition parameter (usually not for many methods after the changes to `Name`), some were changed to a new method `is_any_identifier()` because they really want any possible keyword.

Fixes #17895.
Fixes #17774.
2024-08-16 13:49:32 +00:00
Chayim Refael Friedman
9d3368f2c2 Properly account for editions in names
This PR touches a lot of parts. But the main changes are changing
`hir_expand::Name` to be raw edition-dependently and only when necessary
(unrelated to how the user originally wrote the identifier),
and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware
(this was done in #17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly
escape (or not escape) identifiers now.

The rules of thumb are:

 - If we show the identifier to the user, its rawness should be determined
   by the edition of the edited crate. This is nice for IDE features,
   but really important for changes we insert to the source code.
 - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update
   tests when an edition becomes stable, to avoid churn).
 - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
2024-08-16 16:46:24 +03:00
dfireBird
8a4261aca8
implement basic inferring of lifetimes 2024-08-16 16:40:32 +05:30
bors
fc36e0ca16 Auto merge of #17907 - ChayimFriedman2:no-once_cell, r=Veykril
internal: Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/Lock

This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-16 07:05:59 +00:00
Chayim Refael Friedman
955e609867 Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/Lock
This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-16 09:53:37 +03:00
bors
f3d9c9df90 Auto merge of #17876 - Veykril:semantics-include-simplify, r=Veykril
internal: Remove unreachable logic for include token mapping

Turns out https://github.com/rust-lang/rust-analyzer/pull/17863 made this obsolete 🎉
2024-08-13 07:48:55 +00:00
Lukas Wirth
bd4785a6f0 Remove unreachable logic for include token mapping 2024-08-13 09:44:13 +02:00
bors
518532426d Auto merge of #17863 - Veykril:include-diags, r=Veykril
fix: Resolve included files to their calling modules in IDE layer

Fixes https://github.com/rust-lang/rust-analyzer/issues/17390 at the expense of reporting duplicate diagnostics for modules that have includes in them when both the calling and called file are included.
2024-08-12 11:48:32 +00:00
Lukas Wirth
2362975137 Resolve included files to their calling modules in IDE layer 2024-08-12 13:45:33 +02:00
Lukas Wirth
ded3e21fdd fix: Correctly support #[rustc_deprecated_safe_2024] 2024-08-12 10:56:59 +02:00
Vincent Esche
7dec7e92ea Replace [package.repository] = "…" of published crates with [package.repository.workspace] = true 2024-08-06 00:26:42 +02:00
Vincent Esche
624f2ead7b Unify package descriptions by adding references to "rust-analyzer"
With the lack of a README on the individually published library crates and the somewhat cryptic `ra_ap_` prefix it is hard to figure out where those crates belong to, so mentioning "rust-analyzer" feels like auseful hint there.
2024-08-06 00:25:02 +02:00
Vincent Esche
ddb9686246 Fix spelling of "object-oriented" 2024-08-06 00:25:02 +02:00
Vincent Esche
6f329e6d5b Add repository URL for published crates' missing [package.repository] fields 2024-08-06 00:25:02 +02:00
Vincent Esche
b5b0f4bc5a Replace "TBD" with more helpful desciptions in published crates' [package.description] fields 2024-08-06 00:25:02 +02:00
Shoyu Vanilla
8a51419a2d feat: Implement diagnostic for await outside of async 2024-08-05 21:47:57 +09:00
Lukas Wirth
d46060b168 Fix error spans for include! and compile_error! 2024-07-29 15:57:01 +02:00
Lukas Wirth
ae9c553902 Make basic use of spans for macro expansion errors 2024-07-29 14:52:40 +02:00
Lukas Wirth
7beac14cba Internal: Cleanup proc-macro error handling 2024-07-26 14:38:19 +02:00
Lukas Wirth
f2fa456a8c Fix incorrect handling of cfg'd varargs 2024-07-25 11:02:19 +02:00
Lukas Wirth
9cbafa2d49 Remove Params and Fields from AstIdMap 2024-07-25 10:22:05 +02:00
Vincent Esche
acb50efb3a Add method Impl::all_in_module(…) for supporting more localized querying 2024-07-23 14:43:38 +02:00
Lukas Wirth
7c374a10bd internal: Shrink size of Binding 2024-07-22 17:14:17 +02:00
Lukas Wirth
5806950712 Remove incorrect never! invocations 2024-07-22 10:53:18 +02:00
Lukas Wirth
5264f86242 Encode edition within FileId in the hir layer 2024-07-18 08:49:10 +02:00
Lukas Wirth
2346a80ab4 Remove Name::to_smol_str 2024-07-16 12:43:58 +02:00
Lukas Wirth
df5f1777b8 More symbol usage 2024-07-16 12:05:16 +02:00
Lukas Wirth
93024ad411 Switch token trees to use Symbols 2024-07-16 10:11:59 +02:00
Lukas Wirth
e846c04fbe Encode ident rawness and literal kind separately in tt::Leaf 2024-07-15 12:24:40 +02:00
Lukas Wirth
f2d51073d2 Use statics + clone instead of const until const can access statics 2024-07-14 17:52:59 +02:00
Lukas Wirth
3fe815b0f3 Use Symbol in Name 2024-07-12 16:06:44 +02:00
beetrees
d5db933f9d
Add f16 and f128 support 2024-07-10 10:43:14 +01:00
Lukas Wirth
966798b7ba Make GenericParams::lifetimes private 2024-07-02 13:45:53 +02:00
Lukas Wirth
be1ea4028b Make GenericParams::where_predicates private 2024-07-02 13:45:50 +02:00
Lukas Wirth
372e2d22e6 Make GenericParams::type_or_consts private 2024-07-02 13:45:48 +02:00
Lukas Wirth
1a929d6485 Fix lifetime parameters moving paramter defaults 2024-07-02 12:34:32 +02:00
bors
ea7fdada6a Auto merge of #17520 - Veykril:slim-proc-macro-api, r=Veykril
internal: Cleanup proc-macro-srv some more
2024-06-30 15:12:50 +00:00
Lukas Wirth
21a3d01875 Remove inline rust_2018_idioms, unused_lifetimes lint warn, Cargo.toml already enforces this 2024-06-30 15:23:54 +02:00
bors
56ef2404b3 Auto merge of #17516 - kilpkonn:master, r=kilpkonn
Quality of life improvements to term search

Basically two things:
- Allow optionally disabling "borrow checking" restrictions on term search code assists. Sometimes it is better to get invalid suggestions and fix borrow checking issues later...
- Remove explicit generics in generated expressions. I find it quite rare that one writes `None::<T>` instead of `None`.
2024-06-30 12:41:22 +00:00
Tavo Annus
c19458270d Do not explicit generics to generated expressions 2024-06-30 15:19:19 +03:00
Lukas Wirth
5374ebbf36 Simplify 2024-06-30 14:00:55 +02:00
Lukas Wirth
bfb187aacd Fix expression scope calculation when within macro expansions 2024-06-30 13:26:17 +02:00
Lukas Wirth
8df034d453 Shrink mbe's Op 2024-06-24 10:07:32 +02:00
Lukas Wirth
3168ab5b99 Enum variants are not generic def ids 2024-06-24 10:07:31 +02:00
bors
db69df3216 Auto merge of #17478 - kilpkonn:master, r=Veykril
Simplify some term search tactics

Working on the paper `@phijor` found that "Data constructor" tactic could be simplified quite a bit by running it only in the backwards direction. With n+1 rounds it has same coverage as previous implementation in n rounds, however the tactic it self is more simple and also potentially faster as there is less to do.

In a nutshell the idea is to only work with types in the wish-list rather than with any types.

Turns out it is quite a bit faster:

Before:
```
ripgrep:
Tail Expr syntactic hits: 238/1692 (14%)
Tail Exprs found: 1223/1692 (72%)
Term search avg time: 15ms

nalgebra:
Tail Expr syntactic hits: 125/3001 (4%)
Tail Exprs found: 2143/3001 (71%)
Term search avg time: 849ms
```

After
````
ripgrep:
Tail Expr syntactic hits: 246/1692 (14%)
Tail Exprs found: 1209/1692 (71%)
Term search avg time: 8ms

nalgebra:
Tail Expr syntactic hits: 125/3001 (4%)
Tail Exprs found: 2028/3001 (67%)
Term search avg time: 305ms
````

_Also removed niche optimization of removing scope defs from the search space as this wasn't helping much anyway and made code a bit more complex._
2024-06-24 07:20:50 +00:00
Tavo Annus
51c3bd215a Fix suggestions of unstable constants 2024-06-22 21:33:58 +03:00
Tavo Annus
3825d8bd0f Increase search depth to account for more granual steps 2024-06-22 15:06:07 +03:00
Tavo Annus
b4f3eb48db Simplify impl_method tactic 2024-06-22 14:22:56 +03:00
Tavo Annus
23d3ac70e9 Simplify impl_static_method tactic 2024-06-22 14:14:42 +03:00
Tavo Annus
a3315fe028 Remove remove not-very-helpful optimizations 2024-06-22 10:17:33 +03:00
Tavo Annus
957325a5fe Run data_constructor tactic only backwards 2024-06-21 22:01:06 +03:00
roife
d5bb2f0cba fix: use ItemInNs::Macros to convert ModuleItem to ItemInNs 2024-06-21 21:05:14 +08:00
bors
e08f7953f4 Auto merge of #17462 - Veykril:sema-attr-macro-res, r=Veykril
fix: Fix IDE features breaking in some attr macros

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

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

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

Fixes #14177
2024-06-20 08:39:17 +00:00
Lukas Wirth
bf9a7264d1 Invert matching on builtin macros in expand_allowed_builtins 2024-06-20 10:31:20 +02:00
Ishan Jain
19d9bb808d
removed format_args from allowed expansions 2024-06-19 16:58:48 +05:30
Tavo Annus
c87609fef1 Add tactic for associated item constants 2024-06-18 22:08:44 +03:00
Ishan Jain
020537cd06
Created expand_allowed_builtins, updated expand_macro to call this function 2024-06-15 15:20:46 +05:30
Ishan Jain
2df806a3a5
allow format_args! expansion 2024-06-14 10:13:41 +05:30
Ishan Jain
0adb0e114f
fixed tests 2024-06-14 09:52:46 +05:30
Wilfred Hughes
d68e549205 internal: Fix rustdoc warnings
`cargo doc` generates a bunch of warnings on rust-analyzer. Fix all the
bare URL and empty code block warnings.
2024-06-13 17:29:10 -07:00
Ishan Jain
5d5f68af3f
hir/semantics: Only allow expansion of specific built in macros 2024-06-13 10:45:11 +05:30
bors
22648b2655 Auto merge of #17405 - Veykril:modpath-clone, r=Veykril
internal: Don't unnecessarily clone ModPaths in early name res
2024-06-12 09:27:49 +00:00
Lukas Wirth
855282fa53 internal: Don't unnecessarily clone ModPaths in early name res 2024-06-12 11:25:19 +02:00
roife
224d0dd36e refactor: move the logic that displays container type bounds to function fmt 2024-06-11 21:02:13 +08:00
roife
ab7c7d4501 fix: skip container header if no generics params 2024-06-11 21:02:13 +08:00