Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,33 @@ fn _extern_spec_vec_is_empty<T>(vec: &Vec<T>) -> bool where T: thrust_models::Mo
fn _extern_spec_vec_truncate<T>(vec: &mut Vec<T>, len: usize) where T: thrust_models::Model, T::Ty: PartialEq {
Vec::truncate(vec, len)
}

// TODO: The following specs of some trait methods are too restrictive; we should allow for a
// per-impl spec once we can describe the spec of blanket impls.

#[thrust::extern_spec_fn]
#[thrust_macros::requires(true)]
#[thrust_macros::ensures(result == (*x == *y))]
fn _extern_spec_partialeq_eq<T>(x: &T, y: &T) -> bool
where T: thrust_models::Model + PartialEq, T::Ty: PartialEq
{
PartialEq::eq(x, y)
}
Comment thread
coord-e marked this conversation as resolved.

#[thrust::extern_spec_fn]
#[thrust_macros::requires(true)]
#[thrust_macros::ensures(result == (*x < *y))]
fn _extern_spec_partialord_lt<T>(x: &T, y: &T) -> bool
where T: thrust_models::Model + PartialOrd, T::Ty: PartialOrd
{
PartialOrd::lt(x, y)
}

#[thrust::extern_spec_fn]
#[thrust_macros::requires(true)]
#[thrust_macros::ensures(result == (*x > *y))]
fn _extern_spec_partialord_gt<T>(x: &T, y: &T) -> bool
where T: thrust_models::Model + PartialOrd, T::Ty: PartialOrd
{
PartialOrd::gt(x, y)
}
9 changes: 9 additions & 0 deletions tests/ui/fail/fn_poly_ref_ord.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@error-in-other-file: Unsat

fn lt<T>(x: &T, y: &T) -> bool where T: Ord {
x < y
}

fn main() {
assert!(lt(&1, &0));
}
9 changes: 9 additions & 0 deletions tests/ui/pass/fn_poly_ref_ord.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@check-pass

fn lt<T>(x: &T, y: &T) -> bool where T: Ord {
x < y
}

fn main() {
assert!(lt(&1, &2));
}