Commit Graph

23723 Commits

Author SHA1 Message Date
Maybe Waffle
91a89efcf2 Save source & target types in hir's expr_adjustments 2022-12-20 19:33:27 +00:00
bors
927d56a67d Auto merge of #13764 - WaffleLapkin:badassexprs, r=Veykril
fix: Correctly check for parentheses redundancy in `remove_parentheses` assist

This is quite a bunch of code and some hacks, but I _think_ this time it's correct.

I've added a lot of tests, most of which fail with the assist impl from #13733 :')
2022-12-20 18:11:54 +00:00
bors
5c8f00f835 Auto merge of #13805 - ntBre:master, r=jonas-schievink
Complete enum variants without parens when snippets are disabled

This handles the portion of #13767 that bothered me, but I can try to work on the other parts we discussed if needed.
2022-12-20 17:58:41 +00:00
Brent Westbrook
694ae77bf6 pass snippet_cap to format_literal_label, return early if None 2022-12-20 11:27:19 -05:00
Brent Westbrook
1116cc93ec return immediately from render_tuple_lit if snippet_cap is None
partially addresses #13767
2022-12-20 11:07:37 -05:00
Maybe Waffle
babd4c7f7d Don't panic in Expr::needs_parens_in 2022-12-20 15:16:26 +00:00
bors
9dfb9df4c5 Auto merge of #13804 - WaffleLapkin:inlay_hint_mods, r=Veykril
Split inlay hints into modules per hint type

I think this makes the code a lot easier to maintain.
2022-12-20 14:18:49 +00:00
Maybe Waffle
046a5679e3 Add docs to make tidy tests happy :') 2022-12-20 13:30:53 +00:00
Maybe Waffle
1c8bcf0d4e Move inlay hints tests into implementation modules 2022-12-20 13:05:18 +00:00
Maybe Waffle
191cfba9d2 Split inlay hints into modules 2022-12-20 12:58:57 +00:00
bors
ccbf8fef9b Auto merge of #13800 - lowr:fix/mbe-expr-backwards-compat, r=Veykril
fix: don't let mbe expr fragments match let exprs and inline consts

Fixes #11729

`expr` fragment in mbe should not match let expressions and inline consts for backwards compatibility. See rust-lang/rust#86730 for details.

