Commit graph

664 commits

Author SHA1 Message Date
Jonas Schievink
6f19484c93 Support #[register_attr] and #[register_tool] 2021-05-20 20:40:02 +02:00
Jonas Schievink
df824c2f81 Rename ignore_attrs_on to skip_attrs 2021-05-20 20:18:53 +02:00
Jonas Schievink
9ac5a90522 Simplify 2021-05-20 20:08:39 +02:00
Jonas Schievink
036e5b2806 Refactor name resolution to resolve derive helpers 2021-05-20 19:56:04 +02:00
Jonas Schievink
f088606d89 Rename unexpanded_macros to unresolved_macros 2021-05-20 13:12:29 +02:00
Jonas Schievink
d4eb6708d9 Track in-scope derive helpers during nameres 2021-05-19 23:35:09 +02:00
Jonas Schievink
4a84c3fb21 Fix unresolved attribute fallback again 2021-05-19 22:08:34 +02:00
bors[bot]
49922cb2c3
Merge #8885 #8887
8885: internal: greatly simplify eager macro representation r=jonas-schievink a=jonas-schievink

- Share structures with lazy macros, make both use `MacroCallLoc`.
- Remove `intern_eager_expansion`, `EagerCallLoc`, `EagerMacroId`, and *many* matches on `MacroCallId`.
- Make a lot of FIXMEs obsolete since the code no longer distinguishes between eager and lazy macros.
- Add `EagerCallInfo`, which is `Some` for calls to eager macros and holds the argument or expansion result and the included file.

8887: fix: fix derive collection after unresolved attribute fallback r=jonas-schievink a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/pull/8882#issuecomment-844379170

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-19 19:07:05 +00:00
Jonas Schievink
274d813cff Fix derive collection after unresolved attribute fallback 2021-05-19 21:05:58 +02:00
Jonas Schievink
ea8555b155 Simplify eager macro representation 2021-05-19 20:19:08 +02:00
bors[bot]
1cf0794f5e
Merge #8882
8882: internal: resolve attributes in name resolution (minimal version) r=jonas-schievink a=jonas-schievink

Closes https://github.com/rust-analyzer/rust-analyzer/pull/7049

This should not have any observable effect, since we don't attempt to expand attribute macros yet, and I have implemented a fallback that treats items with unresolved attributes as if the attribute wasn't there.

Derive helpers are not yet resolved. `#![register_{attr,tool}]` are not yet supported.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-19 17:06:49 +00:00
Jonas Schievink
383635a13e Rewrite resolve_imports to use an iterator
This allows reusing the original vector's allocation
2021-05-19 19:05:03 +02:00
Jonas Schievink
aebb60de5c Restructure nameres loop to be a bit clearer 2021-05-19 18:56:00 +02:00
Jonas Schievink
3e186d4778 internal: resolve attributes in name resolution 2021-05-19 15:17:57 +02:00
bors[bot]
16b03d21dc
Merge #8871
8871: internal: Simplify `DefCollector::resolve_macros` r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-18 19:02:32 +00:00
Jonas Schievink
4884d9ec1d Simplify DefCollector::resolve_macros 2021-05-18 17:51:02 +02:00
ivan770
999217374f
Added cov mark 2021-05-17 11:37:24 +02:00
ivan770
a79b54ef73
Fix #8834 2021-05-16 20:05:52 +02:00
bors[bot]
a57bd59f35
Merge #8813
8813: Get some more array lengths! r=lf- a=lf-

This is built on #8799 and thus contains its changes. I'll rebase it onto master when that one gets merged. It adds support for r-a understanding the length of:

* `let a: [u8; 2] = ...`
* `let a = b"aaa"`
* `let a = [0u8; 4]`

I have added support for getting the values of byte strings, which was not previously there. I am least confident in the correctness of this part and it probably needs some more tests, as we currently have only one test that exercised that part (!).

Fixes #2922.

Co-authored-by: Jade <software@lfcode.ca>
2021-05-16 01:53:12 +00:00
Jade
de0ed9860d Address final feedback
* rename ConstExtension->ConstExt
* refactor a manual construction of a Const
2021-05-15 18:51:18 -07:00
Jade
78d6b88f21 Add more tests, refactor array lengths/consteval work
Fix #2922: add unknown length as a condition for a type having unknown.

Incorporate reviews:

