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

impl Drop must not allow adding new bounds on type params #21201

Closed
pnkfelix opened this issue Jan 15, 2015 · 3 comments
Closed

impl Drop must not allow adding new bounds on type params #21201

pnkfelix opened this issue Jan 15, 2015 · 3 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@pnkfelix
Copy link
Member

Spawned off of #21022, #21972.

Before killing unsafe_destructor, we need to address the issue that type-parametric implementations of Drop cannot add new bounds ("new" as in bounds that were not already present on the type definition itself).

Here is an example:

use std::fmt;

pub struct S<T> { t: T }

impl<T: fmt::Show> Drop for S<T> {
    fn drop(&mut self) {
        println!("dropping S {{ t: {:?} }}", self.t);
    }
}

struct NoShow;

fn main() {
    let s1 = S { t: 1u8 };
    let s2 = S { t: 2u16 };
    let s3  =S { t: NoShow };
}

(On master, the above errors because it requires unsafe_destructor).

In the version of the compiler implemented on PR #21022, you get the following ICE:

% ./x86_64-apple-darwin/stage2/bin/rustc /tmp/dtor_ex2.rs
/tmp/dtor_ex2.rs:14:9: 14:11 warning: unused variable: `s1`, #[warn(unused_variables)] on by default
/tmp/dtor_ex2.rs:14     let s1 = S { t: 1u8 };
                            ^~
/tmp/dtor_ex2.rs:15:9: 15:11 warning: unused variable: `s2`, #[warn(unused_variables)] on by default
/tmp/dtor_ex2.rs:15     let s2 = S { t: 2u16 };
                            ^~
/tmp/dtor_ex2.rs:16:9: 16:11 warning: unused variable: `s3`, #[warn(unused_variables)] on by default
/tmp/dtor_ex2.rs:16     let s3  =S { t: NoShow };
                            ^~
/tmp/dtor_ex2.rs:1:1: 1:1 error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(TraitRef(NoShow, core::fmt::Show))` during trans
/tmp/dtor_ex2.rs:1 use std::fmt;
                   ^
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /Users/fklock/Dev/Mozilla/rust-drop-lts/src/libsyntax/diagnostic.rs:123
@pnkfelix pnkfelix added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 15, 2015
@reem
Copy link
Contributor

reem commented Jan 15, 2015

Is this a fundamental limitation or just requires implementation effort to detect which (if any) drop impl to run?

@nikomatsakis
Copy link
Contributor

@reem not a fundamental limitation necessarily.

@pnkfelix
Copy link
Member Author

closing as dupe of #8142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants