]> git.lizzy.rs Git - rust.git/blob - src/test/ui/in-band-lifetimes/impl/trait-underscore.rs
Account for --remap-path-prefix in save-analysis
[rust.git] / src / test / ui / in-band-lifetimes / impl / trait-underscore.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test that `impl MyTrait<'_> for &i32` is equivalent to `impl<'a,
12 // 'b> MyTrait<'a> for &'b i32`.
13 //
14 // run-pass
15
16 #![allow(warnings)]
17
18 #![feature(in_band_lifetimes)]
19
20 trait MyTrait<'a> { }
21
22 // This is equivalent to `MyTrait<'a> for &'b i32`, which is proven by
23 // the code below.
24 impl MyTrait<'_> for &i32 {
25 }
26
27 // When called, T will be `&'x i32` for some `'x`, so since we can
28 // prove that `&'x i32: for<'a> MyTrait<'a>, then we know that the
29 // lifetime parameter above is disconnected.
30 fn impls_my_trait<T: for<'a> MyTrait<'a>>() { }
31
32 fn impls_my_trait_val<T: for<'a> MyTrait<'a>>(_: T) {
33     impls_my_trait::<T>();
34 }
35
36 fn random_where_clause()
37 where for<'a, 'b> &'a i32: MyTrait<'b> { }
38
39 fn main() {
40     let x = 22;
41     let f = &x;
42     impls_my_trait_val(f);
43
44     impls_my_trait::<&'static i32>();
45
46     random_where_clause();
47 }