Skip to content
Closed
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
14 changes: 12 additions & 2 deletions crates/flux-middle/src/global_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,22 @@ impl<'genv, 'tcx> GlobalEnv<'genv, 'tcx> {
== def_id
}

/// Returns whether `def_id` is the `call` method in the `Fn` trait.
/// Returns whether `def_id` is the `call` method in the `Fn` trait,
/// the `call_mut` method in the `FnMut` trait,
/// or the `call_once` method in the `FnOnce` trait.
pub fn is_fn_call(&self, def_id: DefId) -> bool {
let methods_and_names = [
(LangItem::Fn, sym::call),
(LangItem::FnMut, sym::call_mut),
(LangItem::FnOnce, sym::call_once),
];
let tcx = self.tcx();
let Some(assoc_item) = tcx.opt_associated_item(def_id) else { return false };
let Some(trait_id) = assoc_item.trait_container(tcx) else { return false };
assoc_item.name() == sym::call && tcx.is_lang_item(trait_id, LangItem::Fn)

methods_and_names.iter().any(|(lang_item, method_name)| {
assoc_item.name() == *method_name && tcx.is_lang_item(trait_id, *lang_item)
})
}

/// Iterator over all local def ids that are not a extern spec
Expand Down
17 changes: 17 additions & 0 deletions tests/tests/pos/surface/no_panic06.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#[flux::sig(fn(f: F) -> i32)]
#[flux::no_panic_if(F::no_panic())]
fn foo<F: Fn(i32) -> i32>(f: F) -> i32 {
f(3)
}

#[flux::sig(fn(f: F) -> i32)]
#[flux::no_panic_if(F::no_panic())]
fn foo2<F: FnOnce(i32) -> i32>(f: F) -> i32 {
f(3)
}

#[flux::sig(fn(f: F) -> i32)]
#[flux::no_panic_if(F::no_panic())]
fn foo3<F: FnMut(i32) -> i32>(mut f: F) -> i32 {
f(3)
}
Loading