mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 10:58:02 +00:00
Fix IfExpr then branch suggest
- And add logic operation suggest
Example
---
In the old implementation, it always suggested conditions,
this is a lot of noise, e.g `contract_checks()~(use std::intrinsics::contract_checks) const fn() -> bool`
```rust
fn foo() {
if true {
c$0
}
}
```
This commit is contained in:
parent
259a01d73d
commit
07f33e2b81
3 changed files with 82 additions and 8 deletions
|
|
@ -637,6 +637,9 @@ fn expected_type_and_name<'db>(
|
|||
.or_else(|| it.rhs().and_then(|rhs| sema.type_of_expr(&rhs)))
|
||||
.map(TypeInfo::original);
|
||||
(ty, None)
|
||||
} else if let Some(ast::BinaryOp::LogicOp(_)) = it.op_kind() {
|
||||
let ty = sema.type_of_expr(&it.clone().into()).map(TypeInfo::original);
|
||||
(ty, None)
|
||||
} else {
|
||||
(None, None)
|
||||
}
|
||||
|
|
@ -707,9 +710,13 @@ fn expected_type_and_name<'db>(
|
|||
(ty, None)
|
||||
},
|
||||
ast::IfExpr(it) => {
|
||||
let ty = it.condition()
|
||||
.and_then(|e| sema.type_of_expr(&e))
|
||||
.map(TypeInfo::original);
|
||||
let ty = if let Some(body) = it.then_branch()
|
||||
&& token.text_range().end() > body.syntax().text_range().start()
|
||||
{
|
||||
sema.type_of_expr(&body.into())
|
||||
} else {
|
||||
it.condition().and_then(|e| sema.type_of_expr(&e))
|
||||
}.map(TypeInfo::original);
|
||||
(ty, None)
|
||||
},
|
||||
ast::IdentPat(it) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue