resolve types in closure capture copy detection
This commit is contained in:
parent
c5ea2d7adc
commit
60379dabfb
@ -710,14 +710,14 @@ fn is_upvar(&self, place: &HirPlace) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_ty_copy(&self, ty: Ty) -> bool {
|
||||
fn is_ty_copy(&mut self, ty: Ty) -> bool {
|
||||
if let TyKind::Closure(id, _) = ty.kind(Interner) {
|
||||
// FIXME: We handle closure as a special case, since chalk consider every closure as copy. We
|
||||
// should probably let chalk know which closures are copy, but I don't know how doing it
|
||||
// without creating query cycles.
|
||||
return self.result.closure_info.get(id).map(|x| x.1 == FnTrait::Fn).unwrap_or(true);
|
||||
}
|
||||
ty.is_copy(self.db, self.owner)
|
||||
self.table.resolve_completely(ty).is_copy(self.db, self.owner)
|
||||
}
|
||||
|
||||
fn select_from_expr(&mut self, expr: ExprId) {
|
||||
|
@ -301,6 +301,33 @@ impl FnOnce()
|
||||
* `(*x.f2.0.0).f` by mutable borrow
|
||||
"#]],
|
||||
);
|
||||
check(
|
||||
r#"
|
||||
//- minicore: copy, option
|
||||
|
||||
fn do_char(c: char) {}
|
||||
|
||||
fn main() {
|
||||
let x = None;
|
||||
let y = |$0| {
|
||||
match x {
|
||||
Some(c) => do_char(c),
|
||||
None => x = None,
|
||||
}
|
||||
};
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*|*
|
||||
```rust
|
||||
{closure#0} // size = 8, align = 8
|
||||
impl FnMut()
|
||||
```
|
||||
|
||||
## Captures
|
||||
* `x` by mutable borrow
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user