Skip to content

Commit 478bb1f

Browse files
committed
Adjust lint levels for using unsafe blocks in unsafe fns
If the `unsafe_op_in_unsafe_fn` lint is available (since Rust 1.52.0), set it to "deny", requiring `unsafe { }` blocks in order to perform unsafe operations even in unsafe functions; this silences the otherwise default warning of the `unused_unsafe` lint as well. If the `unsafe_op_in_unsafe_fn` lint is not available, then just supress warnings from the `unused_unsafe` lint.
1 parent fcdcff7 commit 478bb1f

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ keywords = ["binary", "heap", "priority", "queue"]
1010
categories = ["data-structures", "algorithms", ]
1111
edition = "2018"
1212

13+
[build-dependencies]
14+
autocfg = "1"
15+
1316
[dependencies]
1417
compare = "0.1.0"
1518
serde = { version = "1.0.116", optional = true, features = ["derive"] }

build.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let ac = autocfg::new();
3+
4+
// Required for stabilization of `unsafe_op_in_unsafe_fn` lint.
5+
ac.emit_rustc_version(1, 52);
6+
7+
autocfg::rerun_path("build.rs");
8+
}

src/binary_heap.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@
155155
//! }
156156
//! ```
157157
158-
#![deny(unsafe_op_in_unsafe_fn)]
158+
#![cfg_attr(has_rustc_1_52, deny(unsafe_op_in_unsafe_fn))]
159+
#![cfg_attr(not(has_rustc_1_52), allow(unused_unsafe))]
159160
#![allow(clippy::needless_doctest_main)]
160161
#![allow(missing_docs)]
161162
// #![stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)