mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
structural_match: non-structural-match ty closures
This commit adds a `Closure` variant to `NonStructuralMatchTy` in `structural_match`, fixing an ICE which can occur when `impl_trait_in_bindings` is used with constants. Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
4fb54ed484
commit
79e08bbc99
@ -130,6 +130,9 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
||||
traits::NonStructuralMatchTy::Generator => {
|
||||
"generators cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Closure => {
|
||||
"closures cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Param => {
|
||||
bug!("use of a constant whose type is a parameter inside a pattern")
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ pub enum NonStructuralMatchTy<'tcx> {
|
||||
Opaque,
|
||||
Generator,
|
||||
Projection,
|
||||
Closure,
|
||||
}
|
||||
|
||||
/// This method traverses the structure of `ty`, trying to find an
|
||||
@ -162,6 +163,10 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
|
||||
self.found = Some(NonStructuralMatchTy::Generator);
|
||||
return true; // Stop visiting.
|
||||
}
|
||||
ty::Closure(..) => {
|
||||
self.found = Some(NonStructuralMatchTy::Closure);
|
||||
return true; // Stop visiting.
|
||||
}
|
||||
ty::RawPtr(..) => {
|
||||
// structural-match ignores substructure of
|
||||
// `*const _`/`*mut _`, so skip `super_visit_with`.
|
||||
@ -211,7 +216,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
|
||||
ty.super_visit_with(self);
|
||||
return false;
|
||||
}
|
||||
ty::Closure(..) | ty::Infer(_) | ty::Placeholder(_) | ty::Bound(..) => {
|
||||
ty::Infer(_) | ty::Placeholder(_) | ty::Bound(..) => {
|
||||
bug!("unexpected type during structural-match checking: {:?}", ty);
|
||||
}
|
||||
ty::Error => {
|
||||
|
8
src/test/ui/impl-trait-in-bindings-issue-73003.rs
Normal file
8
src/test/ui/impl-trait-in-bindings-issue-73003.rs
Normal file
@ -0,0 +1,8 @@
|
||||
// check-pass
|
||||
|
||||
#![feature(impl_trait_in_bindings)]
|
||||
//~^ WARN the feature `impl_trait_in_bindings` is incomplete
|
||||
|
||||
const _: impl Fn() = ||();
|
||||
|
||||
fn main() {}
|
11
src/test/ui/impl-trait-in-bindings-issue-73003.stderr
Normal file
11
src/test/ui/impl-trait-in-bindings-issue-73003.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/impl-trait-in-bindings-issue-73003.rs:3:12
|
||||
|
|
||||
LL | #![feature(impl_trait_in_bindings)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
Loading…
Reference in New Issue
Block a user