Commit Graph

252 Commits

Author SHA1 Message Date
bors[bot]
c48dcf7411
Merge #3549
3549: Implement env! macro r=matklad a=edwin0cheng

This PR implements `env!` macro by adding following things:

1. Added `additional_outdirs` settings in vscode. (naming to be bikeshed)
2. Added `ExternSourceId` which is a wrapping for SourceRootId but only used in extern sources. It is because `OUT_DIR` is not belonged to any crate and we have to access it behind an `AstDatabase`.
3. This PR does not implement the `OUT_DIR` parsing from `cargo check`. I don't have general design about this,  @kiljacken could we reuse some cargo watch code for that ?

~~Block on [#3536]~~

PS: After this PR , we (kind of) completed the `include!(concat!(env!('OUT_DIR'),  "foo.rs")` macro call combo. [Exodia Obliterate!](https://www.youtube.com/watch?v=RfqNH3FoGi0)

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-03-11 10:51:07 +00:00
Florian Diebold
adc7b8ea2d Fix completion with a partially unknown type
To test whether the receiver type matches for the impl, we unify the given self
type (in this case `HashSet<{unknown}>`) with the self type of the
impl (`HashSet<?0>`), but if the given self type contains Unknowns, they won't
be unified with the variables in those places. So we got a receiver type that
was different from the expected one, and concluded the impl doesn't match.

The fix is slightly hacky; if after the unification, our variables are still
there, we make them fall back to Unknown. This does make some sense though,
since we don't want to 'leak' the variables.

Fixes #3547.
2020-03-10 21:02:13 +01:00
Edwin Cheng
5a292309c5 Add and fix tests 2020-03-11 01:06:01 +08:00
Edwin Cheng
22f064cca7 Add resolve_extern_path in DB 2020-03-11 01:06:01 +08:00
kjeremy
d1e9f0af04 Updates insta to 0.15.0 and bumps console to 0.10.0 2020-03-09 10:28:30 -04:00
Aleksey Kladov
0320ebdd10 Use Index for CrateGraph 2020-03-09 11:11:59 +01:00
Kirill Bulatov
e1aa96f2c5 Less abstract CrateData api 2020-03-09 11:26:46 +02:00
Edwin Cheng
18f88ad10b Prevent include! macro include itself 2020-03-07 19:08:42 +08:00
Edwin Cheng
36c7684687 Use a not so dummy implementation of env macro 2020-03-07 12:53:40 +08:00
Aleksey Kladov
9abf0d9659 Normalize waiting queries names 2020-03-07 00:18:04 +01:00
Florian Diebold
9ce30281f6 Don't reuse the Chalk solver
This slows down analysis-stats a bit (~5% in my measurement), but improves
incremental checking a lot because we can reuse trait solve results.
2020-03-06 23:04:14 +01:00
Florian Diebold
d17c5416af Resolve Self::AssocTy in impls
To do this we need to carry around the original resolution a bit, because `Self`
gets resolved to the actual type immediately, but you're not allowed to write
the equivalent type in a projection. (I tried just comparing the projection base
type with the impl self type, but that seemed too dirty.) This is basically how
rustc does it as well.

Fixes #3249.
2020-03-06 18:14:39 +01:00
Aleksey Kladov
b33b843f40 Allow specifying additional info on call to profile 2020-03-06 17:36:51 +01:00
Aleksey Kladov
59f91f2f9b Less confusing profile names 2020-03-06 16:40:38 +01:00
bors[bot]
aa82b5915d
Merge #3494
3494: Implement include macro r=matklad a=edwin0cheng

This PR implement builtin `include` macro.

* It does not support include as expression yet.
* It doesn't consider `env!("OUT_DIR")` yet.


Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-03-06 15:08:41 +00:00
Edwin Cheng
0a06c7e6e6 Implment include macro 2020-03-06 22:58:45 +08:00
Florian Diebold
073a1ef834 Support aliases and Self in struct literals
Fixes #3306.
2020-03-06 15:43:14 +01:00
Aleksey Kladov
fb5891c433 Source map returns a result
cc #2236
2020-03-06 14:44:44 +01:00
Edwin Cheng
e04c0f4222 Fix panic on eager expansion 2020-03-04 02:41:33 +08:00
Edwin Cheng
fe04c28b59 Add test 2020-03-04 01:21:14 +08:00
Laurențiu Nicola
91e02ace06 Drop larlpop-intern dep 2020-03-03 07:57:16 +02:00
Laurențiu Nicola
f60cf882a8 Update chalk for Ty interners 2020-03-03 00:02:19 +02:00
Laurențiu Nicola
807a56bebf Update chalk for RawId removal 2020-03-02 23:30:38 +02:00
bors[bot]
02f761ba4b
Merge #3397 #3398
3397: Minimal viable meta r=matklad a=matklad



bors r+
🤖

3398: Reformat? r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-03-02 13:31:56 +00:00
Aleksey Kladov
62e62d1c23 Reformat? 2020-03-02 14:28:34 +01:00
bors[bot]
79c874803b
Merge #3385
3385: Fix #3373 r=matklad a=flodiebold

Basically, we need to allow variables in the caller self type to unify with the
impl's declared self type. That requires some more contortions in the variable
handling. I'm looking forward to (hopefully) handling this in a cleaner way when
we switch to Chalk's types and unification code.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-03-02 13:23:24 +00:00
Josh Mcguigan
f5efa17515 handle array pattern matching type inference 2020-03-01 14:02:32 -08:00
Josh Mcguigan
b9ef7a6b98 remove match statement, handle suffix 2020-03-01 12:13:05 -08:00
Josh Mcguigan
d0e282f6b1 handle arbitrary length slices 2020-03-01 07:35:15 -08:00
Josh Mcguigan
f353625705 match single prefix slice 2020-03-01 06:25:38 -08:00
Florian Diebold
336a3c6121 Fix #3373
Basically, we need to allow variables in the caller self type to unify with the
impl's declared self type. That requires some more contortions in the variable
handling. I'm looking forward to (hopefully) handling this in a cleaner way when
we switch to Chalk's types and unification code.
2020-03-01 14:31:35 +01:00
Florian Diebold
31171eed5e Do autoderef for indexing 2020-02-29 22:48:53 +01:00
Florian Diebold
e313efb992 Do array unsizing for method receivers
It turns out rustc actually only unsizes array method receivers, so we don't
need to do any trait solving for this (at least for now).

Fixes #2670.
2020-02-29 22:48:53 +01:00
Aleksey Kladov
a1e1869554 Rename ast::ImplBlock -> ast::ImplDef 2020-02-29 21:33:15 +01:00
Florian Diebold
5fe220b987 Fix a common false-positive type mismatch
E.g. for `&{ some_string() }` in a context where a `&str` is expected, we
reported a mismatch inside the block. The problem is that we're passing an
expectation of `str` down, but the expectation is more of a hint in this case.
There's a long comment in rustc about this, which I just copied.

Also, fix reported location for type mismatches in macros.
2020-02-29 15:31:07 +01:00
Aleksey Kladov
c6247f74c7 Basic injections 2020-02-27 16:16:13 +01:00
Laurențiu Nicola
ed69482d90 Bump chalk and replace TypeFamily with Interner 2020-02-24 22:36:57 +02:00
Florian Diebold
5a6e770f99 Shorten some code 2020-02-22 13:15:54 +01:00
Florian Diebold
3e106c77ff Rework find_super_trait_path to protect against cycles 2020-02-22 13:14:39 +01:00
Florian Diebold
c200025794 Fix shift_bound_vars
It should only shift free vars (maybe the name isn't the best...)
2020-02-22 11:09:21 +01:00
Florian Diebold
463df6720c Fix wrong handling of bare dyn Trait exposed by canonicalizer fix
The self type in the `dyn Trait` trait ref should always be ^0, but we didn't
put that in there in the bare case.
2020-02-22 11:09:21 +01:00
Florian Diebold
2d5ab63247 Add &dyn Trait -> &dyn SuperTrait coercion, and fix &T -> &dyn Trait 2020-02-22 11:09:21 +01:00
Florian Diebold
f126808b2e Fix handling of binders in canonicalization
I'm looking forward to getting rid of this in favor of Chalk's implementation.
2020-02-22 11:09:21 +01:00
Florian Diebold
0dfbbaf03b Implement dyn Trait unsizing as well 2020-02-22 11:09:21 +01:00
Florian Diebold
de39d221a1 Implement unsize coercion using proper trait solving 2020-02-22 11:09:21 +01:00
Florian Diebold
f1f45f9191 Fix handling of const patterns
E.g. in `match x { None => ... }`, `None` is a path pattern (resolving to the
option variant), not a binding. To determine this, we need to try to resolve the
name during lowering. This isn't too hard since we already need to resolve names
for macro expansion anyway (though maybe a bit hacky).

Fixes #1618.
2020-02-21 17:01:19 +01:00
Florian Diebold
e50201345e Normalize associated types in types coming from Chalk
Fixes #3232.
2020-02-21 14:06:19 +01:00
bors[bot]
e00b9ca3c9
Merge #3215
3215: Exclude methods from non-parameter types introduced by generic constraints r=flodiebold a=lnicola

Fixes #3184.

r? @flodiebold

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-02-19 19:46:37 +00:00
Aleksey Kladov
9549aad525 Fill missing fields of enum variants 2020-02-19 18:17:09 +01:00
Laurențiu Nicola
5b05209744 Exclude methods from non-parameter types introduced by generic constraints 2020-02-19 10:46:13 +02:00
Kirill Bulatov
f6816c253b Update versions 2020-02-18 16:12:40 +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
bors[bot]
fcf15cc05a
Merge #3169
3169: Show record field names in Enum completion r=flodiebold a=adamrk

Adresses https://github.com/rust-analyzer/rust-analyzer/issues/2947.
Previously the details shown when autocompleting an Enum variant would look like the variant was a tuple even if it was a record:
![2020-02-16-15:59:32_crop](https://user-images.githubusercontent.com/16367467/74607233-64f21980-50d7-11ea-99db-e973e29c71d7.png)

This change will show the names of the fields for a record and use curly braces instead of parentheses:
![2020-02-16-15:33:00_crop](https://user-images.githubusercontent.com/16367467/74607251-8ce17d00-50d7-11ea-9d4d-38d198a4aec0.png)

This required exposing the type `adt::StructKind` from `ra_hir` and adding a function 
```
kind(self, db: &impl HirDatabase) -> StructKind
```
in the `impl` of `EnumVariant`. 

There was also a previously existing function `is_unit(self, db: &impl HirDatabase) -> bool` for `EnumVariant` which I removed because it seemed redundant after adding `kind`.

Co-authored-by: adamrk <ark.email@gmail.com>
2020-02-17 10:54:32 +00:00
adamrk
0e260aa6b1 use 'if let' instead of match on kind in lower.rs 2020-02-17 11:53:12 +01:00
adamrk
68d3743faf replace uses of VariantData::is_unit with VariantData::kind 2020-02-16 16:10:32 +01:00
Florian Diebold
e14e7ffa34 Fix coercion of &T to itself
The autoderef coercion logic did not handle matching placeholders. This led to
some type mismatches.
2020-02-16 12:58:20 +01:00
Florian Diebold
3484d727c3 Extend analysis-stats a bit
This adds some tools helpful when debugging nondeterminism in analysis-stats:
 - a `--randomize` option that analyses everything in random order
 - a `-vv` option that prints even more detail

Also add a debug log if Chalk fuel is exhausted (which would be a source of
nondeterminism, but didn't happen in my tests).

I found one source of nondeterminism (rust-lang/chalk#331), but there are still
other cases remaining.
2020-02-15 18:04:01 +01:00
bors[bot]
b2b94cbf71
Merge #3147
3147: Check that impl self type matches up with expected self type in path mode r=matklad a=flodiebold

Fixes #3144.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-02-14 20:32:55 +00:00
Florian Diebold
f47dc4de8d Check that impl self type matches up with expected self type in path mode
Fixes #3144.
2020-02-14 21:08:25 +01:00
Florian Diebold
001dd6a200 Make Self implement the trait inside trait default methods 2020-02-14 20:39:04 +01:00
Florian Diebold
5028b86cb8 Move hir_fmt code to display module 2020-02-14 15:01:42 +01:00
Florian Diebold
a324d066cb Rename Ty::Param => Ty::Placeholder
This aligns more with Chalk.
2020-02-14 14:44:00 +01:00
Florian Diebold
43df7c3d53 Don't let unknown match arms fall back to ! 2020-02-11 21:09:11 +01:00
Matthew Jasper
8c8d0bb34f Add or- and parenthesized-patterns 2020-02-09 22:06:15 +00:00
Florian Diebold
eefe02ce6e Add two more tests 2020-02-07 18:28:11 +01:00
Florian Diebold
9d6061f3bb Fix some TODOs 2020-02-07 18:28:11 +01:00
Florian Diebold
b0bb8622ee Don't print implicit type args from impl Trait 2020-02-07 18:28:11 +01:00
Florian Diebold
6c70619b01 Deal better with implicit type parameters and argument lists 2020-02-07 18:28:10 +01:00
Florian Diebold
dded90a748 Formatting 2020-02-07 18:28:10 +01:00
Florian Diebold
6787f124b5 Clean up RPIT a bit 2020-02-07 18:28:10 +01:00
Florian Diebold
0718682cff Fix compilation of other crates 2020-02-07 18:28:10 +01:00
Florian Diebold
a3d8cffde3 Use variables in predicates as well 2020-02-07 18:28:10 +01:00
Florian Diebold
86348f5994 Comment fixes / todos 2020-02-07 18:28:10 +01:00
Florian Diebold
3397ca679f Fix APIT some more 2020-02-07 18:28:10 +01:00
Florian Diebold
c6654fd4a7 Fix APIT 2020-02-07 18:28:10 +01:00
Florian Diebold
ed25cf70d5 Change Ty::Param to contain param ID 2020-02-07 18:28:10 +01:00
Florian Diebold
f8b7b64bce WIP use params for APIT 2020-02-07 18:28:10 +01:00
Florian Diebold
33aa2f8e4f Fix assoc type selection 2020-02-07 18:28:10 +01:00
Florian Diebold
4a8279a21a Fix another test 2020-02-07 18:28:10 +01:00
Florian Diebold
dbc14f9d57 First stab at desugaring bounds for APIT 2020-02-07 18:28:10 +01:00
Florian Diebold
a9430865b3 Fix crash 2020-02-07 18:28:10 +01:00
Florian Diebold
a5554dcb17 Fix enum constructors 2020-02-07 18:28:10 +01:00
Florian Diebold
4789a993eb Fix printing of function types 2020-02-07 18:28:10 +01:00
Florian Diebold
16c6937447 Lower impl trait to variables, move away from using placeholders where they don't belong 2020-02-07 18:28:10 +01:00
Florian Diebold
93aa166748 wip lower impl trait to type args 2020-02-07 18:28:10 +01:00
Florian Diebold
9dec65d3b1 wip implement lowering mode 2020-02-07 18:28:10 +01:00
Florian Diebold
7ea4bce1b2 Add impl trait lowering mode 2020-02-07 18:28:10 +01:00
Florian Diebold
22a65b11b3 Introduce TyLoweringContext 2020-02-07 18:28:10 +01:00
Aleksey Kladov
6ca19b2188 Standard formatting for array types 2020-01-28 15:32:20 +01:00
Florian Diebold
339a11c33c Tweak Chalk settings 2020-01-27 21:52:35 +01:00
Florian Diebold
d3a3e5abdf Ignore failing impl Trait tests 2020-01-27 21:38:10 +01:00
Florian Diebold
96ddf2962c Upgrade Chalk 2020-01-27 21:25:33 +01:00
Jeremy Kolb
b89991daed Update crates 2020-01-26 10:46:45 -05:00
Kirill Bulatov
4029e44102 Omit default parameters for reference types 2020-01-22 16:55:09 +02:00
Florian Diebold
33d637f2dd Fix inference for shift operators
Fixes #2602.
2020-01-17 16:59:51 +01:00
bors[bot]
767ff2c13c
Merge #2844
2844: Use dummy value for line! and column! macro r=matklad a=edwin0cheng

Use dummy value `0` for line! and column! macro. 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-01-14 17:59:24 +00:00
Edwin Cheng
6ebb1edf21 Use dummy value for line! and column! macro 2020-01-15 01:47:01 +08:00
Aleksey Kladov
21c5fd8b1b Push resolver further up 2020-01-14 14:24:03 +01:00
Aleksey Kladov
7ec62ea5e6 Push resolver up 2020-01-14 14:11:07 +01:00