about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2020-10-20 13:30:47 -0300
committerSantiago Pastorino <spastorino@gmail.com>2020-10-27 14:45:38 -0300
commitca41681bf0d5175dd39a91e97aca28b007241a29 (patch)
treee29710e2a03892d07237e16b669e9c897afb855c
parent58018d438b3e14624bf33a9c0d2031e906797b8d (diff)
downloadrust-ca41681bf0d5175dd39a91e97aca28b007241a29.tar.gz
rust-ca41681bf0d5175dd39a91e97aca28b007241a29.zip
Do not use unsized_fn_params in patterns
-rw-r--r--compiler/rustc_typeck/src/check/gather_locals.rs2
-rw-r--r--src/test/ui/unsized-locals/unsized-local-pat.rs11
-rw-r--r--src/test/ui/unsized-locals/unsized-local-pat.stderr23
-rw-r--r--src/test/ui/unsized-locals/unsized-parameters.rs2
4 files changed, 37 insertions, 1 deletions
diff --git a/compiler/rustc_typeck/src/check/gather_locals.rs b/compiler/rustc_typeck/src/check/gather_locals.rs
index 8699de4ce14..b2e5e3fe604 100644
--- a/compiler/rustc_typeck/src/check/gather_locals.rs
+++ b/compiler/rustc_typeck/src/check/gather_locals.rs
@@ -129,7 +129,9 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
                 var_ty
             );
         }
+        let old_within_fn_param = mem::replace(&mut self.within_fn_param, false);
         intravisit::walk_pat(self, p);
+        self.within_fn_param = old_within_fn_param;
     }
 
     // Don't descend into the bodies of nested closures.
diff --git a/src/test/ui/unsized-locals/unsized-local-pat.rs b/src/test/ui/unsized-locals/unsized-local-pat.rs
new file mode 100644
index 00000000000..0b9b4ea5959
--- /dev/null
+++ b/src/test/ui/unsized-locals/unsized-local-pat.rs
@@ -0,0 +1,11 @@
+#![feature(box_patterns)]
+#![feature(unsized_fn_params)]
+
+#[allow(dead_code)]
+fn f1(box box _b: Box<Box<[u8]>>) {}
+//~^ ERROR: the size for values of type `[u8]` cannot be known at compilation time [E0277]
+
+fn f2((_x, _y): (i32, [i32])) {}
+//~^ ERROR: the size for values of type `[i32]` cannot be known at compilation time [E0277]
+
+fn main() {}
diff --git a/src/test/ui/unsized-locals/unsized-local-pat.stderr b/src/test/ui/unsized-locals/unsized-local-pat.stderr
new file mode 100644
index 00000000000..ecb108d453d
--- /dev/null
+++ b/src/test/ui/unsized-locals/unsized-local-pat.stderr
@@ -0,0 +1,23 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+  --> $DIR/unsized-local-pat.rs:5:15
+   |
+LL | fn f1(box box _b: Box<Box<[u8]>>) {}
+   |               ^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `Sized` is not implemented for `[u8]`
+   = note: all local variables must have a statically known size
+   = help: unsized locals are gated as an unstable feature
+
+error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
+  --> $DIR/unsized-local-pat.rs:8:12
+   |
+LL | fn f2((_x, _y): (i32, [i32])) {}
+   |            ^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `Sized` is not implemented for `[i32]`
+   = note: all local variables must have a statically known size
+   = help: unsized locals are gated as an unstable feature
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/unsized-locals/unsized-parameters.rs b/src/test/ui/unsized-locals/unsized-parameters.rs
index 2d31b9e4046..a1b772a7eb6 100644
--- a/src/test/ui/unsized-locals/unsized-parameters.rs
+++ b/src/test/ui/unsized-locals/unsized-parameters.rs
@@ -5,7 +5,7 @@
 
 pub fn f0(_f: dyn FnOnce()) {}
 pub fn f1(_s: str) {}
-pub fn f2((_x, _y): (i32, [i32])) {}
+pub fn f2(_x: i32, _y: [i32]) {}
 
 fn main() {
     let foo = "foo".to_string().into_boxed_str();