Commit Graph

10245 Commits

Author SHA1 Message Date
bors[bot]
844b7f7411
Merge #7927
7927: Add more documentation for rustc_private r=matklad a=jyn514



Co-authored-by: Joshua Nelson <jyn514@gmail.com>
2021-03-09 11:22:37 +00:00
Duong Do Minh Chau
73590f0f0b
Fix format 2021-03-09 16:38:07 +07:00
Duong Do Minh Chau
a068cedee0
Add trailing commas 2021-03-09 16:00:06 +07:00
Duong Do Minh Chau
ea835fc800
Update the test to match the change 2021-03-09 15:48:53 +07:00
Duong Do Minh Chau
5fc91058ff
Add completion to turn x.err into Err(x) 2021-03-09 15:36:41 +07:00
bors[bot]
3fdf26a6fc
Merge #7898
7898: generate_function assist: infer return type r=JoshMcguigan a=JoshMcguigan

This PR makes two changes to the generate function assist:

1. Attempt to infer an appropriate return type for the generated function
2. If a return type is inferred, and that return type is not unit, don't render the snippet

```rust
fn main() {
    let x: u32 = foo$0();
    //              ^^^ trigger the assist to generate this function
}

// BEFORE
fn foo() ${0:-> ()} {
    todo!()
}

// AFTER (only change 1)
fn foo() ${0:-> u32} {
    todo!()
}

// AFTER (change  1 and 2, note the lack of snippet around the return type)
fn foo() -> u32 {
    todo!()
}
```

These changes are made as two commits, in case we want to omit change 2. I personally feel like it is a nice change, but I could understand there being some opposition.

#### Pros of change 2
If we are able to infer a return type, and especially if that return type is not the unit type, the return type is almost as likely to be correct as the argument names/types. I think this becomes even more true as people learn how this feature works.

#### Cons of change 2

We could never be as confident about the return type as we are about the function argument types, so it is more likely a user will want to change that. Plus it is a confusing UX to sometimes have the cursor highlight the return type after triggering this assist and sometimes not have that happen.

#### Why omit unit type?

