Commit Graph

3457 Commits

Author SHA1 Message Date
Florian Diebold
69c8cfc4c1 Add test for T::Item cycles 2019-09-17 23:06:05 +02:00
Aleksey Kladov
2890a1450a remove confusing code
I must confess I don't really understand what this code is trying to
do, but it definitely misreports changes during fixedpoint iteration,
and no tests fail if I remove it, so...
2019-09-17 21:04:15 +03:00
Aleksey Kladov
9ad2cea251 show error log by default 2019-09-17 20:53:12 +03:00
Florian Diebold
a040fde3ae Remove TraitItem and ImplItem in favor of AssocItem 2019-09-17 19:47:45 +02:00
Florian Diebold
53a932509d Small review improvements 2019-09-17 19:47:45 +02:00
Florian Diebold
35d1c03896 Add test for <T>::Item 2019-09-17 19:47:45 +02:00
Florian Diebold
fe1dfd2b20 Refactor some more
Type-relative paths (`<T>::foo`) also need to work in type context, for example
`<T>::Item` is legal. So rather than returning the type ref from the resolver
function, just check it before.
2019-09-17 19:47:45 +02:00
Florian Diebold
406280e52f Refactor associated item resolution more
When resolving an associated item in value namespace, use the `Ty` lowering code
for the segments before the last instead of replicating it.
2019-09-17 19:47:45 +02:00
Florian Diebold
828d60574f Refactor a bit to prepare for resolving trait assoc items 2019-09-17 19:47:45 +02:00
Florian Diebold
913ab1ec0a Resolve assoc types on type parameters
E.g. `fn foo<T: Iterator>() -> T::Item`. It seems that rustc does this only for
type parameters and only based on their bounds, so we also only consider traits
from bounds.
2019-09-17 19:47:45 +02:00
Florian Diebold
16ee779483 Adapt some tests 2019-09-17 19:47:45 +02:00
Aleksey Kladov
4551182f94 use usual token tree for macro expansion 2019-09-17 15:51:48 +03:00
Aleksey Kladov
37ef8927c3 split mbe expander code into two modules 2019-09-17 02:06:14 +03:00
bors[bot]
ba583091e6
Merge #1817
1817: Support path starting with a type r=matklad a=uHOOCCOOHu

The path syntax `<Ty>::foo`

Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
2019-09-16 12:43:21 +00:00
Dylan MacKenzie
cd8155b7f7 Remove is_unnamed 2019-09-15 23:08:32 -07:00
Dylan MacKenzie
beac779c96 Gracefully handle const _ items in ConstData 2019-09-15 16:48:50 -07:00
uHOOCCOOHu
7ed3be3291
Define known paths and group names 2019-09-15 20:14:33 +08:00
uHOOCCOOHu
de9670fe45
Move store TypeRef of type based path in PathKind 2019-09-15 19:48:24 +08:00
uHOOCCOOHu
4926bed426
Support path starting with a type 2019-09-15 19:40:32 +08: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
0956323bb7 Generate dot_dot_test 2019-09-14 17:08:22 -07:00
Dylan MacKenzie
da3815122d Bless old tests containing a .. pattern 2019-09-14 17:08:22 -07: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
c413f444a0 Add tests for underscores in const and static items 2019-09-14 16:31:09 -07:00
Dylan MacKenzie
253a18f938 Allow an underscore as the identifier in const items 2019-09-14 16:31:09 -07:00
Florian Diebold
613863abb9 Remove a dbg! 2019-09-14 11:05:42 +02:00
Florian Diebold
dc935be1b5 Support bare Trait without dyn 2019-09-14 10:20:41 +02:00
Florian Diebold
a61615c955 Upgrade Chalk
... and remove Ty::UnselectedProjection. It'll be handled differently.
2019-09-14 10:04:56 +02:00
Aleksey Kladov
7be7f67198 rename add_resolution -> add_scope_def 2019-09-13 16:39:51 +03:00
Aleksey Kladov
2fbe79ed9a make PerNs non-generic 2019-09-13 16:38:59 +03:00
Aleksey Kladov
51e2d76b98 Specify desirable namespace when calling resolve
That way, we are able to get rid of a number of unreachable statements
2019-09-13 16:24:10 +03:00
Aleksey Kladov
114a1b878e rename AdtDef -> Adt 2019-09-13 00:34:52 +03:00
Aleksey Kladov
bcf30d389c generalize impl_froms to nested enums 2019-09-13 00:31:04 +03:00
Aleksey Kladov
45117c6388 make various enums "inherit" from AdtDef 2019-09-13 00:10:16 +03:00
Aleksey Kladov
63e1e63a91 start cleaning up the resolution
Nameres related types, like `PerNs<Resolution>`, can represent
unreasonable situations, like a local in a type namespace. We should
clean this up, by requiring that call-site specifies the kind of
resolution it expects.
2019-09-12 21:34:22 +03:00
JasperDeSutter
e6ee324b85 add macros with local_inner_macros argument 2019-09-12 14:41:16 +02:00
bors[bot]
a1261631a8
Merge #1818
1818: Infer box expression r=matklad a=uHOOCCOOHu

