Skip to content

Commit b3a3fc2

Browse files
celinvaltedinski
authored andcommitted
Add fixme tests that reproduce issues rust-lang#555, rust-lang#556, and rust-lang#560 (rust-lang#952)
Add tests for a few open issues.
1 parent 4166069 commit b3a3fc2

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! This test is a modified version of cast_abstract_args_to_concrete_fixme.rs.
5+
//! The original test requires --no-undefined-function-checks to pass. This is an issue that
6+
//! require investigation. See https://github.com/model-checking/kani/issues/555.
7+
//!
8+
//! Once this issue is fixed. Please remove this test and remove the kani flag from the original
9+
//! test: --no-undefined-function-check
10+
11+
fn main() {
12+
let _x32 = 1.0f32.powi(2);
13+
let _x64 = 1.0f64.powi(2);
14+
15+
unsafe {
16+
let size: libc::size_t = mem::size_of::<i32>();
17+
let my_num: *mut libc::c_void = libc::malloc(size);
18+
if my_num.is_null() {
19+
panic!("failed to allocate memory");
20+
}
21+
let my_num2 = libc::memset(my_num, 1, size);
22+
libc::free(my_num);
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// compile-flags: --edition 2018
5+
// kani-flags: --unwind 4
6+
//
7+
// This reproduces the issue seen in "Failures when iterating over results".
8+
// See https://github.com/model-checking/kani/issues/556 for more information.
9+
#[kani::proof]
10+
pub fn main() {
11+
let numbers = vec![1, 10, -1];
12+
let positives: Vec<_> = numbers.into_iter().filter(|&n| n > 0).collect();
13+
assert_eq!(positives.len(), 2);
14+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// compile-flags: --edition 2018
5+
// kani-flags: --unwind 4
6+
//
7+
// Testcase based on https://doc.rust-lang.org/rust-by-example/generics/phantom/testcase_units.html
8+
// which reproduces issue https://github.com/model-checking/kani/issues/560
9+
10+
use std::marker::PhantomData;
11+
use std::ops::Add;
12+
13+
#[derive(Debug, Clone, Copy)]
14+
enum Mm {}
15+
16+
/// `Length` is a type with phantom type parameter `Unit`,
17+
/// and is not generic over the length type (that is `u32`).
18+
///
19+
/// `u32` already implements the `Clone` and `Copy` traits.
20+
#[derive(Debug, Clone, Copy)]
21+
struct Length<Unit>(u32, PhantomData<Unit>);
22+
23+
/// The `Add` trait defines the behavior of the `+` operator.
24+
impl<Unit> Add for Length<Unit> {
25+
type Output = Length<Unit>;
26+
27+
// add() returns a new `Length` struct containing the sum.
28+
fn add(self, rhs: Length<Unit>) -> Length<Unit> {
29+
// `+` calls the `Add` implementation for `u32`.
30+
Length(self.0 + rhs.0, PhantomData)
31+
}
32+
}
33+
34+
fn main() {
35+
// `one_meter` has phantom type parameter `Mm`.
36+
let one_meter: Length<Mm> = Length(1000, PhantomData);
37+
38+
// `+` calls the `add()` method we implemented for `Length<Unit>`.
39+
//
40+
// Since `Length` implements `Copy`, `add()` does not consume
41+
// `one_foot` and `one_meter` but copies them into `self` and `rhs`.
42+
let two_meters = one_meter + one_meter;
43+
44+
assert!(two_meters.0 == 2000);
45+
}

0 commit comments

Comments
 (0)