Skip to content

[_; 33] implements Copy, but not Clone #40796

New issue

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

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

Already on GitHub? # to your account

Closed
LunaBorowska opened this issue Mar 24, 2017 · 4 comments
Closed

[_; 33] implements Copy, but not Clone #40796

LunaBorowska opened this issue Mar 24, 2017 · 4 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@LunaBorowska
Copy link
Contributor

LunaBorowska commented Mar 24, 2017

From https://www.reddit.com/r/rust/comments/616rc8/rcpp_discusses_rust/dfcjk09/

The following code:

fn clone_copy_type<T: Copy>(t: T) -> T {
    t.clone()
}

fn main() {
    // [_; 33] implements Copy, but not Clone, violating trait inheritance
    clone_copy_type([(); 33]);
}

Causes the following crash in playpen, due to [T; 33] (where T: Copy) implementing Copy, but not Clone, but Copy trait requiring Clone implementation.

error: internal compiler error: /checkout/src/librustc_trans/monomorphize.rs:151: Encountered error `Unimplemented` selecting `Binder(<[(); 33] as std::clone::Clone>)` during trans

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

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:377
note: Run with `RUST_BACKTRACE=1` for a backtrace.
@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 24, 2017
@steveklabnik
Copy link
Member

It's well known that this doesn't implement the trait, but it shouldn't ICE.

@jonas-schievink
Copy link
Contributor

The ICE is also well known. Since Clone is a supertrait of Copy, but isn't implemented in this case, this is technically a prime example for unsoundness. The Compiler is basically correct in assuming this will never happen, hence the ICE.

Also see #24000 and #28229

@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 24, 2017
@tbu-
Copy link
Contributor

tbu- commented Mar 24, 2017

Basically a duplicate of those.

@steveklabnik
Copy link
Member

Okay! Sorry about that @xfix , I didn't see those when I was looking.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants