Skip to content

ICE fictitious type in sizing_type_of() #23958

Closed
@nikomatsakis

Description

@nikomatsakis

This example causes an ICE:

Play: http://is.gd/pqOpJQ

trait MyIntoIterator {
  type IntoIter: Iterator;
  fn into_iter(self) -> Self::IntoIter;
}

// This should be saying `if for any lifetime, a ref to Self is MyIntoIterator`.
trait Iterable where for<'a> &'a Self: MyIntoIterator {
  fn iter<'a>(&'a self) -> <&'a Self as MyIntoIterator>::IntoIter {
    self.into_iter()
  }
}
impl<T> Iterable for T where for<'a> &'a T: MyIntoIterator {}

// Impl MyIntoIterator for &Vec<T> for all lifetimes.
impl<'a, T> MyIntoIterator for &'a Vec<T> {
  type IntoIter = ::std::slice::Iter<'a, T>;
  fn into_iter(self) -> <Self as MyIntoIterator>::IntoIter { self.iter() }
}

// Impl MyIntoIterator for &String for all lifetimes.
impl<'a> MyIntoIterator for &'a String {
  type IntoIter = ::std::str::Chars<'a>;
  fn into_iter(self) -> <Self as MyIntoIterator>::IntoIter { self.chars() }
}

fn iterate<T>(thing: T) where T: Iterable, for<'a> &'a T: MyIntoIterator {
  for x in thing.iter() {
    println!("a thing");
  }
}

fn main() {
  iterate(vec![1,2,3]);
  iterate("abc".to_string());
}

output:

error: internal compiler error: fictitious type <&'static collections::vec::Vec<i32> as MyIntoIterator>::IntoIter in sizing_type_of()
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions