Commit Graph

245 Commits

Author SHA1 Message Date
bors[bot]
f46731a230
Merge #11028
11028: Bump MSRV (1.57) r=Veykril a=iDawer

This bumps MSRV on all crates to 1.57 except `la-arena`

#10986 requires >=1.57 

Co-authored-by: iDawer <ilnur.iskhakov.oss@outlook.com>
2021-12-20 13:45:35 +00:00
Aleksey Kladov
a022ad68c9 internal: move all the lexing to the parser crate 2021-12-18 17:20:38 +03:00
iDawer
676744be6e Bump MSRV (1.57) 2021-12-16 01:56:12 +05:00
Aleksey Kladov
57e6ef0bfb tighten up invariants 2021-12-12 19:22:37 +03:00
Aleksey Kladov
1055a6111a port mbe to soa tokens 2021-12-12 19:06:40 +03:00
Laurențiu Nicola
bff377c712 Clean up some unused cross-crate dependencies 2021-12-05 13:54:49 +02:00
Lukas Wirth
a9c4c6da4c Fix mbe::Shift::new not accounting for non-ident token ids 2021-11-22 18:00:32 +01:00
Lukas Wirth
64cb09ddea Add to macro testing infra to emit token map ids 2021-11-22 16:51:09 +01:00
Aleksey Kladov
5a83d1be66 internal: replace L_DOLLAR/R_DOLLAR with parenthesis hack
The general problem we are dealing with here is this:

```
macro_rules! thrice {
    ($e:expr) => { $e * 3}
}

fn main() {
    let x = thrice!(1 + 2);
}
```

we really want this to print 9 rather than 7.

The way rustc solves this is rather ad-hoc. In rustc, token trees are
allowed to include whole AST fragments, so 1+2 is passed through macro
expansion as a single unit. This is a significant violation of token
tree model.

In rust-analyzer, we intended to handle this in a more elegant way,
using token trees with "invisible" delimiters. The idea was is that we
introduce a new kind of parenthesis, "left $"/"right $", and let the
parser intelligently handle this.

The idea was inspired by the relevant comment in the proc_macro crate:

https://doc.rust-lang.org/stable/proc_macro/enum.Delimiter.html#variant.None

> An implicit delimiter, that may, for example, appear around tokens
> coming from a “macro variable” $var. It is important to preserve
> operator priorities in cases like $var * 3 where $var is 1 + 2.
> Implicit delimiters might not survive roundtrip of a token stream
> through a string.

Now that we are older and wiser, we conclude that the idea doesn't work.

_First_, the comment in the proc-macro crate is wishful thinking. Rustc
currently completely ignores none delimiters. It solves the (1 + 2) * 3
problem by having magical token trees which can't be duplicated:

* https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/TIL.20that.20token.20streams.20are.20magic
* https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Handling.20of.20Delimiter.3A.3ANone.20by.20the.20parser

_Second_, it's not like our implementation in rust-analyzer works. We
special-case expressions (as opposed to treating all kinds of $var
captures the same) and we don't know how parser error recovery should
work with these dollar-parenthesis.

So, in this PR we simplify the whole thing away by not pretending that
we are doing something proper and instead just explicitly special-casing
expressions by wrapping them into real `()`.

In the future, to maintain bug-parity with `rustc` what we are going to
do is probably adding an explicit `CAPTURED_EXPR` *token* which we can
explicitly account for in the parser.

