rust/src/test/compile-fail/exclusive-drop-and-copy.rs
Huon Wilson 3c1ca175d1 Require that types cannot implement both Drop and Copy.
Opt-in built-in traits allowed one to explicitly implement both `Drop`
and `Copy` for a type. This can theoretically make some sense, but the
current implementation means it is codegened totally incorrectly which
can lead to memory unsafety, so this feature is disabled for now.

Fixes #20126.
2015-01-08 10:07:07 +11:00

31 lines
815 B
Rust

// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(unsafe_destructor)]
// issue #20126
#[derive(Copy)] //~ ERROR the trait `Copy` may not be implemented
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {}
}
#[derive(Copy)] //~ ERROR the trait `Copy` may not be implemented
struct Bar<T>;
#[unsafe_destructor]
impl<T> Drop for Bar<T> {
fn drop(&mut self) {}
}
fn main() {}