]> git.lizzy.rs Git - rust.git/blob - tests/ui/type-alias-impl-trait/implied_bounds_closure.rs
Rollup merge of #104965 - zacklukem:p-option-as_ref-docs, r=scottmcm
[rust.git] / tests / ui / type-alias-impl-trait / implied_bounds_closure.rs
1 trait StaticDefaultRef: 'static {
2     fn default_ref() -> &'static Self;
3 }
4
5 impl StaticDefaultRef for str {
6     fn default_ref() -> &'static str {
7         ""
8     }
9 }
10
11 fn into_impl(x: &str) -> &(impl ?Sized + AsRef<str> + StaticDefaultRef + '_) {
12     x
13 }
14
15 fn extend_lifetime<'a>(x: &'a str) -> &'static str {
16     let t = into_impl(x);
17     helper(|_| t) //~ ERROR lifetime may not live long enough
18 }
19
20 fn helper<T: ?Sized + AsRef<str> + StaticDefaultRef>(f: impl FnOnce(&T) -> &T) -> &'static str {
21     f(T::default_ref()).as_ref()
22 }
23
24 fn main() {
25     let r;
26     {
27         let x = String::from("Hello World?");
28         r = extend_lifetime(&x);
29     }
30     println!("{}", r);
31 }