Skip to content

Commit

Permalink
Add test for issue-51506
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Jun 23, 2020
1 parent bb882d7 commit 43ef554
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/test/ui/never_type/issue-51506.rs
Original file line number Diff line number Diff line change
@@ -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);
}
14 changes: 14 additions & 0 deletions src/test/ui/never_type/issue-51506.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0277]: `!` is not an iterator
--> $DIR/issue-51506.rs:13:5
|
LL | type Out: Iterator<Item = u32>;
| ------------------------------- required by `Trait::Out`
...
LL | default type Out = !;
| ^^^^^^^^^^^^^^^^^^^^^ `!` is not an iterator
|
= help: the trait `std::iter::Iterator` is not implemented for `!`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 43ef554

Please sign in to comment.