Skip to content

Commit 5db0316

Browse files
committed
Add a regression test for #54779
1 parent a933de8 commit 5db0316

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/issue-54779-anon-static-lifetime.rs:34:24
3+
|
4+
LL | cx: &dyn DebugContext,
5+
| - let's call the lifetime of this reference `'1`
6+
...
7+
LL | bar.debug_with(cx);
8+
| ^^ cast requires that `'1` must outlive `'static`
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)