]> git.lizzy.rs Git - rust.git/blob - tests/ui/implied-bounds/hrlt-implied-trait-bounds-roundtrip.rs
Rollup merge of #107819 - clubby789:x-py-root, r=jyn514
[rust.git] / tests / ui / implied-bounds / hrlt-implied-trait-bounds-roundtrip.rs
1 // check-pass
2 struct Foo<'a>(&'a ())
3 where
4     (): Trait<'a>;
5
6 trait Trait<'a> {
7     fn id<T>(value: &'a T) -> &'static T;
8 }
9
10 impl Trait<'static> for () {
11     fn id<T>(value: &'static T) -> &'static T {
12         value
13     }
14 }
15
16 fn could_use_implied_bounds<'a, T>(_: Foo<'a>, x: &'a T) -> &'static T
17 where
18     (): Trait<'a>, // This could be an implied bound
19 {
20     <()>::id(x)
21 }
22
23 fn main() {
24     let bar: for<'a, 'b> fn(Foo<'a>, &'b ()) = |_, _| {};
25
26     // If `could_use_implied_bounds` were to use implied bounds,
27     // keeping 'a late-bound, then we could assign that function
28     // to this variable.
29     let bar: for<'a> fn(Foo<'a>, &'a ()) = bar;
30
31     // In this case, the subtyping relation here would be unsound,
32     // allowing us to transmute lifetimes. This currently compiles
33     // because we incorrectly deal with implied bounds inside of binders.
34     let _bar: for<'a, 'b> fn(Foo<'a>, &'b ()) = bar;
35 }