The assumption is that if we infer the return type as unit, it is likely just because of the current structure of the code rather than that actually being the desired return type. However, this is obviously just a heuristic and will sometimes be wrong. But being wrong here just means falling back to the exact behavior that existed before this PR.



Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-08 22:51:04 +00:00
Josh Mcguigan
b275e60905 generate_function assist don't render snippet if ret type inferred 2021-03-08 14:38:36 -08:00
Kirill Bulatov
778deb38fe Better strip turbofishes 2021-03-08 23:59:39 +02:00
Kirill Bulatov
5168ab16e1 Add rustdocs and use better names 2021-03-08 23:59:37 +02:00
Kirill Bulatov
dccbb38d2e Less lifetines: derive SemanticsScope in place 2021-03-08 23:59:20 +02:00
Kirill Bulatov
db61d4ea13 Rebase leftovers 2021-03-08 23:59:20 +02:00
Kirill Bulatov
c56b59d377 Cleanup 2021-03-08 23:59:20 +02:00
Kirill Bulatov
84c575a212 Restrict fuzzy qualifiers for now 2021-03-08 23:59:20 +02:00
Kirill Bulatov
6ca6f101c1 Test for fuzzy unresolved path maatch 2021-03-08 23:59:20 +02:00
Kirill Bulatov
5b7d928075 Enforce the located imports' order 2021-03-08 23:59:20 +02:00
Kirill Bulatov
24a5d3b19d Fix the completion labels and tests 2021-03-08 23:59:20 +02:00
Kirill Bulatov
33c83e72b9 Work towards better import labels 2021-03-08 23:59:20 +02:00
Kirill Bulatov
4d4ac1d4fa Profile import_assets better 2021-03-08 23:59:20 +02:00
Kirill Bulatov
821e8369d9 Update the docs 2021-03-08 23:59:20 +02:00
Kirill Bulatov
e214c3a6bd Simplify 2021-03-08 23:59:20 +02:00
Kirill Bulatov
e74c55bb4a Refactor the import location 2021-03-08 23:59:20 +02:00
Kirill Bulatov
89d410cef5 Do not propose already imported imports 2021-03-08 23:59:20 +02:00
Kirill Bulatov
9482353fa8 Properly handle turbofishes in qualifiers 2021-03-08 23:59:20 +02:00
Kirill Bulatov
d386481fac Fix some tests 2021-03-08 23:59:20 +02:00
Kirill Bulatov
582cee2cdf Return more data about located imports 2021-03-08 23:59:18 +02:00
Kirill Bulatov
309421c117 Draft the qualifier import resolution 2021-03-08 23:58:48 +02:00
Kirill Bulatov
c395c3311d Filter out path items by the qualifier 2021-03-08 23:58:33 +02:00
Kirill Bulatov
f08c0cdd2a Simplify 2021-03-08 23:58:33 +02:00
Kirill Bulatov
7584260b9a Find the code to change 2021-03-08 23:58:33 +02:00
Kirill Bulatov
005bc49d74 Test and initial refactoring 2021-03-08 23:58:32 +02:00
Joshua Nelson
c7b0914b3f Add more documentation for rustc_private 2021-03-08 16:56:42 -05:00
Laurențiu Nicola
fc9eed4836 Use upstream cov-mark 2021-03-08 22:19:44 +02:00
Aleksey Kladov
9faf8dd69a Hygiene is an internal implementation detail of the compiler 2021-03-08 22:14:52 +03:00
Aleksey Kladov
e346a9c5e1 Remove useless code_model indirection 2021-03-08 22:08:30 +03:00
Aleksey Kladov
c0943f84fd Cleanup the error message 2021-03-08 21:45:43 +03:00
Aleksey Kladov
1eb61203b7 Make code generation just work
Contributors don't need to learn about `cargo xtask codegen` if `cargo
test` just does the right thing.
2021-03-08 21:45:37 +03:00
Aleksey Kladov
abb6b8f14c Use the same name in xtask and test utils 2021-03-08 21:45:06 +03:00
Aleksey Kladov
b6ba0dec0c Generalize file ensuring infrastructure 2021-03-08 21:45:06 +03:00
Aleksey Kladov
da73c93c7f Don't punish every crate with serde-json 2021-03-08 20:37:20 +03:00
bors[bot]
d57c9f7980
Merge #7891
7891: Improve handling of rustc_private r=matklad a=DJMcNab

This PR changes how `rust-analyzer` handles `rustc_private`. In particular, packages now must opt-in to using `rustc_private` in `Cargo.toml`, by adding:
```toml
[package.metadata.rust-analyzer]
rustc_private=true
```

This means that depending on crates which also use `rustc_private` will be significantly improved, since their dependencies on the `rustc_private` crates will be resolved properly.

A similar approach could be used in #6714 to allow annotating that your package uses the `test` crate, although I have not yet handled that in this PR.

Additionally, we now only index the crates which are transitive dependencies of `rustc_driver` in the `rustcSource` directory. This should not cause any change in behaviour when using `rustcSource: "discover"`, as the source used then will only be a partial clone. However, if `rustcSource` pointing at a local checkout of rustc, this should significantly improve the memory usage and lower indexing time. This is because we avoids indexing all crates in `src/tools/`, which includes `rust-analyzer` itself.

Furthermore, we also prefer named dependencies over dependencies from `rustcSource`. This ensures that feature resolution for crates which are depended on by both `rustc` and your crate uses the correct set for analysing your crate.

See also [introductory zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Fixed.20crate.20graphs.20and.20optional.20builtin.20crates/near/229086673)

I have tested this in [priroda](https://github.com/oli-obk/priroda/), and it provides a significant improvement to the development experience (once I give `miri` the required data in `Cargo.toml`)

Todo:
- [ ] Documentation

This is ready to review, and I will add documentation if this would be accepted (or if I get time to do so anyway)

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2021-03-08 16:51:20 +00:00
Daniel McNab
20007fd3a8 Document rustc_private in metadata 2021-03-08 16:47:40 +00:00
Daniel McNab
d0a51d710e Never run cargo check on the rustc source 2021-03-08 16:42:18 +00:00
Daniel McNab
d5d406fa78 Only show directory name 2021-03-08 16:41:40 +00:00
Daniel McNab
bbecea03fd Revert "Support disabling rustc build scripts"
This reverts commit ddce6bb282.
2021-03-08 16:37:52 +00:00
kjeremy
e13ac349b5 Cargo update
Chalk changes just a version # bump. There are no actual commits.
2021-03-08 10:39:11 -05:00
Aleksey Kladov
c7b5d6be4c Make code completion "just work" in more cases 2021-03-08 14:57:56 +03:00
Kirill Bulatov
128a6a4ec0 Do not process indexed values more than once 2021-03-08 12:06:15 +02:00
Kirill Bulatov
8f17f3d594 Deduplicate search_dependencies results 2021-03-08 11:48:51 +02:00
Daniel McNab
ddce6bb282 Support disabling rustc build scripts 2021-03-08 09:05:19 +00:00
Daniel McNab
877f745551 Fix the comment
It's worse than I thought...
2021-03-07 13:13:54 +00:00
Daniel McNab
419b5a1bee Extract the large nested block into a function
Also add some more detailed comments
Extract into function deleted the previous comments
2021-03-07 12:59:15 +00:00
Daniel McNab
9246df669a Require opt in to rustc_private
This gives the advantage that

A future extension would be to check for `feature(rustc_private)` instead
2021-03-07 12:24:20 +00:00
Daniel McNab
71a254c1a1 Don't double analyse the same crate 2021-03-07 11:17:14 +00:00
Daniel McNab
b46605cfcd Update crate graph to only use subcrates of rustc_driver 2021-03-07 10:18:01 +00:00
bors[bot]
d54e1157b6
Merge #7889
7889: Make group imports configurable r=lnicola a=asv1



Co-authored-by: asv <asv7c2@gmail.com>
2021-03-07 08:24:02 +00:00
asv
96fc01a30b Make group imports configurable 2021-03-07 10:15:17 +02:00
bors[bot]
708ec9821f
Merge #7895
7895: ⬆️ xflags r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-07 08:13:27 +00:00
Aleksey Kladov
0296cd590e ⬆️ xflags 2021-03-07 11:12:59 +03:00
bors[bot]
f0b7c02f16
Merge #7892
7892: Fix TokenStream::from_str for input consisting of a single group with delimiter r=edwin0cheng a=kevinmehall

TokenStream holds a `tt::Subtree` but assumes its `delimiter` is always `None`. In particular, the iterator implementation iterates over the inner `token_trees` and ignores the `delimiter`.

However, `TokenStream::from_str` violated this assumption when the input consists of a single group by producing a Subtree with an outer delimiter, which was ignored as seen by a procedural macro.

`tt::Subtree` is just `pub delimiter: Option<Delimiter>, pub token_trees: Vec<TokenTree>`, so a Subtree that is statically guaranteed not to have a delimiter is just `Vec<TokenTree>`.

Fixes #7810
Fixes #7875

Co-authored-by: Kevin Mehall <km@kevinmehall.net>
2021-03-07 00:32:56 +00:00
Jonas Schievink
6750c11df3 Rename a few crate_def_maps to def_map
These could all be block `DefMap`s instead of crate-level `DefMap`s
2021-03-07 00:20:13 +01:00
Josh Mcguigan
d645b81b28 generate_function assist infer return type 2021-03-06 14:28:54 -08:00
bors[bot]
c44575b485
Merge #7896
7896: Only replace quotes in replace_string_with_char assist r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-06 20:22:36 +00:00
Lukas Wirth
1a276f8959 Only replace quotes in replace_string_with_char assist 2021-03-06 21:21:18 +01:00
bors[bot]
5480bed936
Merge #7800
7800: [WIP] 7708: Initial implementation of generate Default assist. r=Veykril a=chetankhilosiya

The Generate Default impl from new function.

Co-authored-by: Chetan Khilosiya <chetan.khilosiya@gmail.com>
2021-03-06 20:01:50 +00:00
Chetan Khilosiya
d40a4fc92c 7708: rust ideomatic code fixes. 2021-03-07 01:26:05 +05:30
bors[bot]
856c2850cd
Merge #7865
7865: preserve escape sequences when replacing string with char r=Veykril a=jDomantas

Currently it replaces escape sequence with the actual value, which is very wrong for `"\n"`.

Co-authored-by: Domantas Jadenkus <djadenkus@gmail.com>
2021-03-06 19:54:36 +00:00
Kevin Mehall
aea9749390 Move TokenStream::to_string helpers inside the method 2021-03-06 12:30:43 -07:00
Chetan Khilosiya
e4b6541c7a 7708: handle both FamousDefs fixture and plain code.
Also fix typo in example.
2021-03-07 00:51:48 +05:30
Chetan Khilosiya
9a84daf47d 7708: Added the updated implementation of is_default_implemented.
The implementation uses hir create to find the implemented trait.
2021-03-07 00:49:03 +05:30
Chetan Khilosiya
b8e6d6a606 7708: Added the logic to check is default impl is already present.
Also added test cases for code present within module.
2021-03-07 00:49:03 +05:30
Chetan Khilosiya
a59a97ae04 7708: Updated generate default fn logic. 2021-03-07 00:49:03 +05:30
Chetan Khilosiya
54b4727fa3 7708: Added the work for review comments.
Also added 1 test case to test multiple struct blocks are present.
2021-03-07 00:49:03 +05:30
Chetan Khilosiya
135c9e2027 7708: Fixed many documentaion example issues. 2021-03-07 00:49:03 +05:30
Chetan Khilosiya
69a6e4c80c 7708: Format code through rust-analyzer formatter. 2021-03-07 00:49:03 +05:30
Chetan Khilosiya
cb3f4d43d9 7708: Initial implementation of generate Default assist.
The Generate Default impl from new function.
2021-03-07 00:49:03 +05:30
Josh Mcguigan
e29b53f1e6 generate function assist convert arg names to lower snake case 2021-03-06 09:53:21 -08:00
Kevin Mehall
93c9b34635 Make a placeholder panic message explain its purpose 2021-03-06 09:51:13 -07:00
Kevin Mehall
62f594b390 Refactor TokenStream to hold Vec<TokenTree> instead of tt::Subtree
`TokenStream` assumes that its subtree's delimeter is `None`, and this
should be encoded in the type system instead of having a delimiter field
that is mostly ignored.

`tt::Subtree` is just `pub delimiter: Option<Delimiter>, pub
token_trees: Vec<TokenTree>`, so a Subtree that is statically guaranteed
not to have a delimiter is just Vec<TokenTree>.
2021-03-06 09:48:30 -07:00
Kevin Mehall
632fa8ef4a Fix TokenStream::from_str for input consisting of a single Group
TokenStream holds a `tt::Subtree` but assumes its `delimiter` is always
`None`. In particular, the iterator implementation iterates over the
inner `token_trees` and ignores the `delimiter`.

However, `TokenStream::from_str` violated this assumption when the input
consists of a single Group by producing a Subtree with an outer
delimiter, which was ignored as seen by a procedural macro.

In this case, wrap an extra level of Subtree around it.

Fixes #7810
Fixes #7875
2021-03-06 09:48:08 -07:00
Daniel McNab
7513867aa2 If a manual dependency exists, don't overwrite
This is a hack to work around miri being included in
our analysis of rustc-dev
Really, we should probably use an include set of the actual root libraries

I'm not sure how those are determined however
2021-03-06 13:56:42 +00:00
Daniel McNab
1076d21fc0 Implement opt-in (and opt-out) rustc_private 2021-03-06 12:17:22 +00:00
bors[bot]
750d3cb846
Merge #7887
7887: Fix fail to parse :: for meta in mbe r=edwin0cheng a=edwin0cheng

fixes #7886

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-05 20:59:31 +00:00
Edwin Cheng
20eda09712 Fix fail to parse :: for meta in mbe 2021-03-06 04:57:34 +08:00
bors[bot]
94012e24e0
Merge #7884
7884: Simplify TokenStream FromStr r=edwin0cheng a=edwin0cheng

Make sure `FromStr` ignore all `TokenMap` in all cases.

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-05 20:00:04 +00:00
bors[bot]
7199d5b56d
Merge #7869
7869: Add support for deref assignments to "pull assignment up" assist. r=Veykril a=Jesse-Bakker

Fixes #7867


Co-authored-by: Jesse Bakker <github@jessebakker.com>
2021-03-05 19:52:15 +00:00
Jesse Bakker
ab84a4746b Add support for deref assignments to "pull assignment up" assist.
Fixes #7867
2021-03-05 20:42:23 +01:00
Edwin Cheng
83230b2704 Fix test 2021-03-06 03:30:22 +08:00
Edwin Cheng
0405d758a5 Simplify TokenStream FromStr 2021-03-06 03:17:36 +08:00
Laurențiu Nicola
d3ca22876c Make two calls virtual 2021-03-05 20:25:24 +02:00
bors[bot]
2b55cce49e
Merge #7880
7880: Honor snippet capability when using the extract function assist r=lnicola a=Arthamys

This fixes issue #7793

Co-authored-by: san <san@alien.parts>
2021-03-05 16:24:32 +00:00
san
769b3bca28 Honor snippet capability in extract function assist 2021-03-05 17:20:26 +01:00
bors[bot]
6c27c55041
Merge #7870
7870: Use chalk_ir::AdtId r=Veykril a=Veykril

It's a bit unfortunate that we got two AdtId's now(technically 3 with the alias in the chalk module but that one won't allow pattern matching), one from hir_def and one from chalk_ir(hir_ty). But the hir_ty/chalk one doesn't leave hir so it shouldn't be that bad I suppose. Though if I see this right this will happen for almost all IDs.

I imagine most of the intermediate changes to using chalk ids will turn out not too nice until the refactor is over.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-05 16:04:49 +00:00
Laurențiu Nicola
42057896bc Fix some warnings 2021-03-05 15:59:50 +02:00
Lukas Wirth
50e01d2bc7 Use chalk_ir::AdtId 2021-03-04 19:38:02 +01:00
bors[bot]
16a76aa158
Merge #7868
7868: Migrate to user-centric config name for `cargo check` stuff r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-04 12:39:36 +00:00
Aleksey Kladov
3d80e0a154 Migrate to user-centric config name for cargo check stuff 2021-03-04 15:38:53 +03:00
Edwin Cheng
cc8c40480a Print warning if proc-macro built by old rustc 2021-03-04 14:47:34 +08:00
Jay Somedon
0669abda4a Revise error message regarding metadata version
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2021-03-04 09:15:28 +08:00
Jay Somedon
a8f7326ee5 Update condition check code style
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-04 09:11:43 +08:00
Jay Somedon
c92db2abf9 Update comment
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-04 09:11:43 +08:00