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