Commit graph

1440 commits

Author SHA1 Message Date
Aleksey Kladov
cebeedc66f Next gen IDs for functions
The current system with AstIds has two primaraly drawbacks:

* It is possible to manufacture IDs out of thin air.
  For example, it's possible to create IDs for items which are not
  considered in CrateDefMap due to cfg. Or it is possible to mixup
  structs and unions, because they share ID space.

* Getting the ID of a parent requires a secondary index.

Instead, the plan is to pursue the more traditional approach, where
each items stores the id of the parent declaration. This makes
`FromSource` more awkward, but also more correct: now, to get from an
AST to HIR, we first do this recursively for the parent item, and the
just search the children of the parent for the matching def
2019-11-20 16:22:58 +03:00
Aleksey Kladov
06fa3d8389 Move traits to hir_def 2019-11-20 14:22:38 +03:00
Aleksey Kladov
51baaf298d Rename with_ast -> with_value 2019-11-20 13:09:21 +03:00
Aleksey Kladov
e1a6e38767 Move Generics to hir_def 2019-11-20 12:34:48 +03:00
Aleksey Kladov
0e771915fa Allow non-path default type parameters 2019-11-20 11:46:44 +03:00
Aleksey Kladov
36e3fc9d54 Rename Source::ast -> Source::value 2019-11-20 09:42:30 +03:00
Aleksey Kladov
eec68e6f45
Merge pull request #2297 from kiljacken/master
Add fancy truncation of type hints.
2019-11-20 08:38:25 +03:00
Emil Lauridsen
dadad36bb9 Move type inlay hint truncation to language server
This commit implements a general truncation framework for HirFormatter
that keeps track of how much has been output so far. This information
can then be used to perform truncation inside the language server,
instead of relying on the client.

Initial support is implemented for truncating types hints using the
maxInlayHintLength server config option. The existing solution in the
VSCode extension has been removed in favor of letting the server
truncate type hints.
2019-11-19 17:23:50 +01:00
Edwin Cheng
94c63d2802 Change to use Expansion::file_id and reordering 2019-11-19 22:56:28 +08:00
Edwin Cheng
ae49a22b5c Rebase 2019-11-19 21:49:06 +08:00
Aleksey Kladov
9df3d2e775 Publicise GenericParams
See https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Exposing.20GenericParam.2Ename
2019-11-18 10:35:33 +03:00
Aleksey Kladov
fd52d721e1 More correct expansion mapping
We can't really map arbitrary ranges, we only can map tokens
2019-11-17 20:15:55 +03:00
Aleksey Kladov
7e2f4b30db Disable doctests 2019-11-17 18:35:05 +03:00
Aleksey Kladov
2eaa8c94a8 Goto definition works inside macros 2019-11-16 17:00:54 +03:00
Florian Diebold
ee190388ab Upgrade Chalk again 2019-11-16 13:25:54 +01:00
Florian Diebold
351c29d859 Fix handling of the binders in dyn/impl Trait
We need to be more careful now when substituting bound variables (previously, we
didn't have anything that used bound variables except Chalk, so it was not a
problem).

This is obviously quite ad-hoc; Chalk has more infrastructure for handling this
in a principled way, which we maybe should adopt.
2019-11-16 13:25:54 +01:00
Florian Diebold
9c2a9a9a06 Use Chalk's dyn/impl trait support 2019-11-16 13:11:29 +01:00
Florian Diebold
e21b82e035 Upgrade Chalk
Associated type values (in impls) are now a separate entity in Chalk, so we have
to intern separate IDs for them.
2019-11-16 13:11:29 +01:00
bors[bot]
d9d99369b2
Merge #2271
2271: Force passing Source when creating a SourceAnalyzer r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-11-15 23:12:59 +00:00
Aleksey Kladov
d898ecb8f2 Force passing Source when creating a SourceAnalyzer 2019-11-16 02:12:35 +03:00
bors[bot]
69f3b01dc5
Merge #2268
2268: Handle ast::MacroCall in classify_name and impl FromSource for MacroDef r=matklad a=kjeremy

Fixes #2260

