Commit Graph

767 Commits

Author SHA1 Message Date
Lukas Wirth
7fdbdc4ab2 Enable auto-import and qualify-path in derive attributes 2021-10-28 18:40:38 +02: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
Laurențiu Nicola
ca44b6892e Use array IntoIter 2021-10-22 09:23:29 +03:00
Lukas Wirth
1294bfce86 Migrate to edition 2021 2021-10-21 20:10:40 +02:00
bors[bot]
6aeeb4ef33
Merge #10603
10603: fix: Don't resolve attributes to non attribute macros r=Veykril a=Veykril

Also changes `const`s to `static`s for `Limit`s as we have interior mutability in those(though only used with a certain feature flag enabled).

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-21 10:39:26 +00:00
Lukas Wirth
ea2a2c52fc Don't resolve attributes to non attribute macros 2021-10-21 12:22:40 +02:00
bors[bot]
11326a6847
Merge #10387
10387: Move `IdxRange` into la-arena r=Veykril a=arzg

Currently, `IdxRange` (named `IdRange`) is located in `hir_def::item_tree`, when really it isn’t specific to `hir_def` and could become part of la-arena. The rename from `IdRange` to `IdxRange` is to maintain consistency with the naming convention used throughout la-arena (`Idx` instead of `Id`, `RawIdx` instead of `RawId`). This PR also adds a few new APIs to la-arena on top of `IdxRange` for convenience, namely:

- indexing into an `Arena` by an `IdxRange` and getting a slice of values back
- creating an `IdxRange` from an inclusive range

Currently this PR also exposes a new `Arena::next_idx` method to make constructing inclusive`IdxRange`s using `IdxRange::new` easier; however, it would in my opinion be better to remove this as it allows for easy creation of out-of-bounds `Idx`s, when `IdxRange::new_inclusive` mostly covers the same use-case while being less error-prone.

I decided to bump the la-arena version to 0.3.0 from 0.2.0 because adding a new `Index` impl for `Arena` turned out to be a breaking change: I had to add a type hint in `crates/hir_def/src/body/scope.rs` when one wasn’t necessary before, since rustc couldn’t work out the type of a closure parameter now that there are multiple `Index` impls. I’m not sure whether this is the right decision, though. 

Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
2021-10-20 20:54:36 +00:00
Laurențiu Nicola
24eca25d8a Make some functions non-generic 2021-10-20 20:20:17 +03:00
Aramis Razzaghipour
dce5c640f8
Move IdxRange into la_arena 2021-10-15 13:03:28 +11:00
Aleksey Kladov
634f047d90 internal: add integrated test for token censoring 2021-10-10 16:52:21 +03:00
Aleksey Kladov
a88344152d minor: add a test for derive macros in core 2021-10-10 16:13:45 +03:00
Aleksey Kladov
5af80d8372 internal: move derived tests to the unified macro infra 2021-10-10 16:10:35 +03:00
Aleksey Kladov
55d8be5a24 internal: consistent module naming 2021-10-10 15:44:03 +03:00
Aleksey Kladov
e5acf650d0 move tests 2021-10-10 15:30:54 +03:00
Aleksey Kladov
5f8b708aca move tests 2021-10-10 15:28:24 +03:00
Aleksey Kladov
6a3fc84921 internal: move builtin macro tests to macro expansion suite 2021-10-10 15:17:53 +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
464fb9f0d4 add directory for regression tests 2021-10-10 13:56:41 +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
3c9dda6ca9 internal: consistently use ok!(); for succesfull macro expansion 2021-10-10 11:45:05 +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
b0a104cbd1 test formatting 2021-10-10 11:22:12 +03:00
Aleksey Kladov
2510eaa9b2 test formatting 2021-10-10 11:16:25 +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
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
bors[bot]
64ca0f63bf
Merge #10504
10504: Remove needless clone r=lnicola a=k-nasa

## Why

Delete clones for efficiency

## What

- I erased unnecessary clones


Co-authored-by: k-nasa <htilcs1115@gmail.com>
2021-10-10 07:17:52 +00:00
k-nasa
b50cb5c261 Remove neesless clone 2021-10-10 10:50:51 +09:00
Aleksey Kladov
de136a5340 move test 2021-10-09 19:11:04 +03:00