Commit Graph

755 Commits

Author SHA1 Message Date
Aleksey Kladov
afacdd612d internal: update expect 2021-10-09 17:17:16 +03:00
Jonas Schievink
f8acae7895 Support let...else 2021-10-07 17:06:24 +02:00
crauzer
a4f08c117f Fix stdx::to_snake_case 2021-10-06 23:24:47 +02:00
bors[bot]
86c534f244
Merge #10440
10440: Fix Clippy warnings and replace some `if let`s with `match` r=Veykril a=arzg

I decided to try fixing a bunch of Clippy warnings. I am aware of this project’s opinion of Clippy (I have read both [rust-lang/clippy#5537](https://github.com/rust-lang/rust-clippy/issues/5537) and [rust-analyzer/rowan#57 (comment)](https://github.com/rust-analyzer/rowan/pull/57#discussion_r415676159)), so I totally understand if part of or the entirety of this PR is rejected. In particular, I can see how the semicolons and `if let` vs `match` commits provide comparatively little benefit when compared to the ensuing churn.

I tried to separate each kind of change into its own commit to make it easier to discard certain changes. I also only applied Clippy suggestions where I thought they provided a definite improvement to the code (apart from semicolons, which is IMO more of a formatting/consistency question than a linting question). In the end I accumulated a list of 28 Clippy lints I ignored entirely.

Sidenote: I should really have asked about this on Zulip before going through all 1,555 `if let`s in the codebase to decide which ones definitely look better as `match` :P

Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
2021-10-05 08:58:40 +00:00
Aramis Razzaghipour
9583dd5725
Replace if let with match where appropriate 2021-10-05 09:00:21 +11:00
Jonas Schievink
3aa37d7f80 Avoid cycle when lowering predicates for associated item lookup 2021-10-04 17:39:55 +02:00
Giacomo Stevanato
034dd41ea8 Add regression test 2021-09-29 21:08:44 +02:00
Giacomo Stevanato
7f76a73a38 Add regression test 2021-09-27 16:59:25 +02:00
Lukas Wirth
b6ed91a6de Rename *Owner traits to Has* 2021-09-27 12:54:24 +02:00
Aleksey Kladov
2bf81922f7 internal: more reasonable grammar for blocks
Consider these expples

        { 92 }
  async { 92 }
    'a: { 92 }
   #[a] { 92 }

Previously the tree for them were

  BLOCK_EXPR
    { ... }

  EFFECT_EXPR
    async
    BLOCK_EXPR
      { ... }

  EFFECT_EXPR
    'a:
    BLOCK_EXPR
      { ... }

  BLOCK_EXPR
    #[a]
    { ... }

As you see, it gets progressively worse :) The last two items are
especially odd. The last one even violates the balanced curleys
invariant we have (#10357) The new approach is to say that the stuff in
`{}` is stmt_list, and the block is stmt_list + optional modifiers

  BLOCK_EXPR
    STMT_LIST
      { ... }

  BLOCK_EXPR
    async
    STMT_LIST
      { ... }

  BLOCK_EXPR
    'a:
    STMT_LIST
      { ... }

  BLOCK_EXPR
    #[a]
    STMT_LIST
      { ... }
2021-09-26 19:16:09 +03:00
Lukas Wirth
9c39363ada Simplify 2021-09-19 23:34:07 +02:00
teor
e0a501424c
Fix a comment typo in autoderef.rs 2021-09-16 13:47:01 +10:00
Lukas Wirth
a044175412 Simplify 2021-09-13 18:50:19 +02:00
bors[bot]
3e056b9e90
Merge #10213
10213: minor: Improve resilience of match checking r=flodiebold a=iDawer

In bug condition the match checking strives to recover giving false no-error diagnostic.

Suggested in https://github.com/rust-analyzer/rust-analyzer/pull/9105#discussion_r644656085

Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-09-12 12:23:56 +00:00
Dawer
68dfe190ab Improve resilience of match checking
In bug condition the match checking strives to recover giving false no-error diagnostic.
2021-09-12 16:03:12 +05:00
Florian Diebold
a2d9f7d7bb Avoid type inference panic on bitslice methods
Should fix #10090, #10046, #10179.
This is only a workaround, but the proper fix requires some bigger
refactoring (also related to fixing #10058), and this at least prevents
the crash.
2021-09-12 10:49:40 +02:00
bors[bot]
317059985a
Merge #10202
10202: fix: Type param hover shows correct sized bounds. r=flodiebold a=iDawer

Closes  #9949

This adds implicit `: Sized` bound to type parameters at lowering step.

Hovering on type parameter does not show it's `: Sized` bound be it set explicitly or implicitly. This is because it doesn't track that the bound was set implicitly.

### Perf

```rust
./target/rust-analyzer-baseline-3dae94bf -q analysis-stats --memory-usage .
Database loaded:     4.51s, 311minstr, 110mb (metadata 1.08s, 22minstr, 743kb; build 3.20s, 8730kinstr, -237kb)
  crates: 38, mods: 770, decls: 17173, fns: 12835
Item Collection:     29.63s, 85ginstr, 372mb
  exprs: 353460, ??ty: 364 (0%), ?ty: 232 (0%), !ty: 144
Inference:           118.25s, 284ginstr, 601mb
Total:               147.88s, 370ginstr, 973mb

./target/rust-analyzer-hover-ty-param-dfb15292 -q analysis-stats --memory-usage .
Database loaded:     4.53s, 311minstr, 110mb (metadata 1.10s, 22minstr, 743kb; build 3.20s, 8672kinstr, -189kb)
  crates: 38, mods: 770, decls: 17173, fns: 12835
Item Collection:     29.59s, 85ginstr, 372mb
  exprs: 353460, ??ty: 364 (0%), ?ty: 232 (0%), !ty: 144
Inference:           121.69s, 296ginstr, 601mb
Total:               151.28s, 382ginstr, 974mb

```

Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-09-12 07:54:56 +00:00
Aleksey Kladov
9b2bac621e minor: make code clearer with ControlFlow 2021-09-11 20:49:10 +03:00
Giles Cope
15312aab58
removing seemingly unused dev deps. 2021-09-11 16:26:36 +01:00
Dawer
9ce3c075ad internal: add implicit : Sized bound to type parameters. 2021-09-10 20:41:53 +05:00
bors[bot]
8e47e359fa
Merge #10190
10190: minor: Bump deps r=lnicola a=lnicola

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-09-09 18:13:26 +00:00
Laurențiu Nicola
c930dcca13 Bump chalk 2021-09-09 21:12:38 +03:00
Jonas Schievink
85993171e5 minor: include ImplLoc in panic context 2021-09-09 02:20:55 +02:00
bors[bot]
6a8062092b
Merge #10174
10174: fix: path display error when start with `crate` r=flodiebold a=dzvon

Fixes  #10172

Co-authored-by: Dezhi Wu <wu543065657@163.com>
2021-09-08 14:40:54 +00:00
Yotam Ofek
ebb891246c Split and document array method resolution logic. 2021-09-08 13:15:40 +03:00
Yotam Ofek
9593fe684d Fix resolution of inherent array methods. 2021-09-08 11:49:05 +03:00
Yotam Ofek
1785493cae Add (failing) test for inherent array method resolution. 2021-09-08 11:00:55 +03:00
Dezhi Wu
87436a08fa fix super path wrong display 2021-09-07 17:49:46 +08:00
Dezhi Wu
880af425d4 fix path wrong display 2021-09-07 16:54:02 +08:00
Dezhi Wu
82ae228d98 fix: path display error when start with crate 2021-09-07 14:44:30 +08:00
David Barsky
184fbf24f0 update to tracing-tree 0.1.10, which does not pull in syn. 2021-09-06 10:33:08 -04:00
Jonas Schievink
d6a12b491f Don't dump DefMaps to build the panic context 2021-09-05 20:42:22 +02:00
Jonas Schievink
7d67c71c34 Add panic info for impl_trait/trait_data 2021-09-05 19:19:34 +02:00
Lukas Wirth
36a5ce9790 minor: fix some clippy lints 2021-09-03 16:00:50 +02:00
bors[bot]
25368d2430
Merge #9954
9954: feat: Show try operator propogated types on ranged hover  r=matklad a=Veykril

Basically this just shows the type of the inner expression of the `?` expression as well as the type of the expression that the `?` returns from:
![Code_wIrCxMqLH9](https://user-images.githubusercontent.com/3757771/130111025-f7ee0742-214a-493b-947a-b4a671e4be92.png)

Unless both of these types are `core::result::Result` in which case we show the error types only.
![Code_Xruw5FCBNI](https://user-images.githubusercontent.com/3757771/130111024-f9caef82-92e4-4070-b3dd-f2ff9e5d87a9.png)

If both types are `core::option::Option` with different type params we do not show this special hover either as it would be pointless(instead fallback to default type hover)

Very much open to changes to the hover text here(I suppose we also want to show the actual type of the `?` expression, that is its output type?).

Fixes #9931

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-09-01 09:26:10 +00:00
Jonas Schievink
418b163a4b Allow inherent impl for arrays 2021-08-31 14:15:39 +02:00
Dezhi Wu
ba0947dded switch log crate to tracing 2021-08-30 15:11:42 +08:00
Aleksey Kladov
cfa3f679e9 internal: don't expose impl details out of hir 2021-08-29 18:55:25 +03:00
Aleksey Kladov
76b60efbfb internal: improve compile times a bit
before after for cargo llvm-lines -q --lib --release -p ide_ssr | head -n 24

  Lines          Copies        Function name
  -----          ------        -------------
  297146 (100%)  12748 (100%)  (TOTAL)
    5970 (2.0%)     47 (0.4%)  core::iter::traits::iterator::Iterator::try_fold
    4750 (1.6%)     27 (0.2%)  hashbrown::raw::RawTable<T,A>::resize
    4080 (1.4%)     30 (0.2%)  alloc::raw_vec::RawVec<T,A>::grow_amortized
    3933 (1.3%)     69 (0.5%)  alloc::raw_vec::RawVec<T,A>::current_memory
    3668 (1.2%)     89 (0.7%)  <core::result::Result<T,E> as core::ops::try_trait::Try>::branch
    3500 (1.2%)     50 (0.4%)  hashbrown::raw::RawTable<T,A>::drop_elements
    3436 (1.2%)     33 (0.3%)  hashbrown::raw::RawTable<T,A>::find
    3415 (1.1%)     17 (0.1%)  hashbrown::raw::RawTable<T,A>::rehash_in_place
    3400 (1.1%)     50 (0.4%)  <hashbrown::raw::RawIterRange<T> as core::iter::traits::iterator::Iterator>::next
    2840 (1.0%)     20 (0.2%)  alloc::raw_vec::RawVec<T,A>::allocate_in
    2700 (0.9%)     30 (0.2%)  core::alloc::layout::Layout::array
    2666 (0.9%)     86 (0.7%)  core::ptr::metadata::from_raw_parts_mut
    2495 (0.8%)     50 (0.4%)  core::option::Option<T>::map
    2354 (0.8%)     38 (0.3%)  alloc::alloc::box_free
    2302 (0.8%)      7 (0.1%)  ide_ssr::parsing::RuleBuilder::try_add
    2146 (0.7%)     45 (0.4%)  core::mem::replace
    2070 (0.7%)     69 (0.5%)  <alloc::raw_vec::RawVec<T,A> as core::ops::drop::Drop>::drop
    1979 (0.7%)     16 (0.1%)  hashbrown::map::HashMap<K,V,S,A>::insert
    1926 (0.6%)     18 (0.1%)  <core::iter::adapters::zip::Zip<A,B> as core::iter::adapters::zip::ZipImpl<A,B>>::next
    1922 (0.6%)     62 (0.5%)  core::fmt::ArgumentV1::new
    1885 (0.6%)     13 (0.1%)  alloc::raw_vec::RawVec<T,A>::shrink

  Lines          Copies        Function name
  -----          ------        -------------
  261717 (100%)  11666 (100%)  (TOTAL)
    5239 (2.0%)     42 (0.4%)  core::iter::traits::iterator::Iterator::try_fold
    4750 (1.8%)     27 (0.2%)  hashbrown::raw::RawTable<T,A>::resize
    3933 (1.5%)     69 (0.6%)  alloc::raw_vec::RawVec<T,A>::current_memory
    3536 (1.4%)     26 (0.2%)  alloc::raw_vec::RawVec<T,A>::grow_amortized
    3500 (1.3%)     50 (0.4%)  hashbrown::raw::RawTable<T,A>::drop_elements
    3400 (1.3%)     50 (0.4%)  <hashbrown::raw::RawIterRange<T> as core::iter::traits::iterator::Iterator>::next
    3124 (1.2%)     30 (0.3%)  hashbrown::raw::RawTable<T,A>::find
    2812 (1.1%)     14 (0.1%)  hashbrown::raw::RawTable<T,A>::rehash_in_place
    2604 (1.0%)     84 (0.7%)  core::ptr::metadata::from_raw_parts_mut
    2340 (0.9%)     26 (0.2%)  core::alloc::layout::Layout::array
    2302 (0.9%)      7 (0.1%)  ide_ssr::parsing::RuleBuilder::try_add
    2272 (0.9%)     16 (0.1%)  alloc::raw_vec::RawVec<T,A>::allocate_in
    2201 (0.8%)     35 (0.3%)  alloc::alloc::box_free
    2104 (0.8%)     44 (0.4%)  core::mem::replace
    2079 (0.8%)     42 (0.4%)  <core::result::Result<T,E> as core::ops::try_trait::Try>::branch
    2070 (0.8%)     69 (0.6%)  <alloc::raw_vec::RawVec<T,A> as core::ops::drop::Drop>::drop
    1926 (0.7%)     18 (0.2%)  <core::iter::adapters::zip::Zip<A,B> as core::iter::adapters::zip::ZipImpl<A,B>>::next
    1885 (0.7%)     13 (0.1%)  alloc::raw_vec::RawVec<T,A>::shrink
    1833 (0.7%)     13 (0.1%)  hashbrown::raw::RawTable<T,A>::shrink_to
    1771 (0.7%)     91 (0.8%)  core::ptr::read
    1701 (0.6%)     35 (0.3%)  core::option::Option<T>::map
2021-08-29 18:49:16 +03:00
Florian Diebold
424dda8113 Refactor & improve handling of overloaded binary operators
Fixes #9971. Also records them as method resolutions, which we could use
later.
2021-08-22 17:35:50 +02:00
Frank Steffahn
35a7fdd2c1 Fix two more “a”/“an” typos 2021-08-22 17:24:48 +02:00
Frank Steffahn
3a5a93595f Fix typos “a”→“an” 2021-08-22 14:31:37 +02:00
bors[bot]
9e3517f8f3
Merge #9975
9975: minor: Fix panic caused by #9966 r=flodiebold a=flodiebold

Chalk can introduce new type variables when doing lazy normalization, so we have to do the proper 'fudging' after all.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-08-21 18:07:36 +00:00
Florian Diebold
df77e2448c Fix panic caused by #9966
Chalk can introduce new type variables when doing lazy normalization, so
we have to do the proper 'fudging' after all.
2021-08-21 20:07:07 +02:00
Laurențiu Nicola
104d6124d7 Handle coercion on binary operator RHS 2021-08-21 17:54:45 +03:00
Florian Diebold
1791a35f9f Determine expected parameters from expected return in calls
Fixes #9560
2021-08-21 14:33:31 +02:00
Florian Diebold
cd64353288 Adapt tests for correct behavior 2021-08-21 13:35:36 +02:00
Florian Diebold
5cff355059 Add another test 2021-08-21 13:35:34 +02:00
Lukas Wirth
95923c7b29 Fix imports 2021-08-19 17:33:58 +02:00
Jonas Schievink
4757679b9a feat: type inference for if-let guards 2021-08-14 00:09:30 +02:00