Skip to content

Commit e2fc1f5

Browse files
nbdd0121BennoLossin
authored andcommitted
build: simplify use of nightly features
Instead of check if a feature is already stable, simply enable them and allow the warning if the feature is already stable. This avoids the need of the hardcoding whether a feature has been stabilized at a given version. Signed-off-by: Gary Guo <gary@garyguo.net>
1 parent e7a5b50 commit e2fc1f5

19 files changed

Lines changed: 35 additions & 36 deletions

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ macrotest = "1.0"
3737
prettyplease = { version = "0.2.37", features = ["verbatim"] }
3838

3939
[lints.rust]
40+
stable_features = "allow"
4041
non_ascii_idents = "deny"
4142
unexpected_cfgs = { level = "warn", check-cfg = [
4243
'cfg(UI_TESTS)',

build.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
use rustc_version::{version, Version};
1+
use rustc_version::{version_meta, Channel, Version};
22

33
fn main() {
4-
println!("cargo::rustc-check-cfg=cfg(RUSTC_LINT_REASONS_IS_STABLE)");
5-
println!("cargo::rustc-check-cfg=cfg(RUSTC_NEW_UNINIT_IS_STABLE)");
4+
println!("cargo::rustc-check-cfg=cfg(RUSTC_USE_FEATURE)");
65
println!("cargo::rustc-check-cfg=cfg(CONFIG_RUSTC_HAS_UNSAFE_PINNED)");
7-
if version().unwrap() >= Version::parse("1.81.0").unwrap()
8-
|| version().unwrap() >= Version::parse("1.81.0-nightly").unwrap()
9-
{
10-
println!("cargo:rustc-cfg=RUSTC_LINT_REASONS_IS_STABLE");
11-
}
12-
if version().unwrap() >= Version::parse("1.82.0").unwrap() {
13-
println!("cargo:rustc-cfg=RUSTC_NEW_UNINIT_IS_STABLE");
6+
7+
let meta = version_meta().unwrap();
8+
9+
let use_feature = meta.channel == Channel::Nightly || std::env::var("RUSTC_BOOTSTRAP").is_ok();
10+
if use_feature {
11+
println!("cargo:rustc-cfg=RUSTC_USE_FEATURE");
1412
}
15-
if version().unwrap() >= Version::parse("1.89.0-nightly").unwrap() {
13+
14+
if meta.semver >= Version::parse("1.89.0-nightly").unwrap() && use_feature {
1615
println!("cargo:rustc-cfg=CONFIG_RUSTC_HAS_UNSAFE_PINNED");
1716
}
1817
}

examples/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![allow(clippy::undocumented_unsafe_blocks)]
44
#![cfg_attr(feature = "alloc", feature(allocator_api))]
5-
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
5+
#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))]
66

77
use core::{
88
cell::Cell,

examples/mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![allow(clippy::undocumented_unsafe_blocks)]
44
#![cfg_attr(feature = "alloc", feature(allocator_api))]
5-
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
5+
#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))]
66
#![allow(clippy::missing_safety_doc)]
77

88
use core::{

examples/pthread_mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// inspired by <https://github.com/nbdd0121/pin-init/blob/trunk/examples/pthread_mutex.rs>
44
#![allow(clippy::undocumented_unsafe_blocks)]
55
#![cfg_attr(feature = "alloc", feature(allocator_api))]
6-
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
6+
#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))]
77

88
#[cfg(not(windows))]
99
mod pthread_mtx {

examples/static_init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#![allow(clippy::undocumented_unsafe_blocks)]
44
#![cfg_attr(feature = "alloc", feature(allocator_api))]
5-
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
5+
#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))]
66
#![allow(unused_imports)]
77

88
use core::{

internal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ syn = { version = "2.0.86", features = ["full", "parsing", "visit-mut"] }
2121
rustc_version = "0.4"
2222

2323
[lints.rust]
24+
stable_features = "allow"
2425
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(kernel)'] }

internal/build.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use rustc_version::{version, Version};
1+
use rustc_version::{version_meta, Channel};
22

33
fn main() {
4-
println!("cargo::rustc-check-cfg=cfg(RUSTC_LINT_REASONS_IS_STABLE)");
5-
if version().unwrap() >= Version::parse("1.81.0").unwrap()
6-
|| version().unwrap() >= Version::parse("1.81.0-nightly").unwrap()
7-
{
8-
println!("cargo:rustc-cfg=RUSTC_LINT_REASONS_IS_STABLE");
4+
println!("cargo::rustc-check-cfg=cfg(RUSTC_USE_FEATURE)");
5+
6+
let meta = version_meta().unwrap();
7+
8+
let use_feature = meta.channel == Channel::Nightly || std::env::var("RUSTC_BOOTSTRAP").is_ok();
9+
if use_feature {
10+
println!("cargo:rustc-cfg=RUSTC_USE_FEATURE");
911
}
1012
}

internal/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
//! `pin-init` proc macros.
88
9-
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
9+
#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))]
1010
// Documentation is done in the pin-init crate instead.
1111
#![allow(missing_docs)]
1212

src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,9 @@
264264
//! [`impl Init<T, E>`]: crate::Init
265265
//! [Rust-for-Linux]: https://rust-for-linux.com/
266266
267-
#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
267+
#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))]
268268
#![cfg_attr(
269-
all(
270-
any(feature = "alloc", feature = "std"),
271-
not(RUSTC_NEW_UNINIT_IS_STABLE)
272-
),
269+
all(any(feature = "alloc", feature = "std"), RUSTC_USE_FEATURE),
273270
feature(new_uninit)
274271
)]
275272
#![forbid(missing_docs, unsafe_op_in_unsafe_fn)]

0 commit comments

Comments
 (0)