Commit graph

270 commits

Author SHA1 Message Date
Aleksey Kladov
5c5bde47fb Rename some tokens 2020-04-10 17:07:09 +02:00
Aleksey Kladov
8d71a6bf0c Scale token generation back 2020-04-10 16:10:28 +02:00
Luca Barbieri
74e3b48806 Parse correctly fn f<T>() where T: Fn() -> u8 + Send {}
We used to parse it as T: Fn() -> (u8 + Send), which is different from
the rustc behavior of T: (Fn() -> u8) + Send
2020-04-09 13:05:41 +02:00
Luca Barbieri
60f4d7bd8c Provide more complete AST accessors to support usage in rustc 2020-04-09 11:50:37 +02:00
Edwin Cheng
53d05448c1 Add L_DOLLAR for TYPE_RECOVERY_SET 2020-04-08 18:34:20 +08:00
Aleksey Kladov
da8eb29a2f Macro patterns are not confused with expressions.
We treat macro calls as expressions (there's appropriate Into impl),
which causes problem if there's expresison and non-expression macro in
the same node (like in the match arm).

We fix this problem by nesting macor patterns into another node (the
same way we nest path into PathExpr or PathPat). Ideally, we probably
should add a similar nesting for macro expressions, but that needs
some careful thinking about macros in blocks: `{ am_i_expression!() }`.
2020-04-03 16:12:38 +02:00
Aleksey Kladov
0e46ed8420 Cleanups 2020-04-03 15:44:06 +02:00
Aleksey Kladov
f6188caaa0 Fix parsing lambdas with return type
We should eat only a single block, and not whatever larger expression
may start with a block.

closes #3721
2020-03-25 17:01:28 +01:00
Aleksey Kladov
89694ec8f6 Support arbitrary discriminants
Closes #3661
2020-03-20 08:50:34 +01:00
Florian Diebold
e6ec4a329f Better fix for stuck parser? 2020-03-16 18:38:19 +01:00
Florian Diebold
c32529ddd0 Get tests working 2020-03-16 18:38:19 +01:00
Aleksey Kladov
bee5cdb359 Parse variadics correctly
closes #3571
2020-03-13 13:54:14 +01:00
Aleksey Kladov
1e19847af3 Move verbose tests out of line 2020-03-13 12:20:42 +01:00
Aleksey Kladov
4a745cc8cf Fix parsing of stement-ish binary expressions
closes #3512
2020-03-11 14:28:18 +01:00
Edwin Cheng
1465cc0c4f Implement concat macro 2020-03-04 01:21:14 +08:00
Aleksey Kladov
a1e1869554 Rename ast::ImplBlock -> ast::ImplDef 2020-02-29 21:33:15 +01:00
Edwin Cheng
f4e48ad3e4 Parse attr in rhs of let stmts 2020-02-28 13:08:47 +08:00
Veetaha
59dc797eb3
Fix dat comment 2020-02-22 14:16:13 +02:00
Kirill Bulatov
eceaf94f19 More manual clippy fixes 2020-02-18 16:12:37 +02:00
Kirill Bulatov
b8ddcb0652 Run cargo +nightly fix --clippy -Z unstable-options 2020-02-18 16:03:08 +02:00
Han Mertens
b435fe8b77 Add test for unnamed argument in function pointer 2020-02-12 22:55:37 +01:00
Han Mertens
0e10e77a78 Support unnamed arguments in function pointers
Fixes #3089
2020-02-12 21:40:05 +01:00
Matthew Jasper
49b53cd7a0 Address review comments 2020-02-10 20:11:44 +00:00
Matthew Jasper
8c8d0bb34f Add or- and parenthesized-patterns 2020-02-09 22:06:15 +00:00
Kirill Bulatov
740a26b7d2 Rename add import assist 2020-02-07 23:53:08 +02:00
bors[bot]
8337dcd9e2
Merge #3047
3047: Update async unsafe fn ordering in parser r=matklad a=kiljacken

As of rust-lang/rust#61319 the correct order for functions that are both unsafe and async is: `async unsafe fn` and not `unsafe async fn`.

This commit updates the parser tests to reflect this, and corrects parsing behavior to accept the correct ordering.

Fixes #3025

Co-authored-by: Emil Lauridsen <mine809@gmail.com>
2020-02-07 13:21:02 +00:00
Emil Lauridsen
73ec2ab184 Update async unsafe fn ordering.
As of rust-lang/rust#61319 the correct order for functions that are both
unsafe and async is: `async unsafe fn` and not `unsafe async fn`.

This commit updates the parser tests to reflect this, and corrects
parsing behavior to accept the correct ordering.

Fixes #3025
2020-02-07 13:51:51 +01:00
Toby Dimmick
90ff2be4e8 PR tweaks 2020-02-07 12:36:33 +00:00
Toby Dimmick
0183952d2e Closure params test 2020-02-06 20:39:27 +00:00
Toby Dimmick
e1921ea59c rustfmt 2020-02-06 20:04:35 +00:00
Toby Dimmick
7e66785859 Rework value parameter parsing
- `Fn__(...)` parameters with idents/patterns no longer parse
- Trait function parameters with arbitrary patterns parse
- Trait function parameters without idents/patterns no longer parse
- `fn(...)` parameters no longer parse with patterns other than a single ident
2020-02-06 19:45:51 +00:00
Veetaha
3ec781d4f2 ra_syntax: remove code duplication and token reevaluation from ast::Literal::kind() 2020-01-22 13:02:21 +02:00
Aleksey Kladov
3a859e587f Nest attrs into exprs in function args 2020-01-17 11:47:07 +01:00
Aleksey Kladov
b7c45fba57 Extract expr_with_attrs 2020-01-17 11:44:40 +01:00
Aleksey Kladov
90b8a31b83
Merge pull request #2813 from jyn514/arg_attributes
Allow attributes before function arguments
2020-01-17 11:15:07 +01:00
Joshua Nelson
f077d5c303
move inline function closer to relevant code
also updates generated inline tests
2020-01-16 22:20:17 -05:00
bors[bot]
ea2b27d8b9
Merge #2865
2865: fix(mixed): fixed a couple of typos and added a todo r=kjeremy a=Veetaha

Fixed a couple of typos and added a todo while studying the codebase.

Co-authored-by: Veetaha <gerzoh1@gmail.com>
2020-01-17 02:20:16 +00:00
Aleksey Kladov
5398b9eeba Minimize test 2020-01-16 18:39:29 +01:00
Aleksey Kladov
ab0a11b1de Simplify array parsing 2020-01-16 18:35:03 +01:00
Edwin Cheng
a766883a75 fix formating 2020-01-16 23:48:03 +08:00
Edwin Cheng
ed8d5c86e3 Fix array element attribute position 2020-01-16 23:37:43 +08:00
Joshua Nelson
c78e34968f
shrink inline tes 2020-01-15 19:12:56 -05:00
Veetaha
a24dcd7bab fix(ra_parser.typo): amend 'format language' to 'formal language' 2020-01-15 23:29:55 +02:00
Joshua Nelson
c3ac2c93fb
Allow attributes before function arguments
This adds support for function calls of the form:

```rust
  (
    #[attr(...)] 1.2,
    #[attr_one(...)]
    #[attr_two(...)]
    1.5,
    ... etc ...
  )
```

Closes https://github.com/rust-analyzer/rust-analyzer/issues/2801
2020-01-12 10:25:41 -05:00
Emil Lauridsen
aa433c67d8 Parse trait aliases 2020-01-09 18:40:01 +01:00
Michael Chesser
ce1b34fd59 Improve const generics parsing
- Handle const generics type args
- Fix issue with const generic as first parameter in trait impl
2020-01-07 09:29:03 +10:30
Aleksey Kladov
084bd304f3 Switch ast declaration from ron to a macro 2020-01-03 21:54:10 +01:00
bors[bot]
436df298ba
Merge #2642
2642: Use name instead of ident in parser for macro 2.0 syntax r=matklad a=edwin0cheng



Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-12-22 08:05:02 +00:00
bors[bot]
d33493d779
Merge #2641
2641: Parse const generics r=matklad a=roblabla

Adds very primitive support for parsing const generics (`const IDENT: TY`) so that rust-analyzer stops complaining about the syntax being invalid.

Fixes #1574
Fixes #2281 

Co-authored-by: roblabla <unfiltered@roblab.la>
2019-12-22 07:56:33 +00:00
Edwin Cheng
737045c1ea Use name instead of ident for macro 2.0 sytnax 2019-12-22 11:11:10 +08:00
roblabla
b04d4a88d1 Parse const generics
Fixes #1574
Fixes #2281
2019-12-22 01:32:08 +00:00
Edwin Cheng
4195c0e5f9 Add macro keyword to ITEM_RECOVERY_SET 2019-12-21 18:42:17 +08:00
Edwin Cheng
bea8f58118 Add macro 2.0 support in parser 2019-12-21 18:29:14 +08:00
Edwin Cheng
4a7e19946a Fix parser for macro call in pattern position 2019-12-20 23:26:04 +08:00
Aleksey Kladov
0ed8ce096d Touch up TokenSet a bit 2019-12-19 17:13:33 +01:00
Aleksey Kladov
6edc54a1e6 Refactor macro tests 2019-12-19 16:23:23 +01:00
Aleksey Kladov
5c3c2b8690 Fix parsing of interpolated expressions 2019-12-19 14:43:19 +01:00
Aleksey Kladov
3e2f4e4293 Improve recovery for incomplete lambdas 2019-12-17 12:11:01 +01:00
Aleksey Kladov
5fd68b5929 Fix hir for ast::UnionDef 2019-11-25 17:50:49 +03:00
Aleksey Kladov
e1c0bdaf75 Introduce dedicated AST node for union
Although structs and unions have the same syntax and differ only in
the keyword, re-using the single syntax node for both of them leads to
confusion in practice, and propagates further down the hir in an
upleasent way.

Moreover, static and consts also share syntax, but we use different
nodes for them.
2019-11-25 17:50:49 +03:00
Aleksey Kladov
7e2f4b30db Disable doctests 2019-11-17 18:35:05 +03:00
Geoffry Song
a68aefdc46 Move inclusive range check to validation 2019-11-15 01:04:45 -08:00
Geoffry Song
989cebc99c Fix parsing of "postfix" range expressions.
Right now they are handled in `postfix_dot_expr`, but that doesn't allow it to
correctly handle precedence. Integrate it more tightly with the Pratt parser
instead.

Also includes a drive-by fix for parsing `match .. {}`.

Fixes #2242.
2019-11-15 00:18:28 -08:00
Aleksey Kladov
ef02296b9f Simplify parsing 2019-11-14 17:36:27 +03:00
kjeremy
e670a99413 cargo xtask format with 1.39 2019-11-07 09:44:45 -05:00
Aleksey Kladov
5a6db3ca29 fix parsing of for loops inside expressions
closes #2051
2019-10-28 15:41:34 +03:00
bors[bot]
d9338dfa98
Merge #1951
1951: Lower the precedence of the `as` operator. r=matklad a=goffrie

Previously, the `as` operator was being parsed like a postfix expression, and
therefore being given the highest possible precedence. That caused it to bind
more tightly than prefix operators, which it should not. Instead, parse it
somewhat like a normal binary expression with some special-casing.

Fixes #1851.

Co-authored-by: Geoffry Song <goffrie@gmail.com>
2019-10-08 08:44:26 +00:00
Geoffry Song
b4fe06bc17 Move tests around 2019-10-05 16:33:05 -07:00
Geoffry Song
9638adaa40 Fix parsing of block expressions in "forbid_structs" contexts.
Forbidding block expressions entirely is too strict; instead, we should only
forbid them in contexts where we are parsing an optional RHS (i.e. the RHS of a
range expression).
2019-10-03 00:39:52 -07:00
Geoffry Song
b63f260bbc Lower the precedence of the as operator.
Previously, the `as` operator was being parsed like a postfix expression, and
therefore being given the highest possible precedence. That caused it to bind
more tightly than prefix operators, which it should not. Instead, parse it
somewhat like a normal binary expression with some special-casing.
2019-10-03 00:27:09 -07:00
Alexander Andreev
81efd696cc Merge branch 'master' into feature/issue/1856
# Conflicts:
#	crates/ra_assists/src/ast_editor.rs
2019-09-30 12:07:26 +03:00
Alexander Andreev
fdbd6bb11a Added test for check doc strings in crates.
#1856
2019-09-30 11:58:53 +03:00
uHOOCCOOHu
f7e12559cb
Fixes 2019-09-30 16:17:54 +08:00
uHOOCCOOHu
71efdaa636
Parse correct AttrInput 2019-09-30 16:11:40 +08:00
Aleksey Kladov
d847d53e36 Start simplifying editing API 2019-09-26 22:22:08 +03:00
Aleksey Kladov
66101e931c simplify 2019-09-24 09:28:16 +03:00
kjeremy
fef7fcf5a9 Support loop as argument 2019-09-20 16:35:29 -04:00
kjeremy
2d99e6de27 Simplify match arm 2019-09-20 12:03:25 -04:00
bors[bot]
3575f7c4a2
Merge #1884
1884: Add indexing to record_field_pat r=matklad a=kjeremy

Fixes #1870 

Co-authored-by: kjeremy <kjeremy@gmail.com>
2019-09-20 15:54:01 +00:00
kjeremy
17a45a686c Apply suggestion 2019-09-20 11:49:45 -04:00
kjeremy
5a65d4d9fb Add indexing to record_field_pat 2019-09-20 11:43:34 -04:00
Aleksey Kladov
d57b993ade fix infinite loop in the parser
closes #1866
2019-09-20 16:57:31 +03:00
bors[bot]
c733993658
Merge #1881
1881: don't confuse macro with != r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-09-20 13:24:07 +00:00
Aleksey Kladov
0f70290b6e don't confuse macro with !=
closes #1871
2019-09-20 16:23:24 +03:00
kjeremy
883edd002e Replace usages of bump_any with bump 2019-09-19 15:51:46 -04:00
bors[bot]
2d79a1ad83
Merge #1848
1848: Parse `..` as a full pattern r=matklad a=ecstatic-morse

Resolves #1479.

This PR implements [RFC 2707](https://github.com/rust-lang/rfcs/pull/2707) in the parser. It introduces a new `DotDotPat` AST node modeled on `PlaceholderPat` and changes the parsing of tuple and slice patterns to conform to the RFC.

Notably, this PR does *not* change the resulting AST when `..` appears in a struct pattern (e.g. `Struct { a, b: c, .. }`). I *think* this is the behavior mandated by RFC 2707, but someone should confirm this.

Co-authored-by: Dylan MacKenzie <ecstaticmorse@gmail.com>
2019-09-15 07:10:16 +00:00
Dylan MacKenzie
4a3a15f0e7 Parse .. as a proper pattern 2019-09-14 17:08:22 -07:00
Dylan MacKenzie
426112c97e Add DotDotPat to AST
This is modeled on `PlaceholderPat`.
2019-09-14 17:08:22 -07:00
Dylan MacKenzie
253a18f938 Allow an underscore as the identifier in const items 2019-09-14 16:31:09 -07:00
Aleksey Kladov
3c68da792b don't break parser error recovery in presence of macros
Parser has the invariant that `{}` are balanced.
Previous code tried (unsucesfuly) maintain the same invariant for
`$()` as well, but it was done in a rather ad-hoc manner: it's not at
all obvious that it is possible to maintain both invariants!
2019-09-12 12:38:07 +03:00
Aleksey Kladov
b9d9db83d1 cleanup dollar handling in expressions 2019-09-10 21:28:27 +03:00
Aleksey Kladov
1c5800dee8 "Fix" mbe to work with decomposed tokens
We regressed $i * 2 where $i = 1 + 1, need to fix that!
2019-09-10 15:56:05 +03:00
Aleksey Kladov
40170885e7 WIP: switch to fully decomposed tokens internally 2019-09-10 15:46:39 +03:00
Aleksey Kladov
d8aa9a1d81 introduce bump as a better-checked alternative to bump_any 2019-09-10 01:03:00 +03:00
Aleksey Kladov
e2b378ef7e rename bump -> bump_any 2019-09-10 01:00:38 +03:00
Aleksey Kladov
7910202ecd tiny simplification 2019-09-09 13:23:41 +03:00
Aleksey Kladov
b2be998b7b better error recovery for use trees 2019-09-05 19:53:07 +03:00
Aleksey Kladov
3c2dea7f55 always wrap block into an expression 2019-09-02 20:15:51 +03:00
Aleksey Kladov
c89abd4262 simplify 2019-09-02 18:58:21 +03:00
Aleksey Kladov
32bebfaf0e cleanup 2019-09-02 17:37:48 +03:00