Commit Graph

18615 Commits

Author SHA1 Message Date
bors
4e82988aa2 Auto merge of #118344 - saethlin:rmeta-header-pos, r=WaffleLapkin
Use a u64 for the rmeta root position

Waffle noticed this in https://github.com/rust-lang/rust/pull/117301#discussion_r1405410174

We've upgraded the other file offsets to u64, and this one only costs 4 bytes per file. Also the way the truncation was being done before was extremely easy to miss, I sure missed it! It's not clear to me if not having this change effectively made the other upgrades from u32 to u64 ineffective, but we can have it now.

r? `@WaffleLapkin`
2023-12-11 17:21:14 +00:00
Guillaume Gomez
6adb21a408 Update rust-analyzer to support new injected_env_var function 2023-12-11 16:44:33 +01:00
Kirill Bulatov
8ae42b55e7 Search for parent blocks and items when resolving inlay hints 2023-12-11 15:16:55 +02:00
Kirill Bulatov
be6d34b810 Query for nearest parent block around the hint to resolve
This way, parameter hints will be found for resolution
2023-12-11 14:53:51 +02:00
Laurențiu Nicola
71d98c53bd Fix typo in cfg 2023-12-11 11:55:43 +02:00
Laurențiu Nicola
f532576ac5 Merge commit '457b966b171b09a7e57acb710fbca29a4b3526f0' into sync-from-ra 2023-12-11 11:16:01 +02:00
Ben Kimock
f9453e33c0 Apply suggestions from code review
Co-authored-by: Waffle Maybe <waffle.lapkin@gmail.com>
2023-12-10 23:26:40 -05:00
bors
457b966b17 Auto merge of #16039 - WaffleLapkin:don't-emit-missing-assoc-items-diagnostic-for-negative-impls, r=Veykril
fix: Don't emit "missing items" diagnostic for negative impls

Negative impls can't have items, so there is no reason for this diagnostic.

LMK if I should add a test somewhere. Also LMK if that's not how we usually check multiple things in an if in r-a.
2023-12-10 22:24:32 +00:00
Maybe Waffle
1630477985 fix: Don't emit "missing items" diagnostic for negative impls 2023-12-10 22:21:59 +00:00
bors
4e814e3f24 Auto merge of #16078 - Veykril:fix-view-ir, r=Veykril
fix: Fix view mir, hir and eval function not working when cursor is inside macros

I broke the view ones completely by inverting the macro check by accident a few days ago but we don't talk about that.
2023-12-10 13:46:58 +00:00
Lukas Wirth
306c907425 fix: Fix view mir, hir and eval function not working when cursor is inside macros 2023-12-10 14:44:40 +01:00
surechen
5285df4f6c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
hkalbasi
9337519df5 Replace doc_comments_and_attrs with collect_attrs 2023-12-09 23:32:51 +03:30
Lukas Wirth
5f957658c1 fix: Fix fragment parser replacing matches with dummies on incomplete parses 2023-12-08 20:39:16 +01:00
Lukas Wirth
cf083fefc4 fix: Fix completion failing in format_args! with invalid template 2023-12-08 20:35:33 +01:00
Lukas Wirth
b1a8f83a0c fix: Smaller spans for unresolved field and method diagnostics 2023-12-08 18:46:36 +01:00
Lukas Wirth
35fbc0210c Fallback to method resolution on unresolved field access with matching method name 2023-12-08 16:36:41 +01:00
bors
9c3de09f6d Auto merge of #16054 - Veykril:fix-downmapping, r=Veykril
fix: Fix token downmapping being quadratic

Fixes https://github.com/rust-lang/rust-analyzer/issues/16050
2023-12-08 14:28:18 +00:00
Lukas Wirth
5d951a6a46 fix: Fix token downmapping being quadratic 2023-12-08 15:26:38 +01:00
bors
b03a0bda18 Auto merge of #15627 - jmintb:sort_imports, r=Veykril
feat: Prioritize import suggestions based on the expected type

