Commit graph

875 commits

Author SHA1 Message Date
cui fliter
056b6b9416 remove the repetitive word
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-09-02 14:18:10 +08:00
Lukas Wirth
c09f175d59 Less once_cell more std 2023-09-01 17:30:59 +02:00
xffxff
204bc2cb60 fix: diagnostics for 'while let' loop with label in condition 2023-08-26 10:41:19 +08:00
hkalbasi
fa76f60cc1 Run cargo fmt on 1.72 2023-08-25 22:24:41 +03:30
Laurențiu Nicola
30d8aa1bec Merge commit '9b3d03408c66749d56466bb09baf2a7177deb6ce' into sync-from-ra 2023-08-21 12:44:09 +03:00
Jessie Chatham Spencer
37e0e8af10 Implement extern crate completion 2023-08-20 16:36:59 +00:00
Lukas Wirth
eb6244c5f9 Record import aliases in symbol index 2023-08-18 11:46:35 +02:00
Lukas Wirth
637f496a81 fix: Fix auto-import (and completions) importing #[doc(hidden)] items 2023-08-17 12:30:19 +02:00
bors
49716e681a Auto merge of #15472 - Veykril:import-ide-support, r=Veykril
internal: Record import origins in ItemScope and PerNS

This records the import items definitions come from in the module scope (as well as what an import resolves to in an ItemScope). It does ignore glob imports as thats a lot more work for little to no gain, glob imports act as if the importing items are "inlined" into the scope which suffices for almost all use cases I believe (to my knowledge, attributes on them have little effect).

There is still a lot of work needed to make this available to the IDE layer, but this lays out the ground work for havin IDE layer support.

cc https://github.com/rust-lang/rust-analyzer/issues/14079
2023-08-17 09:56:42 +00:00
Lukas Wirth
a17d73ad36 Thread imports through the resolver 2023-08-17 10:52:13 +02:00
Lukas Wirth
c4e9b5ac64 Add import info to item scope dumps 2023-08-17 09:33:15 +02:00
Lukas Wirth
af8048266c Prepare ItemScope for IDE import resolution 2023-08-16 11:33:42 +02:00
bors
b771de3fdc Auto merge of #15179 - ponyii:fix/default-values-of-const-params-are-ignored, r=HKalbasi
the "add missing members" assists: implemented substitution of default values of const params

To achieve this, I've made `hir::ConstParamData` store the default values
2023-08-15 10:17:43 +00:00
bors
2fbe69d117 Auto merge of #15438 - Veykril:eager-parser-stuck, r=Veykril
fix: Fix parser being stuck in eager macro inputs

Fixes https://github.com/rust-lang/rust-analyzer/issues/15437
2023-08-12 14:30:38 +00:00
Lukas Wirth
9ac88d8d36 Fix parser being stuck in eager macro inputs 2023-08-12 08:27:27 +02:00
Lukas Wirth
9adff006e8 Simplify 2023-08-10 20:10:19 +02:00
Lukas Wirth
bfad781a77 Memoize block_item_tree_query 2023-08-10 19:24:39 +02:00
Lukas Wirth
fde2d9b47c Deduplicate FileId field in ModuleOrigin 2023-08-10 19:04:46 +02:00
Lukas Wirth
e5b23e3bc1 Derive block attributes from block item tree 2023-08-10 18:52:27 +02:00
bors
05b0612051 Auto merge of #15428 - Veykril:lsp-types-pin, r=Veykril
Fix pinned version of lsp-types

lsp-types published a new patch version that breaks semver with the proposed feature set (this is intended and documented), we unfortunately forgot to specify the patch version for the pinned version so this breaks us.
2023-08-09 18:07:44 +00:00
Lukas Wirth
7e04142f25 Fix pinned version of lsp-types 2023-08-09 20:06:08 +02:00
Lukas Wirth
63aba76735 Remove unnecessary ItemTreeId field in ImportSource 2023-08-09 17:06:52 +02:00
Lukas Wirth
c516dd51e9 Simplify 2023-08-09 15:54:10 +02:00
Lukas Wirth
992b928a93 Record import source IDs 2023-08-09 15:20:42 +02:00
ponyii
68e8379ec3 fixed a merge-caused error 2023-08-08 22:16:28 +04:00
ponyii
4ebdc6f052 syntax update: the default value of ConstParam turned from Expr into ConstArg 2023-08-08 21:57:54 +04:00
ponyii
52b4392724 the "add missing members" assists: implemented substitution of default values of const params 2023-08-08 21:57:54 +04:00
bors
af4ba46b40 Auto merge of #15405 - lowr:patch/doc-links-to-fields, r=Veykril
Support doc links that resolve to fields

Fixes #15331

Also removes `Resolver::resolve_module_path_in_trait_assoc_items()` and reimplements it in hir with other `Resolver` methods to decouple things a bit.
2023-08-08 14:13:27 +00:00
bors
f98d654ddf Auto merge of #15350 - max-heller:issue-11756, r=Veykril
Handle `#[cfg]`s on generic parameters

Records attributes on generic parameters in the item tree and filters out generic parameters disabled by `#[cfg]`s in `generic_params_query`.

Closes #11756
2023-08-08 13:05:26 +00:00
Lukas Wirth
cba39f8553 fix: Fix float parser hack creating empty NameRef tokens 2023-08-08 14:44:33 +02:00
Laurențiu Nicola
aa55ce9567 Merge commit 'baee6b338b0ea076cd7a9f18d47f175dd2ba0e5d' into sync-from-ra 2023-08-07 12:03:15 +03:00
Ryo Yoshida
0c433c23b1
Support doc links that resolve to fields 2023-08-07 00:59:35 +09:00
Lukas Wirth
042be329a7 Turn unresolved proc macro expansions into missing expressions 2023-08-05 20:00:37 +02:00
Max Heller
50db877bfa optimization and #[cfg] filtering for function generic params 2023-08-05 08:00:39 -04:00
hkalbasi
cc5664c5a2 Add rustc comment into while desugaring 2023-08-04 16:35:13 +03:30
bors
e37ec7262c Auto merge of #15373 - tadeokondrak:desugar-while-to-loop, r=HKalbasi
internal: Desugar while to loop and break

I was reading through rust-analyzer's code and was wondering why this wasn't desugared into a loop.
2023-08-04 07:26:18 +00:00
Max Heller
3205ed7a41 simplify storing generic parameter attributes in item tree 2023-08-02 09:19:56 -04:00
Lukas Wirth
ecb6d07d57 Add currently unused UseId variants 2023-08-02 14:53:45 +02:00
Lukas Wirth
f86f6a89eb Change terminology, do not name use items and use trees as imports 2023-08-02 14:19:38 +02:00
Lukas Wirth
6e2c3f610b Remove suspicious unwrap 2023-08-02 12:18:10 +02:00
Lukas Wirth
bcff166b3a Add ExternCrateDecl to HIR 2023-08-02 11:52:55 +02:00
Tadeo Kondrak
92a97c292a hir: Remove Expr::While
The previous commit desugared it to a loop.
2023-08-01 19:08:16 -06:00
Tadeo Kondrak
31bcba84f9 hir: Desugar while to loop and break 2023-08-01 19:04:36 -06:00
bors
151c750dac Auto merge of #15367 - Veykril:eager-macro-inputs, r=Veykril
fix: Strip unused token ids from eager macro input token maps
2023-08-01 11:23:02 +00:00
Lukas Wirth
e14d84d0a6 Skip out on single-segment immediate macro resolution when there are errors 2023-08-01 12:38:53 +02:00
Lukas Wirth
d999d34e39 Don't bail eager expansion when inner macros fail to resolve 2023-08-01 11:26:30 +02:00
bors
7736b656e2 Auto merge of #15361 - Veykril:eager-macro-inputs, r=Veykril
fix: Expand eager macros to delimited comma separated expression list

Prior to this, we were just parsing it as an expression which works fine for `()` and `[]` calls as those are tuple and array expressions respectively, but if tails for `{}` calls which with my recent changes reported errors for such eager macro invocations.
2023-07-31 14:24:29 +00:00
bors
cecbed98d8 Auto merge of #15360 - lowr:fix/mbe-transcribe-path-of-different-types, r=HKalbasi
Fixup path fragments upon MBE transcription

