Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Positive coverage: loan_cannot_outlive_universal_regions / loan_not_required_by_universal_regions

loan_not_required_by_universal_regions
LineCoverageSource
1066N/A(let outlived_by_loan = transitively_outlived_by(&env, &outlives, &loan.lt))
1067(if outlived_by_loan.iter().all(|p| match p {
// If `'0: T` then `'0` must hold for entire fn body...
Parameter::Ty(_) => false,

Parameter::Lt(lt) => match lt.as_ref() {
// If `'0: 'static` then `'0` must hold for entire fn body...
Lt::Static => false,

// If `'0: 'a` for some lifetime parameter `'a`, then `'0` must hold for entire fn body...
Lt::Variable(Variable::UniversalVar(_)) => false,

// If `'0: '1`, that's fine.
Lt::Variable(Variable::ExistentialVar(_)) => true,

Lt::Variable(Variable::BoundVar(_)) => panic!("cannot outlive a bound var"),

// Erased lifetimes are used in codegen; treat like existential.
Lt::Erased => true,
},

// Not really clear what this would mean
Parameter::Const(_) => panic!("cannot outlive a constant"),
}))
──────── ("loan_not_required_by_universal_regions")
10919(loan_cannot_outlive_universal_regions(env, _assumptions, outlives, loan) => ())

9 tests exercised this rule:


Source location: tests/borrowck.rs:1968

fn min_problem_case_3<'a>(m: &mut 'a Map) -> &mut 'a Map {
    exists<'r0, 'r1> {
        let n: &mut 'r0 Map = &mut 'r0 *m;
        if true {
            return n;
        } else {
            let o: &mut 'r1 Map = &mut 'r1 *m;
            return o;
        }
    }
}
Proof tree
… (200 of 1324 nodes shown)

Source location: tests/borrowck.rs:2041

fn foo() -> i32 {
    exists<'r0, 'r1> {
        let result: i32;
        {
            let v1: i32 = 22 _ i32;
            let v2: &'r0 i32 = &'r1 v1;
            result = *v2;
        }
        return result;
    }
}
Proof tree
… (200 of 1234 nodes shown)

Source location: tests/borrowck.rs:2156

fn min_problem_case_3<'a>(m: &mut 'a Map) -> &mut 'a Map {
    exists<'r0, 'r1> {
        let n: &mut 'r0 Map = &mut 'r0 *m;
        if true {
        } else {
        }
        let o: &mut 'r1 Map = &mut 'r1 *m;
        return o;
    }
}
Proof tree
… (200 of 1295 nodes shown)

Source location: tests/borrowck.rs:2410

fn foo () -> u32 {
    exists<'l_p, 'l_q, 'loan_0, 'loan_1, 'loan_2, 'loan_3> {
        let a: u32 = 0 _ u32;
        let b: u32 = 0 _ u32;
        // In Rustc, the 1-tuple is needed for some reason
        // Niko does not 100% understand, else rustc is able to
        // see that this program is safe.
        let q: &mut 'l_q u32 = &mut 'loan_0 a;
        let p: &mut 'l_p u32 = &mut 'loan_1 a;
        if true {
            p = &mut 'loan_1 a;
            q = &mut 'loan_2 b;
        } else {
            p = &mut 'loan_3 b;
        }
        *q = 1 _ u32;
        return *p;
    }
}
Proof tree
… (200 of 1495 nodes shown)

Source location: tests/borrowck.rs:2600

fn foo() -> u32 {
    exists<'r0, 'r1> {
        'a: loop {
            let x: i32 = 0 _ i32;
            let r: &'r0 i32 = &'r1 x;
            let _y: i32 = *r;
            continue 'a;
        }
    }
}
Proof tree
… (200 of 1443 nodes shown)

Source location: tests/borrowck.rs:2733

fn foo<'a>(m: &mut 'a Map) -> &mut 'a Map {
    exists<'r0, 'r1> {
        let n: &mut 'r0 Map = &mut 'r0 *m;
        if false {
            return n;
        } else {
            let o: &mut 'r1 Map = &mut 'r1 *m;
            return o;
        }
    }
}
Proof tree
… (200 of 1324 nodes shown)

Source location: tests/borrowck.rs:3120

fn reborrow<'a>(a: &mut 'a u8) -> &mut 'a u8 {
    exists<'r0, 'r1, 'r2, 'r3> {
        // This creates an outlives constraint
        let b: &mut 'r1 u8 = &mut 'r0 *a;
        if true {
            return b;
        } else {
            // this means the loan remains live
        }

        // If the outlives constraint propagated here,
        // we would get an error.
        let c: &mut 'r3 u8 = &mut 'r2 *a;
        return c;
    }
}
Proof tree
… (200 of 1314 nodes shown)

Source location: tests/borrowck.rs:3225

fn foo() -> u32 {
    exists<'r0, 'r1, 'r2> {
        let x: u32 = 22 _ u32;
        let p: &'r1 u32 = &'r0 x;
        let q: &'r2 u32 = p;
        x = 1 _ u32;
        return 0 _ u32;
    }
}
Proof tree
… (200 of 1126 nodes shown)

Source location: tests/well_formed_struct.rs:17

fn main() -> () {
    exists<'y> {
        let a: u32 = 22 _ u32;
        let f: Foo<'y> = Foo::<'y> { y: &'y a };
    }
}
Proof tree
… (200 of 1082 nodes shown)