Co-authored-by: kjeremy <kjeremy@gmail.com>
2019-11-15 22:36:10 +00:00
Aleksey Kladov
1c819fc8f6 Prepare SourceAnalyzer for macros 2019-11-16 01:31:40 +03:00
kjeremy
60fd260e7f Handle ast::MacroCall in classify_name and impl FromSource for MacroDef
Fixes #2260
2019-11-15 16:47:58 -05:00
Aleksey Kladov
0404e647e6 Prepare SourceAnalyzer for macros 2019-11-16 00:40:54 +03:00
Aleksey Kladov
bd8af6a413 Sourcify some more 2019-11-16 00:05:10 +03:00
Aleksey Kladov
4c90b7e2ec Sourcify some things
If we want to support macros properly, we need to get rid of those
FileIds everywhere...
2019-11-15 23:24:56 +03:00
Aleksey Kladov
b21829f7ed Remove old impls infrastructure 2019-11-15 21:35:03 +03:00
Aleksey Kladov
c3f84960aa Flatten expr module 2019-11-15 14:53:09 +03:00
Aleksey Kladov
2f6c0c314b Move scope tests to hir_def 2019-11-15 14:47:26 +03:00
Aleksey Kladov
9167da66ac Reduce visibility 2019-11-15 14:15:04 +03:00
Aleksey Kladov
3564fbb7f5 Auto-upgrade some insta snapshots 2019-11-15 12:56:24 +03:00
Aleksey Kladov
487fc448c3 Reduce visibility 2019-11-15 12:24:30 +03:00
Aleksey Kladov
b80fa14a85 Use Local more 2019-11-15 12:00:36 +03:00
Aleksey Kladov
a28907af8c Privatize modules 2019-11-15 10:42:54 +03:00
Aleksey Kladov
9c7a2aef30 Refactor Module::from_source to properly descend from root file 2019-11-15 10:26:31 +03:00
Aleksey Kladov
1583ab1558 Move body queries to hir_def 2019-11-14 17:37:22 +03:00
Aleksey Kladov
f924ae3b86 Move scopes to hir_def 2019-11-14 11:56:13 +03:00
Aleksey Kladov
da2ca01eba Handle macro-generated expressions slightly less wrong 2019-11-14 10:30:30 +03:00
Aleksey Kladov
8c8ef1432e Rename MacroResolver -> Expander 2019-11-14 09:38:25 +03:00
Aleksey Kladov
b3175b7077 Move current file to MacroResolver 2019-11-14 09:37:33 +03:00
Aleksey Kladov
b8f62095d6 Normalize data
No need to store derivable info
2019-11-14 09:09:42 +03:00
Aleksey Kladov
70dd70b1fc Reduce duplication between uncertain floats & ints 2019-11-13 09:56:33 +03:00
Aleksey Kladov
1a90ad5802 Move expression lowering to hir_def 2019-11-12 18:46:57 +03:00
Aleksey Kladov
fe00db72b9 Remove owner from Body 2019-11-12 16:46:27 +03:00
Aleksey Kladov
d09e5a3d9e Move definition of exprs to hir_def 2019-11-12 15:09:25 +03:00
Aleksey Kladov
f5e1b0f97c Minor refactoring 2019-11-12 12:07:47 +03:00
Aleksey Kladov
fc055281a5 Minor cleanup 2019-11-12 11:49:16 +03:00
Aleksey Kladov
c5a18c44e5 Introduce hir::GenericParam
Unlike existing hir::GenericParams, this is a global ID.
2019-11-11 17:36:27 +03:00
Aleksey Kladov
ff609cc497 Don't reexport generics from HIR 2019-11-11 17:22:06 +03:00
bors[bot]
a599147b42
Merge #2200
2200: Add variables to HIR r=matklad a=matklad

Introduce a `hir::Variable`, which should cover locals, parameters and `self`. Unlike `PatId`, variable knows it's owner so it is self-contained, and should be more convenient to use from `ra_ide_api`. 

The goal here is to hide more details about `Body` from hir, which should make it easier to move `Body` into `hir_def`. I don't think that `ra_ide_api` intrracts with bodies directly at the moment anyway, but the glue layer is based basically on `ast::BindPat`, which seems pretty brittle. 

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-11-11 11:48:02 +00:00
Aleksey Kladov
8b7f853cc1 Add hir::Local 2019-11-11 14:42:08 +03:00
bors[bot]
ef2a9aedb6
Merge #2205
2205: Implement bulitin line! macro r=matklad a=edwin0cheng

This PR implements bulitin macro `line!` and add basic infra-structure for other bulitin macros:

