Commit Graph

250 Commits

Author SHA1 Message Date
Jonas Schievink
cca6ee5757 Expand asm! to format_args! 2021-10-01 12:33:18 +02:00
Jonas Schievink
b994469a13 Add const_format_args! builtin macro, fix highlighting 2021-09-30 17:16:39 +02:00
Jonas Schievink
375a0ff785 Use itertools 2021-09-30 16:37:12 +02:00
Jonas Schievink
b8437f71b6 Less hacky assert! expansion 2021-09-30 16:30:26 +02:00
Jonas Schievink
d05eae6ada Make stringify! prettify its input
This will insert whitespace if the invocation is inside another macro
2021-09-27 19:02:03 +02:00
Lukas Wirth
b6ed91a6de Rename *Owner traits to Has* 2021-09-27 12:54:24 +02:00
Aleksey Kladov
2bf81922f7 internal: more reasonable grammar for blocks
Consider these expples

        { 92 }
  async { 92 }
    'a: { 92 }
   #[a] { 92 }

Previously the tree for them were

  BLOCK_EXPR
    { ... }

  EFFECT_EXPR
    async
    BLOCK_EXPR
      { ... }

  EFFECT_EXPR
    'a:
    BLOCK_EXPR
      { ... }

  BLOCK_EXPR
    #[a]
    { ... }

As you see, it gets progressively worse :) The last two items are
especially odd. The last one even violates the balanced curleys
invariant we have (#10357) The new approach is to say that the stuff in
`{}` is stmt_list, and the block is stmt_list + optional modifiers

  BLOCK_EXPR
    STMT_LIST
      { ... }

  BLOCK_EXPR
    async
    STMT_LIST
      { ... }

  BLOCK_EXPR
    'a:
    STMT_LIST
      { ... }

  BLOCK_EXPR
    #[a]
    STMT_LIST
      { ... }
2021-09-26 19:16:09 +03:00
Jonas Schievink
b8eb63f2b2 Avoid some Arc cloning 2021-09-24 18:57:08 +02:00
Jonas Schievink
af3d6a4b61 Include macro path in eager macro resolve error 2021-09-24 15:34:57 +02:00
bors[bot]
f1d7f98ed0
Merge #10293
10293: fix: Don't bail on parse errors in macro input for builtin expansion r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-09-19 22:33:42 +00:00
Lukas Wirth
e7e87fc69d Don't bail on parse errors in macro input for builtin expansion 2021-09-20 00:33:13 +02:00
Lukas Wirth
a6dde501df Only strip derive attributes when preparing macro input 2021-09-19 23:38:38 +02:00
Lukas Wirth
0f4463e45e fix source_to_def trying to use attribute macro calls as containers 2021-09-14 14:42:14 +02:00
Lukas Wirth
d1e489185f Pick smaller node ancestors first when descending at offset 2021-09-14 14:10:59 +02:00
Lukas Wirth
aa1b36dc6d Downmap the token in attribute inputs when expanding speculatively 2021-09-14 00:04:04 +02:00
Lukas Wirth
2b907652ee Speculatively expand attributes in completions 2021-09-13 19:30:23 +02:00
Giles Cope
15312aab58
removing seemingly unused dev deps. 2021-09-11 16:26:36 +01:00
Aleksey Kladov
104cd0ce88 internal: make name consistent with usage 2021-09-06 18:34:03 +03: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
Lukas Wirth
36a5ce9790 minor: fix some clippy lints 2021-09-03 16:00:50 +02:00
Aleksey Kladov
81602f8a5d internal: reduce coupling
tt is a data structure, data structures cant' go wrong, they shouldn't
have the knowledge that the world outside of them has all kinds of
errors.
2021-08-31 19:14:33 +03:00
Aleksey Kladov
51b955ec8a internal: simplify 2021-08-31 15:09:46 +03:00
Mario Carneiro
b22eb02f8b
fail -> failed 2021-08-30 02:47:10 -07:00
Mario Carneiro
2d349aed2e
Update crates/hir_expand/src/db.rs
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-08-30 02:43:13 -07:00
Mario Carneiro
6e8dedadcd
Fix error message
I'm not entirely sure if the message is still correct, it seems to have survived a number of refactors, but it is mangled english anyway.
2021-08-30 02:36:21 -07:00
Dezhi Wu
ba0947dded switch log crate to tracing 2021-08-30 15:11:42 +08:00
Lukas Wirth
c5059e0623 Return all ranges corresponding to a token id in TokenMap 2021-08-29 00:49:57 +02:00
bors[bot]
fae440c32a
Merge #10025
10025: Don't mutate syntax trees when preparing proc-macro input r=Veykril a=Veykril

Fixes #10013

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-28 14:14:54 +00: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
oxalica
15eccf29e8
Fix missing unsafe block for the nightly change
Fix #10022
2021-08-26 17:21:23 +08:00
Lukas Wirth
d6134b6802 Don't mutate syntax trees when preparing proc-macro input 2021-08-25 18:57:24 +02:00
Lukas Wirth
4933beca87 Respect attributes in Hygiene token up-mapping 2021-08-22 19:12:45 +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
5507512eaf Replace stripped derives with whitespace in process_macro_input 2021-08-22 14:23:59 +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
cee02673d1 Don't ask for the builtin attribute input twice 2021-08-21 12:55:05 +02:00
Aleksey Kladov
1850849325 internal: prep to 2021 edition 2021-08-20 16:20:18 +03:00
Lukas Wirth
82728eb757 Switch AstDatabase::exapnd_proc_macro to ExpandResult 2021-08-20 14:34:46 +02:00
Lukas Wirth
269de9abe3 Switch BuiltinDeriveExpander::expand to ExpandResult 2021-08-20 14:28:36 +02:00
Lukas Wirth
557df6ff3f Use correct HirFileId in find_related_test 2021-08-20 13:50:40 +02:00
Lukas Wirth
7342dcf0b0 Fix runnables not seeing test and bench attributes 2021-08-20 13:50:06 +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
c67ecbebc4 Rename fails on renaming definitions created by macros 2021-08-20 00:12:47 +02:00
bors[bot]
6a07bf6a9f
Merge #9920
9920: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-16 14:13:04 +00:00
Lukas Wirth
0c0142f61a Simplify 2021-08-16 16:12:20 +02:00
Aleksey Kladov
438d1da6c6 minor: simplify 2021-08-16 14:45:54 +03:00
Aleksey Kladov
d29c52354c minor: remove dead code 2021-08-16 14:28:04 +03: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