Skip to content

Commit 736e322

Browse files
committed
Add more variations from the PR thread
1 parent 39d09eb commit 736e322

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/ui/closures/2229_closure_analysis/deref-mut-in-pattern.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//@ check-pass
55
#![allow(unused_assignments)]
66

7+
// Reading the length as part of a pattern captures the pointee.
78
fn f() {
89
let mut x: &mut [u8] = &mut [1, 2, 3];
910
let c = || {
@@ -16,6 +17,7 @@ fn f() {
1617
c();
1718
}
1819

20+
// Plain old deref as part of pattern behaves similarly
1921
fn g() {
2022
let mut x: &mut bool = &mut false;
2123
let mut t = true;
@@ -29,6 +31,23 @@ fn g() {
2931
c();
3032
}
3133

34+
// Like f, but the lifetime implications are expressed in terms of
35+
// returning a closure.
36+
fn f2<'l: 's, 's>(x: &'s mut &'l [u8]) -> impl Fn() + 'l {
37+
|| match *x {
38+
&[] => (),
39+
_ => (),
40+
}
41+
}
42+
43+
// Related testcase that was already accepted before
44+
fn f3<'l: 's, 's>(x: &'s mut &'l [u8]) -> impl Fn() + 'l {
45+
|| match **x {
46+
[] => (),
47+
_ => (),
48+
}
49+
}
50+
3251
fn main() {
3352
f();
3453
g();

0 commit comments

Comments
 (0)