Commit graph

664 commits

Author SHA1 Message Date
Jonas Schievink
9a320bcf38 Support the new rustc_builtin_macro syntax 2021-09-09 21:32:41 +02:00
Aleksey Kladov
104cd0ce88 internal: make name consistent with usage 2021-09-06 18:34:03 +03:00
Jonas Schievink
8e736da456 Recover from statement macro expansion errors 2021-09-06 00:16:12 +02:00
Aleksey Kladov
dbb702cfc1 internal: remove accidental code re-use
FragmentKind played two roles:

* entry point to the parser
* syntactic category of a macro call

These are different use-cases, and warrant different types. For example,
macro can't expand to visibility, but we have such fragment today.

This PR introduces `ExpandsTo` enum to separate this two use-cases.

I suspect we might further split `FragmentKind` into `$x:specifier` enum
specific to MBE, and a general parser entry point, but that's for
another PR!
2021-09-05 22:36:36 +03:00
Jonas Schievink
d6a12b491f Don't dump DefMaps to build the panic context 2021-09-05 20:42:22 +02:00
Jonas Schievink
7d67c71c34 Add panic info for impl_trait/trait_data 2021-09-05 19:19:34 +02:00
bors[bot]
487078feb5
Merge #10155
10155: Minor: replace old name `CrateDefMap` in comments r=jonas-schievink a=toyboot4e

