Skip to content

Commit 2b2baa8

Browse files
celinvalzhassan-awscarolynzech
authored
Run format check in our CI and fix repo format (#205)
Changed the `check-rustc.sh` script to run the format check. Also added a `--bless` mode to apply the changes locally. This change also includes the result of running the script with the `--bless` mode on. Related to #38 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Zyad Hassan <[email protected]> Co-authored-by: Carolyn Zech <[email protected]>
1 parent 1a38674 commit 2b2baa8

32 files changed

+821
-548
lines changed

.github/workflows/rustc.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defaults:
1919
shell: bash
2020

2121
jobs:
22-
build:
22+
upstream_test:
2323
runs-on: ${{ matrix.os }}
2424
strategy:
2525
matrix:
@@ -28,8 +28,8 @@ jobs:
2828
steps:
2929
- name: Checkout Library
3030
uses: actions/checkout@v4
31-
with:
32-
path: head
3331

3432
- name: Run rustc script
35-
run: bash ./head/scripts/check_rustc.sh ${{github.workspace}}/head
33+
env:
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
run: ./scripts/check_rustc.sh

library/alloc/src/collections/vec_deque/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3087,6 +3087,7 @@ impl<T, const N: usize> From<[T; N]> for VecDeque<T> {
30873087
#[unstable(feature = "kani", issue = "none")]
30883088
mod verify {
30893089
use core::kani;
3090+
30903091
use crate::collections::VecDeque;
30913092

30923093
#[kani::proof]
@@ -3120,5 +3121,4 @@ mod verify {
31203121
assert!(deque[k] == arr[k]);
31213122
}
31223123
}
3123-
31243124
}

library/alloc/src/vec/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -4037,15 +4037,15 @@ impl<T, A: Allocator, const N: usize> TryFrom<Vec<T, A>> for [T; N] {
40374037
#[unstable(feature = "kani", issue = "none")]
40384038
mod verify {
40394039
use core::kani;
4040+
40404041
use crate::vec::Vec;
4041-
4042-
// Size chosen for testing the empty vector (0), middle element removal (1)
4043-
// and last element removal (2) cases while keeping verification tractable
4042+
4043+
// Size chosen for testing the empty vector (0), middle element removal (1)
4044+
// and last element removal (2) cases while keeping verification tractable
40444045
const ARRAY_LEN: usize = 3;
40454046

40464047
#[kani::proof]
40474048
pub fn verify_swap_remove() {
4048-
40494049
// Creating a vector directly from a fixed length arbitrary array
40504050
let mut arr: [i32; ARRAY_LEN] = kani::Arbitrary::any_array();
40514051
let mut vect = Vec::from(&arr);
@@ -4067,14 +4067,16 @@ mod verify {
40674067

40684068
// Verifying that the removed index now contains the element originally at the vector's last index if applicable
40694069
if index < original_len - 1 {
4070-
assert!(vect[index] == original_vec[original_len - 1], "Index should contain last element");
4070+
assert!(
4071+
vect[index] == original_vec[original_len - 1],
4072+
"Index should contain last element"
4073+
);
40714074
}
40724075

40734076
// Check that all other unaffected elements remain unchanged
40744077
let k = kani::any_where(|&x: &usize| x < original_len - 1);
40754078
if k != index {
40764079
assert!(vect[k] == arr[k]);
40774080
}
4078-
40794081
}
40804082
}

library/core/src/alloc/layout.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
// collections, resulting in having to optimize down excess IR multiple times.
55
// Your performance intuition is useless. Run perf.
66

7-
use safety::{ensures, Invariant, requires};
7+
use safety::{Invariant, ensures, requires};
8+
9+
#[cfg(kani)]
10+
use crate::cmp;
811
use crate::error::Error;
912
use crate::intrinsics::{unchecked_add, unchecked_mul, unchecked_sub};
10-
use crate::mem::SizedTypeProperties;
11-
use crate::ptr::{Alignment, NonNull};
12-
use crate::{assert_unsafe_precondition, fmt, mem};
13-
1413
#[cfg(kani)]
1514
use crate::kani;
16-
#[cfg(kani)]
17-
use crate::cmp;
18-
15+
use crate::mem::SizedTypeProperties;
16+
use crate::ptr::{Alignment, NonNull};
1917
// Used only for contract verification.
2018
#[allow(unused_imports)]
2119
use crate::ub_checks::Invariant;
20+
use crate::{assert_unsafe_precondition, fmt, mem};
2221

2322
// While this function is used in one place and its implementation
2423
// could be inlined, the previous attempts to do so made rustc
@@ -624,14 +623,15 @@ impl fmt::Display for LayoutError {
624623
}
625624

626625
#[cfg(kani)]
627-
#[unstable(feature="kani", issue="none")]
626+
#[unstable(feature = "kani", issue = "none")]
628627
mod verify {
629628
use super::*;
630629

631630
impl kani::Arbitrary for Layout {
632631
fn any() -> Self {
633632
let align = kani::any::<Alignment>();
634-
let size = kani::any_where(|s: &usize| *s <= isize::MAX as usize - (align.as_usize() - 1));
633+
let size =
634+
kani::any_where(|s: &usize| *s <= isize::MAX as usize - (align.as_usize() - 1));
635635
unsafe { Layout { size, align } }
636636
}
637637
}
@@ -684,8 +684,8 @@ mod verify {
684684
pub fn check_for_value_i32() {
685685
let x = kani::any::<i32>();
686686
let _ = Layout::for_value::<i32>(&x);
687-
let array : [i32; 2] = [1, 2];
688-
let _ = Layout::for_value::<[i32]>(&array[1 .. 1]);
687+
let array: [i32; 2] = [1, 2];
688+
let _ = Layout::for_value::<[i32]>(&array[1..1]);
689689
let trait_ref: &dyn core::fmt::Debug = &x;
690690
let _ = Layout::for_value::<dyn core::fmt::Debug>(trait_ref);
691691
// TODO: the case of an extern type as unsized tail is not yet covered
@@ -724,7 +724,7 @@ mod verify {
724724
pub fn check_padding_needed_for() {
725725
let layout = kani::any::<Layout>();
726726
let a2 = kani::any::<usize>();
727-
if(a2.is_power_of_two() && a2 <= layout.align()) {
727+
if (a2.is_power_of_two() && a2 <= layout.align()) {
728728
let _ = layout.padding_needed_for(a2);
729729
}
730730
}

library/core/src/ascii/ascii_char.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
//! helps with clarity as we're also referring to `char` intentionally in here.
55
66
use safety::{ensures, requires};
7-
use crate::mem::transmute;
8-
use crate::{assert_unsafe_precondition, fmt};
97

108
#[cfg(kani)]
119
use crate::kani;
10+
use crate::mem::transmute;
11+
use crate::{assert_unsafe_precondition, fmt};
1212

1313
/// One of the 128 Unicode characters from U+0000 through U+007F,
1414
/// often known as the [ASCII] subset.
@@ -623,11 +623,12 @@ impl fmt::Debug for AsciiChar {
623623
}
624624

625625
#[cfg(kani)]
626-
#[unstable(feature="kani", issue="none")]
626+
#[unstable(feature = "kani", issue = "none")]
627627
mod verify {
628-
use super::*;
629628
use AsciiChar;
630629

630+
use super::*;
631+
631632
#[kani::proof_for_contract(AsciiChar::from_u8)]
632633
fn check_from_u8() {
633634
let b: u8 = kani::any();

library/core/src/char/convert.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//! Character conversions.
22
3-
use safety::{requires, ensures};
3+
use safety::{ensures, requires};
4+
45
use crate::char::TryFromCharError;
56
use crate::error::Error;
67
use crate::fmt;
8+
#[cfg(kani)]
9+
use crate::kani;
710
use crate::mem::transmute;
811
use crate::str::FromStr;
912
use crate::ub_checks::assert_unsafe_precondition;
1013

11-
#[cfg(kani)]
12-
use crate::kani;
13-
1414
/// Converts a `u32` to a `char`. See [`char::from_u32`].
1515
#[must_use]
1616
#[inline]
@@ -298,7 +298,7 @@ pub(super) const fn from_digit(num: u32, radix: u32) -> Option<char> {
298298
}
299299

300300
#[cfg(kani)]
301-
#[unstable(feature="kani", issue="none")]
301+
#[unstable(feature = "kani", issue = "none")]
302302
mod verify {
303303
use super::*;
304304

library/core/src/char/methods.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
//! impl char {}
22
33
use super::*;
4+
#[cfg(kani)]
5+
use crate::kani;
46
use crate::panic::const_panic;
57
use crate::slice;
68
use crate::str::from_utf8_unchecked_mut;
79
use crate::unicode::printable::is_printable;
810
use crate::unicode::{self, conversions};
911

10-
#[cfg(kani)]
11-
use crate::kani;
12-
1312
impl char {
1413
/// The lowest valid code point a `char` can have, `'\0'`.
1514
///
@@ -1871,19 +1870,20 @@ pub const fn encode_utf16_raw(mut code: u32, dst: &mut [u16]) -> &mut [u16] {
18711870
}
18721871

18731872
#[cfg(kani)]
1874-
#[unstable(feature="kani", issue="none")]
1873+
#[unstable(feature = "kani", issue = "none")]
18751874
mod verify {
1876-
use super::*;
18771875
use safety::ensures;
18781876

1877+
use super::*;
1878+
18791879
#[ensures(|result| c.is_ascii() == (result.is_some() && (result.unwrap() as u8 as char == *c)))]
18801880
fn as_ascii_clone(c: &char) -> Option<ascii::Char> {
18811881
c.as_ascii()
18821882
}
18831883

18841884
#[kani::proof_for_contract(as_ascii_clone)]
18851885
fn check_as_ascii_ascii_char() {
1886-
let ascii: char = kani::any_where(|c : &char| c.is_ascii());
1886+
let ascii: char = kani::any_where(|c: &char| c.is_ascii());
18871887
as_ascii_clone(&ascii);
18881888
}
18891889

library/core/src/ffi/c_str.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
//! [`CStr`] and its related types.
22
3+
use safety::{ensures, requires};
4+
35
use crate::cmp::Ordering;
46
use crate::error::Error;
57
use crate::ffi::c_char;
68
use crate::intrinsics::const_eval_select;
79
use crate::iter::FusedIterator;
10+
#[cfg(kani)]
11+
use crate::kani;
812
use crate::marker::PhantomData;
913
use crate::ptr::NonNull;
1014
use crate::slice::memchr;
11-
use crate::{fmt, ops, slice, str};
12-
use safety::{requires, ensures};
13-
1415
use crate::ub_checks::Invariant;
1516
#[allow(unused_imports)]
1617
use crate::ub_checks::can_dereference;
17-
18-
#[cfg(kani)]
19-
use crate::kani;
18+
use crate::{fmt, ops, slice, str};
2019

2120
// FIXME: because this is doc(inline)d, we *have* to use intra-doc links because the actual link
2221
// depends on where the item is being documented. however, since this is libcore, we can't
@@ -228,7 +227,7 @@ impl Invariant for &CStr {
228227
let bytes: &[c_char] = &self.inner;
229228
let len = bytes.len();
230229

231-
!bytes.is_empty() && bytes[len - 1] == 0 && !bytes[..len-1].contains(&0)
230+
!bytes.is_empty() && bytes[len - 1] == 0 && !bytes[..len - 1].contains(&0)
232231
}
233232
}
234233

@@ -887,7 +886,7 @@ impl FusedIterator for Bytes<'_> {}
887886
#[unstable(feature = "kani", issue = "none")]
888887
mod verify {
889888
use super::*;
890-
889+
891890
// Helper function
892891
fn arbitrary_cstr(slice: &[u8]) -> &CStr {
893892
// At a minimum, the slice has a null terminator to form a valid CStr.
@@ -934,7 +933,7 @@ mod verify {
934933
let len = bytes.len();
935934
assert_eq!(bytes, &slice[..len]);
936935
}
937-
936+
938937
// pub fn bytes(&self) -> Bytes<'_>
939938
#[kani::proof]
940939
#[kani::unwind(32)]
@@ -972,7 +971,7 @@ mod verify {
972971

973972
// pub const fn as_ptr(&self) -> *const c_char
974973
#[kani::proof]
975-
#[kani::unwind(33)]
974+
#[kani::unwind(33)]
976975
fn check_as_ptr() {
977976
const MAX_SIZE: usize = 32;
978977
let string: [u8; MAX_SIZE] = kani::any();
@@ -996,10 +995,10 @@ mod verify {
996995
}
997996
assert!(c_str.is_safe());
998997
}
999-
998+
1000999
// pub const fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, FromBytesWithNulError>
10011000
#[kani::proof]
1002-
#[kani::unwind(17)]
1001+
#[kani::unwind(17)]
10031002
fn check_from_bytes_with_nul() {
10041003
const MAX_SIZE: usize = 16;
10051004
let string: [u8; MAX_SIZE] = kani::any();
@@ -1017,10 +1016,10 @@ mod verify {
10171016
fn check_count_bytes() {
10181017
const MAX_SIZE: usize = 32;
10191018
let mut bytes: [u8; MAX_SIZE] = kani::any();
1020-
1019+
10211020
// Non-deterministically generate a length within the valid range [0, MAX_SIZE]
10221021
let mut len: usize = kani::any_where(|&x| x < MAX_SIZE);
1023-
1022+
10241023
// If a null byte exists before the generated length
10251024
// adjust len to its position
10261025
if let Some(pos) = bytes[..len].iter().position(|&x| x == 0) {
@@ -1029,7 +1028,7 @@ mod verify {
10291028
// If no null byte, insert one at the chosen length
10301029
bytes[len] = 0;
10311030
}
1032-
1031+
10331032
let c_str = CStr::from_bytes_until_nul(&bytes).unwrap();
10341033
// Verify that count_bytes matches the adjusted length
10351034
assert_eq!(c_str.count_bytes(), len);
@@ -1076,7 +1075,9 @@ mod verify {
10761075
let mut string: [u8; MAX_SIZE] = kani::any();
10771076
let ptr = string.as_ptr() as *const c_char;
10781077

1079-
unsafe { super::strlen(ptr); }
1078+
unsafe {
1079+
super::strlen(ptr);
1080+
}
10801081
}
10811082

10821083
// pub const unsafe fn from_ptr<'a>(ptr: *const c_char) -> &'a CStr
@@ -1087,9 +1088,11 @@ mod verify {
10871088
let string: [u8; MAX_SIZE] = kani::any();
10881089
let ptr = string.as_ptr() as *const c_char;
10891090

1090-
unsafe { CStr::from_ptr(ptr); }
1091+
unsafe {
1092+
CStr::from_ptr(ptr);
1093+
}
10911094
}
1092-
1095+
10931096
// pub const fn is_empty(&self) -> bool
10941097
#[kani::proof]
10951098
#[kani::unwind(33)]

library/core/src/mem/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
#![stable(feature = "rust1", since = "1.0.0")]
77

88
use crate::alloc::Layout;
9-
use crate::marker::DiscriminantKind;
10-
use crate::{clone, cmp, fmt, hash, intrinsics, ptr};
11-
129
#[cfg(kani)]
1310
use crate::kani;
11+
use crate::marker::DiscriminantKind;
12+
use crate::{clone, cmp, fmt, hash, intrinsics, ptr};
1413

1514
mod manually_drop;
1615
#[stable(feature = "manually_drop", since = "1.20.0")]
@@ -1372,7 +1371,7 @@ pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) {
13721371
}
13731372

13741373
#[cfg(kani)]
1375-
#[unstable(feature="kani", issue="none")]
1374+
#[unstable(feature = "kani", issue = "none")]
13761375
mod verify {
13771376
use super::*;
13781377
use crate::kani;

0 commit comments

Comments
 (0)