Commit Graph

13209 Commits

Author SHA1 Message Date
bors[bot]
0d45802d67
Merge #6220
6220: implement binary operator overloading type inference r=flodiebold a=ruabmbua

Extend type inference of *binary operator expression*, by adding support for operator overloads.

Before this merge request, the type inference of binary expressions could only resolve operations done on built-in primitive types. This merge requests adds a code path, which is executed in case the built-in inference could not get any results. It resolves the proper operator overload trait in *core::ops* via lang items, and then resolves the associated *Output* type.

```rust
struct V2([f32; 2]);

#[lang = "add"]
pub trait Add<Rhs = Self> {
    /// The resulting type after applying the `+` operator.
    type Output;

    /// Performs the `+` operation.
    #[must_use]
    fn add(self, rhs: Rhs) -> Self::Output;
}

impl Add<V2> for V2 {
    type Output = V2;

    fn add(self, rhs: V2) -> V2 {
        let x = self.0[0] + rhs.0[0];
        let y = self.0[1] + rhs.0[1];
        V2([x, y])
    }
}

fn test() {
    let va = V2([0.0, 1.0]);
    let vb = V2([0.0, 1.0]);

    let r = va + vb; // This infers to V2 now
}
```

There is a problem with operator overloads, which do not explicitly set the *Rhs* type parameter in the respective impl block. 

**Example:**

```rust
impl Add for V2 {
    type Output = V2;

    fn add(self, rhs: V2) -> V2 {
        let x = self.0[0] + rhs.0[0];
        let y = self.0[1] + rhs.0[1];
        V2([x, y])
    }
}
```

In this case, the trait solver does not realize, that the *Rhs* type parameter is actually self in the context of the impl block. This stops type inference in its tracks, and it can not resolve the associated *Output* type.

I guess we can still merge this back, because it increases the amount of resolved types, and does not regress anything (in the tests).

Somewhat blocked by https://github.com/rust-analyzer/rust-analyzer/issues/5685
Resolves  https://github.com/rust-analyzer/rust-analyzer/issues/5544

Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
2020-10-15 18:02:27 +00:00
Laurențiu Nicola
b19013feaa Update GNOME Builder docs 2020-10-15 20:00:09 +03:00
Lukas Wirth
bc11475a2a Properly qualify trait methods in qualify_path assist 2020-10-15 18:31:33 +02:00
bors[bot]
1de2020109
Merge #6244
6244: Document awkward names r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-15 16:14:54 +00:00
Aleksey Kladov
86cc93ebe3 Document awkward names 2020-10-15 18:14:30 +02:00
bors[bot]
d8c6e192f7
Merge #6243
6243: Clarify classification API r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-15 15:39:35 +00:00
Aleksey Kladov
c5868a4879 Clarify the names one more time 2020-10-15 17:38:51 +02:00
Aleksey Kladov
56e67e3a39 More idiomatic classification API 2020-10-15 17:38:17 +02:00
Aleksey Kladov
f9c1336873 More clarifications 2020-10-15 17:37:55 +02:00
Aleksey Kladov
bc287b8f9b Unconfuse expression and pattern field init shorthands 2020-10-15 17:37:36 +02:00
Aleksey Kladov
fa3c449d8f Clarify NameClass names a bit 2020-10-15 17:37:36 +02:00
bors[bot]
7fadc78ebb
Merge #6242
6242: Diagnost shorthand in patterns r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-15 15:11:36 +00:00
Aleksey Kladov
3086fb2ef4 Move field_shorthand to a separate module 2020-10-15 17:10:06 +02:00
Aleksey Kladov
1022672af0 Diagnose shorthand in patterns as well 2020-10-15 17:03:52 +02:00
Aleksey Kladov
e9903a91cd flatten 2020-10-15 16:51:55 +02:00
Aleksey Kladov
c8cbd398e4 Prepare for pat_field_shorthand 2020-10-15 16:48:25 +02:00
bors[bot]
8090799aa2
Merge #6234
6234: Fix hover over field pattern shorthand r=matklad a=Vlad-Shcherbina

Instead of the information about the field, it now shows the information
about the local.

Fixes #6146

Co-authored-by: Vlad Shcherbina <vlad.shcherbina@gmail.com>
2020-10-15 13:09:27 +00:00
bors[bot]
d447a9a381
Merge #6240
6240: Document auto_import as a feature r=Veykril a=Veykril

Closes #6225

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-15 12:59:49 +00:00
Lukas Wirth
f8a7cc678d Document auto_import as a feature 2020-10-15 14:57:19 +02:00
bors[bot]
7dd09a7b34
Merge #6236
6236: Code: Insert a ZWNJ before `after` type hints r=matklad a=lnicola

to prevent the editor from displaying a ligature there. 

