Skip to content

Commit ab0c07a

Browse files
committed
Initiate the inner usage of cfg_match (Compiler)
1 parent 7c3eeb9 commit ab0c07a

File tree

9 files changed

+52
-57
lines changed

9 files changed

+52
-57
lines changed

Cargo.lock

-2
Original file line numberDiff line numberDiff line change
@@ -3594,7 +3594,6 @@ version = "0.0.0"
35943594
dependencies = [
35953595
"arrayvec",
35963596
"bitflags 1.3.2",
3597-
"cfg-if",
35983597
"elsa",
35993598
"ena",
36003599
"indexmap 2.0.0",
@@ -4428,7 +4427,6 @@ dependencies = [
44284427
name = "rustc_span"
44294428
version = "0.0.0"
44304429
dependencies = [
4431-
"cfg-if",
44324430
"indexmap 2.0.0",
44334431
"md-5",
44344432
"rustc_arena",

compiler/rustc_data_structures/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ edition = "2021"
88
[dependencies]
99
arrayvec = { version = "0.7", default-features = false }
1010
bitflags = "1.2.1"
11-
cfg-if = "1.0"
1211
ena = "0.14.2"
1312
indexmap = { version = "2.0.0" }
1413
jobserver_crate = { version = "0.1.13", package = "jobserver" }

compiler/rustc_data_structures/src/flock.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
//! green/native threading. This is just a bare-bones enough solution for
55
//! librustdoc, it is not production quality at all.
66
7-
cfg_if! {
8-
if #[cfg(target_os = "linux")] {
7+
cfg_match! {
8+
cfg(target_os = "linux") => {
99
mod linux;
1010
use linux as imp;
11-
} else if #[cfg(unix)] {
11+
}
12+
cfg(unix) => {
1213
mod unix;
1314
use unix as imp;
14-
} else if #[cfg(windows)] {
15+
}
16+
cfg(windows) => {
1517
mod windows;
1618
use self::windows as imp;
17-
} else {
19+
}
20+
_ => {
1821
mod unsupported;
1922
use unsupported as imp;
2023
}

compiler/rustc_data_structures/src/lib.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,44 @@
66
//!
77
//! This API is completely unstable and subject to change.
88
9+
#![allow(internal_features)]
10+
#![allow(rustc::default_hash_types)]
11+
#![allow(rustc::potential_query_instability)]
12+
#![deny(rustc::diagnostic_outside_of_impl)]
13+
#![deny(rustc::untranslatable_diagnostic)]
14+
#![deny(unsafe_op_in_unsafe_fn)]
915
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
16+
#![feature(allocator_api)]
1017
#![feature(array_windows)]
1118
#![feature(associated_type_bounds)]
1219
#![feature(auto_traits)]
1320
#![feature(cell_leak)]
21+
#![feature(cfg_match)]
1422
#![feature(core_intrinsics)]
1523
#![feature(extend_one)]
24+
#![feature(get_mut_unchecked)]
1625
#![feature(hash_raw_entry)]
1726
#![feature(hasher_prefixfree_extras)]
27+
#![feature(lazy_cell)]
28+
#![feature(lint_reasons)]
29+
#![feature(macro_metavar_expr)]
1830
#![feature(maybe_uninit_uninit_array)]
1931
#![feature(min_specialization)]
32+
#![feature(negative_impls)]
2033
#![feature(never_type)]
21-
#![feature(type_alias_impl_trait)]
2234
#![feature(new_uninit)]
23-
#![feature(lazy_cell)]
35+
#![feature(ptr_alignment_type)]
2436
#![feature(rustc_attrs)]
25-
#![feature(negative_impls)]
37+
#![feature(strict_provenance)]
2638
#![feature(test)]
2739
#![feature(thread_id_value)]
28-
#![feature(vec_into_raw_parts)]
29-
#![feature(allocator_api)]
30-
#![feature(get_mut_unchecked)]
31-
#![feature(lint_reasons)]
40+
#![feature(type_alias_impl_trait)]
3241
#![feature(unwrap_infallible)]
33-
#![feature(strict_provenance)]
34-
#![feature(ptr_alignment_type)]
35-
#![feature(macro_metavar_expr)]
36-
#![allow(rustc::default_hash_types)]
37-
#![allow(rustc::potential_query_instability)]
38-
#![deny(rustc::untranslatable_diagnostic)]
39-
#![deny(rustc::diagnostic_outside_of_impl)]
40-
#![allow(internal_features)]
41-
#![deny(unsafe_op_in_unsafe_fn)]
42+
#![feature(vec_into_raw_parts)]
4243

4344
#[macro_use]
4445
extern crate tracing;
4546
#[macro_use]
46-
extern crate cfg_if;
47-
#[macro_use]
4847
extern crate rustc_macros;
4948

5049
use std::fmt;

compiler/rustc_data_structures/src/marker.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
cfg_if!(
2-
if #[cfg(not(parallel_compiler))] {
1+
cfg_match! {
2+
cfg(not(parallel_compiler)) => {
33
pub auto trait DynSend {}
44
pub auto trait DynSync {}
55

66
impl<T> DynSend for T {}
77
impl<T> DynSync for T {}
8-
} else {
8+
}
9+
_ => {
910
#[rustc_on_unimplemented(
1011
message = "`{Self}` doesn't implement `DynSend`. \
1112
Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Send`"
@@ -48,13 +49,9 @@ cfg_if!(
4849
[std::io::StdoutLock<'_>]
4950
[std::io::StderrLock<'_>]
5051
);
51-
cfg_if!(
52-
// Consistent with `std`
53-
// `os_imp::Env` is `!Send` in these platforms
54-
if #[cfg(any(unix, target_os = "hermit", target_os = "wasi", target_os = "solid_asp3"))] {
55-
impl !DynSend for std::env::VarsOs {}
56-
}
57-
);
52+
53+
#[cfg(any(unix, target_os = "hermit", target_os = "wasi", target_os = "solid_asp3"))]
54+
impl !DynSend for std::env::VarsOs {}
5855

5956
macro_rules! already_send {
6057
($([$ty: ty])*) => {
@@ -123,13 +120,9 @@ cfg_if!(
123120
[std::sync::mpsc::Receiver<T> where T]
124121
[std::sync::mpsc::Sender<T> where T]
125122
);
126-
cfg_if!(
127-
// Consistent with `std`
128-
// `os_imp::Env` is `!Sync` in these platforms
129-
if #[cfg(any(unix, target_os = "hermit", target_os = "wasi", target_os = "solid_asp3"))] {
130-
impl !DynSync for std::env::VarsOs {}
131-
}
132-
);
123+
124+
#[cfg(any(unix, target_os = "hermit", target_os = "wasi", target_os = "solid_asp3"))]
125+
impl !DynSync for std::env::VarsOs {}
133126

134127
macro_rules! already_sync {
135128
($([$ty: ty])*) => {
@@ -183,7 +176,7 @@ cfg_if!(
183176
[thin_vec::ThinVec<T> where T: DynSync]
184177
);
185178
}
186-
);
179+
}
187180

188181
pub fn assert_dyn_sync<T: ?Sized + DynSync>() {}
189182
pub fn assert_dyn_send<T: ?Sized + DynSend>() {}

compiler/rustc_data_structures/src/profiling.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,8 @@ fn get_thread_id() -> u32 {
859859
}
860860

861861
// Memory reporting
862-
cfg_if! {
863-
if #[cfg(windows)] {
862+
cfg_match! {
863+
cfg(windows) => {
864864
pub fn get_resident_set_size() -> Option<usize> {
865865
use std::mem;
866866

@@ -885,7 +885,8 @@ cfg_if! {
885885

886886
Some(pmc.WorkingSetSize)
887887
}
888-
} else if #[cfg(target_os = "macos")] {
888+
}
889+
cfg(target_os = "macos") => {
889890
pub fn get_resident_set_size() -> Option<usize> {
890891
use libc::{c_int, c_void, getpid, proc_pidinfo, proc_taskinfo, PROC_PIDTASKINFO};
891892
use std::mem;
@@ -903,7 +904,8 @@ cfg_if! {
903904
}
904905
}
905906
}
906-
} else if #[cfg(unix)] {
907+
}
908+
cfg(unix) => {
907909
pub fn get_resident_set_size() -> Option<usize> {
908910
let field = 1;
909911
let contents = fs::read("/proc/self/statm").ok()?;
@@ -912,7 +914,8 @@ cfg_if! {
912914
let npages = s.parse::<usize>().ok()?;
913915
Some(npages * 4096)
914916
}
915-
} else {
917+
}
918+
_ => {
916919
pub fn get_resident_set_size() -> Option<usize> {
917920
None
918921
}

compiler/rustc_data_structures/src/sync.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ mod mode {
109109

110110
pub use mode::{is_dyn_thread_safe, set_dyn_thread_safe_mode};
111111

112-
cfg_if! {
113-
if #[cfg(not(parallel_compiler))] {
112+
cfg_match! {
113+
cfg(not(parallel_compiler)) => {
114114
use std::ops::Add;
115115
use std::cell::Cell;
116116

@@ -251,7 +251,8 @@ cfg_if! {
251251
MTLock(self.0.clone())
252252
}
253253
}
254-
} else {
254+
}
255+
_ => {
255256
pub use std::marker::Send as Send;
256257
pub use std::marker::Sync as Sync;
257258

compiler/rustc_span/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ rustc_index = { path = "../rustc_index" }
1313
rustc_arena = { path = "../rustc_arena" }
1414
scoped-tls = "1.0"
1515
unicode-width = "0.1.4"
16-
cfg-if = "1.0"
1716
tracing = "0.1"
1817
sha1 = "0.10.0"
1918
sha2 = "0.10.1"

compiler/rustc_span/src/analyze_source_file.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ pub fn analyze_source_file(
3333
(lines, multi_byte_chars, non_narrow_chars)
3434
}
3535

36-
cfg_if::cfg_if! {
37-
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
36+
cfg_match! {
37+
cfg(any(target_arch = "x86", target_arch = "x86_64")) => {
3838
fn analyze_source_file_dispatch(src: &str,
3939
lines: &mut Vec<RelativeBytePos>,
4040
multi_byte_chars: &mut Vec<MultiByteChar>,
@@ -172,8 +172,8 @@ cfg_if::cfg_if! {
172172
non_narrow_chars);
173173
}
174174
}
175-
} else {
176-
175+
}
176+
_ => {
177177
// The target (or compiler version) does not support SSE2 ...
178178
fn analyze_source_file_dispatch(src: &str,
179179
lines: &mut Vec<RelativeBytePos>,

0 commit comments

Comments
 (0)