Skip to content

Commit

Permalink
Currently failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
avanhatt committed Jul 23, 2021
1 parent 009e9db commit 952cc20
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/test/cbmc/DynTrait/nested_boxed_closure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

// Check that we can codegen various nesting structures of boxes and
// pointer to closures.

fn main() {
// Create a nested boxed once-callable closure
let f: Box<Box<dyn FnOnce(i32)>> = Box::new(Box::new(|x| assert!(x == 1)));
f(1);

// Create a pointer to a closure
let g = |y| assert!(y == 2);
let p: &dyn Fn(i32) = &g;
p(2);

// Additional level of pointer nesting
let q: &dyn Fn(i32) = &p;
q(2);

// Create a boxed pointer to a closure
let r: Box<&dyn Fn(i32)> = Box::new(&g);
r(2);

// Another boxed box
let s: Box<Box<dyn Fn(i32)>> = Box::new(Box::new(|x| assert!(x == 3)));
s(3);

// A pointer to the boxed box
let t: &Box<Box<dyn Fn(i32)>> = &s;
t(3);
}

0 comments on commit 952cc20

Please sign in to comment.