Fixes #14367

There are roughly two types of paths: paths in expression context, where a separator `::` between an identifier and its following generic argument list is mandatory, and paths in type context, where `::` can be omitted.

Unlike rustc, we need to transform the parsed fragments back into tokens during transcription. When the matched path fragment is a type-context path and is transcribed as an expression-context path, verbatim transcription would cause a syntax error.

This PR fixes up path fragments by inserting `::` to make sure they are syntactically correct in all contexts. Note that this works because expression-context paths are a strict superset of type-context paths.
2023-07-30 17:29:36 +00:00
Lukas Wirth
7c765d9f9e fix: Expand eager macros to delimited comma separated expression list 2023-07-30 17:31:26 +02:00
Ryo Yoshida
fd7435d463
Fixup path fragments upon MBE transcription 2023-07-30 23:36:42 +09:00
Lukas Wirth
df725d6b6d fix: Do not create fn macro calls with non-fn expanders 2023-07-30 12:18:19 +02:00
Max Heller
37a8493138 tests 2023-07-28 06:45:35 -04:00
Max Heller
008b639ef5 handle #[cfg]s on generic parameters 2023-07-27 21:17:10 -04:00
Laurențiu Nicola
0155385b57 Merge commit '99718d0c8bc5aadd993acdcabc1778fc7b5cc572' into sync-from-ra 2023-07-24 12:21:34 +03:00
oxalica
59a3e42ac9
Fix unescaping of C string literals 2023-07-18 18:52:34 +08:00
Laurențiu Nicola
4704881b64 Merge commit '37f84c101bca43b11027f30ab0c2852f9325bc3d' into sync-from-ra 2023-07-17 16:49:15 +03:00
bors
8e5f944317 Auto merge of #15282 - HKalbasi:mir, r=HKalbasi
Give real discriminant_type to chalk
2023-07-14 16:46:35 +00:00
hkalbasi
50559118fb Give real discriminant_type to chalk 2023-07-14 20:15:18 +03:30
Lukas Wirth
6a7b905c86 Fix the eager token maps by re-mapping the textranges between the input and input expansion 2023-07-13 09:22:38 +02:00
Lukas Wirth
d5f64f875a Infallibe ExpandDatabase::macro_def 2023-07-10 16:23:29 +02:00
hkalbasi
4a444e768c Implement recursion in mir interpreter without recursion 2023-07-07 15:07:29 +03:30
hkalbasi
3a1054fc1c Replace x with it 2023-07-06 17:33:17 +03:30
Lukas Wirth
7b36a73351 internal: Remove CfgExpander 2023-07-04 10:38:23 +02:00
Lukas Wirth
8886d707b8 Stronger typing for AstId and AstIdMap 2023-07-04 09:16:15 +02:00
bors
daba334611 Auto merge of #15206 - Veykril:let-else-fmt, r=Veykril
internal: Format let-else

As nightly finally got support for it I went ahead and formatted r-a with the latest nightly, then with the latest stable (in case other stuff changed)
2023-07-03 18:41:59 +00:00
Lukas Wirth
69cd3c30ac Format let-else 2023-07-03 20:34:09 +02:00
bors
691600a885 Auto merge of #15181 - lowr:patch/import-map-purge-unused, r=Veykril
Clean up `ImportMap`

There are several things in `hir_def::import_map` that are never used. This PR removes them and restructures the code. Namely:

- Removes `Query::name_only`, because it's *always* true.
  - Because of this, we never took advantage of storing items' full path. This PR removes `ImportPath` and changes `ImportInfo` to only store items' name, which should reduce the memory consumption to some extent.
- Removes `SearchMode::Contains` for `Query` because it's never used.
- Merges `Query::assoc_items_only` and `Query::exclude_import_kinds` into `Query::assoc_mode`, because the latter is never used besides filtering associated items out.

Best reviewed one commit at a time. I made sure each commit passes full test suite. I can squash the first three commits if needed.
2023-07-03 14:37:55 +00:00
Lukas Wirth
321e570d92 Don't diagnose builtin derives 2023-07-03 14:23:36 +02:00
hkalbasi
6f7452882a Fix layout of simd types and respect align in mir interpreter 2023-07-02 00:42:33 +03:30
bors
76bcd9946a Auto merge of #15169 - lowr:patch/impl-header-anon-lifetime, r=HKalbasi
Use anonymous lifetime where possible

Because anonymous lifetimes are *super* cool.

More seriously, I believe anonymous lifetimes, especially those in impl headers, reduce cognitive load to a certain extent because they usually signify that they are not relevant in the signature of the methods within (or that we can apply the usual lifetime elision rules even if they are relevant).
2023-06-30 16:57:20 +00:00
Ryo Yoshida
5db0e1a346
Restructure ImportMap collection 2023-07-01 00:18:23 +09:00
Ryo Yoshida
2b106648a7
Only store item name instead of full path 2023-07-01 00:17:57 +09:00
Ryo Yoshida
860628af7c
Remove SearchMode:Contains
Also micro-optimizes fuzzy search.
2023-06-30 23:37:23 +09:00
Ryo Yoshida
8cd4e9f7ec
Merge assoc_items_only and exclude_import_kinds into assoc_mode 2023-06-30 23:37:10 +09:00
Ryo Yoshida
97b725e269
Remove name_only from import map query 2023-06-30 23:35:55 +09:00
hkalbasi
f53f9230f0 Support #[derive_const(Trait)] 2023-06-29 20:58:35 +03:30
Ryo Yoshida
4e793e7859
Use anonymous lifetime where possible 2023-06-29 23:27:28 +09:00
bors
ad434fc4ac Auto merge of #15157 - HKalbasi:tokio-test, r=HKalbasi
Fix runnable detection for `#[tokio::test]`

fix #15141

It is hacky, and it wouldn't work for e.g. this case:
```Rust
use ::core::prelude;

#[prelude::v1::test]
fn foo() {
}
```
But it works for the tokio case. We should use the name resolution here somehow, and after that we should probably also get rid of the ast based `test_related_attribute` function.
2023-06-28 20:02:00 +00:00
hkalbasi
7901538dc8 Fix runnable detection for #[tokio::test] 2023-06-28 23:31:08 +03:30
Ryo Yoshida
56dd5368f5
Refactor
- don't take `&self` as receiver for `Copy` types
- simplify `hir::Module::nearest_non_block_module()`
- style changes for consistency
2023-06-27 16:01:07 +09:00
Ryo Yoshida
a02846343f
Fix self and super path resolution in block modules 2023-06-27 15:29:08 +09:00
Josh Stone
380773b3e8 Upgrade to indexmap v2 2023-06-24 17:35:20 -07:00
hkalbasi
674cd5ab57 Add run-tests command 2023-06-22 19:33:37 +03:30
Lukas Wirth
8823db6c78 Bump more deps 2023-06-22 11:44:10 +02:00
bors
bc26e81cd5 Auto merge of #15070 - Veykril:analysis-stat-stuff, r=Veykril
internal: Report metric timings for file item trees and crate def map creation
2023-06-21 05:58:13 +00:00
David Lattimore
bea3a33d84 Change in-tree libs to workspace dependencies 2023-06-20 13:53:39 +10:00
hkalbasi
3c87825074 Use ArgumentV1 instead of Argument 2023-06-19 22:48:49 +03:30
Lukas Wirth
9476fdaaa9 HIR ExternCrateDecl 2023-06-19 14:15:08 +02:00
Lukas Wirth
0bde3fc77e Intern use and extern crate items like other items 2023-06-19 13:51:44 +02:00
Laurențiu Nicola
9326cf7f0c Merge commit 'cd3bf9fe51676b520c546460e6d8919b8c8ff99f' into sync-from-ra 2023-06-19 09:14:04 +03:00
Lukas Wirth
c3186202a2 Shrink size of hir::Binding 2023-06-18 12:03:04 +02:00
Lukas Wirth
83d7724629 fix: Add binding definition for for-expr iterator desugared binding 2023-06-18 11:44:01 +02:00
Lukas Wirth
58ac823864 Less eager parsing for module sources 2023-06-17 10:58:52 +02:00
Lukas Wirth
3484b5a116 internal: Do not allocate unnecessarily when importing macros from parent modules 2023-06-16 18:41:06 +02:00
bors
9c967d3809 Auto merge of #15053 - Veykril:crate-root-module-id, r=Veykril
internal: Add a CrateRootModuleId that encodes a module id that is always a crate root
2023-06-14 14:41:06 +00:00
Lukas Wirth
cf178cba8f internal: Add a CrateRootModuleId that encodes a module id that is always a crate root 2023-06-14 15:41:06 +02:00
bors
07bc6cbcad Auto merge of #15040 - lnicola:hash-state-name, r=Veykril
fix: Use a more obscure hasher name in derive expansion

