File: equal-lifetime-params-not-ok.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (40 lines) | stat: -rw-r--r-- 1,228 bytes parent folder | download | duplicates (9)
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
// issue: #112841

#![feature(type_alias_impl_trait)]

trait Trait<'a, 'b> {}
impl<T> Trait<'_, '_> for T {}

mod mod1 {
    type Opaque<'a, 'b> = impl super::Trait<'a, 'b>;
    #[define_opaque(Opaque)]
    fn test<'a>() -> Opaque<'a, 'a> {}
    //~^ ERROR non-defining opaque type use in defining scope
}

mod mod2 {
    type Opaque<'a, 'b> = impl super::Trait<'a, 'b>;
    #[define_opaque(Opaque)]
    fn test<'a: 'b, 'b: 'a>() -> Opaque<'a, 'b> {}
    //~^ ERROR non-defining opaque type use in defining scope
}

mod mod3 {
    type Opaque<'a, 'b> = impl super::Trait<'a, 'b>;
    #[define_opaque(Opaque)]
    fn test<'a: 'b, 'b: 'a>(a: &'a str) -> Opaque<'a, 'b> { a }
    //~^ ERROR non-defining opaque type use in defining scope
}

// This is similar to the previous cases in that 'a is equal to 'static,
// which is some sense an implicit parameter to `Opaque`.
// For example, given a defining use `Opaque<'a> := &'a ()`,
// it is ambiguous whether `Opaque<'a> := &'a ()` or `Opaque<'a> := &'static ()`
mod mod4 {
    type Opaque<'a> = impl super::Trait<'a, 'a>;
    #[define_opaque(Opaque)]
    fn test<'a: 'static>() -> Opaque<'a> {}
    //~^ ERROR expected generic lifetime parameter, found `'static`
}

fn main() {}