A Rust Compiler Error I Don't Understand
Scratching My Head
The folks behind the Rust compiler consider it a bug if you hit an error message that doesn't give you enough info to fix it. I just hit one that stumped me.
I'm not exactly sure where to open the ticket. Writing it up here so I can figure that out later.
Here's the error:
Compiling neopolitan v0.2.0 (/Users/alan/workshop/neopolitan) error: lifetime may not live long enough --> src/page/mod.rs:11:5 | 8 | #[derive(Clone, Debug, Deserialize, Serialize)] | ----------- lifetime `'de` defined here 9 | pub struct Page<'a> { | -- lifetime `'a` defined here 10 | pub source_path: PathBuf, 11 | pub data: Ast<'a>, | ^^^^^^^^^^^^^^^^^ requires that `'de` must outlive `'a` | = help: consider adding the following bound: `'de: 'a` error: could not compile `neopolitan` (lib) due to 2 previous errors warning: build failed, waiting for other jobs to finish... error: could not compile `neopolitan` (lib test) due to 2 previous errors [Command exited with 101]
The problem file is:
which is being used from:
The Ast file is:
I haven't done anything with it yet. I just created it and immediately ran into the problem.
I don't have the spoons right now to try to extract the error more. Hopefully the issue can be found from the small page file.
What I Tried
The help suggestion says:
consider adding the following bound: `'de: 'a`
But, I'm not sure how to go about that.
This is the original code that's throwing the error:
Based on the error message, I tried:
Those all threw their own error messages. I wasn't able to figure out how to fix it from them either.
Next Steps
I haven't dug much further yet. Wanted to get this down first as a submission about the compiler.
I'll update this when I learn more.
-a
Postscript
Okay, I jumped around the issue for now by updating the Ast to use a String
instead of a &str
. That got me going, but I'm still going to open the ticket since the confusion was about the compiler message itself and I took a different path that what it suggested.