Skip to content

Commit 43ef554

Browse files
committed
Add test for issue-51506
1 parent bb882d7 commit 43ef554

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/test/ui/never_type/issue-51506.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![feature(never_type, specialization)]
2+
#![allow(incomplete_features)]
3+
4+
use std::iter::{self, Empty};
5+
6+
trait Trait {
7+
type Out: Iterator<Item = u32>;
8+
9+
fn f(&self) -> Option<Self::Out>;
10+
}
11+
12+
impl<T> Trait for T {
13+
default type Out = !; //~ ERROR: `!` is not an iterator
14+
15+
default fn f(&self) -> Option<Self::Out> {
16+
None
17+
}
18+
}
19+
20+
struct X;
21+
22+
impl Trait for X {
23+
type Out = Empty<u32>;
24+
25+
fn f(&self) -> Option<Self::Out> {
26+
Some(iter::empty())
27+
}
28+
}
29+
30+
fn f<T: Trait>(a: T) {
31+
if let Some(iter) = a.f() {
32+
println!("Some");
33+
for x in iter {
34+
println!("x = {}", x);
35+
}
36+
}
37+
}
38+
39+
pub fn main() {
40+
f(10);
41+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: `!` is not an iterator
2+
--> $DIR/issue-51506.rs:13:5
3+
|
4+
LL | type Out: Iterator<Item = u32>;
5+
| ------------------------------- required by `Trait::Out`
6+
...
7+
LL | default type Out = !;
8+
| ^^^^^^^^^^^^^^^^^^^^^ `!` is not an iterator
9+
|
10+
= help: the trait `std::iter::Iterator` is not implemented for `!`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)