What is lifetime elision in very simple terms?

An item signature is the bit which gives the name and types of your function, i.e. everything you need to call it (without needing to know how it’s implemented); for example: fn foo(x: u32) -> u32; Here’s another which takes a &str reference: fn bar<‘a>(s: &’a str) -> &’a str; In Rust, all references have … Read more

Cannot infer an appropriate lifetime for autoref due to conflicting requirements

Here’s a smaller example that reproduces the problem: struct FontLoader(String); struct Font<‘a>(&’a str); impl FontLoader { fn load(&self) -> Font { Font(&self.0) } } struct Window; struct Phi<‘window> { window: &’window Window, loader: FontLoader, font: Option<Font<‘window>>, } impl<‘window> Phi<‘window> { fn do_the_thing(&mut self) { let font = self.loader.load(); self.font = Some(font); } } fn main() … Read more

“constructing” a trivially-copyable object with memcpy

This is unspecified which is supported by N3751: Object Lifetime, Low-level Programming, and memcpy which says amongst other things: The C++ standards is currently silent on whether the use of memcpy to copy object representation bytes is conceptually an assignment or an object construction. The difference does matter for semantics-based program analysis and transformation tools, … Read more