Skip to content

Commit ca41681

Browse files
committed
Do not use unsized_fn_params in patterns
1 parent 58018d4 commit ca41681

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

compiler/rustc_typeck/src/check/gather_locals.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
129129
var_ty
130130
);
131131
}
132+
let old_within_fn_param = mem::replace(&mut self.within_fn_param, false);
132133
intravisit::walk_pat(self, p);
134+
self.within_fn_param = old_within_fn_param;
133135
}
134136

135137
// Don't descend into the bodies of nested closures.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(box_patterns)]
2+
#![feature(unsized_fn_params)]
3+
4+
#[allow(dead_code)]
5+
fn f1(box box _b: Box<Box<[u8]>>) {}
6+
//~^ ERROR: the size for values of type `[u8]` cannot be known at compilation time [E0277]
7+
8+
fn f2((_x, _y): (i32, [i32])) {}
9+
//~^ ERROR: the size for values of type `[i32]` cannot be known at compilation time [E0277]
10+
11+
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
2+
--> $DIR/unsized-local-pat.rs:5:15
3+
|
4+
LL | fn f1(box box _b: Box<Box<[u8]>>) {}
5+
| ^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `[u8]`
8+
= note: all local variables must have a statically known size
9+
= help: unsized locals are gated as an unstable feature
10+
11+
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
12+
--> $DIR/unsized-local-pat.rs:8:12
13+
|
14+
LL | fn f2((_x, _y): (i32, [i32])) {}
15+
| ^^ doesn't have a size known at compile-time
16+
|
17+
= help: the trait `Sized` is not implemented for `[i32]`
18+
= note: all local variables must have a statically known size
19+
= help: unsized locals are gated as an unstable feature
20+
21+
error: aborting due to 2 previous errors
22+
23+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/unsized-locals/unsized-parameters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
pub fn f0(_f: dyn FnOnce()) {}
77
pub fn f1(_s: str) {}
8-
pub fn f2((_x, _y): (i32, [i32])) {}
8+
pub fn f2(_x: i32, _y: [i32]) {}
99

1010
fn main() {
1111
let foo = "foo".to_string().into_boxed_str();

0 commit comments

Comments
 (0)