Commit Graph

23344 Commits

Author SHA1 Message Date
Ryo Yoshida
e0a161b2e3
fix: treat enum variants as generic item on their own 2022-10-04 00:07:34 +09:00
bors
5bd98e36bc Auto merge of #13335 - lowr:patch/change-generic-param-order, r=Veykril
internal: change generic parameter order

tl;dr: This PR changes the `Substitution` for trait items and methods like so:

```rust
trait Trait<TP, const CP: usize> { // note the implicit Self as first parameter
  type Type<TC, const CC: usize>;
  fn f<TC, const CC: usize>() {}
}
impl<TP, const CP: usize> S {
  fn f<TC, const CC: usize>() {}
}
```

- before this PR: `[Self, TP, CP, TC, CC]` for each trait item, `[TP, CP, TC, CC]` for `S::f`
- after this PR: `[TC, CC, Self, TP, CP]` for each trait item, `[TC, CC, TP, CP]` for `S::f`

---

This PR "inverts" the generic parameters/arguments of an item and its parent. This is to fulfill [chalk's expectation](d875af0ff1/chalk-solve/src/rust_ir.rs (L498-L502)) on the order of generic arguments in `Substitution`s for generic associated types and it's one step forward for GATs support (hopefully). Although chalk doesn't put any constraint for other items, it feels more natural to get everything aligned than special casing GATs.

One complication is that `TyBuilder` now demands its users to pass in parent's `Substitution` upon construction unless it's obvious that the the item has no parent (e.g. an ADT never has parent). All users *should* already know the parent of the item in question, and without this, it cannot be easily reasoned about whether we're pushing the argument for the item or for its parent.

Some additional notes:
- f8f5a5ea57: This isn't related to the change, but I felt it's nicer.

- 78977cd86c: There's one major change here other than the generic param order: Default arguments are now bound by the same `Binder` as the item in question rather than a `Binder` limited to parameters they can refer to (i.e. arguments that syntactically appear before them). Now that the order of generic parameters is changed, it would be somewhat complicated to make such `Binder`s as before, and the "full" `Binder`s shouldn't be a problem because we already make sure that the default arguments don't refer to the generic arguments after them with `fallback_bound_vars()`.

- 7556f74b16: This is split from 4385d3dcd0 to make it easy to revert if it turns out that the GATs with const generics panic is actually not resolved with this PR. cc #11878 #11957
2022-10-03 12:13:25 +00:00
bors
f087ebe6e7 Auto merge of #13338 - Veykril:flycheck, r=Veykril
Prioritize restart messages in flycheck

cc https://github.com/rust-lang/rust-analyzer/issues/12936#issuecomment-1264670905
2022-10-03 12:05:11 +00:00
Lukas Wirth
5916803555 Prioritize restart messages in flycheck 2022-10-03 14:03:54 +02:00
Ryo Yoshida
7556f74b16
Remove hack 2022-10-03 02:40:12 +09:00
Ryo Yoshida
78977cd86c
Adapt to the new generic parameter/argument order 2022-10-03 02:40:07 +09:00
Ryo Yoshida
4385d3dcd0
Change generic parameter/argument order
This commit "inverts" the order of generic parameters/arguments of an
item and its parent. This is to fulfill chalk's expectation on the
order of `Substitution` for generic associated types and it's one step
forward for their support (hopefully).

Although chalk doesn't put any constraint on the order of `Substitution`
for other items, it feels natural to get everything aligned rather than
special casing GATs.

One complication is that `TyBuilder` now demands its users to pass in
parent's `Substitution` upon construction unless it's obvious that the
the item has no parent (e.g. an ADT never has parent). All users
*should* already know the parent of the item in question, and without
this, it cannot be easily reasoned about whether we're pushing the
argument for the item or for its parent.

Quick comparison of how this commit changes `Substitution`:

```rust
trait Trait<TP, const CP: usize> {
  type Type<TC, const CC: usize> = ();
  fn f<TC, const CC: usize>() {}
}
```

- before this commit: `[Self, TP, CP, TC, CC]` for each trait item
- after this commit: `[TC, CC, Self, TP, CP]` for each trait item
2022-10-03 02:39:25 +09:00
Ryo Yoshida
f8f5a5ea57
refactor: use cast() instead of interning GenericArgData 2022-10-02 22:40:55 +09:00
bors
5c28ad1932 Auto merge of #13328 - Veykril:rustc-proc-macro, r=Veykril
Add proc-macro dependency to rustc crates
2022-10-01 19:29:33 +00:00
Lukas Wirth
870825b376 Add proc-macro dependency to rustc crates 2022-10-01 21:29:14 +02:00
bors
cdc5493901 Auto merge of #13327 - Veykril:proc-macro-srv-config, r=Veykril
Add config for supplying sysroot path
2022-10-01 19:17:36 +00:00
Lukas Wirth
5424c51158 Add config for supplying sysroot path 2022-10-01 21:17:06 +02:00
bors
bf5cad8e77 Auto merge of #13326 - Veykril:proc-macro-srv-config, r=Veykril
Do not use the sysroot proc-macro server when a server path is given explicitly
2022-10-01 17:51:47 +00:00
Lukas Wirth
26cf250ccc Do not use the sysroot proc-macro server when a server path is given explicitly 2022-10-01 19:50:34 +02:00
bors
f88293f777 Auto merge of #13324 - Veykril:trait-impl-completion, r=Veykril
Fix trait impl item completions using macro file text ranges

Fixes https://github.com/rust-lang/rust-analyzer/issues/13323
2022-10-01 13:35:08 +00:00
Lukas Wirth
bfd5f00bfc Fix trait impl item completions using macro file text ranges 2022-10-01 15:34:45 +02:00
bors
5b7e40014e Auto merge of #13321 - Veykril:format-str-args, r=Veykril
Fix move_format_string_arg being tokentree unaware

Fixes https://github.com/rust-lang/rust-analyzer/issues/13261
2022-09-30 22:42:40 +00:00
Lukas Wirth
3ad0334718 Fix move_format_string_arg being tokentree unaware 2022-10-01 00:42:16 +02:00
bors
2293949bbf Auto merge of #13318 - Veykril:annotations, r=Veykril
Fix annotations not resolving when lens location is set to whole item

Fixes https://github.com/rust-lang/rust-analyzer/issues/13310
2022-09-30 22:31:05 +00:00
bors
17363b341e Auto merge of #13320 - Veykril:ty-alias-hover, r=Veykril
Fix type alias hovers not rendering generic parameters
2022-09-30 22:22:24 +00:00
Lukas Wirth
77cfc9b392 Fix type alias hovers not rendering generic parameters 2022-10-01 00:21:29 +02:00
Lukas Wirth
3cd57c425a Fix annotations not resolving when lens location is set to whole item 2022-10-01 00:18:23 +02:00
bors
8132b42b73 Auto merge of #13319 - Veykril:req-retry, r=Veykril
Fix requests not being retried anymore
2022-09-30 22:12:48 +00:00
Lukas Wirth
8c433c7296 Fix requests not being retried anymore 2022-10-01 00:07:33 +02:00
bors
97f8f4a3da Auto merge of #13311 - lowr:fix/for-loop-item-resolution, r=Veykril
fix: infer for-loop item type with `IntoIterator` and `Iterator`

Part of #13299

We've been inferring the type of the yielded values in for-loop as `<T as IntoIterator>::Item`. We infer the correct type most of the time when we normalize the projection type, but it turns out not always. We should infer the type as `<<T as IntoIterator>::IntoIter as Iterator>::Item`.

When one specifies `IntoIter` assoc type of `IntoIterator` but not `Item` in generic bounds, we fail to normalize `<T as IntoIterator>::Item` (even though `IntoIter` is defined like so: `type IntoIter: Iterator<Item = Self::Item>` - rustc does *not* normalize projections based on other projection's bound I believe; see [this playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e88e19385094cb98fadbf647b4c2082e)).

Note that this doesn't fully fix # 13299 - given the following code, chalk can normalize `<I as IntoIterator>::IntoIter` to `S`, but cannot normalize `<S as Iterator>::Item` to `i32`.

```rust
struct S;
impl Iterator for S { type Item = i32; /* ... */ }
fn f<I: IntoIterator<IntoIter = S>>(it: I) {
    for elem in it {}
      //^^^^{unknown}
}
```

This is because chalk finds multiple answers that satisfy the query `AliasEq(<S as Iterator>::Item = ?X`: `?X = i32` and `?X = <I as IntoIterator>::Item` - which are supposed to be the same type due to the aforementioned bound on `IntoIter` but chalk is unable to figure it out.
2022-09-29 11:04:47 +00:00
Ryo Yoshida
6d8903ae5f
fix: infer for-loop item type with IntoIterator and Iterator 2022-09-29 19:48:08 +09:00
Jonas Platte
a3d79b5172
Update outside test and generated code 2022-09-27 20:40:51 +02:00
Jonas Platte
2c666a08b0
Add convert_named_struct_to_tuple_struct assist 2022-09-27 20:39:48 +02:00
Lukas Wirth
f310d4cbb4 Don't auto-publish lib crates 2022-09-27 18:22:06 +02:00
bors
ad752bd521 Auto merge of #13301 - Veykril:empty-assist-source-changes, r=Veykril
Make assist tests panic again on empty source changes
2022-09-27 15:54:54 +00:00
Lukas Wirth
f5fe6b157f Make assist tests panic again on empty source changes 2022-09-27 17:48:00 +02:00
bors
9ba55bad4f Auto merge of #13202 - Veykril:cancelled-retry, r=Veykril
Don't retry requests that have already been cancelled
2022-09-27 15:43:57 +00:00
Lukas Wirth
1a6c1595fe Don't retry requests that have already been cancelled 2022-09-27 17:39:15 +02:00
bors
b16b0413dc Auto merge of #13272 - oknozor:master, r=Veykril
docs(guide): fix Analysis and AnalysisHost doc links
2022-09-27 15:10:25 +00:00
bors
03aa7042e6 Auto merge of #13280 - alanz:errorcode-requestfailed, r=Veykril
Add RequestFailed error code, as per spec 3.17

See https://github.com/microsoft/language-server-protocol/issues/1341
2022-09-27 15:03:15 +00:00
bors
093de32f80 Auto merge of #13237 - Veykril:process-changes, r=Veykril
Amalgamate file changes for the same file ids in process_changes

When receiving multiple change events for a single file id where the last change is a delete the server panics, as it tries to access the file contents of a deleted file. This occurs due to the VFS changes and the in memory file contents being updated immediately, while `process_changes` processes the events afterwards in sequence which no longer works as it will only observe the final file contents. By folding these events together, we will no longer try to process these intermediate changes, as they aren't relevant anyways.

Potentially fixes https://github.com/rust-lang/rust-analyzer/issues/13236
2022-09-27 14:41:40 +00:00
Lukas Wirth
c3a6c963e5 Amalgamate file changes for the same file ids in process_changes
When receiving multiple change events for a single file id where the
last change is a delete the server panics, as it tries to access the
file contents of a deleted file. This occurs due to the VFS changes and
the in memory file contents being updated immediately, while
`process_changes` processes the events afterwards in sequence which no
longer works as it will only observe the final file contents. By
folding these events together, we will no longer try to process these
intermediate changes, as they aren't relevant anyways.

Potentially fixes https://github.com/rust-lang/rust-analyzer/issues/13236
2022-09-27 16:41:04 +02:00
bors
bd8c5b6b42 Auto merge of #13300 - Veykril:cfg-false, r=Veykril
Use cfg(any()) instead of cfg(FALSE) for disabling proc-macro test

cc https://github.com/rust-lang/rust-analyzer/pull/13286
2022-09-27 14:11:04 +00:00
bors
8805d05d01 Auto merge of #13296 - Strum355:package-information-package-name, r=Veykril
Fix PackageInformation having the crate name instead of package name

The `PackageInformation` type from the LSIF PR used the _crate_ name instead of the _package_ name. This caused issues when looking up crates by this name on the Sourcegraph backend, where we sync crate contents, for crates such as actix-web and many of its components (actix-files, actix-http etc etc), see screenshot 1 for the observed symptom.

This PR hasnt been tested on other entry points besides cargo (such as project json).

See screenshot 2 for the change in behaviour via SCIP snapshot comparison.

<details>
<summary>Screenshot 1</summary>

![crates.io giving 404](https://user-images.githubusercontent.com/18282288/192286637-8bf7c333-4441-4e60-8cce-de7eaa11ee9f.png)

</details>

<details>
<summary>Screenshot 2</summary>

![before and after from SCIP snapshot output](https://user-images.githubusercontent.com/18282288/192287733-d7e73ff0-abbc-4ae5-82d0-bf9dc45d755c.png)

</details>

Follow-up PR to my question over at the [rust-lang Zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/canonical.20crate.20name.20confusion.20for.20monikers), excuse any incorrect usages of the term package vs crate.
2022-09-27 13:07:05 +00:00
bors
b01cdd89d5 Auto merge of #13189 - unexge:unconfigured-diagnostics-for-fields, r=Veykril
Emit unconfigured code diagnostics for enum variants and struct/union fields

Fixes https://github.com/rust-lang/rust-analyzer/issues/12664
2022-09-27 12:59:45 +00:00
Lukas Wirth
fb736449fd Use cfg(any()) instead of cfg(FALSE) for disabling proc-macro test 2022-09-27 13:52:04 +02:00
bors
f972cdd5fc Auto merge of #13295 - rust-lang:sourcegen, r=Veykril
Remove obsolete in-rust-tree feature from sourcegen
2022-09-27 01:21:07 +00:00
bors
8c7e37697f Auto merge of #13275 - Veykril:find-path, r=Veykril
Fix find_path using the wrong module for visibility calculations
2022-09-27 01:14:02 +00:00
unexge
7e5e5177b6 Generate From impls manually 2022-09-26 19:29:28 +01:00
unexge
3a8d84b4a3 Use Arc<[DefDiagnostic]> instead of Arc<Vec<DefDiagnostic>> 2022-09-26 19:16:02 +01:00
unexge
b21bf25a07 Collect diagnostics in queries instead of nameres 2022-09-26 19:06:29 +01:00
unexge
89107d5469 Emit unconfigured code diagnostics for fields 2022-09-26 19:04:57 +01:00
Noah Santschi-Cooney
651c586035
formatting 2022-09-26 18:35:06 +01:00
Noah Santschi-Cooney
60b432b7e9
fix model tests 2022-09-26 18:18:12 +01:00
Noah Santschi-Cooney
aa093f5a58
Fix PackageInformation having the crate name instead of package name 2022-09-26 17:31:38 +01:00