mirror of https://github.com/rust-lang/rust.git
Fix irrefutable slice patterns in const fn
This commit is contained in:
parent
aef6288d9a
commit
80262e6040
|
@ -470,6 +470,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
ProjectionElem::ConstantIndex {..} |
|
||||
ProjectionElem::Subslice {..} |
|
||||
ProjectionElem::Field(..) |
|
||||
ProjectionElem::Index(_) => {
|
||||
let base_ty = proj.base.ty(this.mir, this.tcx).to_ty(this.tcx);
|
||||
|
@ -499,8 +501,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
|
|||
this.qualif.restrict(ty, this.tcx, this.param_env);
|
||||
}
|
||||
|
||||
ProjectionElem::ConstantIndex {..} |
|
||||
ProjectionElem::Subslice {..} |
|
||||
ProjectionElem::Downcast(..) => {
|
||||
this.not_const()
|
||||
}
|
||||
|
|
|
@ -264,13 +264,10 @@ fn check_place(
|
|||
Place::Static(_) => Err((span, "cannot access `static` items in const fn".into())),
|
||||
Place::Projection(proj) => {
|
||||
match proj.elem {
|
||||
| ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. }
|
||||
| ProjectionElem::Deref | ProjectionElem::Field(..) | ProjectionElem::Index(_) => {
|
||||
check_place(tcx, mir, &proj.base, span)
|
||||
}
|
||||
// slice patterns are unstable
|
||||
| ProjectionElem::ConstantIndex { .. } | ProjectionElem::Subslice { .. } => {
|
||||
return Err((span, "slice patterns in const fn are unstable".into()))
|
||||
}
|
||||
| ProjectionElem::Downcast(..) => {
|
||||
Err((span, "`match` or `if let` in `const fn` is unstable".into()))
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
// compile-pass
|
||||
|
||||
fn main() {}
|
||||
|
||||
const fn tup((a, b): (i32, i32)) -> i32 {
|
||||
a + b
|
||||
}
|
||||
|
||||
const fn array([a, b]: [i32; 2]) -> i32 {
|
||||
a + b
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
fn main() {}
|
||||
|
||||
const fn slice([a, b]: &[i32]) -> i32 { //~ ERROR refutable pattern in function argument
|
||||
a + b
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
error[E0005]: refutable pattern in function argument: `&[]` not covered
|
||||
--> $DIR/const_let_refutable.rs:3:16
|
||||
|
|
||||
LL | const fn slice([a, b]: &[i32]) -> i32 { //~ ERROR refutable pattern in function argument
|
||||
| ^^^^^^ pattern `&[]` not covered
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0005`.
|
Loading…
Reference in New Issue