Infer `box e` to be `std::boxed::Box<T>` where `e: T`

Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
2019-09-12 10:53:29 +00:00
bors[bot]
561e7aea5b
Merge #1821
1821: Macro completion tweaks r=matklad a=SomeoneToIgnore

Thanks @uHOOCCOOHu for making the macro completion happen :)

I've added a few tweaks to the current completion to make it a bit more convenient:

* Automatically add braces and put the editor cursor inside of them:
<img width="159" alt="image" src="https://user-images.githubusercontent.com/2690773/64737220-022b9f00-d4f5-11e9-8088-76d4678921ab.png">

Currently I have to add the braces manually which is a bit cumbersome.
One further improvement can be to detect if macro accepts no parameters and place the cursor differently for this case.

* Add an exclamation mark to the macro completion label

This helps to distinguish macros from other completion items and also allows to show only macros in completion if you type `!`:
<img width="722" alt="image" src="https://user-images.githubusercontent.com/2690773/64736987-8b8ea180-d4f4-11e9-8355-2ce4f83b7aa8.png">

<img width="732" alt="image" src="https://user-images.githubusercontent.com/2690773/64737214-ffc94500-d4f4-11e9-946e-1ba2db1c7fb1.png">


Additionally, automatic formatting hooks had adjusted two `help.rs` files, I've added them as a last commit to the PR even though they are not really related.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2019-09-12 10:45:47 +00:00
Aleksey Kladov
0ffd1fdbe4 fix panic when fetching generics
due to macro expansion, the root node is not always a file
2019-09-12 13:12:26 +03: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
Kirill Bulatov
9c2a3da67c Complete vec macros with square brackets 2019-09-12 12:16:09 +03:00
Kirill Bulatov
2ca8ba783c Fix the formatting issues 2019-09-12 12:16:09 +03:00
Kirill Bulatov
1852b27233 Add ! to the macro completion label 2019-09-12 12:15:33 +03:00
Kirill Bulatov
037e02c08d Complete macros parenthesis 2019-09-12 12:15:33 +03:00
Aleksey Kladov
a31933e4b5 add quiet mode to analysis-stats 2019-09-12 11:45:33 +03:00
Aleksey Kladov
81e216a079 analysis stats uses positional arg again 2019-09-12 11:14:09 +03:00
uHOOCCOOHu
8c078a0164
Infer box expression 2019-09-12 02:35:09 +08:00
bors[bot]
6ce6744e18
Merge #1796
1796: Support completion for macros r=matklad a=uHOOCCOOHu

This is based on #1795 , and fixes #1727 

Also prettify hover text of macros.

Some screenshorts below:

Completion in item place.
<img width="416" alt="Screenshot_20190910_134056" src="https://user-images.githubusercontent.com/14816024/64587159-fa72da00-d3d0-11e9-86bb-c98f169ec08d.png">

After pressing `tab`.
<img width="313" alt="Screenshot_20190910_134111" src="https://user-images.githubusercontent.com/14816024/64587160-fa72da00-d3d0-11e9-9464-21e3f6957bd7.png">

Complete macros from `std`.
<img width="588" alt="Screenshot_20190910_134147" src="https://user-images.githubusercontent.com/14816024/64587161-fb0b7080-d3d0-11e9-866e-5161f0d1b546.png">

Hover text.
<img width="521" alt="Screenshot_20190910_134242" src="https://user-images.githubusercontent.com/14816024/64587162-fb0b7080-d3d0-11e9-8f09-ad17e3f6702a.png">



Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
2019-09-11 14:49:57 +00:00
uHOOCCOOHu
6353b1621f
Split out complete_macro_in_item_position 2019-09-11 22:44:44 +08:00
uHOOCCOOHu
c033d18700
Fix typo 2019-09-11 22:39:02 +08:00
Aleksey Kladov
9eb14e1170 cleanup expansion to item list 2019-09-10 22:22:57 +03:00
Aleksey Kladov
b9d9db83d1 cleanup dollar handling in expressions 2019-09-10 21:28:27 +03:00
bors[bot]
1140a83c1b
Merge #1806
1806: refactor(args): Switch to pico-args r=matklad a=Geobert

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/1768