If/when rustc starts handling delimiter=none properly, we'll port that
logic as well, in addition to special handling.
2021-10-23 20:44:31 +03:00
Laurențiu Nicola
8457ae34bd Set MSRV 2021-10-23 15:07:11 +03:00
Lukas Wirth
1294bfce86 Migrate to edition 2021 2021-10-21 20:10:40 +02:00
Aleksey Kladov
d4d67406d7 internal: clean up code duplication 2021-10-10 21:08:10 +03:00
Aleksey Kladov
634f047d90 internal: add integrated test for token censoring 2021-10-10 16:52:21 +03:00
Aleksey Kladov
bfc5d8529a drop obsolete tests 2021-10-10 15:11:33 +03:00
Aleksey Kladov
0f849a7a35 move test 2021-10-10 15:06:41 +03:00
Aleksey Kladov
dce41e5a03 move tests 2021-10-10 14:58:25 +03:00
Aleksey Kladov
42fd71e6c8 move tests 2021-10-10 14:40:13 +03:00
Aleksey Kladov
be73cc8f83 move test 2021-10-10 14:28:04 +03:00
Aleksey Kladov
af76db3c36 move tests 2021-10-10 14:26:47 +03:00
Aleksey Kladov
6253213a6e move test 2021-10-10 14:23:52 +03:00
Aleksey Kladov
e55797f59d move tests 2021-10-10 14:21:47 +03:00
Aleksey Kladov
8997d742dc move tests 2021-10-10 14:08:49 +03:00
Aleksey Kladov
5ad502dbdb move test 2021-10-10 13:54:44 +03:00
Aleksey Kladov
c986568cbb move test 2021-10-10 13:26:07 +03:00
Aleksey Kladov
5b44770102 move test 2021-10-10 13:24:48 +03:00
Aleksey Kladov
e255e9577f internal: move test 2021-10-10 13:21:42 +03:00
Aleksey Kladov
8670e83cec move test 2021-10-10 12:57:18 +03:00
Aleksey Kladov
7d92b9f6ff move test 2021-10-10 12:55:31 +03:00
Aleksey Kladov
748e6881fc move tests 2021-10-10 12:52:28 +03:00
Aleksey Kladov
6fd2f1d25b internal: move tests 2021-10-10 12:45:17 +03:00
Aleksey Kladov
5a854a7253 internal: move tests 2021-10-10 12:39:58 +03:00
Aleksey Kladov
c88cda04db move some tests 2021-10-10 11:44:46 +03:00
Aleksey Kladov
a3470a8114 move tests 2021-10-10 11:39:08 +03:00
Aleksey Kladov
7e53a3ce23 move test 2021-10-10 11:29:26 +03:00
Aleksey Kladov
408475a593 move test 2021-10-10 11:26:18 +03:00
Aleksey Kladov
9c819eaa9a move tests 2021-10-10 11:15:42 +03:00
Aleksey Kladov
1c15f47e00 internal: move tests 2021-10-10 11:11:50 +03:00
Aleksey Kladov
c6d5c1c946 dead code 2021-10-10 11:09:16 +03:00
Aleksey Kladov
e9902b92ab internal: move some mbe tests 2021-10-10 11:08:02 +03:00
Aleksey Kladov
f17f5d68f9 move tests 2021-10-10 11:08:02 +03:00
Aleksey Kladov
3a47dba761 fix tests 2021-10-10 11:08:02 +03:00
Aleksey Kladov
de136a5340 move test 2021-10-09 19:11:04 +03:00
Aleksey Kladov
e838da18a9 internal: move tests 2021-10-09 18:54:15 +03:00
Aleksey Kladov
0dc87badd7 internal: move test 2021-10-09 18:51:26 +03:00
Aleksey Kladov
0a32c20142 internal: move test 2021-10-09 18:49:14 +03:00
Aleksey Kladov
993ff1c239 internal: drop duplicated test 2021-10-09 18:47:04 +03:00
Aleksey Kladov
419c234333 internal: move test 2021-10-09 18:46:16 +03:00
Aleksey Kladov
b1cfa51ef5 internal: move tests 2021-10-09 18:43:15 +03:00
Aleksey Kladov
3e8ef943c6 internal: move some tests 2021-10-09 18:18:56 +03:00
Aleksey Kladov
a060b9a4b2 internal: move some macro tests 2021-10-09 18:15:05 +03:00
Aleksey Kladov
c41b7bbe69 internal: allow macro tests to inspect parse tree 2021-10-09 17:58:17 +03:00
Aleksey Kladov
aac23f7832 move tests 2021-10-09 17:43:07 +03:00
Aleksey Kladov
036c0ff8c7 move some tests 2021-10-09 17:27:38 +03:00
Aleksey Kladov
afacdd612d internal: update expect 2021-10-09 17:17:16 +03:00
Aleksey Kladov
959da8caa1 internal: move test 2021-10-09 16:31:26 +03:00
Aleksey Kladov
75b0ce17cf move test 2021-10-09 16:27:19 +03:00
Aleksey Kladov
0dd1b35479 move test 2021-10-09 16:25:37 +03:00
Aleksey Kladov
574df660e4 move test 2021-10-09 16:22:42 +03:00
Aleksey Kladov
b21244e080 internal: move test 2021-10-09 16:19:19 +03:00
Aleksey Kladov
ef1251f696 feat: report errors in macro definition
Reporting macro *definition* error at the macro *call site* is a rather
questionable approach, but at least we don't erase the errors
altogether!
2021-10-09 15:23:55 +03:00
Aleksey Kladov
8e9003447c future proof structure 2021-10-09 14:48:38 +03:00
Aleksey Kladov
5ecda802f1 move test 2021-10-09 14:45:52 +03:00
Aleksey Kladov
f4ee0d736c move tests 2021-10-09 14:39:24 +03:00
Aleksey Kladov
1abe3f8275 internal: move tests 2021-10-09 14:22:49 +03:00
Aleksey Kladov
49f5fecf06 internal: move test 2021-10-09 14:18:53 +03:00
Aleksey Kladov
78ca43ef3d internal: move test 2021-10-09 13:51:02 +03:00
Aleksey Kladov
093f99b809 internal: start new macro test suite
I don't like our macro tests -- they are brittle and don't inspire
confidence. I think the reason for that is that we try to unit-test
them, but that is at odds with reality, where macro expansion
fundamentally depends on name resolution.
2021-10-09 13:42:32 +03:00
Aleksey Kladov
4e352275d1 minor: simplify 2021-10-02 20:38:39 +03:00
Aleksey Kladov
613609cc5e minor: cleanup 2021-10-02 20:38:39 +03:00
Aleksey Kladov
77bf761203 internal: move code to where it's used and reduce visibility 2021-10-02 20:38:39 +03: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
Lukas Wirth
d99adc5738 Make hover work for intra doc links in macro invocations 2021-09-23 17:32:39 +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
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
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
Lukas Wirth
1195cb50c2 Add simple test for syntax_node_to_token_tree_censored 2021-08-25 19:57:18 +02:00
Lukas Wirth
d6134b6802 Don't mutate syntax trees when preparing proc-macro input 2021-08-25 18:57:24 +02:00
Frank Steffahn
5f5d45468d Fix two more “a”/“an” typos (this time the other way) 2021-08-22 17:36:58 +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
Aleksey Kladov
78c7940f5c internal: remove dead code 2021-08-14 20:29:46 +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
Aleksey Kladov
86720f2953 minor: drop dummy authors field 2021-07-05 14:19:41 +03:00
Jonas Schievink
c6669776e1 Rewrite convert_tokens to use an explicit stack 2021-06-23 00:21:11 +02:00
Jonas Schievink
6504c3c32a Move subtree collection out of TokenConvertor 2021-06-23 00:19:54 +02:00
Clemens Wasser
47747cd412 Apply some clippy suggestions 2021-06-21 16:40:21 +02:00
Lukas Wirth
95c8c65139 Nest all the or-patterns! 2021-06-17 17:37:14 +02:00
bors[bot]
5a8ddb4b2d
Merge #9260
9260: tree-wide: make rustdoc links spiky so they are clickable r=matklad a=lf-

Rustdoc was complaining about these while I was running with --document-private-items and I figure they should be fixed.

Co-authored-by: Jade <software@lfcode.ca>
2021-06-14 07:16:48 +00:00
Jade
20b325c7d5 tree-wide: make rustdoc links spiky so they are clickable 2021-06-13 21:58:05 -07:00
Maan2003
aabd41cafc
clippy::redundant_field_names 2021-06-13 09:40:22 +05:30