1. Extend `MacroDefId` to support builtin macros
2. Add a `quote!` macro for simple quasi quoting.

Note that for support others builtin macros, eager macro expansion have to be supported first, this PR not try to handle it. :)

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2019-11-11 10:53:24 +00:00
Edwin Cheng
4f7df2aac1 Add MacroDefKind 2019-11-11 18:48:16 +08:00
Aleksey Kladov
ee876e7881 Make primitive tys public 2019-11-11 09:20:18 +03:00
Edwin Cheng
c4aa8b63bc Add line macro and tests 2019-11-11 14:15:09 +08:00
Edwin Cheng
c46768d13d Add basic bultin macro infrastructure 2019-11-11 14:13:31 +08:00
Aleksey Kladov
6294fd5ec9 Unfork struct and union ids 2019-11-09 15:34:00 +03:00
bors[bot]
14e19c0df1
Merge #2179
2179: Use HirDatabase to compute `is_deprecated` r=matklad a=martskins

This PR fixes #2167 by introducing `attributes_query` and adding `fn attrs(&self, def: crate::AttrDef) -> Option<Arc<[Attr]>>;`  to the `DefDatabase` trait.

I'm a little concerned about the two spots in `attributes_query` where code is repeated, but I couldn't figure out a way to avoid that, so.. I welcome suggestions 😄 



