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
2 changes: 1 addition & 1 deletion crates/flux-bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct FluxMetadata {
/// relative to the location of the manifest file.
pub include: Option<Vec<String>>,
/// If present, every function in the module is implicitly labeled with a `no_panic` by default.
/// This means that the only way a function can panic is (1) if it panics, or (2) it calls an external function without this attribute.
/// This means that the only way a function can panic is if it calls an external function without this attribute.
pub no_panic: Option<bool>,
}

Expand Down
3 changes: 3 additions & 0 deletions lib/flux-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ mod clone;
#[cfg(flux)]
mod slice;

#[cfg(flux)]
mod num;

// -------------------------------------------------------------------

#[macro_export]
Expand Down
7 changes: 7 additions & 0 deletions lib/flux-core/src/num/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use flux_attrs::*;

#[extern_spec(core::num)]
impl usize {
#[no_panic]
fn saturating_sub(self, other: usize) -> usize;
}
1 change: 1 addition & 0 deletions lib/flux-core/src/slice/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl<T, I: SliceIndex<[T]>> ops::Index<I> for [T] {
}
)]

#[no_panic]
#[sig(fn(&Self[@len], {I[@idx] | <Self as ops::Index<I>>::in_bounds(len, idx)}) -> &I::Output)]
fn index(&self, index: I) -> &I::Output;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/flux-core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use flux_attrs::*;

#[extern_spec(core::slice)]
impl<T> [T] {
#[no_panic]
#[sig(fn(&Self[@n]) -> usize[n])]
fn len(&self) -> usize;

Expand All @@ -16,6 +17,10 @@ impl<T> [T] {

#[sig(fn(&Self[@n]) -> Iter<T>[0, n])]
fn iter(&self) -> Iter<'_, T>;

#[no_panic]
#[sig(fn(&Self[@n], mid: usize{mid <= n}) -> (&[T][mid], &[T][n - mid]))]
fn split_at(&self, mid: usize) -> (&[T], &[T]);
}

#[cfg(flux_sysroot_test)]
Expand Down
22 changes: 22 additions & 0 deletions tests/tests/pos/surface/no_panic04.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
trait MyTrait {
fn f1(&self) -> usize;
fn f2(&self) -> usize;
}

struct MyImpl {}

impl MyTrait for MyImpl {
#[flux_rs::no_panic]
fn f1(&self) -> usize {
self.f2()
}
#[flux_rs::no_panic]
fn f2(&self) -> usize {
2
}
}

#[flux_rs::no_panic]
fn test00(x: &MyImpl) -> usize {
x.f1() + x.f2()
}