Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE with specialization #39448

Closed
gnzlbg opened this issue Feb 1, 2017 · 2 comments
Closed

ICE with specialization #39448

gnzlbg opened this issue Feb 1, 2017 · 2 comments
Labels
A-specialization Area: Trait impl specialization E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 1, 2017

The following example ices the compiler:

#![feature(specialization)]

trait A : Sized {
    fn foo(self, _: Self) -> Self { self }
}

impl A for u8 {}
impl A for u16 {}

// requires specialization:
impl FromA<u8> for u16 {
    fn from(x: u8) -> u16 { x as u16 }
}

trait FromA<T> {
    fn from(T) -> Self;
}

//impl<T: A, U: A > FromA<T> for U { // no ICE
impl<T: A, U: A + FromA<T>> FromA<T> for U {  // ICE
    default fn from(x: T) -> Self { // specialization: :(
        ToA::to(x)
    }
}

trait ToA<T> {
    fn to(self) -> T;
}

// From implies Into
impl<T, U> ToA<U> for T
    where U: FromA<T>
{
    fn to(self) -> U {
        U::from(self)
    }
}

#[allow(dead_code)]
fn foo<T: A, U: A>(x: T, y: U) -> U {
    x.foo(y.to()).to()
}

fn main() {
    
    let z = foo(8u8, 1u16);
}
@sanxiyn sanxiyn added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-specialization Area: Trait impl specialization labels Feb 14, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@eminence
Copy link
Contributor

eminence commented Dec 6, 2017

Bug triage: On current nightly (rustc 1.23.0-nightly (e97ba8328 2017-11-25)) this is no longer an ICE, instead it yields the following error:

error[E0275]: overflow evaluating the requirement `T: FromA<U>`
  --> a.rs:41:13
   |
41 |     x.foo(y.to()).to()
   |             ^^
   |
   = note: required because of the requirements on the impl of `FromA<U>` for `T`
   = note: required because of the requirements on the impl of `ToA<T>` for `U`

error: aborting due to previous error

@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Jan 25, 2019
@estebank
Copy link
Contributor

This can be closed by adding the repro case as a regression test.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 17, 2019
…Centril

Add regression test for a specialization-related ICE (rust-lang#39448)

Closes rust-lang#39448.

This is my first time contributing, I hope I got everything right. :)
kennytm added a commit to kennytm/rust that referenced this issue Feb 18, 2019
…Centril

Add regression test for a specialization-related ICE (rust-lang#39448)

Closes rust-lang#39448.

This is my first time contributing, I hope I got everything right. :)
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Feb 18, 2019
…Centril

Add regression test for a specialization-related ICE (rust-lang#39448)

Closes rust-lang#39448.

This is my first time contributing, I hope I got everything right. :)
kennytm added a commit to kennytm/rust that referenced this issue Feb 20, 2019
…Centril

Add regression test for a specialization-related ICE (rust-lang#39448)

Closes rust-lang#39448.

This is my first time contributing, I hope I got everything right. :)
bors added a commit that referenced this issue Feb 20, 2019
Rollup of 24 pull requests

Successful merges:

 - #56470 (Modify doctest's auto-`fn main()` to allow `Result`s)
 - #58044 (Make overflowing and wrapping negation const)
 - #58303 (Improve stability tags display)
 - #58336 (Fix search results interactions)
 - #58384 (Fix tables display)
 - #58392 (Use less explicit shifting in std::net::ip)
 - #58409 (rustdoc: respect alternate flag when formatting impl trait)
 - #58456 (Remove no longer accurate diagnostic code about NLL)
 - #58528 (Don't use an allocation for ItemId in StmtKind)
 - #58530 (Monomorphize less code in fs::{read|write})
 - #58534 (Mention capping forbid lints)
 - #58536 (Remove UB in pointer tests)
 - #58538 (Add missing fmt structs examples)
 - #58539 (Add alias methods to PathBuf for underlying OsString (#58234))
 - #58544 (Fix doc for rustc "-g" flag)
 - #58545 (Add regression test for a specialization-related ICE (#39448))
 - #58546 (librustc_codegen_llvm => 2018)
 - #58551 (Explain a panic in test case net::tcp::tests::double_bind)
 - #58553 (Use more impl header lifetime elision)
 - #58562 (Fix style nits)
 - #58565 (Fix typo in std::future::Future docs)
 - #58568 (Fix a transposition in driver.rs.)
 - #58569 (Reduce Some Code Repetitions like `(n << amt) >> amt`)
 - #58576 (Stabilize iter::successors and iter::from_fn)
bors added a commit that referenced this issue Feb 20, 2019
Rollup of 24 pull requests

Successful merges:

 - #56470 (Modify doctest's auto-`fn main()` to allow `Result`s)
 - #58044 (Make overflowing and wrapping negation const)
 - #58303 (Improve stability tags display)
 - #58336 (Fix search results interactions)
 - #58384 (Fix tables display)
 - #58392 (Use less explicit shifting in std::net::ip)
 - #58409 (rustdoc: respect alternate flag when formatting impl trait)
 - #58456 (Remove no longer accurate diagnostic code about NLL)
 - #58528 (Don't use an allocation for ItemId in StmtKind)
 - #58530 (Monomorphize less code in fs::{read|write})
 - #58534 (Mention capping forbid lints)
 - #58536 (Remove UB in pointer tests)
 - #58538 (Add missing fmt structs examples)
 - #58539 (Add alias methods to PathBuf for underlying OsString (#58234))
 - #58544 (Fix doc for rustc "-g" flag)
 - #58545 (Add regression test for a specialization-related ICE (#39448))
 - #58546 (librustc_codegen_llvm => 2018)
 - #58551 (Explain a panic in test case net::tcp::tests::double_bind)
 - #58553 (Use more impl header lifetime elision)
 - #58562 (Fix style nits)
 - #58565 (Fix typo in std::future::Future docs)
 - #58568 (Fix a transposition in driver.rs.)
 - #58569 (Reduce Some Code Repetitions like `(n << amt) >> amt`)
 - #58576 (Stabilize iter::successors and iter::from_fn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-specialization Area: Trait impl specialization E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

5 participants