* Extract some of the const evaluation workings into functions
* Add fixmes on the hacks
* Add tests for impls on specific array lengths (these work!!! 😁)
* Add tests for const generics (indeed we don't support it yet)
2021-05-14 01:39:28 -07:00
bors[bot]
9c8c72b7c4
Merge #8822
8822: minor: Cleanup imports r=Veykril a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-13 20:38:56 +00:00
bors[bot]
908cd23f81
Merge #8820
8820: fix: Return absolute paths in find_path if crate start is ambiguous r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-05-13 16:48:11 +00:00
Aleksey Kladov
ad0648dc95 Cleanup imports 2021-05-13 13:44:47 +03:00
Jade
e666589e63 Add support for lengths in array repeats, if they are literals
Now we will get the type of `[0u8; 4]`.
2021-05-12 21:22:46 -07:00
Jade
73023c0299 Support length for ByteStrings
I am not confident that my added byte string parsing is right.
2021-05-12 21:22:46 -07:00
Jade
8b147624ff Add lowering of array lengths in types
Now e.g.

```rust
fn a(b: [u8; 2]) {
}
```

will know about the length of b.
2021-05-12 21:22:46 -07:00
Lukas Wirth
69e0b10150 Return absolute paths in find_path if crate start is ambiguous 2021-05-13 02:53:32 +02:00
bors[bot]
da80dfc022
Merge #8398
8398: Fix inference with conditionally compiled tails r=flodiebold a=DJMcNab

Fixes #8378

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2021-05-11 19:01:39 +00:00
Jonas Schievink
da08198bc9 Rewrite attr.rs to allow using syntax-based indices 2021-05-10 21:50:42 +02:00
Jonas Schievink
a87bec5148 Move AttrId back into hir_def 2021-05-10 16:35:06 +02:00
Jonas Schievink
fd5a1d1765 Test that none of the macros are reparsed 2021-05-09 16:39:47 +02:00
Jonas Schievink
9cf8d325a2 Precompute macro fragment kind 2021-05-09 01:36:06 +02:00
Jonas Schievink
20ae41c1a1 Reuse database in LowerCtx 2021-05-06 23:23:50 +02:00
Aleksey Kladov
c4f9cb9b53 Update crates/hir_def/src/nameres/tests/incremental.rs
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-06 20:00:43 +02:00
Aleksey Kladov
548e5a5c29 internal: add failing incremental test 2021-05-06 20:00:11 +02:00
Jonas Schievink
976a3226fe Don't store call-site text offsets in hygiene info 2021-05-06 19:59:54 +02:00
Lukas Tobias Wirth
5a78d96d0e Fix block comment intra doc link injection ranges 2021-05-04 13:51:57 +02:00
Daniel McNab
ebbcf9f458 Fix inference with conditionally compiled tails
Fixes #8378
2021-05-03 14:13:05 +01:00
Jonas Schievink
6873920c4f find_path: check only crate-level prelude 2021-04-30 18:41:18 +02:00
Jonas Schievink
0414b65319 Remove ItemTree::all_inner_items 2021-04-21 18:10:25 +02:00
Jonas Schievink
7b7d051e81 Add failing local items test 2021-04-21 17:57:45 +02:00
Jonas Schievink
59630977a5 Fix some find_path bugs around inner items 2021-04-19 19:50:11 +02:00
Aleksey Kladov
5f89a60f1a fix: false positive about inner attrs in docs
closes #8541
2021-04-19 17:11:49 +03:00
bors[bot]
e4f7f1e1bd
Merge #8462
8462: Expand macros at type position r=jonas-schievink a=cynecx



Co-authored-by: cynecx <me@cynecx.net>
2021-04-19 13:01:30 +00:00
Jonas Schievink
b777d46ae6 Fix visibility of items in block modules 2021-04-19 01:06:04 +02:00
cynecx
6ed2fd233b hir_ty: keep body::Expander in TyLoweringContext 2021-04-18 19:56:13 +02:00
cynecx
3d39e77003 hir_def: various cleanups 2021-04-18 18:35:45 +02:00
cynecx
7ed42a3a52 hir_def: refactor expand_macro_type and cleanups 2021-04-17 17:38:45 +02:00
cynecx
14918a3870 hir_def: ignore ast::Type in file_item_tree query 2021-04-17 16:24:56 +02:00
cynecx
cf3b4f1e20 hir_ty: Expand macros at type position 2021-04-17 16:24:56 +02:00
Jonas Schievink
9e8feeb94a Fix TestDB::module_at_position with submodules 2021-04-17 03:34:05 +02:00
bors[bot]
2009556472
Merge #8542
8542: Include path in `unresolved-macro-call` diagnostic r=matklad a=jonas-schievink



Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-04-16 20:52:56 +00:00
Jonas Schievink
543d4ef7c5 Fix primitive shadowing with inner items 2021-04-16 19:28:22 +02:00
Jonas Schievink
ff858376aa Include path in unresolved-macro-call diagnostic 2021-04-16 15:48:03 +02:00
Jonas Schievink
d073c3e56d Remove unneeded annotations from find_path tests 2021-04-15 19:24:09 +02:00
Jonas Schievink
6acd0ac51a Make find_path tests adhere to style guide 2021-04-15 18:32:19 +02:00
bors[bot]
9beed98f2a
Merge #8432
8432: decl_check: consider outer scopes' allows r=jonas-schievink a=lf-

Fix #8417. Also makes it less noisy about no_mangle annotated stuff the
user can do nothing about.

Note: this still is broken with bitfield! macros. A repro in an ignore
test is included here. I believe this bug is elsewhere, and I don't
think I can work around it here.

I would like help filing the remaining bug, as it does actually affect
users, but I don't know how to describe the behaviour (or even if it
is unintended).

