diff options
Diffstat (limited to 'tests/ui/never_type/issue-51506.rs')
-rw-r--r-- | tests/ui/never_type/issue-51506.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/ui/never_type/issue-51506.rs b/tests/ui/never_type/issue-51506.rs new file mode 100644 index 000000000..d0fe6a0f5 --- /dev/null +++ b/tests/ui/never_type/issue-51506.rs @@ -0,0 +1,41 @@ +#![feature(never_type, specialization)] +#![allow(incomplete_features)] + +use std::iter::{self, Empty}; + +trait Trait { + type Out: Iterator<Item = u32>; + + fn f(&self) -> Option<Self::Out>; +} + +impl<T> Trait for T { + default type Out = !; //~ ERROR: `!` is not an iterator + + default fn f(&self) -> Option<Self::Out> { + None + } +} + +struct X; + +impl Trait for X { + type Out = Empty<u32>; + + fn f(&self) -> Option<Self::Out> { + Some(iter::empty()) + } +} + +fn f<T: Trait>(a: T) { + if let Some(iter) = a.f() { + println!("Some"); + for x in iter { + println!("x = {}", x); + } + } +} + +pub fn main() { + f(10); +} |