Open
Description
I tried this code:
struct Foo;
impl Foo {
const ALL_METHODS: &[(&str, fn(&Self) -> usize)] = &[("foo", Self::foo)];
fn foo(&self) -> usize {
123
}
}
I expected to see this happen: successful compile
Instead, this happened:
error[[E0491]](https://doc.rust-lang.org/stable/error_codes/E0491.html): in type `&[(&str, for<'a> fn(&'a Foo) -> usize)]`, reference has a longer lifetime than the data it references
--> src/lib.rs:5:5
|
5 | const ALL_METHODS: &[(&str, fn(&Self) -> usize)] = &[("foo", Self::foo)];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the pointer is valid for the anonymous lifetime as defined here
--> src/lib.rs:5:24
|
5 | const ALL_METHODS: &[(&str, fn(&Self) -> usize)] = &[("foo", Self::foo)];
| ^
note: but the referenced data is only valid for the anonymous lifetime as defined here
--> src/lib.rs:5:24
|
5 | const ALL_METHODS: &[(&str, fn(&Self) -> usize)] = &[("foo", Self::foo)];
|
Adding some 'static
s fixes it, but I think these are supposed to be unnecessary now:
const ALL_METHODS: &'static [(&'static str, fn(&Self) -> usize)] = &[("foo", Self::foo)]