This patch is porting [this logic in rustc](f0c4da4998/compiler/rustc_parse/src/parser/nonterminal.rs (L28-L34)) (which is called [here in rustc's mbe engine](f0c4da4998/compiler/rustc_expand/src/mbe/macro_parser.rs (L576))) to our mbe engine.
2022-12-20 12:01:30 +00:00
Ryo Yoshida
e027ac0fbf
fix: don't let mbe expr fragments match let exprs and inline consts 2022-12-20 20:31:47 +09:00
bors
ffedfc63a1 Auto merge of #13795 - jonas-schievink:fix-rustfmt-edition-in-path-deps, r=jonas-schievink
fix: Use the correct edition when formatting code in path dependencies

Fixes https://github.com/rust-lang/rust-analyzer/issues/13790

Don't go through the Cargo workspace info, since that doesn't contain path dependencies. Instead, query the crate graph via `Analysis::crate_edition`.
2022-12-19 16:57:12 +00:00
Jonas Schievink
5706910add Use the correct edition when formatting path deps 2022-12-19 17:53:56 +01:00
bors
1f74b1b04e Auto merge of #13794 - jonas-schievink:reset-step-limit-after-bump, r=jonas-schievink
fix: fix "parser seems stuck" panic when parsing colossal files

The parser step count is incremented every time the parser inspects a token. It's purpose is to ensure the parser doesn't get stuck in infinite loops. But since `self.pos` grows monotonically when parsing source code, it gives a better idea for whether the parser is stuck or not: if `self.pos` is changed, we know that the parser cannot be stuck, so it is safe to reset the step count to 0. This makes the limit check scale with the size of the file, and so should fix https://github.com/rust-lang/rust-analyzer/issues/13788.
2022-12-19 16:07:40 +00:00
Jonas Schievink
c110481dd4 Reset parser step count when bumping 2022-12-19 16:27:00 +01:00
bors
9ed1829f1f Auto merge of #13792 - Veykril:flycheck, r=Veykril
Add a command to clear flycheck diagnostics

And document the flycheck notifications
2022-12-17 22:45:08 +00:00
Lukas Wirth
cf8d89e46b Add a command to clear flycheck diagnostics 2022-12-17 23:43:26 +01:00
Lukas Wirth
d8ddde27f9 Make cancelFlycheck request a notification 2022-12-17 23:29:31 +01:00
Lukas Wirth
cdfe98fe94 Make manual flycheck runs work when checkOnSave is disabled 2022-12-17 23:26:54 +01:00
bors
e0aa5afd7b Auto merge of #13785 - Veykril:run-flycheck, r=Veykril
Add command for manually running flychecks

Closes https://github.com/rust-lang/rust-analyzer/issues/13125
2022-12-16 22:06:35 +00:00
Lukas Wirth
a04feb915a Add command for manually running flychecks 2022-12-16 22:47:19 +01:00
bors
19c2ede549 Auto merge of #13784 - Veykril:bm-hints, r=Veykril
Deduplicate inserted parentheses in binding mode hints
2022-12-16 20:51:20 +00:00
Lukas Wirth
ba3e3282da Deduplicate inserted parentheses in binding mode hints 2022-12-16 21:17:10 +01:00
bors
8f6d0cd1b0 Auto merge of #13783 - Veykril:bm-hints, r=Veykril
Add parentheses for binding mode hints when they attach to an Or-pattern
2022-12-16 19:53:06 +00:00
Lukas Wirth
b6c2bb21ab Add parentheses for binding mode hints when they attach to an Or-pattern 2022-12-16 20:52:31 +01:00
bors
4909d4fbdb Auto merge of #13777 - dzvon:fix-13776, r=jonas-schievink
fix: add a check for `if` token in patterns parser

Closes #13776
2022-12-16 03:23:38 +00:00
Dezhi Wu
258e532434 docs: update the comment and add a test to half_open_range_pat 2022-12-16 10:44:25 +08:00
Dezhi Wu
6a295fcd3b fix: add a check for if token in patterns parser
Closes #13776
2022-12-15 12:46:02 +08:00
bors
95671d53ea Auto merge of #13772 - noritada:minor/set-experimental-attr-to-changelog-draft, r=lnicola
minor: Set the `experimental` AsciiDoc document attribute to generated draft changelog

This PR sets the `experimental` AsciiDoc document attribute to generated draft changelog.

That attribute is required by the keyboard macro (`kbd:[...]`).
This change of the draft will prevent issues like https://github.com/rust-analyzer/rust-analyzer.github.io/pull/191 .
2022-12-14 14:54:19 +00:00
bors
16de9a7130 Auto merge of #13774 - lowr:fix/no-infer-vars-in-inference-result, r=Veykril
fix: resolve all inference vars in `InferenceResult::assoc_resolutions`

I think this fixes '#13773, ~but still haven't found repro. I'll try finding one so we can have a regression test~.

We should resolve every inference variable in `InferenceResult` after inference is done. We started recording `Substitution`s for each resolved associated items in #13725, but failed to do so which causes crash when analyzing source in IDE layer.
2022-12-14 14:27:32 +00:00
bors
fb4e9359d1 Auto merge of #13769 - jonas-schievink:parse-half-open-range-pat, r=jonas-schievink
feat: Parse half-open `..= X` patterns

Closes https://github.com/rust-lang/rust-analyzer/issues/13739
2022-12-14 14:14:46 +00:00
Ryo Yoshida
bb99d2a6fb
fix: resolve all inference vars in InferenceResult::assoc_resolutions 2022-12-14 23:07:43 +09:00
bors
5bd9373c5b Auto merge of #13766 - rust-lang:fix-config-patch, r=Veykril
Fix wrong config patching logic for addCallParenthesis
2022-12-14 13:50:29 +00:00
Noritada Kobayashi
37b404d6c6 minor: Set the experimental AsciiDoc document attribute to generated draft changelog
The keyboard macro (`kbd:[...]`) requires this attribute.

This default change will prevent issues like
https://github.com/rust-analyzer/rust-analyzer.github.io/pull/191 .
2022-12-14 18:49:26 +09:00
Jonas Schievink
9e0aaf4cf3 Parse ..= X patterns 2022-12-13 17:32:25 +01:00
Florian Diebold
ef4a9f0ac2 Fix wrong config patching logic for addCallParenthesis 2022-12-13 16:39:00 +01:00
Maybe Waffle
7ed0871ff6 Fix "needs parens" check in remove_parentheses assist 2022-12-13 00:06:00 +00:00
bors
4596847a88 Auto merge of #13746 - feniljain:fix_extract_function, r=jonas-schievink
fix: make make_body respect comments in extract_function

Possible fix for #13621

### Points to help in review:

- Earlier we were only considering statements in a block expr and hence comments were being ignored, now we handle tokens hence making it aware of comments and then preserving them using `hacky_block_expr_with_comments`

Seems like I am not able to attach output video, github is glitching for it :(
2022-12-12 14:51:03 +00:00
bors
15ff8a5a9f Auto merge of #13715 - feniljain:fix_completions, r=jonas-schievink
fix: breaking snippets on typed incomplete suggestions

Possible fix for #7929

Fix the case where if a user types `&&42.o`, snippet completion was still applying &&Ok(42). Note this was fixed previously on `&&42.` but this still remained a problem for this case

Previous relevant PR: #13517

### Points to help in review:

- The main problem why everything broke on adding an extra `o` was, earlier `dot_receiver` was `42.` which was a `LITERAL` but now `42.o` becomes a `FIELD_EXPR`

- Till now `include_references` was just checking for parent of `LITERAL` and if it was a `REF_EXPR`, but now we consider `FIELD_EXPR` and traverse all of them, finally to reach `REF_EXPR`. If `REF_EXPR` is not found we  just return the original `initial_element`

- We are constructing a new node during `include_references` because if we rely on `dot_receiver` solely we would get `&&42.o` to be replaced with, but we want `&&42` to be replaced with

### Output Video:

https://user-images.githubusercontent.com/49019259/205420166-efbdef78-5b3a-4aef-ab4b-d892dac056a0.mov

Hope everything I wrote makes sense 😅

Also interestingly previous PR's number was `13517` and this PR's number is `13715`, nicee
2022-12-12 14:37:45 +00:00
bors
e7dff7491a Auto merge of #13726 - feniljain:fix_assists, r=jonas-schievink
feat: allow unwrap block in let initializers

Possible fix for #13679

### Points to help in review:

- I just added a parent case for let statements and it seems everything else was in place already, so turned out to be a small fix
2022-12-12 14:06:45 +00:00
bors
3a7215b92e Auto merge of #13732 - rami3l:fix/gen-partial-eq, r=jonas-schievink
fix: add fallback case in generated `PartialEq` impl

Partially fixes #13727.

When generating `PartialEq` implementations for enums, the original code can already generate the following fallback case:

```rs
_ => std::mem::discriminant(self) == std::mem::discriminant(other),
```

However, it has been suppressed in the following example for no good reason:

```rs
enum Either<T, U> {
    Left(T),
    Right(U),
}

impl<T, U> PartialEq for Either<T, U> {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (Self::Left(l0), Self::Left(r0)) => l0 == r0,
            (Self::Right(l0), Self::Right(r0)) => l0 == r0,
            // _ => std::mem::discriminant(self) == std::mem::discriminant(other),
            // ^ this completes the match arms!
        }
    }
}
```

This PR has removed that suppression logic.

~~Of course, the PR could have suppressed the fallback case generation for single-variant enums instead, but I believe that this case is quite rare and should be caught by `#[warn(unreachable_patterns)]` anyway.~~

After this fix, when the enum has >1 variants, the following fallback arm will be generated :

* `_ => false,` if we've already gone through every case where the variants of `self` and `other` match;
* The original one (as stated above) in other cases.

---

Note: The code example is still wrong after the fix due to incorrect trait bounds.
2022-12-12 13:52:49 +00:00
bors
16c70fe69b Auto merge of #13762 - jonas-schievink:underscore-expr-first, r=jonas-schievink
fix: Fix parsing of `_ = x` in closure body

Fixes https://github.com/rust-lang/rust-analyzer/issues/13757
2022-12-12 12:12:02 +00:00
Jonas Schievink
ed48bd8b9d Fix parsing of _ = x in closure body 2022-12-12 12:57:29 +01:00
bors
21e61bee8b Auto merge of #13756 - flodiebold:simplify-assoc-item-subst, r=flodiebold
Make assoc_resolutions always have a Substitution
2022-12-10 16:06:54 +00:00
Florian Diebold
d3cb032f7e Make assoc_resolutions always have a Substitution 2022-12-10 17:05:33 +01:00
bors
a3ea20a142 Auto merge of #13725 - bvanjoi:resolve-const-triat-impls, r=flodiebold
feat: resolve const for trait impls

Fixed #13694
2022-12-10 13:58:28 +00:00
bvanjoi
7012b50db5 feat: resolve const for trait impls(close #13694) 2022-12-10 20:06:25 +08:00
bors
632f804797 Auto merge of #13750 - lowr:fix/rpit-in-projection, r=flodiebold
fix: normalize projection after discarding free `BoundVar`s in RPIT

Fixes #13307

When we lower the return type of a function, it may contain free `BoundVar`s in `OpaqueType`'s substitution, which would cause panic during canonicalization as part of projection normalization. Those `BoundVar`s are irrelevant in this context and will be discarded, and we should defer projection normalization until then.
2022-12-10 11:30:14 +00:00
bors
518e39bfe6 Auto merge of #13742 - lowr:fix/assoc-type-shorthand-with-gats, r=flodiebold
fix: only shift `BoundVar`s that come from outside lowering context

Fixes #13734

There are some free functions `TyLoweringContext` methods call, which do not know anything about current binders in scope. We need to shift in the `BoundVar`s in substitutions that we get from them (#4952), but not those we get from `TyLoweringContext` methods.
2022-12-10 11:17:18 +00:00