Skip to content

Commit abcd3dc

Browse files
authored
Rollup merge of #73353 - davidtwco:issue-73003-non-structural-match-ty-closures, r=varkor
structural_match: non-structural-match ty closures Fixes #73003. This PR adds a `Closure` variant to `NonStructuralMatchTy` in `structural_match`, fixing an ICE which can occur when `impl_trait_in_bindings` is used with constants.
2 parents 742b1b6 + 79e08bb commit abcd3dc

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/librustc_mir_build/hair/pattern/const_to_pat.rs

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
130130
traits::NonStructuralMatchTy::Generator => {
131131
"generators cannot be used in patterns".to_string()
132132
}
133+
traits::NonStructuralMatchTy::Closure => {
134+
"closures cannot be used in patterns".to_string()
135+
}
133136
traits::NonStructuralMatchTy::Param => {
134137
bug!("use of a constant whose type is a parameter inside a pattern")
135138
}

src/librustc_trait_selection/traits/structural_match.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub enum NonStructuralMatchTy<'tcx> {
1818
Opaque,
1919
Generator,
2020
Projection,
21+
Closure,
2122
}
2223

2324
/// This method traverses the structure of `ty`, trying to find an
@@ -162,6 +163,10 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
162163
self.found = Some(NonStructuralMatchTy::Generator);
163164
return true; // Stop visiting.
164165
}
166+
ty::Closure(..) => {
167+
self.found = Some(NonStructuralMatchTy::Closure);
168+
return true; // Stop visiting.
169+
}
165170
ty::RawPtr(..) => {
166171
// structural-match ignores substructure of
167172
// `*const _`/`*mut _`, so skip `super_visit_with`.
@@ -211,7 +216,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
211216
ty.super_visit_with(self);
212217
return false;
213218
}
214-
ty::Closure(..) | ty::Infer(_) | ty::Placeholder(_) | ty::Bound(..) => {
219+
ty::Infer(_) | ty::Placeholder(_) | ty::Bound(..) => {
215220
bug!("unexpected type during structural-match checking: {:?}", ty);
216221
}
217222
ty::Error => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
3+
#![feature(impl_trait_in_bindings)]
4+
//~^ WARN the feature `impl_trait_in_bindings` is incomplete
5+
6+
const _: impl Fn() = ||();
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/impl-trait-in-bindings-issue-73003.rs:3:12
3+
|
4+
LL | #![feature(impl_trait_in_bindings)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)