This PR replaces the old name `CrateDefMap` in comments with the new name `DefMap`. The renaming was done in [57a82fb0](https://github.com/rust-analyzer/rust-analyzer/commit/57a82fb0) (Jan 2021).

I didn't touch the working code ([CrateDefMapQueryQuery][QQ]). Thank you.

[QQ]: https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_db/src/apply_change.rs#L126


Co-authored-by: toyboot4e <toyboot4e@gmail.com>
2021-09-05 16:57:46 +00:00
Jonas Schievink
65bb5d7511 Add crate name to nameres panic context 2021-09-05 18:48:34 +02:00
toyboot4e
89e46b40c3 Minor: replace old name CrateDefMap 2021-09-05 19:22:34 +09:00
Lukas Wirth
36a5ce9790 minor: fix some clippy lints 2021-09-03 16:00:50 +02:00
Jonas Schievink
b1a4784c95 Augment panic context when resolving path 2021-08-31 13:42:46 +02:00
Dezhi Wu
ba0947dded switch log crate to tracing 2021-08-30 15:11:42 +08:00
bors[bot]
99e67f8998
Merge #10044
10044: minor: Ignore text and bench attributes again r=Veykril a=Veykril

Reverts part of #9943

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-27 20:19:56 +00:00
Lukas Wirth
798c53925a Ignore text and bench attributes again 2021-08-27 22:19:04 +02:00
bors[bot]
97409e5fc8
Merge #9970
9970: feat: Implement attribute input token mapping, fix attribute item token mapping r=Veykril a=Veykril

![image](https://user-images.githubusercontent.com/3757771/130328577-4c1ad72c-51b1-47c3-8d3d-3242ec44a355.png)

The token mapping for items with attributes got overwritten partially by the attributes non-item input, since attributes have two different inputs, the item and the direct input both.
This PR gives attributes a second TokenMap for its direct input. We now shift all normal input IDs by the item input maximum(we maybe wanna swap this see below) similar to what we do for macro-rules/def. For mapping down we then have to figure out whether we are inside the direct attribute input or its item input to pick the appropriate mapping which can be done with some token range comparisons.

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-27 19:30:36 +00:00
Lukas Wirth
0f3617f76f fix: Fix multiple derives in one attribute not expanding all in expand_macro 2021-08-26 03:32:45 +02:00
Lukas Wirth
3f9f63c1bd Improve expand_macro 2021-08-26 02:36:33 +02:00
Lukas Wirth
d99b81f839 Expand derive macros under cursor in Expand Macro Recursively 2021-08-24 16:33:52 +02:00
bors[bot]
996300f4a0
Merge #9989
9989: Fix two more “a”/“an” typos (this time the other way) r=lnicola a=steffahn

Follow-up to #9987

you guys are still merging these fast 😅

_this time I thought – for sure – that I’d get this commit into #9987 before it’s merged…_

Co-authored-by: Frank Steffahn <frank.steffahn@stu.uni-kiel.de>
2021-08-22 16:10:48 +00:00
Frank Steffahn
5f5d45468d Fix two more “a”/“an” typos (this time the other way) 2021-08-22 17:36:58 +02:00
Florian Diebold
424dda8113 Refactor & improve handling of overloaded binary operators
Fixes #9971. Also records them as method resolutions, which we could use
later.
2021-08-22 17:35:50 +02:00
Lukas Wirth
5fb8c0ddfd Remove MappedSubtree 2021-08-21 18:19:18 +02:00
Lukas Wirth
177c70128c Map attribute input tokens correctly 2021-08-21 18:13:41 +02:00
Lukas Wirth
351cec0cb4 Do not replace items annotated with builtin attrs with the attr input 2021-08-20 13:50:06 +02:00
Lukas Wirth
6523a09562 style 2021-08-16 18:29:16 +02:00
Lukas Wirth
c90ecc5c26 Only add entries to SourceToDef dynmaps when they come from the same file 2021-08-16 17:07:25 +02:00
Aleksey Kladov
90357a9090 internal: merge hir::BinaryOp and ast::BinOp 2021-08-14 18:10:01 +03:00
Aleksey Kladov
fe4f059450 internal: prepare to merge hir::BinaryOp and ast::BinOp 2021-08-14 17:07:51 +03:00
Aleksey Kladov
6df00f8495 internal: make naming consistent 2021-08-14 17:01:28 +03:00
Jonas Schievink
d568e7686a Support if let match guards 2021-08-13 00:25:14 +02:00
bors[bot]
baf1494374
Merge #9807
9807: Implicit `Sized` bounds r=iDawer a=iDawer

This should close #8984 

`hir_ty`:
- Type parameters, associated types and `impl Trait` are `Sized` by deafault except `Self` in a trait.
- Implicit `Sized` bound is added to end of predicate list. It does not check if such bound is present already. Also it does not track the bound is implicit.
- Allowed ambiguous unsize coercion if Chalk returns definite guidance.
- Allowed ambiguous autoderef if Chalk returns definite guidance.

`hir_def`:
- `ItemTree` pretty printing shows `?Sized` bounds.

`HirDisplay`:
- `impl Trait` with weird bounds rendered correctly.
- `Sized`/`?Sized` bounds are not shown if they are default.

### Perf
`./target/rust-analyzer-baseline_8a843113 -q analysis-stats --memory-usage .`
```
Database loaded:     1.63s, 287minstr, 91mb
  crates: 38, mods: 741, decls: 15914, fns: 11835
Item Collection:     26.80s, 73ginstr, 338mb
  exprs: 318994, ??ty: 398 (0%), ?ty: 435 (0%), !ty: 174
Inference:           50.28s, 116ginstr, 516mb
Total:               77.08s, 189ginstr, 855mb
```

`./target/rust-analyzer-sized-fixed_ambig_coercion-de074fe6 -q analysis-stats --memory-usage .`
```
Database loaded:     1.63s, 287minstr, 91mb
  crates: 38, mods: 741, decls: 15914, fns: 11835
Item Collection:     26.95s, 73ginstr, 338mb
  exprs: 318994, ??ty: 398 (0%), ?ty: 435 (0%), !ty: 166
Inference:           96.39s, 234ginstr, 543mb
Total:               123.33s, 307ginstr, 881mb
```


Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-08-12 17:55:29 +00:00
Aleksey Kladov
3e5b155716 fix: avoid pathological macro expansions
Today, rust-analyzer (and rustc, and bat, and IntelliJ) fail badly on
some kinds of maliciously constructed code, like a deep sequence of
nested parenthesis.

"Who writes 100k nested parenthesis" you'd ask?

Well, in a language with macros, a run-away macro expansion might do
that (see the added tests)! Such expansion can be broad, rather than
deep, so it bypasses recursion check at the macro-expansion layer, but
triggers deep recursion in parser.

In the ideal world, the parser would just handle deeply nested structs
gracefully. We'll get there some day, but at the moment, let's try to be
simple, and just avoid expanding macros with unbalanced parenthesis in
the first place.

closes #9358
2021-08-09 16:15:02 +03:00
Aleksey Kladov
9aa6be71a5 internal: remove useless helpers
We generally avoid "syntax only" helper wrappers, which don't do much:
they make code easier to write, but harder to read. They also make
investigations harder, as "find_usages" needs to be invoked both for the
wrapped and unwrapped APIs
2021-08-09 15:58:21 +03:00
Lukas Wirth
50d46863ef Look for enum variants and trait assoc functions when looking for lang items 2021-08-07 22:30:13 +02:00
Dawer
14898729f4 Account sized bounds in parentheses printing inside of ptr/ref of rpit. 2021-08-08 00:54:38 +05:00
Dawer
d9e6377b91 adjust hir_def::TypeBound::as_path 2021-08-04 19:49:19 +05:00
Dawer
3981373b93 internal: add implicit Sized bounds to type parameters. 2021-08-04 19:04:21 +05:00
Aleksey Kladov
2f9273633b feat: filter out duplicate macro completions
closes #9303
2021-08-03 17:36:06 +03:00
Aleksey Kladov
12d7f5b56e internal: explain that we don't ref in style.md 2021-08-02 15:59:28 +03:00
Aleksey Kladov
5f3662e01c minor: encode usage convention into API 2021-08-02 15:28:39 +03:00
bors[bot]
33dcc895c1
Merge #9700
9700: fix: Remove the legacy macro scoping hack r=matklad a=jonas-schievink

This stops prepending `self::` to single-ident macro paths, resolving even legacy-scoped macros using the fixed-point algorithm. This is not correct, but a lot easier than fixing this properly (which involves pushing a new scope for every macro definition and invocation).

This allows resolution of macros from the prelude, fixing https://github.com/rust-analyzer/rust-analyzer/issues/9687.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-07-28 12:07:25 +00:00
Alexander Gonzalez
e57ad5456c fix: Typos 2021-07-27 18:31:21 -04:00
Jonas Schievink
18b6327a29 Remove the legacy macro scoping hack 2021-07-26 19:58:14 +02:00
Jonas Schievink
c8d915e2ea Fix formatting and use Iterator::any 2021-07-23 16:45:14 +02:00
Jonas Schievink
b0f7aac72f Respect #[doc(hidden)] in dot-completion 2021-07-23 15:36:43 +02:00
bors[bot]
0bee7cb716
Merge #9453
9453: Add first-class limits. r=matklad,lnicola a=rbartlensky

Partially fixes #9286.

This introduces a new `Limits` structure which is passed as an input
to `SourceDatabase`. This makes limits accessible almost everywhere in
the code, since most places have a database in scope.

One downside of this approach is that whenever you query limits, you
essentially do an `Arc::clone` which is less than ideal.

Let me know if I missed anything, or would like me to take a different approach!

Co-authored-by: Robert Bartlensky <bartlensky.robert@gmail.com>
2021-07-22 10:33:05 +00:00
Jonas Schievink
837eec8dab filter visiblities when resolving in extern crate 2021-07-21 17:51:56 +02:00
bors[bot]
4705df44c7
Merge #9637
9637: Overhaul doc_links testing infra r=Veykril a=Veykril

and fix several issues with current implementation.

Fixes #9617

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-20 16:06:37 +00:00
Aleksey Kladov
7ec8434674 internal: remove potentially slow method 2021-07-20 17:19:58 +03:00
Lukas Wirth
97d63d67cd Resolve paths to assoc items for traits 2021-07-19 20:51:57 +02:00