File: bound-lifetime-constrained.rs

package info (click to toggle)
rustc-web 1.85.0%2Bdfsg3-1~deb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,759,988 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,056; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (48 lines) | stat: -rw-r--r-- 1,128 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
46
47
48
//@ revisions: func object clause ok

#![allow(dead_code)]
#![feature(rustc_attrs)]

trait Foo<'a> {
    type Item;
}

impl<'a> Foo<'a> for() {
    type Item = ();
}

// Check that appearing in a projection input in the argument is not enough:
#[cfg(func)]
fn func1(_: for<'a> fn(<() as Foo<'a>>::Item) -> &'a i32) {
    //[func]~^ ERROR E0581
}

// Check that appearing in a projection input in the return still
// causes an error:
#[cfg(func)]
fn func2(_: for<'a> fn() -> <() as Foo<'a>>::Item) {
    //[func]~^ ERROR E0581
}

#[cfg(object)]
fn object1(_: Box<dyn for<'a> Fn(<() as Foo<'a>>::Item) -> &'a i32>) {
    //[object]~^ ERROR E0582
}

#[cfg(object)]
fn object2(_: Box<dyn for<'a> Fn() -> <() as Foo<'a>>::Item>) {
    //[object]~^ ERROR E0582
}

#[cfg(clause)]
fn clause1<T>() where T: for<'a> Fn(<() as Foo<'a>>::Item) -> &'a i32 {
    //[clause]~^ ERROR `Output` references lifetime `'a`
}

#[cfg(clause)]
fn clause2<T>() where T: for<'a> Fn() -> <() as Foo<'a>>::Item {
    //[clause]~^ ERROR `Output` references lifetime `'a`
}

#[rustc_error]
fn main() { } //[ok]~ ERROR fatal error triggered by #[rustc_error]