Skip to content

Commit 2cc2a5f

Browse files
cjlongoriafacebook-github-bot
authored andcommitted
applying rustfix to fbcode
Summary: applying changes to make code compatible for both 2021 and 2024 rust editions Reviewed By: dtolnay Differential Revision: D74498804 fbshipit-source-id: 4bab03965e061d1b09090f581508da0055af7e47
1 parent 7620391 commit 2cc2a5f

15 files changed

Lines changed: 81 additions & 81 deletions

File tree

below/btrfs/src/btrfs_api/utils.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ impl<T: Sized, const N: usize> DerefMut for WithMemAfter<T, N> {
7272
///
7373
/// Refer to the documentation of `core::ptr::const_ptr::add()`.
7474
pub unsafe fn get_and_move(ptr: &mut *const u8, n: usize) -> *const u8 {
75-
let res = *ptr;
76-
*ptr = (*ptr).add(n);
77-
res
75+
unsafe {
76+
let res = *ptr;
77+
*ptr = (*ptr).add(n);
78+
res
79+
}
7880
}
7981

8082
/// # Safety
8183
///
8284
/// Refer to the documentation of `get_and_move()`.
8385
pub unsafe fn get_and_move_typed<T: Sized>(ptr: &mut *const u8) -> *const T {
84-
get_and_move(ptr, std::mem::size_of::<T>()) as *const T
86+
unsafe { get_and_move(ptr, std::mem::size_of::<T>()) as *const T }
8587
}

below/cgroupfs/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl std::fmt::Display for MemNodes {
184184
}
185185

186186
macro_rules! impl_read_pressure {
187-
( $fn:ident, $e:expr, $typ:tt, FullPressureSupported ) => {
187+
( $fn:ident, $e:expr_2021, $typ:tt, FullPressureSupported ) => {
188188
/// Read $typ
189189
pub fn $fn(&self) -> Result<$typ> {
190190
let (some_pressure, full_pressure_opt, file_name) =
@@ -197,7 +197,7 @@ macro_rules! impl_read_pressure {
197197
})
198198
}
199199
};
200-
( $fn:ident, $e:expr, $typ:tt, FullPressureMaybeSupported ) => {
200+
( $fn:ident, $e:expr_2021, $typ:tt, FullPressureMaybeSupported ) => {
201201
/// Read $typ
202202
pub fn $fn(&self) -> Result<$typ> {
203203
let (some_pressure, full_pressure_opt, _) = impl_read_pressure!(Internal, &self, $e);
@@ -207,7 +207,7 @@ macro_rules! impl_read_pressure {
207207
})
208208
}
209209
};
210-
( Internal, $self:expr, $e:expr) => {{
210+
( Internal, $self:expr_2021, $e:expr_2021) => {{
211211
let file_name = concat!($e, ".pressure");
212212
let mut pressure = PressureMetrics::read($self, file_name)?;
213213
(
@@ -221,7 +221,7 @@ macro_rules! impl_read_pressure {
221221
}
222222

223223
macro_rules! parse_and_set_fields {
224-
($struct:expr; $key:expr; $value:expr; [ $($field:ident,)+ ]) => (
224+
($struct:expr_2021; $key:expr_2021; $value:expr_2021; [ $($field:ident,)+ ]) => (
225225
match $key {
226226
$(stringify!($field) => $struct.$field = Some($value),)*
227227
_ => (),
@@ -656,7 +656,7 @@ trait KVRead: Sized {
656656
// corresponding field is left as `None`. If lines include fields that
657657
// are not listed, they are ignored.
658658
macro_rules! key_values_format {
659-
($struct:ident; $file:expr; [ $( $field:ident ),+ ]) => (
659+
($struct:ident; $file:expr_2021; [ $( $field:ident ),+ ]) => (
660660
impl KVRead for $struct {
661661
fn read(r: &CgroupReader) -> Result<$struct> {
662662
let mut s = $struct::default();
@@ -767,7 +767,7 @@ struct AllowsEmpty(bool);
767767
struct AllowsPressureEOpNotSupp(bool);
768768

769769
macro_rules! name_key_equal_value_format {
770-
($struct:ident; $allows_empty:expr; $allows_pressure_eopnotsupp:expr; [ $($field:ident,)+ ]) => (
770+
($struct:ident; $allows_empty:expr_2021; $allows_pressure_eopnotsupp:expr_2021; [ $($field:ident,)+ ]) => (
771771
impl NameKVRead for $struct {
772772
fn read<P: AsRef<Path> + AsPath + Clone>(r: &CgroupReader, file_name: P) -> Result<BTreeMap<String, $struct>> {
773773
let mut map = BTreeMap::new();

below/common/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const BELOW_RC: &str = "/.config/below/belowrc";
3030
/// 4th, and so on calls.
3131
#[macro_export]
3232
macro_rules! every_n {
33-
($n:expr, $ex:expr) => {{
33+
($n:expr_2021, $ex:expr_2021) => {{
3434
static COUNT: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
3535
let p = COUNT.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
3636
if p % ($n) == 0 {

below/dump/src/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,8 @@ fn test_dump_queue_content() {
10061006

10071007
// we are dumping timestamps assuming they are local time
10081008
// so the timezone needs to be set to the expected TZ
1009-
std::env::set_var("TZ", "US/Pacific");
1009+
// TODO: Audit that the environment access only happens in single-threaded code.
1010+
unsafe { std::env::set_var("TZ", "US/Pacific") };
10101011

10111012
let result = queue_dumper
10121013
.dump_model(&ctx, &model, &mut queue_content, &mut round, false)

below/ethtool/src/ethtool_sys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ impl<T> __IncompleteArrayField<T> {
3333
}
3434
#[inline]
3535
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
36-
::std::slice::from_raw_parts(self.as_ptr(), len)
36+
unsafe { ::std::slice::from_raw_parts(self.as_ptr(), len) }
3737
}
3838
#[inline]
3939
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
40-
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
40+
unsafe { ::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) }
4141
}
4242
}
4343
impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {

below/model/src/collector.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ fn collect_cgroup_sample(
471471
}
472472

473473
macro_rules! usec_pct {
474-
($a_opt:expr, $b_opt:expr, $delta:expr) => {{
474+
($a_opt:expr_2021, $b_opt:expr_2021, $delta:expr_2021) => {{
475475
let mut ret = None;
476476
if let (Some(a), Some(b)) = ($a_opt, $b_opt) {
477477
if a <= b {
@@ -483,7 +483,7 @@ macro_rules! usec_pct {
483483
}
484484

485485
macro_rules! count_per_sec {
486-
($a_opt:expr, $b_opt:expr, $delta:expr) => {{
486+
($a_opt:expr_2021, $b_opt:expr_2021, $delta:expr_2021) => {{
487487
let mut ret = None;
488488
if let (Some(a), Some(b)) = ($a_opt, $b_opt) {
489489
if a <= b {
@@ -492,14 +492,14 @@ macro_rules! count_per_sec {
492492
}
493493
ret
494494
}};
495-
($a:ident, $b:ident, $delta:expr, $target_type:ty) => {{
495+
($a:ident, $b:ident, $delta:expr_2021, $target_type:ty) => {{
496496
let mut ret = None;
497497
if $a <= $b {
498498
ret = Some((($b - $a) as f64 / $delta.as_secs_f64()).ceil() as $target_type);
499499
}
500500
ret
501501
}};
502-
($a_opt:expr, $b_opt:expr, $delta:expr, $target_type:ty) => {{
502+
($a_opt:expr_2021, $b_opt:expr_2021, $delta:expr_2021, $target_type:ty) => {{
503503
let mut ret = None;
504504
if let (Some(a), Some(b)) = ($a_opt, $b_opt) {
505505
if a <= b {

below/model/src/process.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use super::*;
1616

1717
/// Folds two optionals together with either `+` operator or provided closure
1818
macro_rules! fold_optionals {
19-
($left:expr, $right:expr) => {
19+
($left:expr_2021, $right:expr_2021) => {
2020
fold_optionals!($left, $right, |l, r| l + r)
2121
};
2222

23-
($left:expr, $right:expr, $f:expr) => {
23+
($left:expr_2021, $right:expr_2021, $f:expr_2021) => {
2424
match ($left, $right) {
2525
(Some(l), Some(r)) => Some($f(l, r)),
2626
(Some(l), None) => Some(l.clone()),

below/procfs/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ macro_rules! parse_item {
112112
// Parse rhs (an option, usually from an iterator) into type $t or
113113
// report a parse error on $line otherwise
114114
// Returns a Result<Option<$t>>
115-
($path:expr, $rhs:expr, $t:tt, $line:ident) => {
115+
($path:expr_2021, $rhs:expr_2021, $t:tt, $line:ident) => {
116116
if let Some(s) = $rhs {
117117
s.parse::<$t>()
118118
.map_err(|_| Error::ParseError {
@@ -128,7 +128,7 @@ macro_rules! parse_item {
128128
};
129129
// Parse the second item of $line as type $t with the same
130130
// semantics as above
131-
($path: expr, $line:ident, $t:tt) => {{
131+
($path: expr_2021, $line:ident, $t:tt) => {{
132132
let mut items = $line.split_ascii_whitespace();
133133

134134
// Advance past the name
@@ -139,19 +139,19 @@ macro_rules! parse_item {
139139
}
140140

141141
macro_rules! parse_usec {
142-
($path:expr, $rhs:expr, $line:ident) => {
142+
($path:expr_2021, $rhs:expr_2021, $line:ident) => {
143143
parse_item!($path, $rhs, u64, $line).map(|opt| opt.map(|v| v * *MICROS_PER_TICK))
144144
};
145145
}
146146

147147
macro_rules! parse_sec {
148-
($path:expr, $rhs:expr, $line:ident) => {
148+
($path:expr_2021, $rhs:expr_2021, $line:ident) => {
149149
parse_item!($path, $rhs, u64, $line).map(|opt| opt.map(|v| v / *TICKS_PER_SECOND))
150150
};
151151
}
152152

153153
macro_rules! parse_kb {
154-
($path:expr, $rhs:expr, $line:ident) => {
154+
($path:expr_2021, $rhs:expr_2021, $line:ident) => {
155155
parse_item!($path, $rhs, u64, $line).map(|opt| opt.map(|v| v * 1024))
156156
};
157157
}

below/src/main.rs

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,9 @@ fn real_main(init: init::InitToken) {
666666
let rc = match cmd {
667667
Command::External(command) => commands::run_command(init, debug, below_config, command),
668668
Command::Live {
669-
ref interval_s,
670-
ref host,
671-
ref port,
669+
interval_s,
670+
host,
671+
port,
672672
} => {
673673
let host = host.clone();
674674
let port = *port;
@@ -692,15 +692,15 @@ fn real_main(init: init::InitToken) {
692692
)
693693
}
694694
Command::Record {
695-
ref interval_s,
696-
ref retain_for_s,
697-
ref store_size_limit,
698-
ref collect_io_stat,
699-
ref port,
700-
ref skew_detection_threshold_ms,
701-
ref disable_disk_stat,
702-
ref disable_exitstats,
703-
ref compress_opts,
695+
interval_s,
696+
retain_for_s,
697+
store_size_limit,
698+
collect_io_stat,
699+
port,
700+
skew_detection_threshold_ms,
701+
disable_disk_stat,
702+
disable_exitstats,
703+
compress_opts,
704704
} => {
705705
logutil::set_current_log_target(logutil::TargetLog::Term);
706706
run(
@@ -728,11 +728,11 @@ fn real_main(init: init::InitToken) {
728728
)
729729
}
730730
Command::Replay {
731-
ref time,
732-
ref host,
733-
ref port,
734-
ref yesterdays,
735-
ref snapshot,
731+
time,
732+
host,
733+
port,
734+
yesterdays,
735+
snapshot,
736736
} => {
737737
let time = time.clone();
738738
let host = host.clone();
@@ -759,12 +759,12 @@ fn real_main(init: init::InitToken) {
759759
)
760760
}
761761
Command::Snapshot {
762-
ref begin,
763-
ref end,
764-
ref duration,
765-
ref output,
766-
ref host,
767-
ref port,
762+
begin,
763+
end,
764+
duration,
765+
output,
766+
host,
767+
port,
768768
} => {
769769
let begin = begin.clone();
770770
let end = end.clone();
@@ -791,8 +791,8 @@ fn real_main(init: init::InitToken) {
791791
},
792792
)
793793
}
794-
Command::Debug { ref cmd } => match cmd {
795-
DebugCommand::DumpStore { ref time, ref json } => {
794+
Command::Debug { cmd } => match cmd {
795+
DebugCommand::DumpStore { time, json } => {
796796
let time = time.clone();
797797
let json = *json;
798798
run(
@@ -804,14 +804,14 @@ fn real_main(init: init::InitToken) {
804804
)
805805
}
806806
DebugCommand::ConvertStore {
807-
ref begin,
808-
ref end,
809-
ref duration,
810-
ref from_store_dir,
811-
ref to_store_dir,
812-
ref host,
813-
ref port,
814-
ref compress_opts,
807+
begin,
808+
end,
809+
duration,
810+
from_store_dir,
811+
to_store_dir,
812+
host,
813+
port,
814+
compress_opts,
815815
} => {
816816
let begin = begin.clone();
817817
let end = end.clone();
@@ -843,10 +843,10 @@ fn real_main(init: init::InitToken) {
843843
}
844844
},
845845
Command::Dump {
846-
ref host,
847-
ref port,
848-
ref snapshot,
849-
ref cmd,
846+
host,
847+
port,
848+
snapshot,
849+
cmd,
850850
} => {
851851
let store_dir = below_config.store_dir.clone();
852852
let host = host.clone();
@@ -863,10 +863,7 @@ fn real_main(init: init::InitToken) {
863863
},
864864
)
865865
}
866-
Command::GenerateCompletions {
867-
ref shell,
868-
ref output,
869-
} => {
866+
Command::GenerateCompletions { shell, output } => {
870867
generate_completions(*shell, output.clone())
871868
.unwrap_or_else(|_| panic!("Failed to generate completions for {:?}", shell));
872869
0
@@ -1134,7 +1131,7 @@ fn live_local(
11341131
if let Err(e) = bump_memlock_rlimit() {
11351132
warn!(
11361133
logger,
1137-
#"V",
1134+
# "V",
11381135
"Failed to initialize BPF: {}. Data collection will be degraded. \
11391136
You can ignore this warning or try to run with sudo.",
11401137
&e

0 commit comments

Comments
 (0)