File: implied-region-constraints.rs

package info (click to toggle)
rustc-web 1.70.0%2Bdfsg1-7~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,517,036 kB
  • sloc: xml: 147,962; javascript: 10,210; sh: 8,590; python: 8,220; ansic: 5,901; cpp: 4,635; makefile: 4,006; asm: 2,856
file content (45 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#![feature(associated_type_bounds)]

trait Tr1 { type As1; }
trait Tr2 { type As2; }

struct St<'a, 'b, T: Tr1<As1: Tr2>> { // `T: 'b` is *not* implied!
    f0: &'a T, // `T: 'a` is implied.
    f1: &'b <T::As1 as Tr2>::As2, // `<T::As1 as Tr2>::As2: 'a` is implied.
}

fn _bad_st<'a, 'b, T>(x: St<'a, 'b, T>)
where
    T: Tr1,
    T::As1: Tr2,
{
    // This should fail because `T: 'b` is not implied from `WF(St<'a, 'b, T>)`.
    let _failure_proves_not_implied_outlives_region_b: &'b T = &x.f0;
    //~^ ERROR lifetime may not live long enough
}

enum En7<'a, 'b, T> // `<T::As1 as Tr2>::As2: 'a` is implied.
where
    T: Tr1,
    T::As1: Tr2,
{
    V0(&'a T),
    V1(&'b <T::As1 as Tr2>::As2),
}

fn _bad_en7<'a, 'b, T>(x: En7<'a, 'b, T>)
where
    T: Tr1,
    T::As1: Tr2,
{
    match x {
        En7::V0(x) => {
            // Also fails for the same reason as above:
            let _failure_proves_not_implied_outlives_region_b: &'b T = &x;
            //~^ ERROR lifetime may not live long enough
        },
        En7::V1(_) => {},
    }
}

fn main() {}