diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2020-06-09 13:57:33 -0700 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2020-06-19 13:40:51 -0700 |
| commit | 562f4967b4ce7e859b807fc022040bbb22d1f70e (patch) | |
| tree | 07c99b66a3982a652e3e5f11f2ebe5a86d7f4f0d /src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs | |
| parent | a39c7787ba246353178e099373b9240be0d9e603 (diff) | |
| download | rust-562f4967b4ce7e859b807fc022040bbb22d1f70e.tar.gz rust-562f4967b4ce7e859b807fc022040bbb22d1f70e.zip | |
Account for multiple impl/dyn Trait in return type when suggesting `'_`
Diffstat (limited to 'src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs')
| -rw-r--r-- | src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs b/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs new file mode 100644 index 00000000000..f78edb1c83a --- /dev/null +++ b/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.rs @@ -0,0 +1,68 @@ +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 { + current: None, + remaining: self.0.iter(), //~ ERROR cannot infer an appropriate lifetime + } + } +} + +struct Baz(Vec<Box<dyn Foo>>); + +impl Baz { + fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ { + Iter { + current: None, + remaining: self.0.iter(), //~ ERROR cannot infer an appropriate lifetime + } + } +} + +struct Bat(Vec<Box<dyn Foo>>); + +impl Bat { + fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> + 'a { + Iter { + current: None, + remaining: self.0.iter(), //~ ERROR cannot infer an appropriate lifetime + } + } +} + +struct Ban(Vec<Box<dyn Foo>>); + +impl Ban { + fn iter<'a>(&'a self) -> impl Iterator<Item = Box<dyn Foo>> { + Iter { + current: None, + remaining: self.0.iter(), //~ ERROR cannot infer an appropriate lifetime + } + } +} + +fn main() {} |
