2022-06-04 11:34:07 +00:00
|
|
|
fn fn_pointer_static() -> usize {
|
|
|
|
static FN: fn() -> usize = || 1;
|
|
|
|
let res = FN() + 1;
|
|
|
|
res
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: returning the result of a `let` binding from a block
|
|
|
|
//~| NOTE: `-D clippy::let-and-return` implied by `-D warnings`
|
2022-06-04 11:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn fn_pointer_const() -> usize {
|
|
|
|
const FN: fn() -> usize = || 1;
|
|
|
|
let res = FN() + 1;
|
|
|
|
res
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: returning the result of a `let` binding from a block
|
2022-06-04 11:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn deref_to_dyn_fn() -> usize {
|
|
|
|
struct Derefs;
|
|
|
|
impl std::ops::Deref for Derefs {
|
|
|
|
type Target = dyn Fn() -> usize;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&|| 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static FN: Derefs = Derefs;
|
|
|
|
let res = FN() + 1;
|
|
|
|
res
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: returning the result of a `let` binding from a block
|
2022-06-04 11:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|