Use appropriate constructor for const slices
This commit is contained in:
parent
fa4a4d3eda
commit
5510f5589e
6 changed files with 23 additions and 25 deletions
|
|
@ -747,7 +747,7 @@ impl<'tcx> Constructor<'tcx> {
|
|||
.iter()
|
||||
.filter_map(|c: &Constructor<'_>| match c {
|
||||
Slice(slice) => Some(*slice),
|
||||
// FIXME(#65413): We ignore `ConstantValue`s here.
|
||||
// FIXME(oli-obk): implement `deref` for `ConstValue`
|
||||
ConstantValue(..) => None,
|
||||
_ => bug!("bad slice pattern constructor {:?}", c),
|
||||
})
|
||||
|
|
@ -1771,7 +1771,19 @@ fn pat_constructor<'tcx>(
|
|||
if let Some(int_range) = IntRange::from_const(tcx, param_env, value, pat.span) {
|
||||
Some(IntRange(int_range))
|
||||
} else {
|
||||
Some(ConstantValue(value))
|
||||
match (value.val, &value.ty.kind) {
|
||||
(_, ty::Array(_, n)) => {
|
||||
let len = n.eval_usize(tcx, param_env);
|
||||
Some(Slice(Slice { array_len: Some(len), kind: FixedLen(len) }))
|
||||
}
|
||||
(ty::ConstKind::Value(ConstValue::Slice { start, end, .. }), ty::Slice(_)) => {
|
||||
let len = (end - start) as u64;
|
||||
Some(Slice(Slice { array_len: None, kind: FixedLen(len) }))
|
||||
}
|
||||
// FIXME(oli-obk): implement `deref` for `ConstValue`
|
||||
// (ty::ConstKind::Value(ConstValue::ByRef { .. }), ty::Slice(_)) => { ... }
|
||||
_ => Some(ConstantValue(value)),
|
||||
}
|
||||
}
|
||||
}
|
||||
PatKind::Range(PatRange { lo, hi, end }) => {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// check-pass
|
||||
#![feature(slice_patterns)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
|
|
@ -8,8 +9,7 @@ fn main() {
|
|||
match x {
|
||||
&[] => {}
|
||||
&[1..=255] => {}
|
||||
// this shouldn't be unreachable
|
||||
C0 => {} //~ unreachable pattern
|
||||
C0 => {}
|
||||
&[_, _, ..] => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
error: unreachable pattern
|
||||
--> $DIR/65413-constants-and-slices-exhaustiveness.rs:12:9
|
||||
|
|
||||
LL | C0 => {}
|
||||
| ^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/65413-constants-and-slices-exhaustiveness.rs:2:9
|
||||
|
|
||||
LL | #![deny(unreachable_patterns)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
error[E0004]: non-exhaustive patterns: `&[..]` not covered
|
||||
error[E0004]: non-exhaustive patterns: `&[0u8..=64u8, _, _, _]` and `&[66u8..=std::u8::MAX, _, _, _]` not covered
|
||||
--> $DIR/match-byte-array-patterns-2.rs:4:11
|
||||
|
|
||||
LL | match buf {
|
||||
| ^^^ pattern `&[..]` not covered
|
||||
| ^^^ patterns `&[0u8..=64u8, _, _, _]` and `&[66u8..=std::u8::MAX, _, _, _]` not covered
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `&[..]` not covered
|
||||
error[E0004]: non-exhaustive patterns: `&[]`, `&[_]`, `&[_, _]` and 2 more not covered
|
||||
--> $DIR/match-byte-array-patterns-2.rs:10:11
|
||||
|
|
||||
LL | match buf {
|
||||
| ^^^ pattern `&[..]` not covered
|
||||
| ^^^ patterns `&[]`, `&[_]`, `&[_, _]` and 2 more not covered
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ fn main() {
|
|||
}
|
||||
const CONST1: &[bool; 1] = &[true];
|
||||
match s1 {
|
||||
//~^ ERROR `&[..]` not covered
|
||||
//~^ ERROR `&[false]` not covered
|
||||
CONST1 => {}
|
||||
}
|
||||
match s1 {
|
||||
|
|
|
|||
|
|
@ -118,11 +118,11 @@ LL | match s {
|
|||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `&[..]` not covered
|
||||
error[E0004]: non-exhaustive patterns: `&[false]` not covered
|
||||
--> $DIR/slice-patterns-exhaustiveness.rs:99:11
|
||||
|
|
||||
LL | match s1 {
|
||||
| ^^ pattern `&[..]` not covered
|
||||
| ^^ pattern `&[false]` not covered
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue