Closed
Description
This code generates an ICE
#![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 = !;
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);
}
with this message.
error: internal compiler error: librustc/traits/codegen/mod.rs:169: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<! as std::iter::Iterator>)),depth=1),Unimplemented)]` resolving bounds after type-checking
thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:499:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to previous error
Replacing 1.f()
by X.f()
makes the code to compile and run fine, which is strange because ! does not implements Iterator
.
By removing the specialization the compiler refuses to compile the code with the error:
error[E0277]: the trait bound `!: std::iter::Iterator` is not satisfied
--> src/main.rs:10:9
|
10 | impl<T> Trait for T {
| ^^^^^ `!` is not an iterator; maybe try calling `.iter()` or a similar method
|
= 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`.
Metadata
Metadata
Assignees
Labels
Area: Trait impl specializationArea: Trait systemCategory: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(never_type)]``#![feature(specialization)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.This issue requires a nightly compiler in some way.