Skip to content

Commit 2563481

Browse files
committed
auto merge of #14988 : pcwalton/rust/unsafe-destructor-feature-gate, r=alexcrichton
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] r? @alexcrichton
2 parents 43d1938 + dcbf4ec commit 2563481

36 files changed

+78
-33
lines changed

src/doc/guide-unsafe.md

Lines changed: 6 additions & 2 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 4 additions & 2 deletions
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;

0 commit comments

Comments
 (0)