Closes #15039
2023-06-13 06:13:35 +00:00
Laurențiu Nicola
0b441ca6a5 Use a more obscure hasher name in derive expansion 2023-06-13 08:50:27 +03:00
Lukas Wirth
abe249559d internal: Give ConstBlockId and InTypeConstId named Location types 2023-06-12 18:21:17 +02:00
hkalbasi
a4695788ca Add a bunch of fixme comments 2023-06-12 00:37:11 +03:30
hkalbasi
e83b56739f Flatten the TypeOwnerId 2023-06-11 01:36:32 +03:30
hkalbasi
f8594f78bb Use ConstArg instead of Expr for AstId of InTypeConstId 2023-06-11 00:39:28 +03:30
hkalbasi
d9136df9e5 Handle return types for in type const bodies 2023-06-11 00:39:28 +03:30
hkalbasi
a481e004b0 Lower const params with a bad id 2023-06-11 00:39:28 +03:30
Lukas Wirth
b6fb35f20c Shrink hir_expand::attr::AttrInput by boxing a variant 2023-06-10 01:21:52 +02:00
Lukas Wirth
a02b9b279e internal: Lazy eager macros 2023-06-09 13:02:13 +02:00
hkalbasi
30e16e20d0 Fix unwrap on None in expanding format args 2023-06-08 00:17:22 +03:30
Ryo Yoshida
4f0c6fac17
fix: only generate trait bound for associated types in field types 2023-06-07 20:52:49 +09:00
Laurențiu Nicola
c48062fe2a Merge commit 'aa9bc8612514d216f84eec218dfd19ab83f3598a' into sync-from-ra 2023-06-05 12:04:23 +03:00
Laurențiu Nicola
c3dbe7c717 Merge remote-tracking branch 'upstream/master' into sync-from-rust 2023-06-05 11:07:47 +03:00
bors
9d5c34a80e Auto merge of #14970 - HKalbasi:mir-fix, r=HKalbasi
Detect "bound more than once" error and suppress `need-mut` for it.

Fix the `need-mut` false positive for `izip!`
2023-06-04 09:33:53 +00:00
hkalbasi
71f3e4b08c Detect "bound more than once" error and suppress need-mut for it. 2023-06-04 12:39:36 +03:30
Lukas Wirth
f9a9e40c0a Update builtin attribute list 2023-06-04 10:02:11 +02:00
bors
0b4c09b1d2 Auto merge of #14941 - Veykril:def-map, r=Veykril
Shrink `DefMap`, share crate level items with block def maps
2023-06-01 16:42:12 +00:00
Lukas Wirth
11b937177b Skip extern prelude path resolution in block def maps 2023-06-01 17:58:08 +02:00
bors
4458e7f190 Auto merge of #14942 - HKalbasi:for-loop-label, r=HKalbasi
fix bug in labeled for loop desugaring

fix https://github.com/rust-lang/rust-analyzer/pull/14892#discussion_r1213091393
2023-06-01 14:54:47 +00:00
hkalbasi
f4c52b40bd fix bug in labeled for loop desugaring 2023-06-01 17:51:53 +03:30
Lukas Wirth
54e3ef658a Rename nameres::CrateData to DefMapCrateData 2023-06-01 15:50:19 +02:00
Lukas Wirth
1e6406e223 Move extern prelude into CrateData 2023-06-01 15:49:05 +02:00
Lukas Wirth
bdca349573 Arc DefMap::data so the block def maps can share it 2023-06-01 15:27:05 +02:00
Lukas Wirth
5c466ccc2b Refactor out some crate wide data in DefMap into nested struct 2023-06-01 15:04:38 +02:00
Lukas Wirth
dc7c6d43c7 Slightly shrink DefMap 2023-06-01 14:46:36 +02:00
Lukas Wirth
0e28202832 Insert missing expr/pat for leading comma tuples 2023-06-01 08:56:40 +02:00
Oli Scherer
1570299af4 Remove const eval limit and implement an exponential backoff lint instead 2023-05-31 10:24:17 +00:00
bors
76d86502f7 Auto merge of #14912 - Veykril:cargo-alltargets, r=Veykril
Don't add --all-targets to runnables for no-std crates

Fixes https://github.com/rust-lang/rust-analyzer/issues/14155
2023-05-30 12:34:28 +00:00
hkalbasi
51368793b4 MIR episode 6 2023-05-28 23:25:15 +03:30
Lukas Wirth
8bc826dd53 Add diagnostic for _ expressions (typed holes) 2023-05-28 14:55:28 +02:00
Lukas Wirth
bbd9e41606 Don't add --all-targets to runnables for no-std crates 2023-05-28 14:18:44 +02:00
Ryo Yoshida
0d4d1d7e3b
Implement ${count()} metavariable expression 2023-05-28 19:54:36 +09:00
Ryo Yoshida
9ebaa85d37
Split test module for metavariable expressions 2023-05-28 19:54:23 +09:00
hkalbasi
780349bdaf fix need-mut false positive in closure capture of match scrutinee 2023-05-26 02:08:37 +03:30
hkalbasi
b0f17668f7 use ::core instead of $crate in option_env! 2023-05-25 18:46:34 +03:30
Lukas Wirth
c7ef6c25b7 internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
bors
2f840c2236 Auto merge of #14874 - Veykril:crate-cfg, r=Veykril
expand: Change how `#![cfg(FALSE)]` behaves on crate root

Closes https://github.com/rust-lang/rust-analyzer/issues/14769
2023-05-24 16:06:09 +00:00
bors
2df56cadcb Auto merge of #14755 - poliorcetics:clippy-fixes, r=Veykril
Fix: a TODO and some clippy fixes

- fix(todo): implement IntoIterator for ArenaMap<IDX, V>
- chore: remove unused method
- fix: remove useless `return`s
- fix: various clippy lints
- fix: simplify boolean test to a single negation
2023-05-24 11:13:52 +00:00
Lukas Wirth
74d6826858 expand: Change how #![cfg(FALSE)] behaves on crate root 2023-05-24 13:02:38 +02:00
hkalbasi
c5ea2d7adc handle match scrutinee in closure captures 2023-05-19 12:04:12 +03:30
hkalbasi
4adfbbfbad partially support panic message in MirEvalError 2023-05-18 18:30:49 +03:30
bors
9ce95674e8 Auto merge of #14837 - Veykril:rustc-lexer, r=Veykril
Support c string literals
2023-05-18 11:55:38 +00:00
Lukas Wirth
3e528b85f9 Fix cstring literals construct &CStr not &str 2023-05-18 12:03:15 +02:00
bors
034d7c8537 Auto merge of #14787 - HKalbasi:mir2, r=HKalbasi
MIR episode 5