Hi, this is a draft PR to solve #15384. `Adt` types work and now I have a few questions :)

1. What other types make sense in this context? Looking at [ModuleDef](05666441ba/crates/hir/src/lib.rs (L275)) I am thinking everything except Modules.
2. Is there an existing way of converting between `ModeuleDef` and `hir::Type` in the rustanalyzer code base?
3. Does this approach seem sound to you?

Ups: Upon writing this I just realised that the enum test is invalided as there are no enum variants and this no variant is passed as a function argument.
2023-12-08 12:39:23 +00:00
Lukas Wirth
1475848250 Cleanup 2023-12-08 13:31:31 +01:00
bors
86cccc76e3 Auto merge of #16048 - Veykril:concat-bytes-fix, r=Veykril
fix: Fix concat_bytes! expansion emitting an identifier

Fixes https://github.com/rust-lang/rust-analyzer/issues/16046 (note that this has always been broken)
2023-12-08 12:27:58 +00:00
Jessie Chatham Spencer
6abba17a5b Implement function type matching 2023-12-08 12:37:26 +01:00
Jessie Chatham Spencer
14a7a614c1 WIP - Sort suggested imports by type for data types 2023-12-08 12:37:26 +01:00
bors
6bbb2ac304 Auto merge of #15705 - rmehri01:14485_fix_delegate_self_references, r=Veykril
fix: resolve Self type references in delegate method assist

This PR makes the delegate method assist resolve any `Self` type references in the parameters or return type. It also works across macros such as the `uint_impl!` macro used for `saturating_mul` in the issue example.

Closes #14485
2023-12-08 11:31:34 +00:00
Ryan Mehri
7e768cbe70 fix: prefer keeping Self if it is in the same impl def 2023-12-08 12:30:14 +01:00
Ryan Mehri
f4349ff26e fix: preserve where clause in delegate method 2023-12-08 12:29:34 +01:00
Ryan Mehri
934358e95c fix: resolve Self type references in delegate method assist 2023-12-08 12:29:34 +01:00
bors
4f3d862fcf Auto merge of #15486 - petr-tik:n15134_hide_private_from_autocomplete_2, r=Veykril
fix: Fix item tree lowering pub(self) to pub()

Prior to this, the item tree lowered `pub(self)` visibility to `pub()`
Fix #15134 - tested with a unit test and
a manual end-to-end test of building rust-analyzer from my branch and opening the reproduction repository
2023-12-08 11:02:08 +00:00
Lukas Wirth
d54745aed3 fix: Fix item tree lowering pub(self) to pub() 2023-12-08 11:59:44 +01:00
petr-tik
2d879e0431 Stop offering private functions in completions
Before
Private functions have RawVisibility module, but were
missed because take_types returned None early. After resolve_visibility
returned None, Visibility::Public was set instead and private functions
ended up being offered in autocompletion.

Choosing such a function results in an immediate error diagnostic
about using a private function.

After
Pattern match of take_types that returns None and
query for Module-level visibility from the original_module

Fix #15134 - tested with a unit test and a manual end-to-end
test of building rust-analyzer from my branch and opening
the reproduction repository

REVIEW
Refactor to move scope_def_applicable and check function visibility
from a module

Please let me know what's the best way to add a unit tests to
nameres, which is where the root cause was
2023-12-08 11:38:54 +01:00
Matheus Cardoso
3d9221291f flip binexpr works for lhs cmp 2023-12-08 11:36:30 +01:00
Matheus Cardoso
e18b89452e Flip binexpr works for lhs binexpr 2023-12-08 11:36:30 +01:00
Lukas Wirth
71337f6682 fix: Fix concat_bytes! expansion 2023-12-08 11:34:03 +01:00
Lukas Wirth
143203b713 Make TraitEnvironment's constructor private 2023-12-08 10:47:36 +01:00
bors
bc9c952b6d Auto merge of #16028 - Young-Flash:fix-issue-16012, r=HKalbasi
fix: make drop inlay hint more readable

