Skip to content

Instantly share code, notes, and snippets.

@phaylon phaylon/main.rs Secret
Created Aug 14, 2018

Embed
What would you like to do?
Match Ergonomics Issue B: Lifetime semantics change
macro_rules! fn_handler {
() => {
struct Final<'a> {
_ptr_a: *const i32,
_ptr_b: *const i32,
_marker: ::std::marker::PhantomData<&'a ()>,
}
fn handle<'a, 'b>(data: &Data<'a, 'b>) -> Final<'a> {
let (a, b) = get(data);
Final {
_ptr_a: a as *const _,
_ptr_b: b as *const _,
_marker: ::std::marker::PhantomData,
}
}
}
}
mod single {
struct Data<'a, 'b> {
first: &'a (i32, i32),
_second: &'b i32,
}
pub fn run() {
handle(&Data {
first: &(23, 42),
_second: &93,
});
}
fn get<'a, 'b>(data: &Data<'a, 'b>) -> &'a (i32, i32) { data.first }
fn_handler!();
}
mod multiple {
struct Data<'a, 'b> {
first_a: &'a i32,
first_b: &'b i32,
_second: &'b i32,
}
fn get<'a, 'b>(data: &Data<'a, 'b>) -> (&'a i32, &'b i32) { (data.first_a, data.first_b) }
pub fn run() {
handle(&Data {
first_a: &23,
first_b: &42,
_second: &93,
});
}
fn_handler!();
}
fn main() {
single::run();
multiple::run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.