File: capture-parent-arg.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 (35 lines) | stat: -rw-r--r-- 1,037 bytes parent folder | download | duplicates (4)
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
trait Tr {
    type Assoc;
}

struct W<'a>(&'a ());

impl Tr for W<'_> {
    type Assoc = ();
}

// The normal way of capturing `'a`...
impl<'a> W<'a> {
    fn good1() -> impl Into<<W<'a> as Tr>::Assoc> + use<'a> {}
}

// This ensures that we don't error when we capture the *parent* copy of `'a`,
// since the opaque captures that rather than the duplicated `'a` lifetime
// synthesized from mentioning `'a` directly in the bounds.
impl<'a> W<'a> {
    fn good2() -> impl Into<<Self as Tr>::Assoc> + use<'a> {}
}

// The normal way of capturing `'a`... but not mentioned in the bounds.
impl<'a> W<'a> {
    fn bad1() -> impl Into<<W<'a> as Tr>::Assoc> + use<> {}
    //~^ ERROR `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
}

// But also make sure that we error here...
impl<'a> W<'a> {
    fn bad2() -> impl Into<<Self as Tr>::Assoc> + use<> {}
    //~^ ERROR `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
}

fn main() {}