Skip to content

Commit

Permalink
Do not use unsized_fn_params in patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Oct 27, 2020
1 parent 58018d4 commit ca41681
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compiler/rustc_typeck/src/check/gather_locals.rs
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions 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() {}
23 changes: 23 additions & 0 deletions 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`.
2 changes: 1 addition & 1 deletion src/test/ui/unsized-locals/unsized-parameters.rs
Expand Up @@ -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();
Expand Down

0 comments on commit ca41681

Please sign in to comment.