]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-header-lifetime-elision/dyn-trait.rs
Rollup merge of #53110 - Xanewok:save-analysis-remap-path, r=nrc
[rust.git] / src / test / ui / impl-header-lifetime-elision / dyn-trait.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 #![allow(warnings)]
15
16 #![feature(impl_header_lifetime_elision)]
17
18 use std::fmt::Debug;
19
20 // Equivalent to `Box<dyn Debug + 'static>`:
21 trait StaticTrait { }
22 impl StaticTrait for Box<dyn Debug> { }
23
24 // Equivalent to `Box<dyn Debug + 'static>`:
25 trait NotStaticTrait { }
26 impl NotStaticTrait for Box<dyn Debug + '_> { }
27
28 fn static_val<T: StaticTrait>(_: T) {
29 }
30
31 fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
32     static_val(x); //~ ERROR cannot infer
33 }
34
35 fn not_static_val<T: NotStaticTrait>(_: T) {
36 }
37
38 fn with_dyn_debug_not_static<'a>(x: Box<dyn Debug + 'a>) {
39     not_static_val(x); // OK
40 }
41
42 fn main() {
43 }