Co-authored-by: Geobert Quach <geobert@protonmail.com>
2019-09-10 17:37:21 +00:00
Aleksey Kladov
4fdaec99c0 simiplify 2019-09-10 20:28:50 +03:00
Aleksey Kladov
6e5198cd6d add fragmets to expansion 2019-09-10 20:26:41 +03:00
Geobert Quach
aa894ace1f refactor(args): Apply comments 2019-09-10 16:17:11 +01:00
Aleksey Kladov
ed726081d1 add a jointness parser tests
cc https://github.com/rust-lang/rust/issues/64242
2019-09-10 15:57:51 +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
Geobert Quach
4e94c46713 refactor(args): Switch to pico-args in ra_tools 2019-09-10 12:56:45 +01:00
Geobert Quach
735845d86e refactor(args): Switch to pico-args 2019-09-10 11:31:40 +01:00
uHOOCCOOHu
c66a789a04
Show macro definition in hover text 2019-09-10 13:33:02 +08:00
uHOOCCOOHu
7de9537ccc
Support completion for macros 2019-09-10 13:32:47 +08: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
bors[bot]
c3d96f64ef
Merge #1795
1795: Make macro scope a real name scope and fix some details r=matklad a=uHOOCCOOHu

This PR make macro's module scope a real name scope in `PerNs`, instead of handling `Either<PerNs, MacroDef>` everywhere.

In `rustc`, the macro scope behave exactly the same as type and value scope.
It is valid that macros, types and values having exact the same name, and a `use` statement will import all of them. This happened to module `alloc::vec` and macro `alloc::vec!`.
So `Either` is not suitable here.