Co-authored-by: Martin Asquino <martin.asquino@gmail.com>
2019-11-06 21:11:42 +00:00
Martin Asquino
cb3767f28a HirDatabase stored attributes 2019-11-04 18:16:35 -03:00
Aleksey Kladov
739babc391 Move Namespace enum closer to usage 2019-11-04 23:02:35 +03:00
Aleksey Kladov
50364bd478 Appease the linter by dummy doc comments 2019-11-04 22:33:21 +03:00
Aleksey Kladov
fd7819c3c0 Simplify 2019-11-04 22:29:51 +03:00
Aleksey Kladov
74d827bb80 Rename MockDatabase -> TestDB
Actually working rename is sooo useful!
2019-11-04 22:21:15 +03:00
Aleksey Kladov
7649a8ebbe remove dead code 2019-11-04 22:19:06 +03:00
Aleksey Kladov
24894aca31 Remove more duplication in test fixtures 2019-11-04 22:12:49 +03:00
Aleksey Kladov
dcdcc9e4c8 Remove some duplicated test functions 2019-11-04 22:04:51 +03:00
Aleksey Kladov
38b941db13 Cleanup unused marks 2019-11-04 13:29:07 +03:00
Aleksey Kladov
dfdb6321ac Use new text DSL instead of crate_graph! macro 2019-11-04 13:25:42 +03:00
Aleksey Kladov
3603d02134 Reexport relative_path from ra_db 2019-11-04 01:14:17 +03:00
Aleksey Kladov
8922a44395 Add small module-level docs 2019-11-04 00:23:14 +03:00
Aleksey Kladov
f0eb9cc6e6 Remove last traces of nameres from hir 2019-11-03 23:49:44 +03:00
Aleksey Kladov
6fba51c5fc move crate_def_map tests to hir_def 2019-11-03 23:35:48 +03:00
Aleksey Kladov
ba2efca2bb Move CrateDefMap to hir_def 2019-11-03 18:04:06 +03:00
Aleksey Kladov
13735d91a7 Move diagnostics to hir_expand 2019-11-02 23:42:38 +03:00
Aleksey Kladov
b8533413cf Move Source to hir_expand 2019-11-02 23:11:27 +03:00
Florian Diebold
c5e44b2084 Upgrade Chalk 2019-11-02 15:32:08 +01:00
Florian Diebold
8952380884 Change SourceAnalyzer method resoltion API 2019-11-01 20:01:21 +01:00
Florian Diebold
b29092ade3 Various review fixes 2019-11-01 19:57:08 +01:00
Florian Diebold
dc4066ebed Add some doc comments 2019-11-01 19:57:08 +01:00
Florian Diebold
79cb0a0dab Complete trait assoc items 2019-11-01 19:57:08 +01:00
Florian Diebold
b0bf1deb7c Refactor a bit 2019-11-01 19:57:08 +01:00
Florian Diebold
f4181deb0d Don't do autoderef for path resolution 2019-11-01 19:57:08 +01:00
Florian Diebold
1173c3dab5 Refactor to unify with method resolution 2019-11-01 19:57:08 +01:00
Florian Diebold
c7cedea270 Record assoc item resolution 2019-11-01 19:57:08 +01:00
Florian Diebold
7b7133ec58 Insert type vars before doing assoc item resolution 2019-11-01 19:57:08 +01:00
Florian Diebold
44279ef1df Add another unrelated, currently not working test 2019-11-01 19:57:08 +01:00
Florian Diebold
b634ba41e0 Get trait assoc item resolution mostly working 2019-11-01 19:57:08 +01:00
kjeremy
c46be83a34 Fixes #2143 2019-10-31 13:29:56 -04:00
Aleksey Kladov
09f9733ca6 move struct & enum data to hir_def 2019-10-31 16:40:36 +03:00
Aleksey Kladov
1602db7d7d add ModuleDefId to hir_def 2019-10-31 11:23:30 +03:00
Aleksey Kladov
b20d37cb49 move builtin types to hir_def 2019-10-31 10:51:54 +03:00
Aleksey Kladov
6f4d5f7339 move mod_resolution to hir_def 2019-10-31 10:31:29 +03:00
kjeremy
b205a0ced3 source_binder => match_ast! 2019-10-30 16:08:27 -04:00
Aleksey Kladov
ab559f170e move hygiene to hir_expand 2019-10-30 19:10:53 +03:00
Aleksey Kladov
872ac566bf push name down to hir_expand 2019-10-30 18:56:20 +03:00
Aleksey Kladov
b05d6e53fb push either to hir_expand 2019-10-30 18:50:10 +03:00
Aleksey Kladov
0bc7d28518 refactor $crate handling
Introduce proper hygiene module, which should grow quite a bit
eventually.
2019-10-30 18:41:50 +03:00
Aleksey Kladov
e34e71c62d remove forward pointer for attrs 2019-10-30 18:06:08 +03:00
Aleksey Kladov
c1ed9ccc4e fix compilation 2019-10-30 18:04:24 +03:00
Aleksey Kladov
e5300ad3ba remove forward pointer for type_ref 2019-10-30 17:43:14 +03:00
Aleksey Kladov
e564334320 remove forward pointer to Path 2019-10-30 17:43:14 +03:00
Aleksey Kladov
f8ddef875a remove forward pointer for name 2019-10-30 17:43:14 +03:00
Aleksey Kladov
16e620c052 move raw_items to hir_def 2019-10-30 17:43:11 +03:00
Aleksey Kladov
c9cd6aa370 Move ids to hir_def crate 2019-10-30 13:11:38 +03:00
Aleksey Kladov
a136cc0653 introduce ra_hir_def 2019-10-30 12:27:54 +03:00
Aleksey Kladov
56bc874f1d move ty interning to ty 2019-10-30 11:18:38 +03:00
bors[bot]
e38cdf6e56
Merge #2114
2114: Move macro expansion to a separate crate r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-10-29 13:19:45 +00:00
Aleksey Kladov
bca708ba4c cleanup 2019-10-29 16:19:08 +03:00
Aleksey Kladov
7de6eaa58a remove not that useful indirection 2019-10-29 16:01:14 +03:00
Aleksey Kladov
b8b7969bfb remove empty module 2019-10-29 15:53:25 +03:00
Aleksey Kladov
2a5254c106 reduce visibility 2019-10-29 15:25:46 +03:00
Aleksey Kladov
6bf7faf315 flatten hir_expand 2019-10-29 15:11:42 +03:00
Florian Diebold
632a22ae62 Upgrade Chalk, make use of TypeName::Error variant 2019-10-29 13:01:33 +01:00
Aleksey Kladov
5b803055b7 rename hir_def -> hir_expand 2019-10-29 14:59:55 +03:00
Aleksey Kladov
5413875644 move expansion-related code to a separate crate 2019-10-29 14:55:39 +03:00
Aleksey Kladov
77f90caf2d start ra_hir_def crate 2019-10-29 11:15:51 +03:00
Aleksey Kladov
54d3e47318 weaken requirements of AstDef 2019-10-28 20:29:57 +03:00
Aleksey Kladov
8464c45086 remove relative_path_buf workaround
The upstream problem was fixed with the change to 1.0
2019-10-27 12:36:40 +03:00
Florian Diebold
b342ee5616 Upgrade Chalk (without using its dyn/impl Trait support) 2019-10-26 15:11:39 +02:00
Laurențiu Nicola
27a0cb3025 Specify working chalk revisions in manifest 2019-10-25 13:33:14 +03:00
kjeremy
64c1dd10b8 bump insta 2019-10-24 10:35:22 -04:00
Aleksey Kladov
68ea9bd1bf restore assert 2019-10-23 11:31:16 +03:00
Ekaterina Babshukova
55e1910d00 classify module from declaration 2019-10-22 23:47:31 +03:00
Ekaterina Babshukova
835173d065 replace trait by a bunch of functions 2019-10-22 23:47:31 +03:00
Ekaterina Babshukova
121aa35f12 return Declaration from classify_name_ref 2019-10-22 23:47:31 +03:00
Ekaterina Babshukova
0b5d0a41fd replace a chain of if let by macro 2019-10-22 23:47:31 +03:00
Ekaterina Babshukova
11577288c2 initial classify_name 2019-10-22 23:47:31 +03:00
kjeremy
c3045c68a9 relative-path 1.0 2019-10-17 13:08:33 -04:00
Laurențiu Nicola
a6b980d6d4 Bump deps 2019-10-17 18:08:11 +03:00
Aleksey Kladov
260ae2dbc9 minor cleanup 2019-10-16 13:26:02 +03:00
bors[bot]
8e3864fd58
Merge #2008
2008: Prepare SourceDatabase API for lazy file loading r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-10-14 13:26:42 +00:00
Aleksey Kladov
abf2179c0b Prepare SourceDatabase API for lazy file loading 2019-10-14 16:23:55 +03:00
bors[bot]
e182825170
Merge #2006
2006: Improvements around `Arc<[T]>` r=matklad a=sinkuu

