提交 dcbf4ec2 编写于 作者: P Patrick Walton

librustc: Put `#[unsafe_destructor]` behind a feature gate.

Closes #8142.

This is not the semantics we want long-term. You can continue to use
`#[unsafe_destructor]`, but you'll need to add
`#![feature(unsafe_destructor)]` to the crate attributes.

[breaking-change]
上级 6750eb5a
...@@ -192,6 +192,8 @@ As an example, we give a reimplementation of owned boxes by wrapping ...@@ -192,6 +192,8 @@ As an example, we give a reimplementation of owned boxes by wrapping
reimplementation is as safe as the `Box` type. reimplementation is as safe as the `Box` type.
``` ```
#![feature(unsafe_destructor)]
extern crate libc; extern crate libc;
use libc::{c_void, size_t, malloc, free}; use libc::{c_void, size_t, malloc, free};
use std::mem; use std::mem;
...@@ -242,10 +244,12 @@ impl<T: Send> Unique<T> { ...@@ -242,10 +244,12 @@ impl<T: Send> Unique<T> {
// A key ingredient for safety, we associate a destructor with // A key ingredient for safety, we associate a destructor with
// Unique<T>, making the struct manage the raw pointer: when the // Unique<T>, making the struct manage the raw pointer: when the
// struct goes out of scope, it will automatically free the raw pointer. // struct goes out of scope, it will automatically free the raw pointer.
//
// NB: This is an unsafe destructor, because rustc will not normally // NB: This is an unsafe destructor, because rustc will not normally
// allow destructors to be associated with parametrized types, due to // allow destructors to be associated with parameterized types, due to
// bad interaction with managed boxes. (With the Send restriction, // bad interaction with managed boxes. (With the Send restriction,
// we don't have this problem.) // we don't have this problem.) Note that the `#[unsafe_destructor]`
// feature gate is required to use unsafe destructors.
#[unsafe_destructor] #[unsafe_destructor]
impl<T: Send> Drop for Unique<T> { impl<T: Send> Drop for Unique<T> {
fn drop(&mut self) { fn drop(&mut self) {
......
...@@ -1940,12 +1940,13 @@ interpreted: ...@@ -1940,12 +1940,13 @@ interpreted:
enum representation in C is undefined, and this may be incorrect when the C enum representation in C is undefined, and this may be incorrect when the C
code is compiled with certain flags. code is compiled with certain flags.
- `simd` - on certain tuple structs, derive the arithmetic operators, which - `simd` - on certain tuple structs, derive the arithmetic operators, which
lower to the target's SIMD instructions, if any. lower to the target's SIMD instructions, if any; the `simd` feature gate
is necessary to use this attribute.
- `static_assert` - on statics whose type is `bool`, terminates compilation - `static_assert` - on statics whose type is `bool`, terminates compilation
with an error if it is not initialized to `true`. with an error if it is not initialized to `true`.
- `unsafe_destructor` - allow implementations of the "drop" language item - `unsafe_destructor` - allow implementations of the "drop" language item
where the type it is implemented for does not implement the "send" language where the type it is implemented for does not implement the "send" language
item. item; the `unsafe_destructor` feature gate is needed to use this attribute
- `unsafe_no_drop_flag` - on structs, remove the flag that prevents - `unsafe_no_drop_flag` - on structs, remove the flag that prevents
destructors from being run twice. Destructors might be run multiple times on destructors from being run twice. Destructors might be run multiple times on
the same object with this attribute. the same object with this attribute.
......
...@@ -69,7 +69,8 @@ ...@@ -69,7 +69,8 @@
html_root_url = "http://doc.rust-lang.org/")] html_root_url = "http://doc.rust-lang.org/")]
#![no_std] #![no_std]
#![feature(phase)] #![feature(phase, unsafe_destructor)]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
#[phase(plugin, link)] #[phase(plugin, link)]
extern crate core; extern crate core;
......
...@@ -27,7 +27,10 @@ ...@@ -27,7 +27,10 @@
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")] html_root_url = "http://doc.rust-lang.org/")]
#![feature(unsafe_destructor)]
#![allow(missing_doc)] #![allow(missing_doc)]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::cmp; use std::cmp;
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
html_playground_url = "http://play.rust-lang.org/")] html_playground_url = "http://play.rust-lang.org/")]
#![feature(macro_rules, managed_boxes, default_type_params, phase, globs)] #![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
#![feature(unsafe_destructor)]
#![no_std] #![no_std]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
#[phase(plugin, link)] extern crate core; #[phase(plugin, link)] extern crate core;
extern crate alloc; extern crate alloc;
......
...@@ -55,8 +55,9 @@ ...@@ -55,8 +55,9 @@
html_playground_url = "http://play.rust-lang.org/")] html_playground_url = "http://play.rust-lang.org/")]
#![no_std] #![no_std]
#![feature(globs, macro_rules, managed_boxes, phase, simd)] #![feature(globs, macro_rules, managed_boxes, phase, simd, unsafe_destructor)]
#![deny(missing_doc)] #![deny(missing_doc)]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
#[cfg(test)] extern crate realcore = "core"; #[cfg(test)] extern crate realcore = "core";
#[cfg(test)] extern crate libc; #[cfg(test)] extern crate libc;
......
...@@ -52,15 +52,17 @@ ...@@ -52,15 +52,17 @@
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")] html_root_url = "http://doc.rust-lang.org/")]
#![deny(unused_result, unused_must_use)] #![deny(unused_result, unused_must_use)]
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![allow(deprecated)] #![allow(deprecated)]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
#![feature(default_type_params)] #![feature(default_type_params)]
// NB this crate explicitly does *not* allow glob imports, please seriously // NB this crate explicitly does *not* allow glob imports, please seriously
// consider whether they're needed before adding that feature here (the // consider whether they're needed before adding that feature here (the
// answer is that you don't need them) // answer is that you don't need them)
#![feature(macro_rules)] #![feature(macro_rules, unsafe_destructor)]
extern crate alloc; extern crate alloc;
extern crate libc; extern crate libc;
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
("log_syntax", Active), ("log_syntax", Active),
("trace_macros", Active), ("trace_macros", Active),
("concat_idents", Active), ("concat_idents", Active),
("unsafe_destructor", Active),
("simd", Active), ("simd", Active),
("default_type_params", Active), ("default_type_params", Active),
...@@ -220,6 +221,17 @@ fn visit_item(&mut self, i: &ast::Item, _:()) { ...@@ -220,6 +221,17 @@ fn visit_item(&mut self, i: &ast::Item, _:()) {
} }
} }
ast::ItemImpl(..) => {
if attr::contains_name(i.attrs.as_slice(),
"unsafe_destructor") {
self.gate_feature("unsafe_destructor",
i.span,
"`#[unsafe_destructor]` allows too \
many unsafe patterns and may be \
removed in the future");
}
}
_ => {} _ => {}
} }
......
...@@ -29,8 +29,9 @@ ...@@ -29,8 +29,9 @@
html_root_url = "http://doc.rust-lang.org/")] html_root_url = "http://doc.rust-lang.org/")]
#![allow(deprecated)] #![allow(deprecated)]
#![feature(macro_rules, globs, struct_variant, managed_boxes, quote, #![allow(unknown_features)] // NOTE: remove after a stage0 snap
default_type_params, phase)] #![feature(macro_rules, globs, struct_variant, managed_boxes, quote)]
#![feature(default_type_params, phase, unsafe_destructor)]
extern crate arena; extern crate arena;
extern crate debug; extern crate debug;
......
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")] html_root_url = "http://doc.rust-lang.org/")]
#![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm,
linkage)] #![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm)]
#![feature(linkage, unsafe_destructor)]
#![no_std] #![no_std]
#![experimental] #![experimental]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
#[phase(plugin, link)] extern crate core; #[phase(plugin, link)] extern crate core;
extern crate alloc; extern crate alloc;
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#![crate_type = "rlib"] #![crate_type = "rlib"]
#![crate_type = "dylib"] #![crate_type = "dylib"]
#![feature(macro_rules)] #![feature(macro_rules, unsafe_destructor)]
#![deny(unused_result, unused_must_use)] #![deny(unused_result, unused_must_use)]
#![allow(visible_private_types)] #![allow(visible_private_types)]
......
...@@ -103,14 +103,16 @@ ...@@ -103,14 +103,16 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/", html_root_url = "http://doc.rust-lang.org/",
html_playground_url = "http://play.rust-lang.org/")] html_playground_url = "http://play.rust-lang.org/")]
#![feature(macro_rules, globs, managed_boxes,
linkage, default_type_params, phase)] #![feature(macro_rules, globs, managed_boxes)]
#![feature(linkage, default_type_params, phase, unsafe_destructor)]
// Don't link to std. We are std. // Don't link to std. We are std.
#![no_std] #![no_std]
#![allow(deprecated)] #![allow(deprecated)]
#![deny(missing_doc)] #![deny(missing_doc)]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
// When testing libstd, bring in libuv as the I/O backend so tests can print // When testing libstd, bring in libuv as the I/O backend so tests can print
// things and all of the std::io tests have an I/O interface to run on top // things and all of the std::io tests have an I/O interface to run on top
......
...@@ -26,10 +26,11 @@ ...@@ -26,10 +26,11 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/", html_root_url = "http://doc.rust-lang.org/",
html_playground_url = "http://play.rust-lang.org/")] html_playground_url = "http://play.rust-lang.org/")]
#![feature(phase, globs, macro_rules)]
#![feature(phase, globs, macro_rules, unsafe_destructor)]
#![deny(missing_doc)] #![deny(missing_doc)]
#![no_std] #![no_std]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
#[phase(plugin, link)] extern crate core; #[phase(plugin, link)] extern crate core;
extern crate alloc; extern crate alloc;
......
...@@ -27,9 +27,10 @@ ...@@ -27,9 +27,10 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")] html_root_url = "http://doc.rust-lang.org/")]
#![feature(macro_rules, globs, managed_boxes, default_type_params, phase, #![feature(macro_rules, globs, managed_boxes, default_type_params, phase)]
quote)] #![feature(quote, unsafe_destructor)]
#![allow(deprecated)] #![allow(deprecated)]
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
extern crate serialize; extern crate serialize;
extern crate term; extern crate term;
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#![crate_id="issue_2526#0.2"] #![crate_id="issue_2526#0.2"]
#![crate_type = "lib"] #![crate_type = "lib"]
#![feature(unsafe_destructor)]
struct arc_destruct<T> { struct arc_destruct<T> {
_data: int, _data: int,
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
extern crate collections; extern crate collections;
extern crate time; extern crate time;
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(unsafe_destructor)]
extern crate debug; extern crate debug;
struct defer<'a> { struct defer<'a> {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
extern crate debug; extern crate debug;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
extern crate debug; extern crate debug;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
extern crate debug; extern crate debug;
use std::cell::Cell; use std::cell::Cell;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
// error-pattern:quux // error-pattern:quux
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(unsafe_destructor)]
use std::mem::size_of; use std::mem::size_of;
#[unsafe_no_drop_flag] #[unsafe_no_drop_flag]
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(unsafe_destructor)]
struct S<T> { struct S<T> {
x: T x: T
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
use std::cell::Cell; use std::cell::Cell;
use std::gc::{Gc, GC}; use std::gc::{Gc, GC};
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(unsafe_destructor)]
pub type Task = int; pub type Task = int;
// tjc: I don't know why // tjc: I don't know why
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
use std::cell::Cell; use std::cell::Cell;
use std::gc::{Gc, GC}; use std::gc::{Gc, GC};
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
use std::cell::Cell; use std::cell::Cell;
use std::gc::{Gc, GC}; use std::gc::{Gc, GC};
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(unsafe_destructor)]
extern crate debug; extern crate debug;
trait X { trait X {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
use std::cell::Cell; use std::cell::Cell;
use std::gc::{GC, Gc}; use std::gc::{GC, Gc};
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
// Make sure the destructor is run for newtype structs. // Make sure the destructor is run for newtype structs.
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
use std::cell::Cell; use std::cell::Cell;
use std::gc::{GC, Gc}; use std::gc::{GC, Gc};
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
extern crate debug; extern crate debug;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
use std::cell::Cell; use std::cell::Cell;
use std::gc::{GC, Gc}; use std::gc::{GC, Gc};
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
// Ensures that class dtors run if the object is inside an enum // Ensures that class dtors run if the object is inside an enum
// variant // variant
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
use std::task; use std::task;
use std::gc::{Gc, GC}; use std::gc::{Gc, GC};
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(managed_boxes)] #![feature(managed_boxes, unsafe_destructor)]
use std::cell::Cell; use std::cell::Cell;
use std::gc::{Gc, GC}; use std::gc::{Gc, GC};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册