]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/issue-54779-anon-static-lifetime.rs
Rollup merge of #106664 - chenyukang:yukang/fix-106597-remove-lseek, r=cuviper
[rust.git] / tests / ui / nll / issue-54779-anon-static-lifetime.rs
1 // Regression test for #54779, checks if the diagnostics are confusing.
2
3 trait DebugWith<Cx: ?Sized> {
4     fn debug_with<'me>(&'me self, cx: &'me Cx) -> DebugCxPair<'me, Self, Cx> {
5         DebugCxPair { value: self, cx }
6     }
7
8     fn fmt_with(&self, cx: &Cx, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result;
9 }
10
11 struct DebugCxPair<'me, Value: ?Sized, Cx: ?Sized>
12 where
13     Value: DebugWith<Cx>,
14 {
15     value: &'me Value,
16     cx: &'me Cx,
17 }
18
19 trait DebugContext {}
20
21 struct Foo {
22     bar: Bar,
23 }
24
25 impl DebugWith<dyn DebugContext> for Foo {
26     fn fmt_with(
27         &self,
28         cx: &dyn DebugContext,
29         fmt: &mut std::fmt::Formatter<'_>,
30     ) -> std::fmt::Result {
31         let Foo { bar } = self;
32         bar.debug_with(cx); //~ ERROR: lifetime may not live long enough
33         Ok(())
34     }
35 }
36
37 struct Bar {}
38
39 impl DebugWith<dyn DebugContext> for Bar {
40     fn fmt_with(
41         &self,
42         cx: &dyn DebugContext,
43         fmt: &mut std::fmt::Formatter<'_>,
44     ) -> std::fmt::Result {
45         Ok(())
46     }
47 }
48
49 fn main() {}