First commit tries to avoid cloning `Arc<[T]>` to a temporary `Vec` for mutating it, if there are no other strong references. Second commit utilizes [`FromIterator for Arc<[T]>`](https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-FromIterator%3CT%3E) instead of `.collect::<Vec<_>>().into()` to avoid allocation in `From<Vec<T>> for Arc<[T]>`.

Co-authored-by: Shotaro Yamada <sinkuu@sinkuu.xyz>
2019-10-14 13:14:18 +00:00
Aleksey Kladov
1555a1aa0d remove one more dependency on source roots 2019-10-14 15:15:47 +03:00
Shotaro Yamada
3a55b5bf01 make_mut_slice 2019-10-14 19:50:12 +09:00
Shotaro Yamada
b462eb96b8 import make_mut_arc_slice 2019-10-14 17:21:38 +09:00
Shotaro Yamada
965ca0d271 .collect() directly into Arc<[T]> 2019-10-14 14:25:05 +09:00
Shotaro Yamada
f8d4cdc170 Avoid cloning Arc<[T]> into a vec if possible 2019-10-14 14:25:05 +09:00
Florian Diebold
2955fbc7e1 Split up infer.rs further
- coercion logic goes to `coerce.rs`
 - expression inference goes to `expr.rs`
 - pattern inference goes to `pat.rs`
2019-10-12 18:41:11 +02:00
bors[bot]
0896ca04c4
Merge #1989
1989: Chalk update to simplified IR r=flodiebold a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2019-10-11 11:12:27 +00:00
bors[bot]
f70c54ccfb
Merge #1994
1994: remove last traces of source roots from hir r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-10-11 07:49:39 +00:00
Aleksey Kladov
e44c7ce200 remove last traces of source roots from hir 2019-10-11 10:48:46 +03:00
Shotaro Yamada
0d0a444d43 Remove as_original_file 2019-10-11 06:53:43 +09:00
kjeremy
4ba2c5b2de Chalk update to simplified IR 2019-10-10 14:51:50 -04:00
Aleksey Kladov
29e83988be don't special case macro_use 2019-10-10 17:48:30 +03:00
Aleksey Kladov
89826a50fc don't special case path attr 2019-10-10 17:42:29 +03:00
Aleksey Kladov
b36b8970cc simplify a bit 2019-10-10 17:23:01 +03:00
Aleksey Kladov
5140283277 simplify some tests 2019-10-10 14:51:35 +03:00
Aleksey Kladov
ce0d4a3b1d Refactor and fix some more edge cases around name resolution 2019-10-10 14:46:14 +03:00
Ekaterina Babshukova
aa2f58550a add module methods 2019-10-09 14:59:47 +03:00
Aleksey Kladov
d9f83d9b16 add <> for type aliases as well 2019-10-09 11:53:32 +03:00
Aleksey Kladov
5144f3b22f refactor 2019-10-08 20:33:43 +03:00
bors[bot]
06a8deae4a
Merge #1969
1969: restore coloring of attributes r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-10-08 11:55:27 +00:00
Aleksey Kladov
972079c0e3 macro DSL for cfg in tests 2019-10-08 14:39:44 +03:00
ice1000
b043358be9 Address comments: fix docs, add completion test for Self. 2019-10-08 07:32:41 -04:00
Aleksey Kladov
355419d404 use slightly more idiomatic api for cfg 2019-10-08 14:22:49 +03:00
ice1000
6bad638928 Support inferring Self type in enum definitions
Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>
2019-10-07 19:40:14 -04:00
bors[bot]
ae6305b90c
Merge #1928
1928: Support `#[cfg(..)]` r=matklad a=oxalica

