Commit Graph

3396 Commits

Author SHA1 Message Date
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
Aleksey Kladov
7a9d7dd637 switch to rustc_lexer crate 2019-09-05 23:07:17 +03:00
bors[bot]
419eec3d2f
Merge #1771
1771: Further tweak for macro_use on extern crate r=matklad a=uHOOCCOOHu

Some more tweaks to #1743 to behave more like `rustc`
1. Hoist macros from `#[macro_use] extern crate`, so that they can be used before `extern crate`.
2. Implicit `#[macro_use]` for `prelude` if exists


Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
2019-09-05 19:50:06 +00:00
bors[bot]
c705fff309
Merge #1770
1770: rename test file to match impl file r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-09-05 18:54:20 +00:00
Aleksey Kladov
5a38a80d1a rename test file to match impl file 2019-09-05 21:43:32 +03:00
Aleksey Kladov
33965f0f3e fix renaming of modules 2019-09-05 21:36:40 +03:00
Aleksey Kladov
3e5f7299e1 move mod resolution to a separate file 2019-09-05 20:27:10 +03:00
Aleksey Kladov
b2be998b7b better error recovery for use trees 2019-09-05 19:53:07 +03:00
bors[bot]
edc2016f8b
Merge #1766
1766: always use \n newlines r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-09-05 14:51:14 +00:00
Aleksey Kladov
8b8a11ded7 always use \n newlines 2019-09-05 17:50:39 +03:00
ivfranco
4854408f28 close #1763 2019-09-05 22:04:56 +08:00
uHOOCCOOHu
67d33cc21a
Hoist macros from extern crate with macro_use 2019-09-05 18:50:04 +08:00
uHOOCCOOHu
dec43a0c5d
Consider prelude to be macro_use 2019-09-05 18:50:04 +08:00
bors[bot]
82f3317e2b
Merge #1761
1761: "move type bounds to where clause" assist r=matklad a=viorina



Co-authored-by: Ekaterina Babshukova <ekaterina.babshukova@yandex.ru>
2019-09-05 10:39:35 +00:00
Ekaterina Babshukova
acb89d2be1 add assist to move type bounds to where clause 2019-09-05 13:29:13 +03:00
bors[bot]
6702f5b7b5
Merge #1743
1743: Support `#[macro_use]` on `extern crate` r=matklad a=uHOOCCOOHu

