Commit Graph

839 Commits

Author SHA1 Message Date
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
Lukas Wirth
69782f55de Move incorrect case diagnostic things into their module 2021-11-20 17:25:57 +01:00
Lukas Wirth
91def936bc Replace Vec with Box in Path.generic_args field 2021-11-20 16:37:41 +01:00
Lukas Wirth
ceaec9d866 internal: Replace Vec with Box in hir Pat 2021-11-20 16:17:30 +01:00
Lukas Wirth
cc327774b7 internal: Replace Vec with Box in hir Expr 2021-11-20 16:00:45 +01:00
Jonas Schievink
9f4c26e780 Format Fn traits using parentheses 2021-11-19 19:58:00 +01:00
Lukas Wirth
ea03defeac fix: Diagnose invalid derive attribute input 2021-11-19 13:17:35 +01:00
Lukas Wirth
6757910934 fix: Diagnose using derive on non-adt items 2021-11-19 12:10:55 +01:00
Lukas Wirth
966cae384f minor: Simplify 2021-11-18 21:43:54 +01:00
Lukas Wirth
f72512f1c6 Simplify 2021-11-17 21:02:33 +01:00
Lukas Wirth
91bbc55eed Check for derive attributes by item path, not derive identifier 2021-11-17 20:46:57 +01:00
bors[bot]
32f425d801
Merge #10787
10787: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-17 14:55:18 +00:00
Lukas Wirth
6e1ecaef4f Simplify 2021-11-17 15:54:38 +01:00
zhoufan
1f1682ee1e minor: remove duplicate calls 2021-11-17 18:16:25 +08:00
Lukas Wirth
b57289c4cb Skip test/bench attr expansion in resolution instead of collection 2021-11-16 20:23:56 +01:00
Lukas Wirth
92f7db447c minor: Lift out FxIndex{Map/Set} types into ide_db 2021-11-16 12:15:47 +01:00
Lukas Wirth
5c0b895f69 Rename intern_macro -> intern_macro_call 2021-11-14 16:25:47 +01:00
Lukas Wirth
7776aad166 internal: Flatten Definition::ModuleDef variant 2021-11-11 00:05:53 +01:00
Lukas Wirth
3c8898b1b1 Do not search through all three namespaces in ItemScope::name_of 2021-11-10 16:08:40 +01:00
Lukas Wirth
439a8194b0 Replace more Name::to_string usages with Name::to_smol_str 2021-11-04 18:12:05 +01:00
Lukas Wirth
ebd63ec1cf feat: Make unqualified derive attributes flyimportable 2021-10-29 14:51:26 +02:00
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
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
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
c2e425dd00 internal: make sure macro test expand to valid syntax 2021-10-09 18:06:24 +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
6407e2e789 indent macro output when pprinting 2021-10-09 17:36:41 +03:00
Aleksey Kladov
a0d9e78ec3 align tests to code style 2021-10-09 17:31:24 +03:00
Aleksey Kladov
036c0ff8c7 move some tests 2021-10-09 17:27:38 +03:00
Aleksey Kladov
cb1b6a273f internal: don't un-indent macro tests manually 2021-10-09 17:17:37 +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
59c86ff300 rename 2021-10-09 16:28:11 +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
84d182c7a2 internal: docs 2021-10-09 15:29:31 +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
b3d1de93af get organizized 2021-10-09 14:53:15 +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