![drop_inlay_hint](https://github.com/rust-lang/rust-analyzer/assets/71162630/bb18707f-3278-435d-a938-ccff4c685586)

follow up https://github.com/rust-lang/rust-analyzer/pull/16000, close https://github.com/rust-lang/rust-analyzer/issues/16012
2023-12-07 21:45:24 +00:00
bors
4196675f44 Auto merge of #16045 - HKalbasi:rustc-tests-fixup, r=HKalbasi
Fix panic with closure inside array len

I was working on #15947 and found out that we panic on this test:
```
fn main() {
    let x = [(); &(&'static: loop { |x| {}; }) as *const _ as usize]
}
```
This PR fixes the panic. Closures in array len are still broken, but closure in const eval is not stable anyway.
2023-12-07 21:26:18 +00:00
hkalbasi
c11a002bca Fix panic with closure inside array len 2023-12-08 00:44:45 +03:30
bors
49dd3804c0 Auto merge of #16009 - werifu:fix-extract-function, r=Veykril
fix: bug in extract_function.rs

There is a little bug in extract_function: It appends `use path::to::ControlFlow;` if the function created contains string "ControlFlow".

 A case below (also in the test named `does_not_import_control_flow` which will fail in the original code)

<img width="322" alt="image" src="https://github.com/rust-lang/rust-analyzer/assets/53432474/4b80bb58-0cfd-4d56-b64c-d9649eed336e">
<img width="391" alt="image" src="https://github.com/rust-lang/rust-analyzer/assets/53432474/3d7262f4-8a4c-44ea-822d-304b8b23fe28">

Now I have changed the condition determining whether adding import statement. Only when the new function body contains ControlFlow::Break or ControlFlow::Continue can the import statement be added.

Last related PR: https://github.com/rust-lang/rust-analyzer/pull/10309
2023-12-07 17:28:41 +00:00
bors
421a0a4ff4 Auto merge of #15990 - Young-Flash:trait_impl_reduntant_assoc_item, r=Veykril
feat: add trait_impl_reduntant_assoc_item diagnostic

part of https://github.com/rust-lang/rust-analyzer/issues/15958, will try to add quickfix for the diagnostic if this PR is ok with you guys
2023-12-07 13:24:57 +00:00
Young-Flash
fbe494a106 fix: change default diagnostic range into impl body 2023-12-07 20:45:42 +08:00
Lukas Wirth
5544f4fa3d Bump and unlock some dependencies 2023-12-07 11:48:58 +01:00
Lukas Wirth
45d81048c9 internal: Bump salsa 2023-12-07 10:57:51 +01:00
David Barsky
c17dcc8d90 internal: switch to Arc::from_iter 2023-12-06 13:08:45 -05:00
bors
7e8a3391bb Auto merge of #16037 - Veykril:proc-macro-backtrace, r=Veykril
fix: Don't print proc-macro panic backtraces in the logs

Fixes https://github.com/rust-lang/rust-analyzer/issues/9859
2023-12-06 17:02:17 +00:00
Lukas Wirth
80dc20f7d8 fix: Don't print proc-macro panic backtraces in the logs 2023-12-06 17:49:48 +01:00
Young-Flash
861e47431b update: make each trait_impl_reduntant_assoc_item into individual diagnostic 2023-12-06 22:17:55 +08:00
Young-Flash
5d84edd430 feat: add trait_impl_reduntant_assoc_item diagnostic 2023-12-06 22:17:55 +08:00
Johannes Hostert
374affea3c
make ParamLoweringMode accessible 2023-12-06 15:12:55 +01:00
bors
77e362c34d Auto merge of #16035 - Veykril:macro-diagnostics, r=Veykril
fix: Fix diagnostics panicking when resolving to different files due to macros

Fixes https://github.com/rust-lang/rust-analyzer/issues/14968
2023-12-06 13:50:36 +00:00
Lukas Wirth
ba01ff4f88 Fix diagnostics panicking when resolving to different files due to macros 2023-12-06 14:39:26 +01:00
Lukas Wirth
634d588fd7 Simplify 2023-12-06 14:36:39 +01:00
bors
cc8faa697c Auto merge of #16034 - Veykril:ide-macro-improvements, r=Veykril
feat: Allow navigation targets to be duplicated when the focus range lies in the macro definition site

![Code_KI1EfbAHRZ](https://github.com/rust-lang/rust-analyzer/assets/3757771/2cc82e5c-320f-4de2-9d55-fe975d180f2a)

Basically if a name of an item originates from the macro definition we now point to that as well as the creating macro call.

Big diff because I also made `FileId`s field private due to some debugging I had to do (having a searchable constructor makes things easier).
2023-12-06 11:47:46 +00:00
Lukas Wirth
9cb13b6efb Allow navigation targets to be duplicated when the focus range lies in the macro definition site 2023-12-06 12:38:19 +01:00
Michael Goulet
76c972cb54 Rollup merge of #118123 - RalfJung:internal-lib-features, r=compiler-errors
Add support for making lib features internal

We have the notion of an "internal" lang feature: a feature that is never intended to be stabilized, and using which can cause ICEs and other issues without that being considered a bug.

This extends that idea to lib features as well. It is an alternative to https://github.com/rust-lang/rust/pull/115623: instead of using an attribute to declare lib features internal, we simply do this based on the name. Everything ending in `_internals` or `_internal` is considered internal.

Then we rename `core_intrinsics` to `core_intrinsics_internal`, which fixes https://github.com/rust-lang/rust/issues/115597.
2023-12-05 14:52:41 -05:00
bors
05df6c52ca Auto merge of #16027 - Veykril:implicit-format-args, r=Veykril
feat: Implicit format args support

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

![image](https://github.com/rust-lang/rust-analyzer/assets/3757771/14fe2caf-4ea3-40a5-8aa4-ff08ea0ccbde)
Too lazy to make a gif of this right now (would probably be good to show renaming)
2023-12-05 16:15:45 +00:00
Lukas Wirth
9b7ec5e31b Ignore strings in token trees in syntax highlighting 2023-12-05 17:07:00 +01:00
Lukas Wirth
4525787ed5 Add test for implicit format args support through nested macro call 2023-12-05 17:07:00 +01:00
Lukas Wirth
fe0a85ca29 Resolve implicit format args in syntax highlighting 2023-12-05 17:07:00 +01:00
Lukas Wirth
d2cd30007c Implicit format args support 2023-12-05 17:07:00 +01:00
Lukas Wirth
5b8e386bae Improve macro descension API 2023-12-05 17:06:57 +01:00
Young-Flash
afc4075c7c fix: make drop inlay hint more readable 2023-12-05 22:56:51 +08:00
bors
afc1ae1aa3 Auto merge of #16016 - dfireBird:regression-fix-15879, r=lnicola
fix: Insert fn call parens only if the parens inserted around field name

Fixes #16014.

Sorry I missed it in previous PR. I've added a test as level to prevent regressions again.
Give any suggestions to improve the test if anything.
2023-12-05 14:53:29 +00:00
bors
986577faaa Auto merge of #16026 - lnicola:bump-rustc-deps, r=lnicola
minor: Bump rustc deps
2023-12-05 11:42:14 +00:00
Laurențiu Nicola
73b9f885f6 Bump ra-ap-rustc_index and ra-ap-rustc_abi 2023-12-05 13:40:29 +02:00
Laurențiu Nicola
22676ce946 Revert "Temporarily revert delay_bug to delayed_bug change"
This reverts commit 6d2543b622.
2023-12-05 13:39:45 +02:00
Laurențiu Nicola
a9b037f510 Bump ra-ap-rustc_parse_format 2023-12-05 13:39:17 +02:00
Laurențiu Nicola
1834b38dbe Bump ra-ap-rustc_lexer 2023-12-05 13:38:35 +02:00
Igor Matuszewski
a7224c998d Don't explicitly warn against semicolon_in_expressions_from_macros
This has been warn-by-default for two years now and has already been
added to the future-incompat lints in 1.68.
2023-12-05 11:35:09 +01:00
bors
e91fdf7860 Auto merge of #15959 - Veykril:macro-shower3, r=lnicola
TokenMap -> SpanMap rewrite

Opening early so I can have an overview over the full diff more easily, still very unfinished and lots of work to be done.

The gist of what this PR does is move away from assigning IDs to tokens in arguments and expansions and instead gives the subtrees the text ranges they are sourced from (made relative to some item for incrementality). This means we now only have a single map per expension, opposed to map for expansion and arguments.

A few of the things that are not done yet (in arbitrary order):
- [x] generally clean up the current mess
- [x] proc-macros, have been completely ignored so far
- [x] syntax fixups, has been commented out for the time being needs to be rewritten on top of some marker SyntaxContextId
- [x] macro invocation syntax contexts are not properly passed around yet, so $crate hygiene does not work in all cases (but most)
  - [x] builtin macros do not set spans properly, $crate basically does not work with them rn (which we use)
~~- [ ] remove all uses of dummy spans (or if that does not work, change the dummy entries for dummy spans so that tests will not silently pass due to havin a file id for the dummy file)~~
  - [x] de-queryfy `macro_expand`, the sole caller of it is `parse_macro_expansion`, and both of these are lru-cached with the same limit so having it be a query is pointless
- [x] docs and more docs
- [x] fix eager macro spans and other stuff
  - [x] simplify include! handling
- [x] Figure out how to undo the sudden `()` expression wrapping in expansions / alternatively prioritize getting invisible delimiters working again
- [x] Simplify InFile stuff and HirFIleId extensions
~~- [ ] span crate containing all the file ids, span stuff, ast ids. Then remove the dependency injection generics from tt and mbe~~

Fixes https://github.com/rust-lang/rust-analyzer/issues/10300
Fixes https://github.com/rust-lang/rust-analyzer/issues/15685
2023-12-04 19:59:53 +00:00
Laurențiu Nicola
6d2543b622 Temporarily revert delay_bug to delayed_bug change 2023-12-04 21:41:19 +02:00
Laurențiu Nicola
26c0963281 Merge branch 'master' into sync-from-rust 2023-12-04 21:39:22 +02:00
dfireBird
20c6f27024
Insert fn call parens only if the parens inserted around field name 2023-12-04 22:37:34 +05:30
werifu
05e8b926e6 fix: bug in extract_function: should not import ControlFlow in some cases 2023-12-04 16:23:18 +08:00
Laurențiu Nicola
30fc9329d1 Merge commit 'e402c494b7c7d94a37c6d789a216187aaf9ccd3e' into sync-from-ra 2023-12-04 09:19:15 +02:00
Lukas Wirth
18f1a3c3c6 Some final touches 2023-12-03 20:20:59 +01:00
Lukas Wirth
81410ab500 Cleanup FileId stuff 2023-12-02 19:32:53 +01:00
Lukas Wirth
02a3a9438a Some more minor cleanups 2023-12-02 17:04:13 +01:00
Lukas Wirth
5edf7bddc6 Fix mod item in included file resolving incorrectly 2023-12-02 13:49:09 +01:00
Lukas Wirth
d2a31acda1 Fix macro expansion expression parenthesis wrapping 2023-12-02 13:03:46 +01:00
Nicholas Nethercote
40da288eb0 Rename LayoutCalculator::delay_bug as LayoutCalculator::delayed_bug.
To match with the previous commits.
2023-12-02 09:01:34 +11:00
Nicholas Nethercote
4375419b24 Rename HandlerInner::delay_span_bug as HandlerInner::span_delayed_bug.
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug`
follows the pattern used everywhere else: `span_err`, `span_warning`,
etc.
2023-12-02 09:01:19 +11:00
bors
e402c494b7 Auto merge of #15879 - dfireBird:fix-14656, r=Veykril
Implement completion for the callable fields.

Fixes #14656

PR is opened with basic changes. It could be improved by having a new `SymbolKind` for the callable fields and implementing a separate render function similar to the `render_method` for the new `SymbolKind`.
It could also be done without any changes to the `SymbolKind` of course, have the new function called based on the type of field.
I prefer the former method.

Please give any thoughts or changes you think is appropriate for this method. I could start working on that in this same PR.
2023-12-01 16:20:36 +00:00
Lukas Wirth
efa67294ed Fix eager macro input spans being discarded 2023-12-01 16:29:58 +01:00
Lukas Wirth
c11737cd63 Simplify include handling 2023-12-01 14:58:57 +01:00
bors
6e6a0b0a3d Auto merge of #16000 - HKalbasi:drop-inlay-hint, r=HKalbasi
Initial support for implicit drop inlay hint

cc #15785
2023-12-01 13:36:08 +00:00
dfireBird
b7effe54ee
fix close parens position to move after field access 2023-12-01 18:55:26 +05:30
Lukas Wirth
0003e568ca Pass calling span through to builtin macro expansions 2023-12-01 14:11:57 +01:00
hkalbasi
4d55cac466 Initial support for implicit drop inlay hint 2023-12-01 16:16:46 +03:30
bors
c2f133489c Auto merge of #15912 - Sarrus1:master, r=HKalbasi
chore: remove unused `PhantomData`

This PR removes an unused `PhantomData` in `FileItemTreeId`.

*Note:* I am not sure how this should be implemented, maybe as a type instead of a wrapper struct? I'd be happy to do so if needed 👍
2023-12-01 11:07:35 +00:00
Yutaro Ohno
e076192dd8 Improve error handling for top-level let statements
This commit addresses the issue of excessive and unrelated errors
generated by top-level `let` statements. Now, only a single error is
produced, indicating that `let` statements are invalid at the top level.
2023-12-01 10:37:21 +09:00
bors
1c51e25a5a Auto merge of #15994 - ChayimFriedman2:err-comma-after-fus, r=Veykril
fix: Err for comma after functional update syntax

Error message copied from rustc, https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=20aeedb2db504c4e4ced54b665e761d6.

Fixes #15989.
2023-11-30 15:59:31 +00:00
bors
56abc0a29c Auto merge of #15971 - Young-Flash:fix_match_arm, r=lnicola
fix: don't make `MissingMatchArms` diagnostic for empty match body

before
<img width="423" alt="before" src="https://github.com/rust-lang/rust-analyzer/assets/71162630/5c0e46fb-0c03-42f2-96ff-8e5245c25965">

after
<img width="423" alt="after" src="https://github.com/rust-lang/rust-analyzer/assets/71162630/e2479dc5-3634-479b-af29-0b0ec7dc4a4f">

close https://github.com/rust-lang/rust-analyzer/issues/15954
2023-11-30 12:10:45 +00:00
Chayim Refael Friedman
2fd19ed598 Err for comma after functional update syntax 2023-11-30 14:04:36 +02:00
Young-Flash
b46f37854e update: filter out syntax error in test 2023-11-30 19:35:25 +08:00
Lukas Wirth
f48fa0c6cb Re-implement syntax fixups 2023-11-29 16:00:39 +01:00
Ben Kimock
5ef5e55749 Use a u64 for the rmeta root position 2023-11-28 18:03:50 -05:00
dfireBird
21c09eb544
update dot tests function with check_edit 2023-11-28 22:21:57 +05:30
dfireBird
5c0c8ceaf7
refactor complete_fn_fields function and correct branch checks 2023-11-28 22:21:57 +05:30
dfireBird
8296b16f38
fix the insertion of the surronding parens
Before it was inserting whenever function field is found but it should
happend only in the case of function call.
2023-11-28 22:21:57 +05:30