diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-05-13 16:03:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-13 16:03:23 +0200 |
| commit | 281be096c181076aef96ff3b81e869fbebbe6b50 (patch) | |
| tree | 1c1a31ac8cc7625edc3e410af17c30a6e806393b | |
| parent | feb18d102a733c7f42647e309e56bce7672a9347 (diff) | |
| parent | 5db03162f0ea4bc9b2a0f23d57e87b641e807e02 (diff) | |
| download | rust-281be096c181076aef96ff3b81e869fbebbe6b50.tar.gz rust-281be096c181076aef96ff3b81e869fbebbe6b50.zip | |
Rollup merge of #96615 - JohnTitor:test-54779, r=compiler-errors
Add a regression test for #54779 Closes #54779 r? `@jackh726`
| -rw-r--r-- | src/test/ui/nll/issue-54779-anon-static-lifetime.rs | 51 | ||||
| -rw-r--r-- | src/test/ui/nll/issue-54779-anon-static-lifetime.stderr | 11 |
2 files changed, 62 insertions, 0 deletions
diff --git a/src/test/ui/nll/issue-54779-anon-static-lifetime.rs b/src/test/ui/nll/issue-54779-anon-static-lifetime.rs new file mode 100644 index 00000000000..4bb983dd358 --- /dev/null +++ b/src/test/ui/nll/issue-54779-anon-static-lifetime.rs @@ -0,0 +1,51 @@ +// Regression test for #54779, checks if the diagnostics are confusing. + +#![feature(nll)] + +trait DebugWith<Cx: ?Sized> { + fn debug_with<'me>(&'me self, cx: &'me Cx) -> DebugCxPair<'me, Self, Cx> { + DebugCxPair { value: self, cx } + } + + fn fmt_with(&self, cx: &Cx, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result; +} + +struct DebugCxPair<'me, Value: ?Sized, Cx: ?Sized> +where + Value: DebugWith<Cx>, +{ + value: &'me Value, + cx: &'me Cx, +} + +trait DebugContext {} + +struct Foo { + bar: Bar, +} + +impl DebugWith<dyn DebugContext> for Foo { + fn fmt_with( + &self, + cx: &dyn DebugContext, + fmt: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + let Foo { bar } = self; + bar.debug_with(cx); //~ ERROR: lifetime may not live long enough + Ok(()) + } +} + +struct Bar {} + +impl DebugWith<dyn DebugContext> for Bar { + fn fmt_with( + &self, + cx: &dyn DebugContext, + fmt: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { + Ok(()) + } +} + +fn main() {} diff --git a/src/test/ui/nll/issue-54779-anon-static-lifetime.stderr b/src/test/ui/nll/issue-54779-anon-static-lifetime.stderr new file mode 100644 index 00000000000..9dc9bdbab8d --- /dev/null +++ b/src/test/ui/nll/issue-54779-anon-static-lifetime.stderr @@ -0,0 +1,11 @@ +error: lifetime may not live long enough + --> $DIR/issue-54779-anon-static-lifetime.rs:34:24 + | +LL | cx: &dyn DebugContext, + | - let's call the lifetime of this reference `'1` +... +LL | bar.debug_with(cx); + | ^^ cast requires that `'1` must outlive `'static` + +error: aborting due to previous error + |
