Skip to content

Commit 75511af

Browse files
authored
Remove obsolete private_in_public lint in nightly and beta. (#113)
RFC 2145 is in beta now, deprecating the public_in_private lint. https://rust-lang.github.io/rfcs/2145-type-privacy.html public_in_private has been superceded by three new lints. The first two are warn-by-default and the third is allow-by-default. See the excerpt below for some details. This change skips this lint in nightly and beta in favor of the new warn-by-default lints. This change revealed a bug in the toolchain config option for color-spantrace -- it doesn't exist! The lint it was guarding was never turned on. This adds a minimal build script to check for toolchain to color-spantrace. Its functionality is tested in the eyre crate, which seems sufficient to me. After this change there are only two more build warnings for eyre and color-spantrace, the future-incompat dependency warning and the more serious filename collision. <quote> Lint private_interfaces is reported when a type with visibility x is used in primary interface of an item with effective visibility y and x < y. This lint is warn-by-default. Lint private_bounds is reported when a type or trait with visibility x is used in secondary interface of an item with effective visibility y and x < y. This lint is warn-by-default. Lint unnameable_types is reported when effective visibility of a type is larger than module in which it can be named, either directly, or through reexports, or through trivial type aliases (type X = Y;, no generics on both sides). This lint is allow-by-default. Compatibility lint private_in_public is never reported and removed. </quote>
1 parent fc4f006 commit 75511af

File tree

5 files changed

+106
-17
lines changed

5 files changed

+106
-17
lines changed

color-spantrace/build.rs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use std::env;
2+
use std::ffi::OsString;
3+
use std::process::Command;
4+
use std::str;
5+
6+
fn main() {
7+
let version = match rustc_version_info() {
8+
Some(version) => version,
9+
None => return,
10+
};
11+
version.toolchain.set_feature();
12+
}
13+
14+
#[derive(PartialEq)]
15+
enum Toolchain {
16+
Stable,
17+
Beta,
18+
Nightly,
19+
}
20+
21+
impl Toolchain {
22+
fn set_feature(self) {
23+
match self {
24+
Toolchain::Nightly => println!("cargo:rustc-cfg=nightly"),
25+
Toolchain::Beta => println!("cargo:rustc-cfg=beta"),
26+
Toolchain::Stable => println!("cargo:rustc-cfg=stable"),
27+
}
28+
}
29+
}
30+
31+
struct VersionInfo {
32+
toolchain: Toolchain,
33+
}
34+
35+
fn rustc_version_info() -> Option<VersionInfo> {
36+
let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc"));
37+
let output = Command::new(rustc).arg("--version").output().ok()?;
38+
let version = str::from_utf8(&output.stdout).ok()?;
39+
let mut pieces = version.split(['.', ' ', '-']);
40+
if pieces.next() != Some("rustc") {
41+
return None;
42+
}
43+
let _major: u32 = pieces.next()?.parse().ok()?;
44+
let _minor: u32 = pieces.next()?.parse().ok()?;
45+
let _patch: u32 = pieces.next()?.parse().ok()?;
46+
let toolchain = match pieces.next() {
47+
Some("beta") => Toolchain::Beta,
48+
Some("nightly") => Toolchain::Nightly,
49+
_ => Toolchain::Stable,
50+
};
51+
let version = VersionInfo { toolchain };
52+
Some(version)
53+
}

color-spantrace/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@
6161
//! [`color-backtrace`]: https://github.com/athre0z/color-backtrace
6262
#![doc(html_root_url = "https://docs.rs/color-spantrace/0.2.0")]
6363
#![cfg_attr(
64-
nightly_features,
64+
nightly,
6565
feature(rustdoc_missing_doc_code_examples),
6666
warn(rustdoc::missing_doc_code_examples)
6767
)]
68+
#![cfg_attr(stable, warn(private_in_public))]
6869
#![warn(
6970
missing_debug_implementations,
7071
missing_docs,
@@ -78,7 +79,6 @@
7879
overflowing_literals,
7980
path_statements,
8081
patterns_in_fns_without_body,
81-
private_in_public,
8282
unconditional_recursion,
8383
unused,
8484
unused_allocation,

eyre/build.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ fn main() {
6161
None => return,
6262
};
6363

64-
if version.is_nightly {
65-
println!("cargo:rustc-cfg=nightly_features");
66-
}
64+
version.toolchain.set_feature();
6765

