Skip to content

Commit dcbf4ec

Browse files
committed
librustc: Put #[unsafe_destructor] behind a feature gate.
Closes rust-lang#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]
1 parent 6750eb5 commit dcbf4ec

36 files changed

+78
-33
lines changed

src/doc/guide-unsafe.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ As an example, we give a reimplementation of owned boxes by wrapping
192192
reimplementation is as safe as the `Box` type.
193193

194194
```
195+
#![feature(unsafe_destructor)]
196+
195197
extern crate libc;
196198
use libc::{c_void, size_t, malloc, free};
197199
use std::mem;
@@ -242,10 +244,12 @@ impl<T: Send> Unique<T> {
242244
// A key ingredient for safety, we associate a destructor with
243245
// Unique<T>, making the struct manage the raw pointer: when the
244246
// struct goes out of scope, it will automatically free the raw pointer.
247+
//
245248
// NB: This is an unsafe destructor, because rustc will not normally
246-
// allow destructors to be associated with parametrized types, due to
249+
// allow destructors to be associated with parameterized types, due to
247250
// bad interaction with managed boxes. (With the Send restriction,
248-
// we don't have this problem.)
251+
// we don't have this problem.) Note that the `#[unsafe_destructor]`
252+
// feature gate is required to use unsafe destructors.
249253
#[unsafe_destructor]
250254
impl<T: Send> Drop for Unique<T> {
251255
fn drop(&mut self) {

src/doc/rust.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1940,12 +1940,13 @@ interpreted:
19401940
enum representation in C is undefined, and this may be incorrect when the C
19411941
code is compiled with certain flags.
19421942
- `simd` - on certain tuple structs, derive the arithmetic operators, which
1943-
lower to the target's SIMD instructions, if any.
1943+
lower to the target's SIMD instructions, if any; the `simd` feature gate
1944+
is necessary to use this attribute.
19441945
- `static_assert` - on statics whose type is `bool`, terminates compilation
19451946
with an error if it is not initialized to `true`.
19461947
- `unsafe_destructor` - allow implementations of the "drop" language item
19471948
where the type it is implemented for does not implement the "send" language
1948-
item.
1949+
item; the `unsafe_destructor` feature gate is needed to use this attribute
19491950
- `unsafe_no_drop_flag` - on structs, remove the flag that prevents
19501951
destructors from being run twice. Destructors might be run multiple times on
19511952
the same object with this attribute.

src/liballoc/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
html_root_url = "http://doc.rust-lang.org/")]
7070

7171
#![no_std]
72-
#![feature(phase)]
72+
#![feature(phase, unsafe_destructor)]
73+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
7374

7475
#[phase(plugin, link)]
7576
extern crate core;

src/libarena/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2828
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2929
html_root_url = "http://doc.rust-lang.org/")]
30+
31+
#![feature(unsafe_destructor)]
3032
#![allow(missing_doc)]
33+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
3134

3235
use std::cell::{Cell, RefCell};
3336
use std::cmp;

src/libcollections/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
html_playground_url = "http://play.rust-lang.org/")]
2323

2424
#![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
25+
#![feature(unsafe_destructor)]
2526
#![no_std]
27+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
2628

2729
#[phase(plugin, link)] extern crate core;
2830
extern crate alloc;

src/libcore/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
html_playground_url = "http://play.rust-lang.org/")]
5656

5757
#![no_std]
58-
#![feature(globs, macro_rules, managed_boxes, phase, simd)]
58+
#![feature(globs, macro_rules, managed_boxes, phase, simd, unsafe_destructor)]
5959
#![deny(missing_doc)]
60+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
6061

6162
#[cfg(test)] extern crate realcore = "core";
6263
#[cfg(test)] extern crate libc;

src/libnative/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@
5252
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
5353
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
5454
html_root_url = "http://doc.rust-lang.org/")]
55+
5556
#![deny(unused_result, unused_must_use)]
5657
#![allow(non_camel_case_types)]
5758
#![allow(deprecated)]
59+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
5860
#![feature(default_type_params)]
5961

6062
// NB this crate explicitly does *not* allow glob imports, please seriously
6163
// consider whether they're needed before adding that feature here (the
6264
// answer is that you don't need them)
63-
#![feature(macro_rules)]
65+
#![feature(macro_rules, unsafe_destructor)]
6466

6567
extern crate alloc;
6668
extern crate libc;

src/librustc/front/feature_gate.rs

+12
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
5050
("log_syntax", Active),
5151
("trace_macros", Active),
5252
("concat_idents", Active),
53+
("unsafe_destructor", Active),
5354

5455
("simd", Active),
5556
("default_type_params", Active),
@@ -220,6 +221,17 @@ impl<'a> Visitor<()> for Context<'a> {
220221
}
221222
}
222223

224+
ast::ItemImpl(..) => {
225+
if attr::contains_name(i.attrs.as_slice(),
226+
"unsafe_destructor") {
227+
self.gate_feature("unsafe_destructor",
228+
i.span,
229+
"`#[unsafe_destructor]` allows too \
230+
many unsafe patterns and may be \
231+
removed in the future");
232+
}
233+
}
234+
223235
_ => {}
224236
}
225237

src/librustc/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ This API is completely unstable and subject to change.
2929
html_root_url = "http://doc.rust-lang.org/")]
3030

3131
#![allow(deprecated)]
32-
#![feature(macro_rules, globs, struct_variant, managed_boxes, quote,
33-
default_type_params, phase)]
32+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
33+
#![feature(macro_rules, globs, struct_variant, managed_boxes, quote)]
34+
#![feature(default_type_params, phase, unsafe_destructor)]
3435

