File: generic-not-strictly-equal.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (38 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download | duplicates (3)
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
// `Opaque<'?1> := u8` is not a valid defining use here.
//
// Due to fundamental limitations of the member constraints algorithm,
// we require '?1 to be *equal* to some universal region.
//
// While '?1 is eventually inferred to be equal to 'x because of the constraint '?1: 'x,
// we don't consider them equal in the strict sense because they lack the bidirectional outlives
// constraints ['?1: 'x, 'x: '?1]. In NLL terms, they are not part of the same SCC.
//
// See #113971 for details.

//@ revisions: basic member_constraints
#![feature(type_alias_impl_trait)]

trait Captures<'a> {}
impl<T> Captures<'_> for T {}

fn ensure_outlives<'a, X: 'a>(_: X) {}
fn relate<X>(_: X, _: X) {}

type Opaque<'a> = impl Copy + Captures<'a>;

fn test<'x>(_: Opaque<'x>) {
    let opaque = None::<Opaque<'_>>; // let's call this lifetime '?1

    #[cfg(basic)]
    let hidden = None::<u8>;

    #[cfg(member_constraints)]
    let hidden = None::<&'x u8>;

    ensure_outlives::<'x>(opaque); // outlives constraint: '?1: 'x
    relate(opaque, hidden); // defining use: Opaque<'?1> := u8
    //[basic]~^ ERROR expected generic lifetime parameter, found `'_`
    //[member_constraints]~^^ ERROR captures lifetime that does not appear in bounds
}

fn main() {}