This PR inits drop support (it is very broken at this stage, some things are dropped multiple time, drop scopes are wrong, ...) and adds stdout support (`println!` doesn't work since its expansion is dummy, but `stdout().write(b"hello world\n")` works if you use `RA_SYSROOT_HACK`) for interpreting. There is no useful unit test that it can interpret yet, but it is a good sign that it didn't hit a major road block yet.

In MIR lowering, it adds support for slice pattern and anonymous const blocks, and some fixes so that we can evaluate `SmolStr::new_inline` in const eval. With these changes, 57 failed mir body remains.
2023-05-18 09:44:26 +00:00
bors
f9be79603a Auto merge of #14820 - HKalbasi:format-args, r=HKalbasi
Expand `format_args!` with more details
2023-05-18 09:09:06 +00:00
Lukas Wirth
4b577e2bc8 Support c string literals 2023-05-18 11:06:05 +02:00
hkalbasi
5c83e222a3 fix format_args expansion error with raw strings 2023-05-18 12:32:41 +03:30
bors
c7b03491cd Auto merge of #14834 - Veykril:ty-diag-unit, r=Veykril
internal: Less file parsing for symbol index generation
2023-05-18 06:25:40 +00:00
Lukas Wirth
d6dcfa5744 internal: Less file parsing for symbol index generation 2023-05-18 08:25:06 +02:00
Ryo Yoshida
68a74decb6
Process macro_use prelude in semantic scope resolver 2023-05-17 17:45:44 +09:00
hkalbasi
a2fba7c67e Add test for eager expanding of format_args 2023-05-17 01:15:04 +03:30
hkalbasi
a6e5a912f9 Expand format_args! with more details 2023-05-16 19:12:40 +03:30
bors
9eb26a9375 Auto merge of #14809 - lowr:patch/macro_use-filter, r=Veykril
Support `#[macro_use(name, ...)]`

This PR adds support for another form of the `macro_use` attribute: `#[macro_use(name, ...)]` ([reference]).

Note that this form of the attribute is only applicable to extern crate decls, not to mod decls.

[reference]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
2023-05-15 10:04:05 +00:00
bors
bc03418127 Auto merge of #14746 - lowr:patch/associated-return-types, r=Veykril
Parse associated return type bounds

This PR implements parser support for associated return type bounds: `T: Foo<bar(): Send>`. This PR does not implement associated return types (`T::bar(): Send`) because it's not implemented even in rustc, and also removes `(..)`-style return type notation because it has been removed in rust-lang/rust#110203 (effectively reverting #14465).

I don't plan to proactively follow this unstable feature unless an RFC is accepted and my main motivation here is to remove no-longer-valid syntax `(..)` from our parser, nevertheless adding minimal parser support so anyone interested (as can be seen in #14465) can experiment it without rust-analyzer's syntax errors.
2023-05-15 09:16:51 +00:00
Ryo Yoshida
1bc7f8a4c6
Support #[macro_use(name, ...)] 2023-05-15 00:05:44 +09:00
bors
daa03b0b0b Auto merge of #14800 - lowr:patch/macro-subns-and-prelude, r=Veykril
Expand more single ident macro calls upon item collection

Addresses https://github.com/rust-lang/rust-analyzer/pull/14781#issuecomment-1546201022

I believe this (almost) brings the number of unresolved names back to pre-#14781:

|r-a version|`analysis-stats compiler/rustc` (rust-lang/rust@69fef92ab2) |
|---|---|
|pre-#14781 (b069eb720b) | exprs: 2747778, ??ty: 122236 (4%), ?ty: 107826 (3%), !ty: 728 |
| #14781 (a7944a93a1) | exprs: 2713080, ??ty: 139651 (5%), ?ty: 114444 (4%), !ty: 730 |
| with this fix | exprs: 2747871, ??ty: 122237 (4%), ?ty: 108171 (3%), !ty: 676 |

(I haven't investigated on the increase in some numbers but hopefully not too much of a problem)

This is only a temporary solution. The core problem is that we haven't fully implemented the textual scope of legacy macros. For example, we *have been* failing to resolve `foo` in the following snippet, even before #14781 or after this patch. As noted in a FIXME, we need a way to resolve names in textual scope without eager expansion during item collection.

```rust
//- /main.rs crate:main deps:lib
lib::mk_foo!();
const A: i32 = foo!();
             //^^^^^^ unresolved-macro-call

//- /lib.rs crate:lib
#[macro_export]
macro_rules! mk_foo {
    () => {
        macro_rules! foo { () => { 42 } }
    }
}
```
2023-05-13 18:47:42 +00:00
Ryo Yoshida
e9ddb62c65
Expand more single ident macro calls upon their collection 2023-05-14 03:11:10 +09:00
hkalbasi
cbcafd3539 MIR episode 5 2023-05-12 18:17:15 +03:30
hkalbasi
7da80d4f67 Use double reference in debug derive 2023-05-12 12:36:57 +03:30
Ryo Yoshida
f2a35deb50
Consider macro sub-namespace during name resolution 2023-05-11 21:13:12 +09:00
Ryo Yoshida
3203ea896d
Add macro_use prelude to DefMap 2023-05-11 21:13:11 +09:00
Ryo Yoshida
96113b7b8e
Remove prelude fallback path for Rust <1.52.0
We've already removed non-sysroot proc macro server, which effectively
removed support for Rust <1.64.0, so this removal of fallback path
shouldn't be problem at this point.
2023-05-11 21:13:10 +09:00
Ryo Yoshida
34a9129333
fix: column!() and line!() built-in macros return u32 2023-05-11 21:13:05 +09:00
Ryo Yoshida
a0a7860141
Refactor 2023-05-11 18:17:16 +09:00
Arpad Borsos
35940bcda3 Remove identity_future from stdlib
This function/lang_item was introduced in #104321 as a temporary workaround of future lowering.
The usage and need for it went away in #104833.
After a bootstrap update, the function itself can be removed from `std`.
2023-05-07 10:52:01 +02:00
Alexis (Poliorcetics) Bourget
d7fdf141a4 fix: various clippy lints 2023-05-07 09:43:37 +02:00
Ryo Yoshida
fa2340a4df
Parse associated return type bounds 2023-05-06 20:31:11 +09:00
Ryo Yoshida
d7d8971203
Remove (..)-style return type notation 2023-05-06 20:30:17 +09:00
bors
0dd94d3b07 Auto merge of #14738 - Veykril:def-map-fix, r=Veykril
fix: Fix body lowering not using block def maps

Fixes the issue in the comment here https://github.com/rust-lang/rust-analyzer/issues/10084#issuecomment-1534320254, not the general issue unfortunately.
2023-05-04 18:47:04 +00:00
Lukas Wirth
9419fcb109 fix: Fix body lowering not using block def maps 2023-05-04 20:46:05 +02:00
hkalbasi
d9f4cbbe8f Emit function bodies in expanding builtin derives 2023-05-03 14:14:47 +03:30
Laurențiu Nicola
7197a27028 Use triomphe Arc 2023-05-02 20:02:43 +03:00
hkalbasi
3a3c3630a2 fix break-outside-of-loop false positive in try block 2023-05-02 03:11:56 +03:30
hkalbasi
6312fbf521 MIR episode 4 2023-05-01 23:23:10 +03:30
Lukas Wirth
cf8f13b531 fix: Fix restart server button trying to start instead of restart the server 2023-04-28 21:34:31 +02:00
Matthias Krüger
e99a9904aa Rollup merge of #110766 - m-ou-se:fmt-rt, r=jyn514
More core::fmt::rt cleanup.

- Removes the `V1` suffix from the `Argument` and `Flag` types.

- Moves more of the format_args lang items into the `core::fmt::rt` module. (The only remaining lang item in `core::fmt` is `Arguments` itself, which is a public type.)

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

Follow-up to https://github.com/rust-lang/rust/pull/110616
2023-04-28 07:34:02 +02:00
Lukas Wirth
10d7d7304b
Revert "Handle dev-dependency cycles" 2023-04-25 14:29:26 +02:00
Lukas Wirth
e205af259d Prefer test duped crates for ide features 2023-04-25 11:39:58 +02:00
Matthias Krüger
6bd8fee558 Revert "Remove #[alloc_error_handler] from the compiler and library"
This reverts commit abc0660118cc95f47445fd33502a11dd448f5968.
2023-04-25 00:08:35 +02:00
bors
707382c21d Auto merge of #14652 - Veykril:pat2021, r=Veykril
fix: Fix pat fragment handling in 2021 edition

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

The fix isn't that great, but we are kind of forced to do it the quick and hacky way right now since std has changed the `matches` macro to make use of this now. And for a proper fix we need to track hygiene for identifiers which is a long way off anyways
2023-04-24 20:36:45 +00:00
Lukas Wirth
d1ca505525 fix: Fix pat fragment handling in 2021 edition 2023-04-24 22:21:37 +02:00
Mara Bos
429d06b879 Remove "V1" from ArgumentsV1 and FlagsV1. 2023-04-24 16:16:14 +02:00
bors
b2e6f3a9da Auto merge of #14636 - Veykril:macros, r=Veykril
internal: Remove unnecessary is_derive field from MacroCallKind::Attr
2023-04-24 06:13:18 +00:00
hkalbasi
232f293c19 Fix some typos in StructFlags 2023-04-23 21:55:47 +03:30
Lukas Wirth
cebc018e2a Remove unnecessary is_derive field from MacroCallKind::Attr 2023-04-22 14:29:28 +02:00
bors
442a769f82 Auto merge of #14634 - Veykril:assoc-collect, r=Veykril
fix: Report remaining macro errors in assoc item collection
2023-04-22 09:49:57 +00:00
Lukas Wirth
77afc6e793 fix: Report remaining macro errors in assoc item collection 2023-04-22 11:49:00 +02:00
bors
34ebb30e84 Auto merge of #14610 - lowr:fix/hygiene-for-meta-item, r=Veykril
fix: Resolve `$crate` in derive paths

Paths in derive meta item list may contain any kind of paths, including those that start with `$crate` generated by macros. We need to take hygiene into account when we lower paths in the list.

This issue was identified while investigating #14607, though this patch doesn't fix the broken trait resolution.
2023-04-22 09:36:38 +00:00
Ryo Yoshida
85e76542fe
Cache Hygiene in DefCollector 2023-04-22 18:22:29 +09:00
bors
6f43a56201 Auto merge of #14633 - Veykril:assoc-collect, r=Veykril
internal: Don't reparse files when trying to expand assoc item macro calls
2023-04-22 09:02:25 +00:00
Lukas Wirth
2aa44c8e37 internal: Don't reparse files when trying to expand assoc item macro calls 2023-04-22 11:02:11 +02:00
bors
1379b5fac7 Auto merge of #14630 - Veykril:arc, r=Veykril
internal: `Arc<String>` -> `Arc<str>`
2023-04-22 07:58:13 +00:00
Lukas Wirth
f00dcf9a69 internal: Arc<String> -> Arc<str> 2023-04-22 09:48:37 +02:00
Ryo Yoshida
cf72b6232b
Resolve $crate in derive paths 2023-04-20 15:50:17 +09:00
bors
2400b36a2e Auto merge of #14577 - jsoref:spelling, r=lnicola
Spelling

This PR corrects misspellings identified by the [check-spelling action](https://github.com/marketplace/actions/check-spelling).

The misspellings have been reported at https://github.com/jsoref/rust-analyzer/actions/runs/4699991040#summary-12751355796

The action reports that the changes in this PR would make it happy: https://github.com/jsoref/rust-analyzer/actions/runs/4699991284#summary-12751356293

closes #14567
2023-04-19 14:05:40 +00:00
Josh Soref
bc7d84c3ce Spelling
* a rule
* access
* after
* amount
* annotations
* assignment
* assist
* associated
* attribute
* borrowed
* built-in type
* clarification
* command
* const
* constructor
* corresponding
* counterparts
* curlies
* dependencies
* deterministic
* diagnostic
* duplicates
* edge
* edited
* efficient
* elsewhere
* execution
* expression
* extensions
* extracted
* fill
* github
* helper
* heuristic
* incomplete
* indent end
* inlay
* invocation
* lifetime
* looking
* maybe
* move
* mutability
* mutable
* necessarily
* necessary
* negative
* nonexistent
* occurred
* offsets
* offsetted
* overridden
* parameters
* params
* params_and_where_preds_in_scope
* paredit
* parent
* parentheses
* prepended if
* punctuation
* receive
* receiver
* referring
* repeated
* representing
* semantically
* separately
* shouldnot
* siblings
* similar
* something's
* statement
* struct
* structure
* surprise
* the
* this
* transparent
* unimplemented
* unnamed
* unnecessary
* unneeded
* unreachable
* unterminated
* utilities
* variant
* variants
* visibility
* work around (v)
* workaround

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-19 09:45:55 -04:00
bors
9b835f334f Auto merge of #14594 - Veykril:Simplify, r=Veykril
internal: Move Expander and LowerCtx into separate modules
2023-04-17 19:00:42 +00:00
Lukas Wirth
bca8029a6e Move Expander and LowerCtx into separate modules 2023-04-17 20:44:06 +02:00
Laurențiu Nicola
160ab88bb9 Bump bitflags 2023-04-17 18:42:59 +03:00
bors
9b54e39762 Auto merge of #14587 - Veykril:macro-def-err, r=Veykril
fix: Bring back LRU limit for macro_expand query

Should fix the memory increase
2023-04-16 19:30:42 +00:00
Lukas Wirth
76718ea2fc Bring back LRU limit for macro_expand query 2023-04-16 21:30:04 +02:00
bors
924d30a772 Auto merge of #14585 - Veykril:macro-def-err, r=Veykril
Make `ExpandDatabase::parse_macro_expansion` and `ExpandDatabase::parse_or_expand` infallible
2023-04-16 18:50:02 +00:00
Lukas Wirth
4ea5d7f6a0 Re-introduce option for macro_arg to prevent calling macros with empty inputs 2023-04-16 20:26:26 +02:00
bors
697b335fda Auto merge of #14584 - Veykril:macro-def-err, r=Veykril
internal: Report item-level macro expansion syntax errors
2023-04-16 17:40:20 +00:00
Lukas Wirth
a2a3fecae3 Option begone part 2 2023-04-16 19:20:48 +02:00
Lukas Wirth
96a774261f Option begone part 1 2023-04-16 19:20:42 +02:00
Lukas Wirth
0f4ffaa5af Fix duplicate eager expansion errors 2023-04-16 19:20:35 +02:00
Amanieu d'Antras
35fc5780a7 Remove #[alloc_error_handler] from the compiler and library 2023-04-16 08:35:50 -07:00
Lukas Wirth
d1632c2727 Report syntax errors from item level macro expansions 2023-04-16 17:22:06 +02:00
Lukas Wirth
6ae8d49e15 Simplify eager macro error handling 2023-04-16 15:46:12 +02:00
bors
f0a40c3a0e Auto merge of #14583 - Veykril:macro-def-err, r=Veykril
internal: Report macro definition errors on the definition

We still report them on the call site as well for the time being, and the diagnostic doesn't know where the error in the definition comes from, but that can be done later on
2023-04-16 12:17:24 +00:00
Lukas Wirth
a5558cdfe5 internal: Report macro definition errors on the definition 2023-04-16 14:15:59 +02:00
bors
c0889589d1 Auto merge of #14581 - Veykril:layout-ty, r=Veykril
internal: Move layout logic from hir-def to hir-ty
2023-04-16 10:22:24 +00:00
Lukas Wirth
0bb9a17312 internal: Move layout logic from hir-def to hir-ty 2023-04-16 12:21:12 +02:00
Ryo Yoshida
89a1439de3
Parse exclusive range pattern 2023-04-16 04:28:29 +09:00
bors
96407424de Auto merge of #14574 - Veykril:blocks, r=Veykril
internal: Make block_def_map infallible
2023-04-14 11:48:33 +00:00
Lukas Wirth
c32d51979d internal: Make block_def_map infallible 2023-04-14 13:17:38 +02:00
bors
4667379f7e Auto merge of #14575 - Veykril:attrs, r=Veykril
internal: Put Attrs behind a query instead of AttsWithOwner

We call this for pretty much every item, so this is unnecessary wasted memory
2023-04-14 11:17:18 +00:00
Lukas Wirth
ed3a5eac3c internal: Put Attrs behind a query instead of AttsWithOwner 2023-04-14 12:47:33 +02:00
Lukas Wirth
ce0896b78c Allocate ExprScopes ScopeEntries in a single arena instead of per ScopeData 2023-04-14 12:05:11 +02:00
bors
7afd2048f0 Auto merge of #14544 - HKalbasi:dev, r=Veykril
Infer types of nested RPITs

fix https://github.com/rust-lang/rust-analyzer/issues/14474#issuecomment-1501235394
2023-04-11 14:49:04 +00:00
Ryo Yoshida
0ce71dd76f
completion: check stability 2023-04-11 21:21:13 +09:00
hkalbasi
a584cb998f Infer types of nested RPITs 2023-04-11 04:32:11 +03:30
hkalbasi
59b6f2d9f2 Compute closure captures 2023-04-10 23:04:34 +03:30
hkalbasi
c54cb88950 Add bounds for associated types in derive macro 2023-04-07 19:33:14 +03:30
Lukas Wirth
435d585d0c
Revert "Add bounds for fields in derive macro" 2023-04-07 11:01:17 +02:00
bors
bca364c3fe Auto merge of #14525 - Veykril:hir-pretty, r=Veykril
internal: Remove parameter names from function item tree
2023-04-07 07:57:58 +00:00
Lukas Wirth
79c4c4fb48 Remove parameter names from function item tree 2023-04-07 09:57:19 +02:00
bors
d73161b491 Auto merge of #14524 - Veykril:hir-pretty, r=Veykril
internal: Render function parameters in hir-def pretty printing
2023-04-07 07:34:45 +00:00
Lukas Wirth
513d4a9c9a Render function parameters in hir-def pretty printing 2023-04-07 09:34:04 +02:00
hkalbasi
0241b52dad Add bounds for fields in derive macro 2023-04-07 02:21:46 +03:30
Lukas Wirth
f742943a4b Don't recreate Hygiene unnecessarily 2023-04-06 21:16:11 +02:00
Lukas Wirth
b7c443569a Don't unnecessarily query the ast_id_map for blocks if they aren't interned 2023-04-06 20:19:59 +02:00
Lukas Wirth
a1b96b1e00 Remove unnecessary Names from FunctionData::params 2023-04-06 20:14:51 +02:00
Lukas Wirth
3f5c9920d6 Move hir_def::builtin_attr to hir_def::attr::builtin 2023-04-06 19:55:49 +02:00
Lukas Wirth
12b069f434 Move hir_def::keys to hir_def::dyn_map 2023-04-06 19:49:33 +02:00
Lukas Wirth
40c068f502 Use hir_def::builtin_attr::find_builtin_attr_idx 2023-04-06 19:44:29 +02:00
Lukas Wirth
99b69525f4 hir_def::expr -> hir_def::hir, hir_def::type_ref -> hir_def::hir::type_ref 2023-04-06 19:36:25 +02:00
Lukas Wirth
8e7c104b3a Move hir_def::adt to hir_def::data::adt 2023-04-06 19:23:29 +02:00
Lukas Wirth
0e7117900c internal: Resolve labels in body lowering 2023-04-06 14:21:20 +02:00
bors
25124a84de Auto merge of #14490 - Veykril:crategraph-dedup, r=Veykril
internal: Switch crate graph to use an Arena instead of a hashmap
2023-04-05 14:12:11 +00:00
bors
a1ca52e2a9 Auto merge of #14486 - HKalbasi:dev, r=Veykril
Desugar async fn completely

fix #14479
2023-04-05 13:58:38 +00:00
bors
265f83031f Auto merge of #14433 - hecatia-elegua:alias-based-completion, r=Veykril
Add doc-alias based completion

Closes #14406.

I adapted the parsing code from the CfgExpr parsing code, maybe there's a better abstraction for both, or attribute parsing in general. It also includes `doc(hidden)`-parsing, which means it could replace the other function.
There are a few tests for parsing.

`process_all_names` changed the most, I added some docs there to explain what happens.

Many call sites just pass an empy vec to `add_path_resolution`'s `doc_aliases`, since either it doesn't make sense to pass anything (e.g. visibility completion) or I don't know where to get them from. Shouldn't really matter, as it will just not show aliases if the vec is empty and we can extend alias completion in these cases later.

I added two tests in `special.rs` for struct name completion (which was the main thing I wanted). I also tried function and field names, but these don't work yet. I want to add those in a follow-up PR.
2023-04-05 13:44:51 +00:00
bors
af30656785 Auto merge of #14436 - lowr:patch/normalize-assoc-type-in-path-expr, r=HKalbasi
Normalize associated types in paths in expressions

Part of #14393

When we resolve paths in expressions (either path expressions or paths in struct expressions), there's a need of projection normalization, which `TyLoweringContext` cannot do on its own. We've been properly applying normalization for paths in struct expressions without type anchor, but not for others:

```rust
enum E {
    S { v: i32 }
    Empty,
}

impl Foo for Bar {
    type Assoc = E;
    fn foo() {
        let _ = Self::Assoc::S { v: 42 };   // path in struct expr without type anchor; we already support this
        let _ = <Self>::Assoc::S { v: 42 }; // path in struct expr with type anchor; resolves with this PR
        let _ = Self::Assoc::Empty;         // path expr; resolves with this PR
    }
}
```

With this PR we correctly resolve the whole path, but we need some more tweaks in HIR and/or IDE layers to properly resolve a qualifier (prefix) of such paths and provide IDE features that are pointed out in #14393 to be currently broken.
2023-04-05 10:47:47 +00:00
Lukas Wirth
7f0fbf7f9d Switch crate graph to use an Arena instead of a hashmap 2023-04-05 10:32:02 +02:00
hkalbasi
c26b12d01c Desugar async fn completely 2023-04-04 23:07:38 +03:30
hecatia-elegua
170822b018
Add note for future me or others 2023-04-02 16:03:42 +02:00
tamasfe
25910bcde6
chore: replace TODO comment with FIXME 2023-04-01 16:31:16 +02:00
tamasfe
0b9c0c5088
feat(syntax): RTN in bounds
Limited syntactic support for experimental return type notations.
https://github.com/rust-lang/rust/issues/109417
2023-04-01 15:26:03 +02:00
hkalbasi
8a6ca86247 Use async block in async fn type inference 2023-04-01 04:35:28 +03:30
hecatia-elegua
c469936aac Address review comments part 1 2023-03-30 17:35:57 +02:00
Lukas Wirth
e244942209 internal: Set Durability to HIGH for enable_proc_attr_macros input 2023-03-30 15:11:22 +02:00
bors
02ea92fecb Auto merge of #14445 - Veykril:adt-flags, r=Veykril
internal: Introduce StructFlags
2023-03-30 12:34:37 +00:00
bors
fc8c5139fa Auto merge of #14410 - Veykril:query-lru-capacities, r=Veykril
internal: Add config to specifiy lru capacities for all queries

Might help figuring out what queries should be limited by LRU by default, as currently we only limit `parse`, `parse_macro_expansion` and `macro_expand`.
2023-03-30 12:20:24 +00:00
Lukas Wirth
5616d91b73 internal: Add config to specifiy lru capacities for all queries 2023-03-30 12:52:28 +02:00
Lukas Wirth
33b6012827 Introduce StructFlags 2023-03-30 12:49:08 +02:00
Ryo Yoshida
8aef04f1a7
Resolve and normalize path segments one by one in variant resolution 2023-03-29 23:32:37 +09:00
hecatia-elegua
ba2b48d1b8 Fix3 2023-03-29 14:58:33 +02:00
hecatia-elegua
c351f6bf43 Fix 2023-03-29 14:27:20 +02:00
hecatia-elegua
0863389dd1 Add doc-alias based completion 2023-03-29 14:08:25 +02:00
Lukas Wirth
342fd2b9f3 fix: Properly handle local trait impls 2023-03-28 08:34:29 +02:00
Lukas Wirth
c04a13cb19 Simplify 2023-03-27 17:16:45 +02:00
bors
82ec4586f1 Auto merge of #14408 - Veykril:intern-block, r=Veykril
internal: Only intern blocks that declare items

We only used `BlockId` for the block defmap, so this is wasted memory. Lowering for non item declaring blocks is also cheaper now as we no longer have to fully lower a block that defines not items.
2023-03-25 19:48:04 +00:00
Lukas Wirth
675fc88afd internal: Only intern blocks that declare items 2023-03-25 20:44:12 +01:00
Lukas Wirth
d154ea88f9 Split out proc-macros from the CrateGraph 2023-03-25 16:46:44 +01:00
Laurențiu Nicola
dbf04a5ee2 ⬆️ rust-analyzer 2023-03-20 08:31:01 +02:00
hkalbasi
8e73ea5253 Desugar try blocks 2023-03-19 13:02:51 +03:30
hkalbasi
eb4939e217 Support overloaded deref MIR lowering 2023-03-17 14:02:55 +03:30
hkalbasi
9564773d5e Improve pattern matching MIR lowering 2023-03-17 13:08:36 +03:30
hkalbasi
b7b9ae59a0 desugar ? operator 2023-03-17 13:08:35 +03:30
Lukas Wirth
3bf07a5f04 Simplify 2023-03-15 13:54:06 +01:00
Zachary S
af175ddcdc Add test for async closure types.
(rebased onto 6dfd8ae)
2023-03-15 13:10:35 +01:00
Zachary S
6746a08b44 fix: Fix return type of async closures.
(rebased onto 6dfd8ae)
2023-03-15 13:10:00 +01:00
Lukas Wirth
610a94c421 Add fundamental attributes to data 2023-03-14 20:16:41 +01:00
Lukas Wirth
f34b2469bd lint incoherent inherent impls 2023-03-14 19:20:44 +01:00
Lukas Wirth
1a9fbf0a6d fix: Fix visibility resolution not respecting parent blocks 2023-03-14 13:42:08 +01:00
bors
6a98e961f8 Auto merge of #14340 - Veykril:expand, r=lnicola
internal: Rename AstDatabase to ExpandDatabase
2023-03-14 09:37:54 +00:00
hkalbasi
d7da9e64d1 Add storage dead for let bindings without initializer 2023-03-14 12:15:16 +03:30
Lukas Wirth
aaf08bdcc5 Shrink ProcMacroExpander size 2023-03-13 16:49:38 +01:00
Lukas Wirth
9fb9ee3b6a internal: Rename AstDatabase to ExpandDatabase 2023-03-13 16:35:41 +01:00
Laurențiu Nicola
b2f6fd4f96 ⬆️ rust-analyzer 2023-03-13 10:42:24 +02:00
Lukas Wirth
879cac4b28 minor: Remove dead code 2023-03-09 15:40:51 +01:00
Lukas Wirth
d038892947 fix: Fix block defmap not looking into tail expressions for macro calls 2023-03-08 14:37:27 +01:00
hkalbasi
af90ec8096 Partially support "overloaded deref" MIR lowering 2023-03-06 21:09:09 +03:30
hkalbasi
a25710b0c0 Add need-mut and unused-mut diagnostics 2023-03-06 21:09:08 +03:30
hkalbasi
61ad6a96ad Add BindingId 2023-03-06 21:09:08 +03:30
Lukas Wirth
27fad2ad75 Lift segment check out of the loop in resolve_path_in_value_ns 2023-03-05 15:42:40 +01:00
Lukas Wirth
a51267c5e0 Allocate traits in scope upfront when type checking instead of recollecting them everytime 2023-03-05 15:04:46 +01:00
Lukas Wirth
a8606e5363 Re-use the resolver in InferenceContext instead of rebuilding it on every expression change 2023-03-05 14:37:44 +01:00
Lukas Wirth
95c4cb991f Handle new hir block kinds in scope calculations 2023-03-04 15:22:39 +01:00
Lukas Wirth
1b5bc83118 Remove weird nesting of effect blocks in hir 2023-03-04 14:45:57 +01:00
Lukas Wirth
24ba1bed04 Set expectation for no-semi expression statements to unit 2023-03-04 12:48:57 +01:00
bors
6756294aa0 Auto merge of #14184 - lowr:feat/trait-alias-def, r=Veykril
Handle trait alias definitions

Part of #2773

This PR adds a bunch of structs and enum variants for trait aliases. Trait aliases should be handled as an independent item because they are semantically distinct from traits.

I basically started by adding `TraitAlias{Id, Loc}` to `hir_def::item_tree` and iterated adding necessary stuffs until compiler stopped complaining what's missing. Let me know if there's still anything I need to add.

I'm opening up this PR for early review and stuff. I'm planning to add tests for IDE functionalities in this PR, but not type-related support, for which I put FIXME notes.
2023-03-03 15:45:18 +00:00
Ryo Yoshida
29c957f973
Lower and handle trait aliases in HIR 2023-03-04 00:24:07 +09:00
Ryo Yoshida
e2ec3a6561
Refactor generic parameter lowering
Since we moved impl trait handling to other place, there are only two
cases now: those that introduce implicit `Self` parameter and those that
don't.
2023-03-04 00:24:05 +09:00
Ryo Yoshida
356d12eae4
refactor: leverage HasAttrs for code brevity 2023-03-04 00:24:03 +09:00
Ryo Yoshida
2e7d2c2d04
Parse trait alias as a distinct AST type 2023-03-04 00:23:56 +09:00
Lukas Wirth
ec273c3d12 Split pattern inference into more functions 2023-03-03 10:42:46 +01:00
bors
32424d0aba Auto merge of #14176 - lowr:fix/assoc-func-vis-in-local-impl, r=Veykril
Fix associated item visibility in block-local impls

Fixes #14046

When we're resolving visibility of block-local items...

> `self` normally refers to the containing non-block module, and `super` to its parent (etc.). However, visibilities must only refer to a module in the DefMap they're written in, so we restrict them when that happens. ([link])

 ...unless we're resolving visibility of associated items in block-local impls, because that impl is semantically "hoisted" to the nearest (non-block) module. With this PR, we skip the adjustment for such items.

Since visibility representation of those items is modified, this PR also adjusts visibility rendering in `HirDisplay`.

[link]: a6603fc21d/crates/hir-def/src/nameres/path_resolution.rs (L101-L103)
2023-03-01 12:40:55 +00:00
bors
c386316fe0 Auto merge of #14185 - anergictcell:fix_14142, r=HKalbasi
Fix: Run doctests for structs with lifetime parameters from IDE

Fixes #14142: Doctests can't be triggered for structs with lifetimes

This MR adds lifetime parameters to the structs path for runnables so that they can be triggered from an IDE as well.

This is my first MR for rust-analyzer, please let me know if I should change something, either in code or the description here.
2023-02-28 09:52:03 +00:00
bors
a0be16b0b2 Auto merge of #14040 - HKalbasi:mir, r=HKalbasi
Beginning of MIR

This pull request introduces the initial implementation of MIR lowering and interpreting in Rust Analyzer.

The implementation of MIR has potential to bring several benefits:
- Executing a unit test without compiling it: This is my main goal. It can be useful for quickly testing code changes and print-debugging unit tests without the need for a full compilation (ideally in almost zero time, similar to languages like python and js). There is a probability that it goes nowhere, it might become slower than rustc, or it might need some unreasonable amount of memory, or we may fail to support a common pattern/function that make it unusable for most of the codes.
- Constant evaluation: MIR allows for easier and more correct constant evaluation, on par with rustc. If r-a wants to fully support the type system, it needs full const eval, which means arbitrary code execution, which needs MIR or something similar.
- Supporting more diagnostics: MIR can be used to detect errors, most famously borrow checker and lifetime errors,  but also mutability errors and uninitialized variables, which can be difficult/impossible to detect in HIR.
- Lowering closures: With MIR we can find out closure capture modes, which is useful in detecting if a closure implements the `FnMut` or `Fn` traits, and calculating its size and data layout.

But the current PR implements no diagnostics and doesn't support closures. About const eval, I removed the old const eval code and it now uses the mir interpreter. Everything that is supported in stable rustc is either implemented or is super easy to implement. About interpreting unit tests, I added an experimental config, disabled by default, that shows a `pass` or `fail` on hover of unit tests (ideally it should be a button similar to `Run test` button, but I didn't figured out how to add them). Currently, no real world test works, due to missing features including closures, heap allocation, `dyn Trait` and ... so at this point it is only useful for me selecting what to implement next.

The implementation of MIR is based on the design of rustc, the data structures are almost copy paste (so it should be easy to migrate it to a possible future stable-mir), but the lowering and interpreting code is from me.
2023-02-28 09:12:19 +00:00
hkalbasi
cd67589f63 beginning of MIR 2023-02-27 23:45:54 +03:30
Jonas Marcello
9942cc425b Fix 14142: Annotate lifetime paramaters in doctest runnables 2023-02-27 18:08:17 +01:00
shilangyu
44e47fe408 Add check for extra path segments after an angled one 2023-02-25 16:16:49 +01:00
Laurențiu Nicola
7e711da2f0 ⬆️ rust-analyzer 2023-02-20 10:14:12 +02:00
Ryo Yoshida
83e24fec98
Fix associated item visibility in block-local impls 2023-02-19 23:55:55 +09:00
Ryo Yoshida
443801755c
Refactor
- Remove unnecessary references and derefs
- Manual formatting
2023-02-19 23:55:49 +09:00
Lukas Wirth
026a8c976d Simplify 2023-02-15 13:38:42 +01:00
Lukas Wirth
4aee911ce4 Slim down GenericArgs by one usize once more 2023-02-14 17:41:16 +01:00
Lukas Wirth
853ae1927d Slim down GenericArgs by one usize 2023-02-14 17:40:24 +01:00
Lukas Wirth
4c2aef650a Slim down AssociatedTypeBinding by one usize 2023-02-14 17:40:24 +01:00
bors
41db8c2b59 Auto merge of #14151 - Veykril:smallvec, r=Veykril
internal: Enable smallvec's `union` feature
2023-02-14 16:24:21 +00:00
Lukas Wirth
a18ebf40cb Don't allocate the generic_args vec in hir_def::Path if it consists only of None args 2023-02-14 17:01:38 +01:00
Lukas Wirth
3c0f20a7bd internal: Enable smallvec's union feature 2023-02-14 17:01:01 +01:00
bors
44568007d1 Auto merge of #14128 - Veykril:parser, r=Veykril
internal: Improve parser recovery for delimited lists

Closes https://github.com/rust-lang/rust-analyzer/issues/11188, https://github.com/rust-lang/rust-analyzer/issues/10410, https://github.com/rust-lang/rust-analyzer/issues/10173

Should probably be merged after the stable release as this might get the parser stuck if I missed something
2023-02-14 12:59:39 +00:00
Lukas Wirth
4f6b5f41d4 Recover better for more delimited sequences 2023-02-14 13:52:15 +01:00
bors
2a57b01980 Auto merge of #14122 - lowr:patch/abort-macro-expansion-on-overflow, r=Veykril
fix: Don't expand macros in the same expansion tree after overflow

This patch fixes 2 bugs:

- In `Expander::enter_expand_id()` (and in code paths it's called), we never check whether we've reached the recursion limit. Although it hasn't been reported as far as I'm aware, this may cause hangs or stack overflows if some malformed attribute macro is used on associated items.
- We keep expansion even when recursion limit is reached. Take the following for example:

  ```rust
  macro_rules! foo { () => {{ foo!(); foo!(); }} }
  fn main() { foo!(); }
  ```

  We keep expanding the first `foo!()` in each expansion and would reach the limit at some point, *after which* we would try expanding the second `foo!()` in each expansion until it hits the limit again. This will (by default) lead to ~2^128 expansions.

  This is essentially what's happening in #14074. Unlike rustc, we don't just stop expanding macros when we fail as long as it produces some tokens so that we can provide completions and other services in incomplete macro calls.

This patch provides a method that takes care of recursion depths (`Expander::within_limit()`) and stops macro expansions in the whole macro expansion tree once it detects recursion depth overflow. To be honest, I'm not really satisfied with this fix because it can still be used in unintended ways to bypass overflow checks, and I'm still seeking ways such that misuses are caught by the compiler by leveraging types or something.

Fixes #14074
2023-02-14 07:37:53 +00:00
Laurențiu Nicola
354b1aaa50 Merge branch 'master' into sync-from-rust 2023-02-14 08:40:55 +02:00
Laurențiu Nicola
bc45c7659a ⬆️ rust-analyzer 2023-02-13 13:55:14 +02:00
Lukas Wirth
1be24e0899 internal: Improve parser recovery a bunch 2023-02-11 20:28:36 +01:00
Ryo Yoshida
ae7e62c50f
Don't expand macros in the same expansion tree after overflow 2023-02-11 18:19:08 +09:00
Lukas Wirth
e59487de38 Add tests for float access macro call inputs 2023-02-07 17:12:24 +01:00
Lukas Wirth
c6e7917d6e Fix up token_tree_to_syntax_node float split handling 2023-02-07 15:21:37 +01:00
Lukas Wirth
41a46a78f2 Make tt generic over the span data 2023-01-31 14:58:16 +01:00
bors
06981d4b10 Auto merge of #14062 - WaffleLapkin:сurrent_edition, r=Veykril
internal: Set "current" edition to 2021

:p
2023-01-31 11:03:49 +00:00
Maybe Waffle
249ea9502d Set "current" edition to 2021 2023-01-31 10:51:43 +00:00
Lukas Wirth
c65782e64a Parse macros allow_internal_unsafe attribute 2023-01-30 15:41:08 +01:00
Lukas Wirth
4a677e91aa minor: Remove unnecessary arg in LowerCtx::ast_id 2023-01-25 21:52:28 +01:00
Lukas Wirth
f8ed4d7ae4 Use lang item resolution instead of known paths 2023-01-21 19:03:36 +01:00
Lukas Wirth
1535881836 Replace SmolStr usage with lang item enum for lang items 2023-01-21 17:55:45 +01:00
Laurențiu Nicola
392a6ee422 Bump once_cell 2023-01-21 08:48:46 +02:00
bors
fa874627f0 Auto merge of #13969 - Veykril:workspace.dependencies, r=Veykril
Use workspace.dependencies to declare local dependencies
2023-01-17 10:29:27 +00:00
bors
62907858d5 Auto merge of #13964 - Veykril:workspace.package, r=Veykril
Specify authors, edition, license and rust-versian via workspace.package
2023-01-17 10:13:24 +00:00
Lukas Wirth
bed4db3c62 Use workspace.dependencies to declare local dependencies 2023-01-17 10:52:26 +01:00
hkalbasi
77efa0267d Don't compute layout if TargetDataLayout is not available 2023-01-16 22:43:27 +03:30
Lukas Wirth
e4858fe480 Specify authors, edition and license via workspace.package 2023-01-16 16:44:00 +01:00
Lukas Wirth
679df2adf1 Specify rust-version via workspace.package 2023-01-16 16:33:01 +01:00
bors
cdbe025232 Auto merge of #13922 - danieleades:loop-that-never-loops, r=lnicola
minor: loop-that-never-loops

closes #13921
2023-01-13 11:23:51 +00:00
Daniel Eades
7413a9954f interior-mutable types should be 'static' rather than 'const 2023-01-12 10:48:10 +00:00
daniel.eades
a3114c3697 move loop index inside iterator 2023-01-11 16:07:35 +00:00
Albert Larsan
3e0e51c108 Change src/test to tests in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00
Daniel Eades
95fc3ba41c fixup 2023-01-10 19:51:21 +00:00
Daniel Eades
ac3844a0bb a number of code simplifications 2023-01-10 18:48:51 +00:00
bors
c3b78f440e Auto merge of #13917 - Veykril:raw-attrs, r=Veykril
Split out hir-def attribute handling parts into hir-expand

This should help with `cfg_attr` handling for macro inputs
2023-01-10 17:35:37 +00:00
Daniel Eades
6153ea8dce loop-that-never-loops 2023-01-10 08:28:28 +00:00
Lukas Wirth
621e96bd6a Encode one level of cfg_attr in attr_id 2023-01-09 21:06:13 +01:00
arcnmx
25242fe93f ⬆️ rust-analyzer
Merge commit '368e0bb32f1178cf162c2ce5f7e10b7ae211eb26'
2023-01-09 10:36:22 -08:00
Lukas Wirth
68723043db Split out hir-def attribute handling parts into hir-expand 2023-01-09 19:29:28 +01:00
bors
e125bee055 Auto merge of #13890 - lowr:fix/unescape-inline-mod-name, r=Veykril
fix: unescape inline module names in module resolution

Fixes #13884
2023-01-09 15:07:06 +00:00
Ryo Yoshida
21ea0048cd
fix: unescape inline module names in module resolution 2023-01-04 18:22:01 +09:00
Daniel Eades
4f8ffd0ba4 remove unnecessary lifetimes that can be elided 2023-01-02 15:02:54 +00:00
Daniel Eades
efd2c20e96 remove useless conversions 2023-01-02 15:02:54 +00:00
Daniel Eades
cc80c5bd07 remove unnecessary lazy evaluations 2023-01-02 15:02:54 +00:00