Unfortunately, #1688 is still an issue. My guess is wrong :(

Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
2019-09-05 09:04:02 +00:00
uHOOCCOOHu
3ff5d7e73c
Fix typo 2019-09-05 12:03:32 +08:00
uHOOCCOOHu
0d23286caf
Let macro_use bypass module scope 2019-09-05 11:46:00 +08:00
kjeremy
cb063a9b30 lsp-types 0.61.0 2019-09-03 10:50:39 -04:00
Florian Diebold
b8c1e402fa Make type walking infrastructure a bit nicer
If/when we switch to using Chalk's Ty, we'll need to replace this by its `Fold`
trait, but I didn't want to import the whole thing just yet.
2019-09-03 14:00:35 +02:00
Florian Diebold
c4fcfa2b0d Properly format impl Trait<Type = Foo> types
It's a bit complicated because we basically have to 'undo' the desugaring, and
the result is very dependent on the specifics of the desugaring and will
probably produce weird results otherwise.
2019-09-03 14:00:35 +02:00
Florian Diebold
741e350d4b Add support for associated type bindings (where Trait<Type = X>) 2019-09-03 14:00:35 +02:00
Florian Diebold
966ab9abd2 Add test for assoc type bindings 2019-09-03 13:25:29 +02:00
Aleksey Kladov
9c3b25177e Correctly build BodySourceMap for macro-expanded expressions 2019-09-03 11:04:38 +03:00
Aleksey Kladov
4b51c92fee slightly simplify expr lowering flow 2019-09-03 09:41:21 +03:00
Aleksey Kladov
da850361ba clearer ignore 2019-09-03 09:01:09 +03:00
Aleksey Kladov
82b218b7bf remove needless refs 2019-09-03 08:59:44 +03:00
Aleksey Kladov
48ffbf29b7 use recrod terminology for hir::Pat 2019-09-03 08:59:09 +03:00
Aleksey Kladov
db69d134fb move expr lowering to lower 2019-09-03 08:56:36 +03:00
Aleksey Kladov
e94587e315 fix assists 2019-09-02 21:52:06 +03:00
Aleksey Kladov
5e3f291195 fix hir for new block syntax 2019-09-02 21:23:19 +03:00
Aleksey Kladov
dcf8e89503 fix generated AST 2019-09-02 20:15:51 +03:00
Aleksey Kladov
470fc4765c update test data 2019-09-02 20:15:51 +03:00
Aleksey Kladov
3c2dea7f55 always wrap block into an expression 2019-09-02 20:15:51 +03:00
bors[bot]
a8397deab9
Merge #1751
1751: remove useless trait r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-09-02 16:46:10 +00:00
Aleksey Kladov
f377b94628 remove useless trait 2019-09-02 19:45:41 +03:00
Aleksey Kladov
e2b3844493 remove needless clone 2019-09-02 19:21:28 +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
Florian Diebold
f92177cfb5 Add an expr_source method analogous to the source methods in the code model
... and use that instead of exposing the source map.
2019-09-02 14:56:38 +02:00
Florian Diebold
a7858bb7bf Report type mismatches in analysis-stats
Only the number usually; each one individually when running with -v.
2019-09-02 14:56:38 +02:00
uHOOCCOOHu
a66214b34e
Fix import strategy of macro_use and its test 2019-09-02 14:36:20 +08:00
Aleksey Kladov
4b6bccb58c ⬆️ once_cell 2019-09-01 23:18:15 +03:00
uHOOCCOOHu
dfa758f6a9
Add test 2019-09-01 02:03:33 +08:00
uHOOCCOOHu
f5bea9051b
Support resolution of #[macro_use] extern crate 2019-09-01 01:54:41 +08:00
Aleksey Kladov
4e3f5cc729 cleanup main loop 2019-08-31 14:47:37 +03:00
Aleksey Kladov
983de30a56 inline thread-worker 2019-08-30 20:32:59 +03:00
Aleksey Kladov
7cc14a7596 ⬆️ lsp-server 2019-08-30 20:18:57 +03:00
Aleksey Kladov
72a3722470 move lsp-server to a separate repository 2019-08-30 17:24:11 +03:00
Aleksey Kladov
0f6c048ce1 ⬆️ insta 2019-08-29 17:04:01 +03:00
Kirill Bulatov
4adfdea1ad Small fixes 2019-08-26 23:00:35 +03:00
Kirill Bulatov
590aed2eec Remove redundant tests 2019-08-26 23:00:27 +03:00
Florian Diebold
c256a72b03 Fix 'missing Ok in tail expr' validation
Because of the coercion change, the type mismatch now only happens on the block
expression.
2019-08-26 22:44:50 +03:00
Florian Diebold
e37b6c5837 Make infer_block not unify; add back calculate_least_upper_bound 2019-08-26 22:44:50 +03:00
Kirill Bulatov
44386d5373 An attempt to add the coercion logic for Never 2019-08-26 22:44:50 +03:00
Kirill Bulatov
89f3cc587d Properly coerce never types 2019-08-26 22:44:50 +03:00
Kirill Bulatov
8b612251fd Remove extra inference test 2019-08-26 22:44:50 +03:00
Kirill Bulatov
44cf7b34fe Fix never in if expressions 2019-08-26 22:44:50 +03:00
Kirill Bulatov
c1f47c3788 Add test marks 2019-08-26 22:44:50 +03:00
Kirill Bulatov
0ce05633a1 Fix match type inference for Never match arms 2019-08-26 22:44:50 +03:00
Kirill Bulatov
f63cfd5fca Tests 2019-08-26 22:44:50 +03:00
bors[bot]
1fbe5ffba8
Merge #1735
1735: ⬆️ vfs r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-08-25 10:13:37 +00:00