Open
Description
The cached!
macro doesn't work inside struct's impl
block. (Haven't tried other impl blocks.)
Repro:
#[macro_use]
extern crate cached;
#[macro_use]
extern crate lazy_static;
cached! {
FIB;
fn fib(n: u64) -> u64 = {
if n == 0 || n == 1 { return n }
fib(n-1) + fib(n-2)
}
}
struct Foo {}
impl Foo {
cached! {
ANOTHER_FIB;
fn another_fib(n: u64) -> u64 = {
if n == 0 || n == 1 { return n }
another_fib(n-1) + another_fib(n-2)
}
}
}
fn main() {
println!("fib(10): {}", fib(10));
let _ = Foo {};
println!("another_fib(10): {}", another_fib(10));
}
Error:
error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, or `unsafe`, found `struct`
--> src/main.rs:18:5
|
18 | cached! {
| _____^
| |_____|
| ||
19 | || ANOTHER_FIB;
20 | || fn another_fib(n: u64) -> u64 = {
21 | || if n == 0 || n == 1 { return n }
22 | || another_fib(n-1) + another_fib(n-2)
23 | || }
24 | || }
| || ^
| ||_____|
| |______expected one of 10 possible tokens here
| unexpected token
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to previous error
Metadata
Metadata
Assignees
Labels
No labels