This PR implement `#[cfg(..)]` conditional compilation. It read default cfg options from `rustc --print cfg` with also hard-coded `test` and `debug_assertion` enabled.
Front-end settings are **not** included in this PR.

There is also a known issue that inner control attributes are totally ignored. I think it is **not** a part of `cfg` and create a separated issue for it. #1949

Fixes #1920 

Related: #1073 


Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
Co-authored-by: oxalica <oxalicc@pm.me>
2019-10-05 14:25:59 +00:00
uHOOCCOOHu
b271cb18d5
Add docs 2019-10-03 02:50:22 +08:00
uHOOCCOOHu
e0100e63ae
Optimize 2019-10-03 02:28:03 +08:00
uHOOCCOOHu
43f09ad36c
Refactor CfgOptions inside 2019-10-03 02:28:02 +08:00
uHOOCCOOHu
a49ad47e5a
Support cfg attribute on impl blocks 2019-10-03 02:28:02 +08:00
uHOOCCOOHu
d2ea776b8f
Enable CfgOptions test for workspace crates 2019-10-03 02:28:02 +08:00
uHOOCCOOHu
b1ed887d81
Introduce ra_cfg to parse and evaluate CfgExpr 2019-10-03 02:28:02 +08:00
uHOOCCOOHu
ffe179a736
Pass attributes as token tree to DefCollector 2019-10-03 02:27:11 +08:00
Laurențiu Nicola
f491567fb3 Handle divergence in type inference for blocks 2019-10-02 17:31:34 +03: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
5a4b4f507e
Fix API of Attr 2019-09-30 16:17:53 +08:00
Aleksey Kladov
e60677178e correctly reset chalk state after a panic 2019-09-28 18:49:00 +03:00
Aleksey Kladov
35f1655b0b replace horrible hack with a slightly less horrible one 2019-09-27 20:47:36 +03:00
bors[bot]
2b69c84396
Merge #1815
1815: Support correct `$crate` expansion in macros r=uHOOCCOOHu a=uHOOCCOOHu

This PR makes normal use cases of `$crate` from macros work as expected.

It makes more macros from `std` work. Type inference works well with `panic`, `unimplemented`, `format`, and maybe more.
Sadly that `vec![1, 2, 3]` still not works, but it is not longer an issue about macro.

