mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Rollup merge of #90028 - tmiasko:structural-match-closure, r=spastorino
Reject closures in patterns Fixes #90013.
This commit is contained in:
commit
9ed9025ea9
@ -130,6 +130,9 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
||||
traits::NonStructuralMatchTy::Opaque => {
|
||||
"opaque types cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Closure => {
|
||||
"closures cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Generator => {
|
||||
"generators cannot be used in patterns".to_string()
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ pub enum NonStructuralMatchTy<'tcx> {
|
||||
Dynamic,
|
||||
Foreign,
|
||||
Opaque,
|
||||
Closure,
|
||||
Generator,
|
||||
Projection,
|
||||
}
|
||||
@ -154,6 +155,9 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
|
||||
ty::Projection(..) => {
|
||||
return ControlFlow::Break(NonStructuralMatchTy::Projection);
|
||||
}
|
||||
ty::Closure(..) => {
|
||||
return ControlFlow::Break(NonStructuralMatchTy::Closure);
|
||||
}
|
||||
ty::Generator(..) | ty::GeneratorWitness(..) => {
|
||||
return ControlFlow::Break(NonStructuralMatchTy::Generator);
|
||||
}
|
||||
@ -197,7 +201,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
|
||||
// First check all contained types and then tell the caller to continue searching.
|
||||
return ty.super_visit_with(self);
|
||||
}
|
||||
ty::Closure(..) | ty::Infer(_) | ty::Placeholder(_) | ty::Bound(..) => {
|
||||
ty::Infer(_) | ty::Placeholder(_) | ty::Bound(..) => {
|
||||
bug!("unexpected type during structural-match checking: {:?}", ty);
|
||||
}
|
||||
ty::Error(_) => {
|
||||
|
@ -0,0 +1,8 @@
|
||||
// Regression test for issue 90013.
|
||||
// check-pass
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(inline_const)]
|
||||
|
||||
fn main() {
|
||||
const { || {} };
|
||||
}
|
14
src/test/ui/pattern/non-structural-match-types.rs
Normal file
14
src/test/ui/pattern/non-structural-match-types.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// edition:2021
|
||||
#![allow(incomplete_features)]
|
||||
#![allow(unreachable_code)]
|
||||
#![feature(const_async_blocks)]
|
||||
#![feature(inline_const)]
|
||||
|
||||
fn main() {
|
||||
match loop {} {
|
||||
const { || {} } => {}, //~ ERROR cannot be used in patterns
|
||||
}
|
||||
match loop {} {
|
||||
const { async {} } => {}, //~ ERROR cannot be used in patterns
|
||||
}
|
||||
}
|
14
src/test/ui/pattern/non-structural-match-types.stderr
Normal file
14
src/test/ui/pattern/non-structural-match-types.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: `[closure@$DIR/non-structural-match-types.rs:9:17: 9:22]` cannot be used in patterns
|
||||
--> $DIR/non-structural-match-types.rs:9:9
|
||||
|
|
||||
LL | const { || {} } => {},
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: `impl Future` cannot be used in patterns
|
||||
--> $DIR/non-structural-match-types.rs:12:9
|
||||
|
|
||||
LL | const { async {} } => {},
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user