6866
if version.minor < 52 {
6967
println!("cargo:rustc-cfg=eyre_no_fmt_arguments_as_str");
@@ -91,9 +89,26 @@ fn compile_probe(probe: &str) -> Option<ExitStatus> {
9189
.ok()
9290
}
9391

92+
// TODO factor this toolchain parsing and related tests into its own file
93+
#[derive(PartialEq)]
94+
enum Toolchain {
95+
Stable,
96+
Beta,
97+
Nightly,
98+
}
99+
impl Toolchain {
100+
fn set_feature(self) {
101+
match self {
102+
Toolchain::Nightly => println!("cargo:rustc-cfg=nightly"),
103+
Toolchain::Beta => println!("cargo:rustc-cfg=beta"),
104+
Toolchain::Stable => println!("cargo:rustc-cfg=stable"),
105+
}
106+
}
107+
}
108+
94109
struct VersionInfo {
95110
minor: u32,
96-
is_nightly: bool,
111+
toolchain: Toolchain,
97112
}
98113

99114
fn rustc_version_info() -> Option<VersionInfo> {
@@ -107,7 +122,11 @@ fn rustc_version_info() -> Option<VersionInfo> {
107122
let _major: u32 = pieces.next()?.parse().ok()?;
108123
let minor = pieces.next()?.parse().ok()?;
109124
let _patch: u32 = pieces.next()?.parse().ok()?;
110-
let is_nightly = pieces.next() == Some("nightly");
111-
let version = VersionInfo { minor, is_nightly };
125+
let toolchain = match pieces.next() {
126+
Some("beta") => Toolchain::Beta,
127+
Some("nightly") => Toolchain::Nightly,
128+
_ => Toolchain::Stable,
129+
};
130+
let version = VersionInfo { minor, toolchain };
112131
Some(version)
113132
}

eyre/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,11 @@
316316
//! [`color-backtrace`]: https://github.com/athre0z/color-backtrace
317317
#![doc(html_root_url = "https://docs.rs/eyre/0.6.8")]
318318
#![cfg_attr(
319-
nightly_features,
319+
nightly,
320320
feature(rustdoc_missing_doc_code_examples),
321321
warn(rustdoc::missing_doc_code_examples)
322322
)]
323+
#![cfg_attr(stable, warn(private_in_public))]
323324
#![warn(
324325
missing_debug_implementations,
325326
missing_docs,
@@ -334,7 +335,6 @@
334335
overflowing_literals,
335336
path_statements,
336337
patterns_in_fns_without_body,
337-
private_in_public,
338338
unconditional_recursion,
339339
unused,
340340
unused_allocation,

eyre/tests/test_toolchain.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1+
// These tests check our build script against rustversion.
2+
13
#[rustversion::attr(not(nightly), ignore)]
2-
//#[cfg_attr(miri, ignore)]
34
#[test]
45
fn nightlytest() {
5-
if !cfg!(nightly_features) {
6-
panic!("nightly feature isn't set when the toolchain is nightly");
6+
if !cfg!(nightly) {
7+
panic!("nightly feature isn't set when the toolchain is nightly.");
8+
}
9+
if cfg!(any(beta, stable)) {
10+
panic!("beta, stable, and nightly are mutually exclusive features.")
11+
}
12+
}
13+
14+
#[rustversion::attr(not(beta), ignore)]
15+
#[test]
16+
fn betatest() {
17+
if !cfg!(beta) {
18+
panic!("beta feature is not set when the toolchain is beta.");
19+
}
20+
if cfg!(any(nightly, stable)) {
21+
panic!("beta, stable, and nightly are mutually exclusive features.")
722
}
823
}
924

10-
#[rustversion::attr(nightly, ignore)]
11-
//#[cfg_attr(miri, ignore)]
25+
#[rustversion::attr(not(stable), ignore)]
1226
#[test]
1327
fn stabletest() {
14-
if cfg!(nightly_features) {
15-
panic!("nightly feature is set when the toolchain isn't nightly");
28+
if !cfg!(stable) {
29+
panic!("stable feature is not set when the toolchain is stable.");
30+
}
31+
if cfg!(any(nightly, beta)) {
32+
panic!("beta, stable, and nightly are mutually exclusive features.")
1633
}
1734
}

0 commit comments

Comments
 (0)