Co-authored-by: Jade <software@lfcode.ca>
2021-04-13 12:02:26 +00:00
Jonas Schievink
e2c1da36f5 Support macros in pattern position 2021-04-11 01:25:50 +02:00
Jonas Schievink
30ce8b20ec Avoid an unnecessary collect 2021-04-09 22:52:13 +02:00
bors[bot]
343b14f7e0
Merge #8450
8450: Don't ignore unnamed consts when looking for definitions r=Veykril a=Veykril

Fixes #8448
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-04-09 15:16:36 +00:00
Lukas Wirth
ec2895e956 Insert unnamed consts to ChildBySource DynMap 2021-04-09 17:14:48 +02:00
Jonas Schievink
75614b126b Resolve prelude and crate root names in the root DefMap 2021-04-09 15:29:42 +02:00
bors[bot]
3b1692c3e8
Merge #8443 #8446
8443: Rewrite `#[derive]` removal code to be based on AST r=jonas-schievink a=jonas-schievink

We now remove any `#[derive]` before and including the one we want to expand, in the `macro_arg` query.

The same infra will be needed by attribute macros (except we only remove the attribute we're expanding, not any preceding ones).

Part of https://github.com/rust-analyzer/rust-analyzer/issues/8434 (doesn't implement the cfg-expansion yet, because that's more difficult)

8446: Undo path resolution hack for extern prelude r=jonas-schievink a=jonas-schievink

Reverts the change made in https://github.com/rust-analyzer/rust-analyzer/pull/7959

We don't populate the extern prelude for block DefMaps anymore,
so this is unnecessary

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-04-09 12:53:49 +00:00
Jonas Schievink
4ea5f690bc Undo path resolution hack for extern prelude
We don't populate the extern prelude for block DefMaps anymore,
so this is unnecessary
2021-04-09 14:46:52 +02:00
Jonas Schievink
c0dd36fd42 Store #[derive] attribute ID along macro invoc 2021-04-09 13:38:01 +02:00
Jonas Schievink
546da15972 Rename Attrs index field to id 2021-04-09 13:36:22 +02:00
Jonas Schievink
3fcdd1bcdf Add AttrId to track attribute sources 2021-04-09 13:32:03 +02:00
Jade
4529f1be81 decl_check: consider outer scopes' allows
Fix #8417. Also makes it less noisy about no_mangle annotated stuff the
user can do nothing about.

Note: this still is broken with bitfield! macros. A repro in an ignore
test is included here. I believe this bug is elsewhere, and I don't
think I can work around it here.
2021-04-08 14:43:19 -07:00
Jonas Schievink
86b7861612 Use named fields in MacroCallKind 2021-04-08 20:43:07 +02:00
Jonas Schievink
014774764a Track recursion limit when expanding custom derive 2021-04-08 18:49:30 +02:00
Jonas Schievink
053dac88ca Update OUT_DIR diagnostic to match setting 2021-04-07 20:19:28 +02:00
Jonas Schievink
7c1c0e6fea Collect trait impls inside unnamed consts 2021-04-07 03:33:22 +02:00
Jonas Schievink
f04f38d3d7 nameres: collect unnamed consts 2021-04-07 03:12:40 +02:00
Jonas Schievink
035d84558c Avoid O(n²) when constructing AttrSourceMap 2021-04-06 22:25:44 +02:00
Jonas Schievink
0d4c931416 Lower attributes on tuple fields 2021-04-06 20:19:53 +02:00
Jonas Schievink
e9752308bb infer: remove record_field_resolutions field
It stores no useful data, since we can derive all fields from
`variant_resolutions`
2021-04-06 17:59:18 +02:00
Jonas Schievink
a25fbdb30a Intern TypeRefs stored in Body
Minor improvement to memory usage (1 MB or so)
2021-04-06 16:07:45 +02:00
Alexandru Macovei
32304d14a1 Use Box'es to reduce the size of hir_def::expr::Pat from 112 to 64 bytes on 64bit 2021-04-06 16:01:31 +03:00
Alexandru Macovei
fb1f544e24 Use Box'es to reduce size of hir_def::expr::Expr from 128 to 72 bytes (on 64bit systems)
Rationale: only a minority of variants used almost half the size.
By keeping large members (especially in Option) behind a box
the memory cost is only payed when the large variants are needed.

This reduces the size Vec<Expr> needs to allocate.
2021-04-06 16:01:31 +03:00
bors[bot]
72781085bb
Merge #8352
8352: Remove dead legacy macro expansion code r=lnicola a=brandondong

I was investigating some unrelated macro issue when I noticed this dead code. This legacy macro expansion logic was changed in https://github.com/rust-analyzer/rust-analyzer/pull/8128.

Co-authored-by: Brandon <brandondong604@hotmail.com>
2021-04-05 19:00:27 +00:00
Brandon
4dbec2d545 Remove dead legacy macro expansion code 2021-04-05 11:47:06 -07:00
Jonas Schievink
b57462d60d Interned<T>: Only hash the pointer 2021-04-05 17:07:53 +02:00
Jonas Schievink
a0b50bcf1e Make impl_internable! macro public 2021-04-05 16:59:13 +02:00
bors[bot]
c2be91dcd8
Merge #8245
8245: Properly resolve intra doc links in hover and goto_definition r=matklad a=Veykril

Unfortunately involves a bit of weird workarounds due to pulldown_cmark's incorrect lifetimes on `BrokenLinkCallback`... I should probably open an issue there asking for the fixes to be pushed to a release since they already exist in the repo for quite some time it seems.

Fixes #8258, Fixes #8238

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-04-05 12:30:20 +00:00
Jonas Schievink
6f1ee9a7f4 simplify visibility.rs 2021-04-05 04:27:57 +02:00
Jonas Schievink
7c0c713a10 Intern GenericParams
Also share the same instance between `ItemTree` and `generic_params`
query.
2021-04-05 03:50:10 +02:00
Jonas Schievink
adcf18e27d Add GenericParams::shrink_to_fit
Reduces memory usage by over 10 MB
2021-04-05 03:32:43 +02:00
Jonas Schievink
24e876b52e Intern more TypeRefs in generics
Saves ~3 MB
2021-04-05 02:03:37 +02:00
Aleksey Kladov
d1474ae518 Check if bitflags deps pulls its weight
Bitflags is generally a good dependency -- it's lightweight, well
maintained and embraced by the ecosystem.

I wonder, however, do we really need it? Doesn't feel like it adds much
to be honest.
2021-04-04 12:06:01 +03:00
bors[bot]
c9bcbf9a43
Merge #8324
8324: Add `Body::shrink_to_fit` r=jonas-schievink a=jonas-schievink

Saves ~15 MB

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-04-04 01:27:14 +00:00
Jonas Schievink
1da6d0bed9 Add Body::shrink_to_fit 2021-04-04 03:26:16 +02:00
Jonas Schievink
9b13e1bb91 Only remember blocks that have a DefMap 2021-04-04 03:16:26 +02:00
bors[bot]
4c8ee9a531
Merge #8322
8322: Access a body's block def maps via a method r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-04-04 01:04:44 +00:00
Jonas Schievink
d8bf9bef80 Access a body's block def maps via a method 2021-04-04 03:03:18 +02:00
Jonas Schievink
f774a56af2 Use exhaustive matches in shrink_to_fit impls 2021-04-04 02:56:11 +02:00
Jonas Schievink
3abcdc03ba Make ast_to_token_tree infallible
It could never return `None`, so reflect that in the return type
2021-04-04 01:46:45 +02:00
Jonas Schievink
d1bce6070d Use shrink_to_fit to reduce DefMap sizes 2021-04-03 23:45:27 +02:00
Jonas Schievink
ee4b5a34d8 Use bitflags to compress function properties
Very minor savings, only 1 MB or so
2021-04-03 20:58:42 +02:00
Jonas Schievink
f7e6b186e1 Intern ModPath in Import
Minor savings only
2021-04-03 20:57:25 +02:00
Edwin Cheng
20d55ce44d Allow include! an empty content file 2021-04-03 12:50:55 +08:00
Jonas Schievink
5742cdf3f1 Support #[rustc_builtin_macro = "builtin_name"] 2021-04-03 03:13:04 +02:00
Jonas Schievink
85757be59a Allow interning strings 2021-04-03 01:00:45 +02:00
Jonas Schievink
e73d26fa62 Stop using an upgradeable read lock in interning
Only one upgradeable read lock can be handed out at the same time, and
we never acquire a non-upgradeable read lock, so this has no benefit
over just using a write lock in the first place.
2021-04-02 20:46:37 +02:00
Jonas Schievink
7ceaba21df Only populate prelude for crate-level DefMaps 2021-04-02 19:00:26 +02:00
Jonas Schievink
6e227b80a7 Remove ?Sized on PartialEq/Eq impls 2021-04-02 18:26:34 +02:00
Jonas Schievink
76452956e4 Split Intern::drop into hot and cold path 2021-04-02 18:11:08 +02:00
Jonas Schievink
afd83e0686 Remove unnecessary region, relax Sized bounds 2021-04-01 22:24:40 +02:00
Jonas Schievink
39d992ef55 Intern Attr, MacroCall and Path components 2021-04-01 20:35:21 +02:00
Jonas Schievink
b00266b79f Global TypeRef/TraitRef interning 2021-04-01 19:46:43 +02:00
Edwin Cheng
6a3f2ce76c Fix block inner item defined in macro 2021-04-01 03:45:21 +08:00
bors[bot]
c69f6f31d1
Merge #8266
8266: Fix generic arguments being incorrectly offset in qualified trait casts r=flodiebold a=Veykril

We reverse the segments and generic args of the lowered path after building it, this wasn't accounted for when inserting the self parameter in `Type as Trait` segments.

Fixes #5886

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-31 09:52:47 +00:00
Lukas Wirth
6f0575f08a Fix generic arguments being incorrectly offset in qualified trait casts 2021-03-30 23:23:00 +02:00
Lukas Wirth
8d786dc4c3 Replace Range<usize> usage with TextRange 2021-03-30 22:42:21 +02:00
Lukas Wirth
9a327311e4 Implement basic Documentation source to syntax range mapping 2021-03-30 17:20:43 +02:00
Lukas Wirth
b4bb774381 Remove TraitRef::Error 2021-03-29 18:41:21 +02:00
Lukas Wirth
c2a63b97a8 Rename target_ty to self_ty 2021-03-29 17:47:47 +02:00
Lukas Wirth
bb6e1bf811 Lower traits to TraitRef instead of TypeRef 2021-03-29 17:11:28 +02:00
Edwin Cheng
7729879118 Remove unused test fixtures 2021-03-28 10:41:18 +08:00
Edwin Cheng
a193666361 Basic Support Macro 2.0 2021-03-27 13:44:54 +08:00
Edwin Cheng
8ce15b02de Fix recursive macro statement expansion 2021-03-26 04:21:15 +08:00
bors[bot]
d7db38fff9
Merge #7907
7907: Autoderef with visibility r=cynecx a=cynecx

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/7841.

I am not sure about the general approach here. Right now this simply tries to check whether the autoderef candidate is reachable from the current module. ~~However this doesn't exactly work with traits (see the `tests::macros::infer_derive_clone_in_core` test, which fails right now).~~ see comment below

Refs:

- `rustc_typeck` checking fields: 66ec64ccf3/compiler/rustc_typeck/src/check/expr.rs (L1610) 


r? @flodiebold

Co-authored-by: cynecx <me@cynecx.net>
2021-03-24 22:37:48 +00:00
cynecx
96c88680b2 hir_def: move visibility queries from hir_ty to hir_def 2021-03-24 23:00:03 +01:00
Jonas Schievink
1d5d44f7f7 Merge bang-macros and derives in name resolution 2021-03-23 17:23:10 +01:00
Jonas Schievink
2633e23f2b resolver: manually traverse nested block scopes 2021-03-22 18:55:51 +01:00
Kirill Bulatov
129353255c Code review fixes 2021-03-22 15:15:53 +02:00
Kirill Bulatov
3a4e99115d Do not revisit recursively imported modules 2021-03-22 00:46:52 +02:00
bors[bot]
31ed164161
Merge #8134
8134: Correct the paths of submodules from the include! macro r=edwin0cheng a=sticnarf

This PR should fix #7846. It mostly follows the instructions from @edwin0cheng in that issue.

Co-authored-by: Yilin Chen <sticnarf@gmail.com>
2021-03-21 17:57:45 +00:00
Yilin Chen
7b693470c4
check is_include_macro only when attr_path is not specified
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
2021-03-22 01:54:05 +08:00
bors[bot]
d51cf133f6
Merge #8135
8135: more clippy::{perf, complexity, style} fixes r=Veykril a=matthiaskrgr



Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
2021-03-21 15:49:31 +00:00
bors[bot]
5bb65bb496
Merge #8128
8128: Expand legacy-scoped macro during collection r=jonas-schievink a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/8120



Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-21 15:21:11 +00:00
Yilin Chen
3bb9efb6b7
use the included file as the source of expanded include macro
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
2021-03-21 23:02:01 +08:00
Matthias Krüger
ae7e55c1dd clippy::complexity simplifications related to Iterators 2021-03-21 13:13:34 +01:00
Matthias Krüger
3d9b3a8575 remove more redundant clones (clippy::redundant_clone()) 2021-03-21 12:10:39 +01:00
Jonas Schievink
5322cd830e Expand legacy-scoped macro during collection 2021-03-21 01:45:24 +01:00
Lukas Wirth
64957acb5f Fix incorrect scoping in while expressions 2021-03-21 01:28:42 +01:00
Lukas Wirth
cbd325707b Track labels in scopes 2021-03-21 01:02:01 +01:00
Jonas Schievink
636de3c709 Add AttrsWithOwner and clean up source_map 2021-03-19 21:23:57 +01:00
Jonas Schievink
93aeb16eb2 Return Either from MacroDefId::ast_id 2021-03-19 19:56:13 +01:00
Jonas Schievink
cf494a515f Fix handling of #![cfg] in outline module file 2021-03-19 18:24:04 +01:00
Jonas Schievink
506467b4c8 Add builtin macro-like attributes 2021-03-19 14:33:31 +01:00
Jonas Schievink
54c78c96db Rename derive-specific APIs 2021-03-19 14:23:13 +01:00
bors[bot]
7200b994c9
Merge #8097
8097: Parse extended_key_value_attributes r=jonas-schievink a=Veykril

Companion PR https://github.com/rust-analyzer/ungrammar/pull/31

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-19 11:38:40 +00:00
Lukas Wirth
4771a56791 Parse extended_key_value_attributes 2021-03-19 02:13:46 +01:00
Jonas Schievink
fcbaf585cb Document fields of ModuleId 2021-03-19 00:06:35 +01:00
bors[bot]
b70bea0d79
Merge #8083
8083: Track source file IDs in source mapping of Attrs r=jonas-schievink a=Veykril

Fixes the panics/incorrect injection highlighting of outline module declarations until we figure out a nicer source mapping strategy for attributes.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-18 19:26:10 +00:00
Jonas Schievink
6489e5b785 Add test 2021-03-18 20:04:20 +01:00
Jonas Schievink
268f45a099 Record custom derive helpers in DefMap
Also clean up proc macro attribute parsing a bit
2021-03-18 19:56:37 +01:00
Jonas Schievink
c05a1a6e37 Store an AstId for procedural macros 2021-03-18 16:11:18 +01:00
Jonas Schievink
b84efbaacf Make MacroDefId's AstId mandatory when possible 2021-03-18 15:37:14 +01:00
bors[bot]
d3da042a62
Merge #8082
8082: Proper handle inner recursive macro rules cases r=edwin0cheng a=edwin0cheng

Fixes #7645

cc @jonas-schievink 

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-18 12:25:44 +00:00
Edwin Cheng
13f30e9ef5 Handle inner recursive macro rules cases 2021-03-18 20:19:15 +08:00
Lukas Wirth
d41a1690d2 Track source file IDs in source mapping of Attrs 2021-03-18 13:16:27 +01:00
Jonas Schievink
5fbb97a0f0 Rename item_tree query to file_item_tree 2021-03-18 01:53:37 +01:00
Jonas Schievink
759f8c83e5 Make ItemTreeId its own type 2021-03-18 01:53:22 +01:00
Jonas Schievink
b5cb2829a4 Avoid cloning CfgOptions 2021-03-18 01:41:38 +01:00
Jonas Schievink
94b3b32c98 Support #[cfg] on all associated items 2021-03-18 01:28:55 +01:00
bors[bot]
afcc0da3a1
Merge #8075
8075: Fix `use crate as <name>;` imports r=jonas-schievink a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/4644

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-17 21:25:25 +00:00
Jonas Schievink
a54564378b Fix use crate as <name>; imports 2021-03-17 22:24:51 +01:00
Jonas Schievink
5f80364ede Improve diagnostic when including nonexistent file 2021-03-17 21:56:09 +01:00
Jonas Schievink
c64adfe706 Use first early expansion error during nameres 2021-03-17 21:41:32 +01:00
Jonas Schievink
ba0e4c745d Apply #[cfg]s when computing function signatures 2021-03-17 18:28:27 +01:00
Jonas Schievink
622c780a8c ItemTree: lower attributes on fn parameters 2021-03-17 18:28:27 +01:00
bors[bot]
edf11480ce
Merge #8065
8065: Better handling of block doc comments r=Veykril a=Veykril

Moves doc string processing to `Attrs::docs`, as we need the indent info from all comments before being able to know how much to strip

Closes #7774

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-17 16:00:43 +00:00
Lukas Wirth
5734b347dd Fix incorrect newline emission in Attrs::docs 2021-03-17 17:00:08 +01:00
Jonas Schievink
cb530e7c97 Handle #[cfg] on call arguments 2021-03-17 15:10:46 +01:00
Lukas Wirth
ec824a92d0 Better handling of block doc comments 2021-03-17 14:48:57 +01:00
bors[bot]
0fbfab3b45
Merge #8059
8059: Move doc-comment highlight injection from AST to HIR r=matklad,jonas-schievink a=Veykril

Fixes #5016

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-17 11:13:54 +00:00
Lukas Wirth
cdfb5c353f Remove quadratic attr source lookup 2021-03-17 11:22:40 +01:00
bors[bot]
f7fbea509f
Merge #8063
8063: couple clippy::complexity fixes r=matklad a=matthiaskrgr

avoid redundant `.into()` calls to convert T into identical T (`let x: String = String::from("hello").into();`)
use `if let Some(x)` instead of `.is_some()` + `.unwrap()`
don't clone Copy types
remove redundant wrapped ?s:  `Some(Some(3)?)` can just be `Some(3)`
use `.map(|x| y)` instead of `and_then(|x| Some(y)` on `Option`s

Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
2021-03-17 08:12:34 +00:00
bors[bot]
6fcb5d772f
Merge #8048
8048: Fix missing unresolved macro diagnostic in function body r=edwin0cheng a=brandondong

This was an issue I found while working on https://github.com/rust-analyzer/rust-analyzer/pull/7970.

**Reproduction:**
1. Call a non-existent macro in a function body.
```
fn main() {
  foo!();
}
```
2. No diagnostics are raised. An unresolved-macro-call diagnostic is expected.
3. If the macro call is instead outside of the function body, this works as expected.

I believe this worked previously and regressed in https://github.com/rust-analyzer/rust-analyzer/pull/7805.

**Behavior prior to https://github.com/rust-analyzer/rust-analyzer/pull/7805:**
- The unresolved-macro-call diagnostic did not exist. Instead, a macro-error diagnostic would be raised with the text "could not resolve macro [path]".
- This was implemented by adding an error to the error sink (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8L657).
- The error was propagated through 1a82af3527/crates/hir_def/src/body.rs (L123) eventually reaching 1a82af3527/crates/hir_def/src/body/lower.rs (L569).

**Behavior after:**
- Instead of writing to the error sink, an UnresolvedMacro error is now returned (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8R631).
- The parent caller throws away the error as its function signature is `Option<MacroCallId>` (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8R604).
- We instead now reach the warn condition (1a82af3527/crates/hir_def/src/body.rs (L124)) and no diagnostics are created in 1a82af3527/crates/hir_def/src/body/lower.rs (L575).

**Fix:**
- Make sure to propagate the UnresolvedMacro error. Report the error using the new unresolved-macro-call diagnostic.


Co-authored-by: Brandon <brandondong604@hotmail.com>
2021-03-17 07:20:28 +00:00
Brandon
a79b5673e8 Follow established ErrorEmitted pattern 2021-03-16 23:31:14 -07:00
Matthias Krüger
966c23f529 avoid converting types into themselves via .into() (clippy::useless-conversion)
example: let x: String = String::from("hello world").into();
2021-03-17 01:27:56 +01:00
Lukas Wirth
c766492d26 Properly handle doc attributes in doc-comment highlight injection 2021-03-16 21:15:26 +01:00
Lukas Wirth
3daa302cd3 Fix attribute index assignment in cfg_attr resolution 2021-03-16 19:55:40 +01:00
Lukas Wirth
11e9bc60a2 Move doc-comment highlight injection from AST to HIR 2021-03-16 18:57:47 +01:00
bors[bot]
1a82af3527
Merge #7900 #8000
7900: show function params in completion detail r=matklad a=JoshMcguigan

This resolves #7842 by updating the detail for function completions from `-> T` to `fn(T, U) -> V`. I added an expicit unit test for this, `ide_completion::render::fn_detail_includes_args_and_return_type`, which passes.

Lots of other unit tests fail (~60 of them) due to this change, although I believe the failures are purely cosmetic (they were testing the exact format of this output). I'm happy to go update those tests, but before I do that I'd like to make sure this is in fact the format we want for the detail?

edit - I realized `UPDATE_EXPECT=1 cargo test` automatically updates `expect!` tests. Big 👍 to whoever worked on that! So I'll go ahead and update all these tests soon. But I still would like to confirm `fn(T, U) -> V` is the desired content in the `detail` field. 

8000: Use hir formatter for hover text r=matklad a=oxalica

Fix #2765 , (should) fix #4665

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
Co-authored-by: oxalica <oxalicc@pm.me>
2021-03-16 08:05:24 +00:00
Brandon
0103f5df8f Fix missing unresolved macro diagnostic in function body 2021-03-16 00:52:58 -07:00
Edwin Cheng
8e07b23b84 Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
bors[bot]
47b74cadf9
Merge #7970
7970: Fix incorrect diagnostics for failing built in macros r=jonas-schievink a=brandondong

**Reproduction:**
1. Use a built in macro in such a way that rust-analyzer fails to expand it. For example:

**lib.rs**
```
include!("<valid file but without a .rs extension so it is not indexed by rust-analyzer>");
```
2. rust-analyzer highlights the macro call and says the macro itself cannot be resolved even though include! is in the standard library (unresolved-macro-call diagnostic).
3. No macro-error diagnostic is raised.

**Root cause for incorrect unresolved-macro-call diagnostic:**
1. collector:collect_macro_call is able to resolve include! in legacy scope but the expansion fails. Therefore, it's pushed into unexpanded_macros to be retried with module scope.
2. include! fails at the resolution step in collector:resolve_macros now that it's using module scope. Therefore, it's retained in unexpanded_macros.
3. Finally, collector:finish tries resolving the remaining unexpanded macros but only with module scope. include! again fails at the resolution step so a diagnostic is created.

**Root cause for missing macro-error diagnostic:**
1. In collector:resolve_macros, directive.legacy is None since eager expansion failed in collector:collect_macro_call. The macro_call_as_call_id fails to resolve since we're retrying in module scope. Therefore, collect_macro_expansion is not called for the macro and no macro-error diagnostic is generated.

**Fix:**
- In collector:collect_macro_call, do not add failing built-in macros to the unexpanded_macros list and immediately raise the macro-error diagnostic. This is in contrast to lazy macros which are resolved in collector::resolve_macros and later expanded in collect_macro_expansion where a macro-error diagnostic may be raised.

Co-authored-by: Brandon <brandondong604@hotmail.com>
Co-authored-by: brandondong <brandondong604@hotmail.com>
2021-03-15 18:24:22 +00:00
brandondong
ebb10da563
Update crates/hir_def/src/nameres/collector.rs
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-15 11:16:58 -07:00
oxalica
87171238c6
Use hir formatter more 2021-03-16 01:04:33 +08:00
oxalica
ef416e0154
Impl HirDisplay for function hover message 2021-03-16 01:04:20 +08:00
oxalica
2bb8956a10
Introduce FunctionQualifier for hir::FunctionData 2021-03-16 01:03:07 +08:00
Laurențiu Nicola
88cee24c6c Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
Aleksey Kladov
f7156cb0ae Simplify source maps for fields 2021-03-15 15:38:50 +03:00
Brandon
2df637f419 Fix incorrect diagnositics for failing built in eager macros 2021-03-13 21:28:10 -08:00
Brandon
4245973e24 Fix spelling error 2021-03-13 20:07:20 -08:00
Florian Diebold
c82d1823a1 Create TraitEnvironment through a query 2021-03-13 20:38:45 +01:00
Jonas Schievink
1848bd0fa0 Handle cfg_attr gating multiple attributes 2021-03-13 18:18:42 +01:00
Jonas Schievink
72785fb94d Extend cfg_attr test 2021-03-13 18:18:05 +01:00
Jonas Schievink
2b5ea5c730 Simplify hir_def TestDB 2021-03-13 02:24:53 +01:00
Jonas Schievink
8447f101ac Remove ItemTree::source
`HasSource` should be used instead
2021-03-12 23:54:29 +01:00
Jonas Schievink
c2622c9228 Prefer names from outer DefMap over extern prelude 2021-03-10 16:33:18 +01:00
Jonas Schievink
7beec8fda1 Stop fetching ItemTrees for no reason 2021-03-10 02:32:16 +01:00
Aleksey Kladov
842d8ad9c8 Compilation speed 2021-03-09 22:30:58 +03:00
Jonas Schievink
b885e6bdee Delete ContainerId 2021-03-09 19:09:02 +01:00
Jonas Schievink
a430549aa6 Stop using ContainerId in AssocContainerId 2021-03-09 18:27:23 +01:00
Jonas Schievink
12f6bdcfd9 Check ancestor maps when computing traits in scope 2021-03-09 18:27:23 +01:00
Jonas Schievink
6be4f30cae Remove item_scope field from Body 2021-03-09 18:27:23 +01:00