Screenshot:
![Screenshot_20190927_022136](https://user-images.githubusercontent.com/14816024/65714465-b4568f80-e0cd-11e9-8043-dd44c2ae8040.png)




Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
2019-09-27 02:58:26 +00:00
uHOOCCOOHu
edadeb95be
Fix 2019-09-27 10:55:25 +08:00
Florian Diebold
daaf46177e Add SubstsBuilder
+ further refactoring.
2019-09-26 23:03:39 +02:00
uHOOCCOOHu
2ecb126f5c
Support $crate in item and expr place. 2019-09-27 02:05:06 +08:00
uHOOCCOOHu
8cd23a4fb8
Store crate info in MacroDefId 2019-09-27 02:05:06 +08:00
uHOOCCOOHu
128dc5355b
Refactor Name ready for hygienic macro 2019-09-27 02:04:47 +08:00
uHOOCCOOHu
29e56b8ee4
Support all coercion places 2019-09-26 06:16:58 +08:00
uHOOCCOOHu
5807e261c2
Support custom CoerceUnsized
Split out tests about coercion
2019-09-26 06:16:52 +08:00
uHOOCCOOHu
bf161fa3e5
Better handle never type and branch merging
Split out tests for never type to another file
2019-09-26 06:04:43 +08:00
uHOOCCOOHu
4bb66df6de
Support basic implicit type coerce 2019-09-26 06:04:39 +08:00
uHOOCCOOHu
5205c84ec7
Support auto-deref in argument position 2019-09-26 06:02:04 +08:00
Florian Diebold
c35ef5013c Resolve trait associated items
E.g. `Default::default` or `<Foo as Default>::default`.
2019-09-25 21:41:17 +02:00
Florian Diebold
d0d1a202d4 Fix retrieval of the Fn traits
I used the wrong query, so it only used the lang items from the respective
crate...
2019-09-25 20:04:37 +02:00
bors[bot]
63433ba79a
Merge #1906
1906: Add missing lang-items to `def_crates` r=matklad a=sinkuu



Co-authored-by: Shotaro Yamada <sinkuu@sinkuu.xyz>
2019-09-25 08:55:32 +00:00
Shotaro Yamada
89d0ff1623 Add missing lang-items to def_crates 2019-09-25 12:02:53 +09:00
Shotaro Yamada
9c45a9e586 Remove redundant clone() 2019-09-25 10:32:01 +09:00
Shotaro Yamada
7e0fa71532 Avoid intermediate allocation 2019-09-25 10:30:33 +09:00
Florian Diebold
6a86706650 Implement the call argument checking order hack for closures 2019-09-24 23:05:12 +02:00
Florian Diebold
a0aeb6e7ad Make the closure_1 test work 2019-09-24 23:05:12 +02:00
Florian Diebold
3b06faad26 Make closures impl closure traits 2019-09-24 23:05:12 +02:00
Florian Diebold
619a8185a6 Give closures types 2019-09-24 23:05:12 +02:00
Florian Diebold
7bb6fdcf52 Upgrade Chalk again 2019-09-24 22:29:52 +02:00
bors[bot]
c12a713739
Merge #1898
1898: Drive by lints r=kjeremy a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
Co-authored-by: Jeremy Kolb <kjeremy@gmail.com>
2019-09-23 18:47:14 +00:00
Florian Diebold
6df9c4035a Upgrade Chalk 2019-09-23 20:36:15 +02:00
kjeremy
1808175f98 Drive by lints 2019-09-23 14:31:30 -04:00
Florian Diebold
4f1afe77b9 Split off path expression inference code into submodule 2019-09-23 18:53:52 +02:00
Florian Diebold
bc905d202c Handle projection types from Chalk 2019-09-22 20:08:46 +02:00
Florian Diebold
18bf278c25 Handle associated type shorthand (T::Item)
This is only allowed for generic parameters (including `Self` in traits), and
special care needs to be taken to not run into cycles while resolving it,
because we use the where clauses of the generic parameter to find candidates for
the trait containing the associated type, but the where clauses may themselves
contain instances of short-hand associated types.

In some cases this is even fine, e.g. we might have `T: Trait<U::Item>, U:
Iterator`. If there is a cycle, we'll currently panic, which isn't great, but
better than overflowing the stack...
2019-09-22 20:02:32 +02:00
gfreezy
6a4cf48bff fix module attr path 2019-09-20 23:20:43 +08:00
Ekaterina Babshukova
2867c40925 introduce FromSource trait 2019-09-19 19:38:27 +03:00
Aleksey Kladov
7d15c81a33 account for impls generated by macros 2019-09-18 04:34:48 +03:00
bors[bot]
54379ec6f8
Merge #1862
1862: Assoc item resolution refactoring (again) r=flodiebold a=flodiebold

This is #1849, with the associated type selection code removed for now. Handling cycles there will need some more thought.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2019-09-17 21:16:28 +00:00
Florian Diebold
c2f9558e1a Remove assoc type selection code for now to fix crashes 2019-09-17 23:11:20 +02:00
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
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
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
Dylan MacKenzie
426112c97e Add DotDotPat to AST
This is modeled on `PlaceholderPat`.
2019-09-14 17:08:22 -07: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
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
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
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
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
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
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
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
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