Fixes #6235

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-10-15 10:50:26 +00:00
bors[bot]
ba6679dc6c
Merge #6239
6239: Cleanup alloc advice r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-15 10:22:01 +00:00
Aleksey Kladov
dedfaa3844 Cleanup alloc advice 2020-10-15 12:21:38 +02:00
Laurențiu Nicola
010d123f23 Insert a ZWNJ before type hints 2020-10-15 10:56:28 +03:00
bors[bot]
3a38554f86
Merge #6231
6231: Factor macro_rules and format-string highlighting out into submodules r=Veykril a=Veykril

This moves `format`-like macro string highlighting and macro_rules highlight skipping out of the main module.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-14 20:52:41 +00:00
Lukas Wirth
bab29e65eb Default::default the highlighters 2020-10-14 22:50:26 +02:00
Vlad Shcherbina
e6fbb94edd Fix hover over field pattern shorthand
Instead of the information about the field, it now shows the information
about the local.

Fixes #6146
2020-10-14 21:22:00 +03:00
Lukas Wirth
d983f18df7 Add mark tests to qualify_path assist 2020-10-14 20:04:57 +02:00
bors[bot]
b2205bd107
Merge #6233
6233: Style: default over new r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-14 18:02:36 +00:00
Aleksey Kladov
9c285b0341 Style: default over new 2020-10-14 20:02:03 +02:00
Lukas Wirth
9f41f074be Add qualify path assist 2020-10-14 19:56:20 +02:00
Lukas Wirth
8c6dc5f28a Factor macro_rules! highlighting out 2020-10-14 19:23:59 +02:00
Lukas Wirth
df87be88d8 Factor format string highlighting out 2020-10-14 19:23:45 +02:00
Roland Ruckerbauer
0e9d1e17d6 binary operator overload type inference: add test mark 2020-10-14 19:00:04 +02:00
bors[bot]
84d6cdef86
Merge #6230
6230: Log around sysroot discovery r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-14 15:23:02 +00:00
Aleksey Kladov
1b3b8c7fda Log around sysroot discovery 2020-10-14 17:22:07 +02:00
bors[bot]
f7144dcd52
Merge #6229
6229: Add docs for dbgr and call r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-10-14 13:32:32 +00:00
Laurențiu Nicola
8cc175ee9b Add docs for dbgr and call 2020-10-14 16:23:51 +03:00
bors[bot]
f9b2dea0d7
Merge #6228
6228: Introduce S-actionable and S-unactionable labels r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-14 13:23:45 +00:00
Aleksey Kladov
190011168d Introduce S-actionable and S-unactionable labels
I've noticed that a significant fraction of issues are inert.
They are valid, acknowledged and useful, but effectively can't be
fixed for variety of reasons (no reproduction, dependencies on some
other issues, no review capacity, etc).

Marking issues that can be fixed by just applying some elbow grease
seems useful!
2020-10-14 15:20:31 +02:00
bors[bot]
3e450cf89f
Merge #6207 #6224 #6226 #6227
6207: Extract ImportAssets out of auto_import r=matklad a=Veykril

See https://github.com/rust-analyzer/rust-analyzer/pull/6172#issuecomment-707182140

I couldn't fully pull out `AssistContext` as `find_node_at_offset_with_descend`: 81fa00c5b5/crates/assists/src/assist_context.rs (L90-L92) requires the `SourceFile` which is private in it and I don't think making it public just for this is the right call?

6224: ⬆️ salsa r=matklad a=matklad

bors r+
🤖

6226: Add reminder to update lsp-extensions.md r=matklad a=matklad

bors r+
🤖

6227: Reduce bors timeout r=matklad a=matklad

bors r+
🤖

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-14 11:37:51 +00:00
Aleksey Kladov
74b5f7cd82 Reduce bors timeout 2020-10-14 13:37:20 +02:00
Aleksey Kladov
d852189e56 Add reminder to update lsp-extensions.md 2020-10-14 13:30:06 +02:00
Aleksey Kladov
41e2639f35 ⬆️ salsa 2020-10-14 12:40:48 +02:00
bors[bot]
b62f48f535
Merge #6217
6217: Bump pulldown-cmark r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-10-14 10:26:13 +00:00
bors[bot]
69f1c8aa6e
Merge #6222
6222: Fix stackoverflow in insert_use::recursive_merge r=matklad a=Veykril

Fixes #6221.

#6108 shouldn't be related to this as autocompletion doesn't depend on this code.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-14 10:15:51 +00:00
Lukas Wirth
03b77b03fe Fix stackoverflow in insert_use::recursive_merge 2020-10-14 01:43:56 +02:00
Roland Ruckerbauer
4e49b2f731 Implement binary operator overloading type inference 2020-10-13 20:48:08 +02:00
Lukas Wirth
01b410c69a Slightly cleanup import_assets module 2020-10-13 20:02:14 +02:00
Laurențiu Nicola
e559066bed Bump pulldown-cmark 2020-10-13 20:41:49 +03:00
Lukas Wirth
02b844e9fb Adhere to style guidelines in import_assets 2020-10-13 18:58:37 +02:00