Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#![feature(nll, type_ascription)]
#![allow(dead_code, unused_mut)]
type Pair<T> = (T, T);
pub fn swap<T>(_: &mut T, _: &mut T) { unimplemented!() }
fn static_to_a_to_static_through_tyvar<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 {
let local = 3;
let (mut y, mut _z): Pair<&u32> = (s, &local);
// let (mut y, mut _z): Pair<&u32> = (s, &local);
// I should be able to add the call to `swap` below at whim based
// on the above type annotation, which should coerce both `s` and
// `local` to `&'1 u32` (and then `'1` should be inferred to be a
// function-local region).
// Furthermore, since I should be able to add the below call to
// `swap`, it should also be legal for me to include the `unsafe`
// code block given below, which has the same end effect of
// swapping the two values. (And that *definitely* will break the
// return type.)
// swap(&mut y, &mut _z);
unsafe {
let p_y = &mut y as *mut _;
let p_z = &mut _z as *mut _;
let t = *p_y;
*p_y = *p_z;
*p_z = t;
// Likewise, the same rules that caused `y` and `_z` to have the
// same `&'1 u32` type should likewise cause a borrow-check error
// at this attempt to return a `&'static u32`.
fn main() {
static_to_a_to_static_through_tyvar(&3, &4);
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.