Commit graph

3120 commits

Author SHA1 Message Date
pcpthm
4cf179c089 Replace contract_child to a less ad-hoc API 2019-03-19 18:44:23 +09:00
pcpthm
e2ed813e89 Mark non-code block as text 2019-03-19 18:12:05 +09:00
pcpthm
2fb110e1fa Error about attributes on
unallowed types of expression statement
2019-03-19 17:37:08 +09:00
pcpthm
ffed132e52 Allow attributes on top level expression
A top level expression is either
- a expression statement or
- the last expression in a block
2019-03-19 17:24:02 +09:00
bors[bot]
1cd18f9237 Merge #991
991: Use Marker argument for item parsers r=matklad a=pcpthm

Before doing this for expressions, I found that the pattern (Marker argument) should be applied to the item parsers because visiblity and modifiers are parsed in a separate function.

Fixed some parser bugs:
- Fix pub_expr: `pub 42;` was allowed.
- Fix incorrect parsing of crate::path: incorrectly parsed as `crate` as a visibility.

Co-authored-by: pcpthm <pcpthm@gmail.com>
2019-03-18 09:32:28 +00:00
bors[bot]
7c117567ab Merge #989
989: Implement naive version of fill_struct_fields assist r=matklad a=yanchith

Fixes #964

This implements the `fill_struct_fields` assist. Currently only works for named struct fields, but not for tuple structs, because we seem to be missing a `TupleStructLit` (akin to `StructLit`, but for tuple structs). I am happy to implement `TupleStructLit` parsing given some guidance (provided it's really missing) and make the assist work for tuple structs as well. Could do so either in this PR, or another one 🙂 

Sorry if I missed something important, this is my first PR for Rust Analyzer.

Btw is there any way to run the assists in emacs?

UPDATE: I just realized that parsing `TupleStructLit` would be quite difficult as it it really similar, if not identical to a function call...

Co-authored-by: yanchith <yanchi.toth@gmail.com>
2019-03-18 08:24:18 +00:00
yanchith
ca262fbab8 Only replace NamedFieldList and add test for preserving Self 2019-03-18 09:03:10 +01:00
yanchith
8d47e004b8 Remove unachievable TODO 2019-03-18 08:19:51 +01:00
pcpthm
76075c7410 Use Marker argument for item parsers
- Fix pub_expr
- Fix incorrect parsing of crate::path
2019-03-18 14:34:08 +09:00
bors[bot]
4c1ea0b628 Merge #987
987: Refactor maybe_item to use Marker argument r=pcpthm a=pcpthm

As suggested at <https://github.com/rust-analyzer/rust-analyzer/pull/980#issuecomment-473659745>.
For expression paring functions, changing signature
- from `fn(&mut Parser) -> Option<CompletedMarker>` to `fn(&mut Parser, Marker) -> Result<CompletedMarker, Marker>`
- from `fn(&mut Parser) -> CompletedMarker` to `fn(&mut Parser, Marker) -> CompletedMarker`
is my plan.

Co-authored-by: pcpthm <pcpthm@gmail.com>
2019-03-18 04:16:20 +00:00
pcpthm
3d9c2beb8e Apply stylistic changes suggested 2019-03-18 13:14:47 +09:00
bors[bot]
40c6dd1f4c Merge #982
982: Implement BindingMode for pattern matching. r=flodiebold a=mjkillough

Implement `BindingMode` for pattern matching, so that types can be
correctly inferred using match ergonomics. The binding mode defaults to
`Move` (referred to as 'BindingMode::BindByValue` in rustc), and is
updated by automatic dereferencing of the value being matched.

Fixes #888.

 - [Binding modes in The Reference](https://doc.rust-lang.org/reference/patterns.html#binding-modes)
 - [`rustc` implementation](e17c48e2f2/src/librustc_typeck/check/_match.rs (L77)) (and [definition of `BindingMode`](e957ed9d10/src/librustc/ty/binding.rs))
 - [Match Ergonomics RFC](https://github.com/rust-lang/rfcs/blob/master/text/2005-match-ergonomics.md#binding-mode-rules)

Co-authored-by: Michael Killough <michaeljkillough@gmail.com>
2019-03-17 21:41:37 +00:00
Michael Killough
6299ccd350 Split test case and use tested_by!. 2019-03-17 19:08:51 +00:00
Michael Killough
33add0ee30 Simplify match statement. 2019-03-17 18:50:22 +00:00
yanchith
907f7307af Implement naive version of fill_struct_fields assist 2019-03-17 19:48:25 +01:00
Michael Killough
354134ffb4 impl Default for BindingMode.
This decouples callers from knowing what the default binding mode of
pattern matching is.
2019-03-17 18:46:01 +00:00
bors[bot]
91e7a3b6f2 Merge #983
983: support remainder assignment operator r=matklad a=JeanMertz

`%=` was returning errors for me, turns out it wasn't added as a valid assignment operation.

I'm not sure what the best location would be to add a test for this. Please let me know and I'll add one.

Co-authored-by: Jean Mertz <jean@mertz.fm>
2019-03-17 14:34:14 +00:00
Jean Mertz
a8ee994ae0
support remainder assignment operator 2019-03-17 14:11:24 +01:00
pcpthm
e570267515 Refactor maybe_item to use Marker argument 2019-03-17 22:04:25 +09:00
bors[bot]
290a3d0a6b Merge #986
986: Fix parse tree of attribute on match arm r=matklad a=pcpthm

```rust
match () {
    #[attr]
    () => (),
}
```
Incorrect parse tree: `MatchArmList(Attr(..), MatchArm(..))`.
Fixed: `MatchArmList(MatchArm(Attr(..), ...))`.

Co-authored-by: pcpthm <pcpthm@gmail.com>
2019-03-17 12:14:36 +00:00
pcpthm
a67fe4ea7e Fix parse tree of attribute on match arm 2019-03-17 20:57:27 +09:00
bors[bot]
aea9c98f53 Merge #985
985: simplify parsing blocks a bit r=pcpthm a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-03-17 10:26:45 +00:00
bors[bot]
3ec28dd9b8 Merge #984
984: Allow attribute on struct literal field r=matklad a=pcpthm

Cherrypicked from #980

Co-authored-by: pcpthm <pcpthm@gmail.com>
2019-03-17 10:16:34 +00:00
Aleksey Kladov
a8271cb31f simplify parsing blocks a bit 2019-03-17 13:14:17 +03:00
pcpthm
a1d84f5fb0 Allow attribute on struct literal field 2019-03-17 19:08:35 +09:00
bors[bot]
7d3f48cdaf Merge #968
968: Macro aware name resoltion r=matklad a=matklad

The first commit lays the ground work for new name resolution, including

* extracting position-indendent items from parse trees
* walking the tree of modules
* old-style macro_rules resolve

cc @pnkfelix: this looks like an API name resolution should interact with. 

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-03-17 09:59:04 +00:00
Aleksey Kladov
3a77023365 docs 2019-03-17 12:53:22 +03:00
Aleksey Kladov
4d7fa6d30b remove fixme 2019-03-17 12:53:22 +03:00
Aleksey Kladov
6955e392f8 remove old macro support 2019-03-17 12:53:22 +03:00
Aleksey Kladov
ee3cf6172b rename ModuleId -> CrateModuleId 2019-03-17 12:53:22 +03:00
Aleksey Kladov
c51a6a7bdd fix error on wrong path 2019-03-17 12:53:22 +03:00
Aleksey Kladov
0d6b8baa89 log time 2019-03-17 12:53:22 +03:00
Aleksey Kladov
967a4b64af Reorganize name resolution 2019-03-17 12:53:22 +03:00
Aleksey Kladov
d4449945a0 hack around non-terminating macro expansion 2019-03-17 12:52:52 +03:00
Aleksey Kladov
b2a6c17362 remove lower module 2019-03-17 12:52:52 +03:00
Aleksey Kladov
c7259a899c remove ItemMap 2019-03-17 12:52:05 +03:00
Aleksey Kladov
71e5adf694 move tests over to crate-def-map 2019-03-17 12:49:07 +03:00
Aleksey Kladov
2195d1db6d Replace module_tree with CrateDefMap 2019-03-17 12:49:07 +03:00
Aleksey Kladov
182c05a96c add name resolution from the old impl
unlike the old impl, this also handles macro imports across crates
2019-03-17 12:46:13 +03:00
Aleksey Kladov
0d8d918656 add skeleton for macro-aware name resolutions 2019-03-17 12:46:13 +03:00
bors[bot]
65e763fa84 Merge #947
947: Add missing impl members r=matklad a=Xanewok

Closes #878.

This took longer than expected as I wrapped my head around the API and the project - hopefully I didn't miss any edge case here.

r? @matklad 

Co-authored-by: Igor Matuszewski <xanewok@gmail.com>
2019-03-17 08:51:06 +00:00
Igor Matuszewski
30a226c725 Move the primary assist fn to the top of the file 2019-03-16 23:24:17 +01:00
Igor Matuszewski
5b0b87f8de Provide assist when cursor is immediately outside impl item block 2019-03-16 23:19:14 +01:00
Igor Matuszewski
2f36f47dab Do a cleanup/legibility pass 2019-03-16 22:41:13 +01:00
Igor Matuszewski
1df81f3d65 Take into account parent indent when filling trait members 2019-03-16 22:41:13 +01:00
Igor Matuszewski
b3742873d9 Simplify trait resolution fragment 2019-03-16 22:41:13 +01:00
Igor Matuszewski
0e47c371fd Ignore unnamed trait fns and add more tests 2019-03-16 22:41:13 +01:00
Igor Matuszewski
406343492c Simplify calculation of missing functions
Asymptotically computing a set difference is faster but in the average
case we won't have more than ~10 functions. Also prefer not using hash
sets as these may yield nondeterministic results.
2019-03-16 22:41:13 +01:00
Igor Matuszewski
713975b1c1 Properly support the case when the cursor is inside an empty block or outside 2019-03-16 22:41:13 +01:00
Igor Matuszewski
38eece97ec Redo indent calculation when adding missing impl members 2019-03-16 22:41:13 +01:00