]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #73353 - davidtwco:issue-73003-non-structural-match-ty-closures,...
authorRalf Jung <post@ralfj.de>
Mon, 15 Jun 2020 07:57:37 +0000 (09:57 +0200)
committerGitHub <noreply@github.com>
Mon, 15 Jun 2020 07:57:37 +0000 (09:57 +0200)
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.

src/librustc_mir_build/hair/pattern/const_to_pat.rs
src/librustc_trait_selection/traits/structural_match.rs
src/test/ui/impl-trait-in-bindings-issue-73003.rs [new file with mode: 0644]
src/test/ui/impl-trait-in-bindings-issue-73003.stderr [new file with mode: 0644]

index 46b687d76e50431e89e1c1c33f43e10bfd769ebc..087c2c064cfaf3c57f4de92a1911f85905ff2b4b 100644 (file)
@@ -130,6 +130,9 @@ fn to_pat(
                     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")
                     }
index e59fbd313c8bc0160c25ca022a4de4a02f036df7..c4deb639140ca3119191d60e7376e4526f70395c 100644 (file)
@@ -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 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
                 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 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
                 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 => {
diff --git a/src/test/ui/impl-trait-in-bindings-issue-73003.rs b/src/test/ui/impl-trait-in-bindings-issue-73003.rs
new file mode 100644 (file)
index 0000000..fd8fe5f
--- /dev/null
@@ -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() {}
diff --git a/src/test/ui/impl-trait-in-bindings-issue-73003.stderr b/src/test/ui/impl-trait-in-bindings-issue-73003.stderr
new file mode 100644 (file)
index 0000000..715671c
--- /dev/null
@@ -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
+