Skip to content

Commit 9829efb

Browse files
committed
Range PatKind implies discr should be read
1 parent eba3228 commit 9829efb

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

compiler/rustc_typeck/src/expr_use_visitor.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,15 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
267267
}
268268
}
269269
}
270-
PatKind::Lit(_) => {
271-
// If the PatKind is a Lit then we want
270+
PatKind::Lit(_) | PatKind::Range(..) => {
271+
// If the PatKind is a Lit or a Range then we want
272272
// to borrow discr.
273273
needs_to_be_read = true;
274274
}
275-
_ => {}
275+
_ => {
276+
// If the PatKind is Or, Box, Slice or Ref, the decision is made later
277+
// as these patterns contains subpatterns
278+
}
276279
}
277280
}));
278281
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-pass
2+
// edition:2021
3+
4+
pub fn foo() {
5+
let ref_x_ck = 123;
6+
let _y = || match ref_x_ck {
7+
2_000_000..=3_999_999 => { println!("A")}
8+
_ => { println!("B")}
9+
};
10+
}
11+
12+
fn main() {
13+
foo();
14+
}

0 commit comments

Comments
 (0)