Commit Graph

848 Commits

Author SHA1 Message Date
Lukas Wirth
eba90936c1 Move ide crates to new hir::Macro 2022-03-08 23:52:26 +01:00
bors[bot]
79a7ba0bdf
Merge #11623
11623: fix: Add type variable table to InferenceTableSnapshot r=flodiebold a=tysg

Fixes #11601. 

I observed that removing the `rollback` line in 6fc3d3aa4c fixes the issue.  

Looking at the stacktrace, I believe not restoring `type_variable_table` causes `type_variable_table` and `var_unification_table` to go out of sync, then when `hir_ty::infer::unify::InferenceTable::new_var` tries to extend `type_variable_table` to be the same length as `var_unification_table`, problems will arise.

However, I cannot pinpoint exactly how or where the vector capacity overflow happens, so my understanding might not be correct after all. 

Co-authored-by: Tianyi Song <42670338+tysg@users.noreply.github.com>
2022-03-05 10:32:07 +00:00
Tianyi Song
c49bcc7814 Add type variable table to InferenceTableSnapshot 2022-03-05 17:59:28 +08:00
hkalbasi
660fd4ab41 Resolve only type params in type ns 2022-03-04 12:30:53 +03:30
hkalbasi
4fa8749c44 Preserve order of generic args 2022-03-04 11:46:14 +03:30
Florian Diebold
82fe1c77b5 Add a (currently failing) test for #11242 2022-03-03 18:32:40 +01:00
Chayim Refael Friedman
744f0ea2e7
Remove misleading comments
They're not true anymore after #11375.
2022-02-27 09:52:11 +02:00
Laurențiu Nicola
87c4a4104d Fix body selection in while loops 2022-02-26 16:45:06 +02:00
Jonas Schievink
a247fffdf6 Resolve $crate in HirDisplay of Path 2022-02-25 18:38:51 +01:00
Florian Diebold
6fc3d3aa4c Avoid autoderef coercions leaking if they don't apply 2022-02-25 15:46:02 +01:00
Florian Diebold
187e6bacac Fix unreachable pub 2022-02-25 12:09:49 +01:00
Florian Diebold
6fb5abbc03 Refactor autoderef and method resolution
- don't return the receiver type from method resolution; instead just
 return the autorefs/autoderefs that happened and repeat them. This
 ensures all the effects like trait obligations and whatever we learned
 about type variables from derefing them are actually applied. Also, it
 allows us to get rid of `decanonicalize_ty`, which was just wrong in
 principle.

 - Autoderef itself now directly works with an inference table. Sadly
 this has the effect of making it harder to use as an iterator, often
 requiring manual `while let` loops. (rustc works around this by using
 inner mutability in the inference context, so that things like unifying
 types don't require a unique reference.)

 - We now record the adjustments (autoref/deref) for method receivers
 and index expressions, which we didn't before.

 - Removed the redundant crate parameter from method resolution, since
 the trait_env contains the crate as well.

 - in the HIR API, the methods now take a scope to determine the trait env.
 `Type` carries a trait env, but I think that's probably a bad decision
 because it's easy to create it with the wrong env, e.g. by using
 `Adt::ty`. This mostly didn't matter so far because
 `iterate_method_candidates` took a crate parameter and ignored
 `self.krate`, but the trait env would still have been wrong in those
 cases, which I think would give some wrong results in some edge cases.

Fixes #10058.
2022-02-25 11:47:14 +01:00
Florian Diebold
6858694001 Add some tests 2022-02-25 11:47:14 +01:00
Lukas Wirth
41b6b372a7 fix: Resolve private fields in type inference 2022-02-23 16:45:58 +01:00
bors[bot]
24255e5b3d
Merge #11481
11481: Display parameter names when hovering over a function pointer r=Veykril a=Vannevelj

Implements #11474

The idea is pretty straightforward: previously we constructed the hover based on just the parameter types, now we pass in the parameter names as well. I went for a quick-hit approach here but I expect someone will be able to point me to a better way of resolving the identifier.

I haven't figured out yet how to actually run my rust-analyzer locally so I can see it in action but the unit test indicates it should work.

Co-authored-by: Jeroen Vannevel <jer_vannevel@outlook.com>
2022-02-21 13:08:31 +00:00
Jeroen Vannevel
9c6542f209
parameters.split_last() 2022-02-21 10:29:38 +00:00
Chayim Refael Friedman
a1b7169b48 Update tests
Unfortunately, we lost some recovery for expressions.
2022-02-21 08:34:35 +02:00
Chayim Refael Friedman
13ac5c3491 Fix various IDE features
As a side benefit, we got `let` guard support for `move_guard` for free.
2022-02-21 08:34:35 +02:00
Chayim Refael Friedman
fe1e324694 Type-inference for let expressions 2022-02-21 08:34:35 +02:00
Jeroen Vannevel
d1fc208c9c
re-added FIXME 2022-02-18 09:12:52 +00:00
Chayim Refael Friedman
4b2985a23e Infer the array size for slice patterns 2022-02-16 12:19:26 +00:00
Jeroen Vannevel
f083c86890
simplified write 2022-02-15 19:27:56 +00:00
Jeroen Vannevel
e1df78820e
removed unwrap 2022-02-15 14:58:06 +00:00
Jeroen Vannevel
0a80cc82b1
cleaning 2022-02-15 14:55:21 +00:00
Jeroen Vannevel
3bba811e92
fmt 2022-02-15 14:47:51 +00:00
Jeroen Vannevel
c450d0ce41
cleanup 2022-02-15 14:47:23 +00:00
Jeroen Vannevel
73e49493bd
rough, but appears to work 2022-02-15 14:39:22 +00:00
Lukas Wirth
6940cca760 Move attribute path completions into attribute completion module 2022-02-03 15:50:14 +01:00
Florian Diebold
4ed5fe1554 Fix assoc type shorthand from method bounds
In code like this:
```rust
impl<T> Option<T> {
    fn as_deref(&self) -> T::Target where T: Deref {}
}
```

when trying to resolve the associated type `T::Target`, we were only
looking at the bounds on the impl (where the type parameter is defined),
but the method can add additional bounds that can also be used to refer
to associated types. Hence, when resolving such an associated type, it's
not enough to just know the type parameter T, we also need to know
exactly where we are currently.

This fixes #11364 (beta apparently switched some bounds around).
2022-02-03 13:15:02 +01:00
Lukas Wirth
d7a544e69a fix: Complete functions and methods from block level impls 2022-02-01 23:29:40 +01:00
Laurențiu Nicola
bdfdb525bb Bump chalk 2022-01-21 19:51:21 +02:00
Jonas Schievink
601dc50b5a Print a single ellipsis for any number of omitted types 2022-01-10 16:55:53 +01:00
bors[bot]
40009e07d0
Merge #11145
11145: feat: add config to use reasonable default expression instead of todo! when filling missing fields r=Veykril a=bnjjj

Use `Default::default()` in struct fields when we ask to fill it instead of putting `todo!()` for every fields

before:

```rust
pub enum Other {
    One,
    Two,
}

pub struct Test {
    text: String,
    num: usize,
    other: Other,
}

fn t_test() {
    let test = Test {<|>};
}
``` 

after: 

```rust
pub enum Other {
    One,
    Two,
}

pub struct Test {
    text: String,
    num: usize,
    other: Other,
}

fn t_test() {
    let test = Test {
        text: String::new(),
        num: 0,
        other: todo!(),
    };
}
``` 



Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Coenen Benjamin <benjamin.coenen@hotmail.com>
2022-01-07 14:10:11 +00:00
Benjamin Coenen
f4ce0d78bb add better default behavior on fill struct fields diagnostic
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2022-01-06 15:42:29 +01:00
Aaron Hill
04cb85032f
Remove unused lifetime 2022-01-05 10:19:10 -05:00
bors[bot]
ac3ea3e81c
Merge #11112
11112: Evaluate constants in array repeat expression r=HKalbasi a=HKalbasi

cc #8655 

Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
2022-01-04 21:51:37 +00:00
hkalbasi
75c2acae6e Evaluate constants in array repeat expression 2022-01-05 01:17:01 +03:30
bors[bot]
b14af5cc6f
Merge #11115
11115: internal: refactor: avoid separate traversal in replace filter map next with find map r=Veykril a=rainy-me

fix: #7428

Co-authored-by: rainy-me <github@yue.coffee>
2022-01-03 16:00:05 +00:00
Kirill Bulatov
03291db801 Allow adding partially resolved types 2022-01-03 01:34:33 +02:00
rainy-me
d77d3234ce refactor: avoid filter map next with find map separate traversal 2021-12-25 09:08:13 +09:00
hkalbasi
e6139cf47b show values of constants in hover 2021-12-23 17:53:46 +03:30
bors[bot]
851af5a52b
Merge #11074
11074: Bump default CHALK_SOLVER_MAX_SIZE to 150 r=lnicola a=lnicola

Fixes #11072

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-12-20 18:38:47 +00:00
Laurențiu Nicola
3f3aee53b4 Bump default CHALK_SOLVER_MAX_SIZE to 150 2021-12-20 20:35:45 +02:00
bors[bot]
8dc3a270f6
Merge #11067
11067: internal: Store function param names in ItemTree r=Veykril a=Veykril

This prevents us reparsing source files for completions, sometimes slowing them down massively if the source file is not cached at the expense of a slightly bigger memory usage.

related info https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Completion.20performance

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-12-20 14:43:39 +00:00
Lukas Wirth
cd9d76e0ca internal: Store function param names in ItemTree 2021-12-20 15:24:37 +01:00
bors[bot]
f46731a230
Merge #11028
11028: Bump MSRV (1.57) r=Veykril a=iDawer

This bumps MSRV on all crates to 1.57 except `la-arena`

#10986 requires >=1.57 

Co-authored-by: iDawer <ilnur.iskhakov.oss@outlook.com>
2021-12-20 13:45:35 +00:00
iDawer
a9ad7be748 Respect binding mode of a binding pattern for exhaustiveness check 2021-12-20 00:14:39 +05:00
iDawer
b17aefb83a internal: Normalize field type after substituting 2021-12-20 00:14:39 +05:00
iDawer
1280961b51 internal: sync match checking with rust-lang/rust f31622a50 2021-11-12 2021-12-20 00:10:01 +05:00
Dawer
deb05930ef internal: Sync match checking algorithm with rustc
Original version: rust-lang/rust  68b76a483 2021-10-01
2021-12-20 00:10:01 +05:00