Skip to content

Commit 60379da

Browse files
committed
resolve types in closure capture copy detection
1 parent c5ea2d7 commit 60379da

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

crates/hir-ty/src/infer/closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,14 +710,14 @@ impl InferenceContext<'_> {
710710
false
711711
}
712712

713-
fn is_ty_copy(&self, ty: Ty) -> bool {
713+
fn is_ty_copy(&mut self, ty: Ty) -> bool {
714714
if let TyKind::Closure(id, _) = ty.kind(Interner) {
715715
// FIXME: We handle closure as a special case, since chalk consider every closure as copy. We
716716
// should probably let chalk know which closures are copy, but I don't know how doing it
717717
// without creating query cycles.
718718
return self.result.closure_info.get(id).map(|x| x.1 == FnTrait::Fn).unwrap_or(true);
719719
}
720-
ty.is_copy(self.db, self.owner)
720+
self.table.resolve_completely(ty).is_copy(self.db, self.owner)
721721
}
722722

723723
fn select_from_expr(&mut self, expr: ExprId) {

crates/ide/src/hover/tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,33 @@ fn main() {
301301
* `(*x.f2.0.0).f` by mutable borrow
302302
"#]],
303303
);
304+
check(
305+
r#"
306+
//- minicore: copy, option
307+
308+
fn do_char(c: char) {}
309+
310+
fn main() {
311+
let x = None;
312+
let y = |$0| {
313+
match x {
314+
Some(c) => do_char(c),
315+
None => x = None,
316+
}
317+
};
318+
}
319+
"#,
320+
expect![[r#"
321+
*|*
322+
```rust
323+
{closure#0} // size = 8, align = 8
324+
impl FnMut()
325+
```
326+
327+
## Captures
328+
* `x` by mutable borrow
329+
"#]],
330+
);
304331
}
305332

306333
#[test]

0 commit comments

Comments
 (0)