There is a trap that not only does `#[macro_use]` import all `#[macro_export] macro_rules`, but also imports all macros `use`d in the crate root.
In other words, it just _imports all macros in the module scope of crate root_. (Visibility of `use` doesn't matter.)

And it also happened to `libstd` which has `use alloc_crate::vec;` in crate root to re-export `alloc::vec`, which it both a module and a macro.
The current implementation of `#[macro_use] extern crate` doesn't work here, so that is why only macros directly from  `libstd` like `dbg!` work, while `vec!` from `liballoc` doesn't.
This PR fixes this.

Another point is that, after some tests, I figure out that _`macro_rules` does NOT define macro in current module scope at all_.
It defines itself in legacy textual scope. And if `#[macro_export]` is given, it also is defined ONLY in module scope of crate root. (Then being `macro_use`d, as mentioned above)
(Well, the nightly [Declarative Macro 2.0](https://github.com/rust-lang/rust/issues/39412) simply always define in current module scope only, just like normal items do. But it is not yet supported by us)

After this PR, in my test, all non-builtin macros are resolved now. (Hover text for documentation is available) So it fixes #1688 . Since compiler builtin macros are marked as `#[rustc_doc_only_macro]` instead of `#[macro_export]`, we can simply tweak the condition to let it resolved, but it may cause expansion error.

Some critical notes are also given in doc-comments.

<img width="447" alt="Screenshot_20190909_223859" src="https://user-images.githubusercontent.com/14816024/64540366-ac1ef600-d352-11e9-804f-566ba7559206.png">


Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
2019-09-09 21:09:23 +00:00
Niko Matsakis
85fdf57dbd modify tests
Some method resolution tests now yield `{unknown}` where they did not
before.

Other tests now succeed, likely because this is helping the solver
steer its efforts.
2019-09-09 16:05:31 -04:00
Niko Matsakis
3f9996d18a also make "unknown" case non-enumerable 2019-09-09 15:30:26 -04:00
Niko Matsakis
65582933cf make all traits non-enumerable
As discussed on Zulip, this actually matches the present behavior of
rustc.
2019-09-09 15:24:24 -04:00
uHOOCCOOHu
5f48ef3902
Strip 2019-09-10 01:21:29 +08:00
bors[bot]
7258523a51
Merge #1789
1789: Debug r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-09-09 14:35:21 +00:00
Aleksey Kladov
e5a8093dd4 document module 2019-09-09 17:31:11 +03:00
uHOOCCOOHu
40f9134159
Make macro scope a real name scope
Fix some details about module scoping
2019-09-09 20:54:02 +08:00
Aleksey Kladov
7910202ecd tiny simplification 2019-09-09 13:23:41 +03:00
Aleksey Kladov
ef2b84ddf1 introduce hir debugging infra
This is to make debugging rust-analyzer easier.

The idea is that `dbg!(krate.debug(db))` will print the actual, fuzzy
crate name, instead of precise ID. Debug printing infra is a separate
thing, to make sure that the actual hir doesn't have access to global
information.

Do not use `.debug` for `log::` logging: debugging executes queries,
and might introduce unneded dependencies to the crate graph
2019-09-09 12:32:16 +03:00
bors[bot]
734a43e95a
Merge #1793
1793: Fix outer doc-comments of `macro_rules` r=matklad a=uHOOCCOOHu

Document comments of `macro_rules!` is currently parsed outside the `MACRO_CALL` node,
which makes `DocCommentsOwner::doc_comments()` always empty.

For the input:
```rust
/// Some docs
macro_rules! foo {
    () => {};
}
```

Current parsing tree is:
```
SOURCE_FILE
  COMMENT    // <- This should be children of MACRO_CALL
  WHITESPACE
  MACRO_CALL
    PATH
<...omitted...>
```

It should be:
```
SOURCE_FILE
  MACRO_CALL
    COMMENT
    WHITESPACE
    PATH
<...omitted...>
```


Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
2019-09-09 08:45:00 +00:00
uHOOCCOOHu
f3cbdb07c5
Fix outer doc-comments of macro_rules 2019-09-09 11:13:14 +08:00
uHOOCCOOHu
9ed21d65fb
Fix test 2019-09-09 01:34:53 +08:00
uHOOCCOOHu
92c07803cc
Rename textual_macro -> legacy_macro
Add comments
2019-09-09 01:34:53 +08:00
uHOOCCOOHu
f7f7c2aff8
Revert "Replace with immutable map to avoid heavy cloning"
This reverts commit 2c494eb803c88ef5d23607c3b156fce60c2b8076.

See: https://github.com/rust-analyzer/rust-analyzer/pull/1784#issuecomment-529119924
2019-09-09 01:34:53 +08:00
uHOOCCOOHu
c90256429b
Replace with immutable map to avoid heavy cloning 2019-09-09 01:34:53 +08:00
uHOOCCOOHu
26b092bd3b
Resolve textual scoped macros inside item 2019-09-09 01:34:53 +08:00
uHOOCCOOHu
e0f305a6bf
Support textual scoped macros 2019-09-09 01:33:28 +08:00
Nelson Chen
14585468e2
Minor typo fix for ra_assists code doc 2019-09-08 02:10:53 -07:00
Aleksey Kladov
6021a2a83a cleanup hir db imports 2019-09-08 09:55:12 +03:00
Aleksey Kladov
bcc9a28734 don't cycle when processing macros from prelude in prelude 2019-09-07 21:47:59 +03:00
Florian Diebold
8fb3cab76c Fix crash for super trait cycles 2019-09-07 16:49:57 +02:00
Florian Diebold
9db34eec20 Fix Chalk environments
The clauses need to be wrapped in `FromEnv` clauses for elaboration (i.e.
things like inferring `T: Clone` from `T: Copy`) to work correctly.
2019-09-07 16:30:37 +02:00
Florian Diebold
a1776b27c7 Use traits from where clauses for method resolution
E.g. if we have `T: some::Trait`, we can call methods from that trait without it
needing to be in scope.
2019-09-07 16:30:31 +02:00
Florian Diebold
d21cdf3c99 Lower Fn(X, Y) -> Z paths 2019-09-07 15:13:05 +02:00
Florian Diebold
60bdb66ef2 Lower bounds on trait definition, and resolve assoc types from super traits 2019-09-07 14:31:43 +02:00
Florian Diebold
4ae4d9c311 Add some more tests 2019-09-07 13:35:41 +02:00
Aleksey Kladov
6c11935712 simplify 2019-09-06 21:57:11 +03:00
Aleksey Kladov
219287a14c don't deadlock on shutdown
Specifically, when we tear down IO threads, we should take care to
dispose connection.

closes #1775
2019-09-06 20:58:21 +03:00
Aleksey Kladov
28df377759 add option to disable notify 2019-09-06 17:21:29 +03:00
bors[bot]
007737a0e7
Merge #1779
1779: minor r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-09-06 11:33:37 +00:00
Aleksey Kladov
f477f2516a minor 2019-09-06 14:30:24 +03:00
Aleksey Kladov
9ae455ea52 make source_root API more abstract 2019-09-06 14:21:11 +03:00
bors[bot]
4576e6597e
Merge #1772
1772: switch to rustc_lexer crate r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-09-05 20:12:19 +00:00