3536
extern crate arena;
3637
extern crate debug;

src/librustrt/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
1616
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
1717
html_root_url = "http://doc.rust-lang.org/")]
18-
#![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm,
19-
linkage)]
18+
19+
#![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm)]
20+
#![feature(linkage, unsafe_destructor)]
2021
#![no_std]
2122
#![experimental]
23+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
2224

2325
#[phase(plugin, link)] extern crate core;
2426
extern crate alloc;

src/librustuv/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ via `close` and `delete` methods.
4040
#![crate_type = "rlib"]
4141
#![crate_type = "dylib"]
4242

43-
#![feature(macro_rules)]
43+
#![feature(macro_rules, unsafe_destructor)]
4444
#![deny(unused_result, unused_must_use)]
4545
#![allow(visible_private_types)]
4646

src/libstd/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,16 @@
103103
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
104104
html_root_url = "http://doc.rust-lang.org/",
105105
html_playground_url = "http://play.rust-lang.org/")]
106-
#![feature(macro_rules, globs, managed_boxes,
107-
linkage, default_type_params, phase)]
106+
107+
#![feature(macro_rules, globs, managed_boxes)]
108+
#![feature(linkage, default_type_params, phase, unsafe_destructor)]
108109

109110
// Don't link to std. We are std.
110111
#![no_std]
111112

112113
#![allow(deprecated)]
113114
#![deny(missing_doc)]
115+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
114116

115117
// When testing libstd, bring in libuv as the I/O backend so tests can print
116118
// things and all of the std::io tests have an I/O interface to run on top

src/libsync/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2727
html_root_url = "http://doc.rust-lang.org/",
2828
html_playground_url = "http://play.rust-lang.org/")]
29-
#![feature(phase, globs, macro_rules)]
3029

30+
#![feature(phase, globs, macro_rules, unsafe_destructor)]
3131
#![deny(missing_doc)]
3232
#![no_std]
33+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
3334

3435
#[phase(plugin, link)] extern crate core;
3536
extern crate alloc;

src/libsyntax/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ This API is completely unstable and subject to change.
2727
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2828
html_root_url = "http://doc.rust-lang.org/")]
2929

30-
#![feature(macro_rules, globs, managed_boxes, default_type_params, phase,
31-
quote)]
30+
#![feature(macro_rules, globs, managed_boxes, default_type_params, phase)]
31+
#![feature(quote, unsafe_destructor)]
3232
#![allow(deprecated)]
33+
#![allow(unknown_features)] // NOTE: remove after a stage0 snap
3334

3435
extern crate serialize;
3536
extern crate term;

src/test/auxiliary/issue-2526.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#![crate_id="issue_2526#0.2"]
1212
#![crate_type = "lib"]
1313

14+
#![feature(unsafe_destructor)]
15+
1416
struct arc_destruct<T> {
1517
_data: int,
1618
}

src/test/bench/task-perf-alloc-unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
extern crate collections;
1414
extern crate time;

src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(unsafe_destructor)]
12+
1113
extern crate debug;
1214

1315
struct defer<'a> {

src/test/compile-fail/no-send-res-ports.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
extern crate debug;
1414

src/test/compile-fail/pinned-deep-copy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
extern crate debug;
1414

src/test/compile-fail/unique-vec-res.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
extern crate debug;
1414
use std::cell::Cell;

src/test/run-fail/unwind-resource-fail3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
// error-pattern:quux
1414

src/test/run-pass/attr-no-drop-flag-size.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(unsafe_destructor)]
12+
1113
use std::mem::size_of;
1214

1315
#[unsafe_no_drop_flag]

src/test/run-pass/drop-trait-generic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(unsafe_destructor)]
12+
1113
struct S<T> {
1214
x: T
1315
}

src/test/run-pass/init-res-into-things.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
use std::cell::Cell;
1414
use std::gc::{Gc, GC};

src/test/run-pass/issue-2718.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// option. This file may not be copied, modified, or distributed
1010
// except according to those terms.
1111

12+
#![feature(unsafe_destructor)]
13+
1214
pub type Task = int;
1315

1416
// tjc: I don't know why

src/test/run-pass/issue-2735-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
use std::cell::Cell;
1414
use std::gc::{Gc, GC};

src/test/run-pass/issue-2735-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
use std::cell::Cell;
1414
use std::gc::{Gc, GC};

src/test/run-pass/issue-4252.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(unsafe_destructor)]
12+
1113
extern crate debug;
1214

1315
trait X {

src/test/run-pass/issue-979.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
use std::cell::Cell;
1414
use std::gc::{GC, Gc};

src/test/run-pass/newtype-struct-drop-run.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
// Make sure the destructor is run for newtype structs.
1414

src/test/run-pass/option-unwrap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
use std::cell::Cell;
1414
use std::gc::{GC, Gc};

src/test/run-pass/resource-assign-is-not-copy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
extern crate debug;
1414

src/test/run-pass/resource-destruct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
use std::cell::Cell;
1414
use std::gc::{GC, Gc};

src/test/run-pass/resource-in-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
// Ensures that class dtors run if the object is inside an enum
1414
// variant

src/test/run-pass/unwind-resource2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(managed_boxes)]
11+
#![feature(managed_boxes, unsafe_destructor)]
1212

1313
use std::task;
1414
use std::gc::{Gc, GC};

0 commit comments

Comments
 (0)