diff options
| author | Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> | 2023-01-05 09:13:28 +0100 |
|---|---|---|
| committer | Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> | 2023-01-11 09:32:08 +0000 |
| commit | cf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch) | |
| tree | 40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs | |
| parent | ca855e6e42787ecd062d81d53336fe6788ef51a9 (diff) | |
| download | rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip | |
Move /src/test to /tests
Diffstat (limited to 'tests/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs')
| -rw-r--r-- | tests/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs b/tests/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs new file mode 100644 index 00000000000..ff27011f89e --- /dev/null +++ b/tests/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs @@ -0,0 +1,72 @@ +trait Foo {} +impl<'a, T: Foo> Foo for &'a T {} +impl<T: Foo + ?Sized> Foo for Box<T> {} + +struct Iter<'a, T> { + current: Option<Box<dyn Foo + 'a>>, + remaining: T, +} + +impl<'a, T> Iterator for Iter<'a, T> +where + T: Iterator, + T::Item: Foo + 'a, +{ + type Item = Box<dyn Foo + 'a>; + + fn next(&mut self) -> Option<Self::Item> { + let result = self.current.take(); + self.current = Box::new(self.remaining.next()).map(|f| Box::new(f) as _); + result + } +} + +struct Bar(Vec<Box<dyn Foo>>); + +impl Bar { + fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> { + Iter { + //~^ ERROR lifetime may not live long enough + current: None, + remaining: self.0.iter(), + } + } +} + +struct Baz(Vec<Box<dyn Foo>>); + +impl Baz { + fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ { + Iter { + //~^ ERROR lifetime may not live long enough + current: None, + remaining: self.0.iter(), + } + } +} + +struct Bat(Vec<Box<dyn Foo>>); + +impl Bat { + fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> + 'a { + Iter { + //~^ ERROR lifetime may not live long enough + current: None, + remaining: self.0.iter(), + } + } +} + +struct Ban(Vec<Box<dyn Foo>>); + +impl Ban { + fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> { + Iter { + //~^ ERROR lifetime may not live long enough + current: None, + remaining: self.0.iter(), + } + } +} + +fn main() {} |
