diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6bee5dc2d6f47..d472a4e270c59 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,6 +20,7 @@ jobs: run: | cargo fmt --check rustfmt --check build_system/mod.rs + rustfmt --check example/* test: diff --git a/example/arbitrary_self_types_pointers_and_wrappers.rs b/example/arbitrary_self_types_pointers_and_wrappers.rs index d270fec6b7115..f7edfa960a229 100644 --- a/example/arbitrary_self_types_pointers_and_wrappers.rs +++ b/example/arbitrary_self_types_pointers_and_wrappers.rs @@ -3,8 +3,8 @@ #![feature(arbitrary_self_types, unsize, coerce_unsized, dispatch_from_dyn)] use std::{ - ops::{Deref, CoerceUnsized, DispatchFromDyn}, marker::Unsize, + ops::{CoerceUnsized, Deref, DispatchFromDyn}, }; struct Ptr(Box); @@ -33,7 +33,6 @@ impl Deref for Wrapper { impl, U> CoerceUnsized> for Wrapper {} impl, U> DispatchFromDyn> for Wrapper {} - trait Trait { // This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable // without unsized_locals), but wrappers around `Self` currently are not. diff --git a/example/dst-field-align.rs b/example/dst-field-align.rs index 6c338e99912ec..22fc6ff33e33f 100644 --- a/example/dst-field-align.rs +++ b/example/dst-field-align.rs @@ -2,7 +2,7 @@ #![allow(dead_code)] struct Foo { a: u16, - b: T + b: T, } trait Bar { @@ -10,58 +10,57 @@ trait Bar { } impl Bar for usize { - fn get(&self) -> usize { *self } + fn get(&self) -> usize { + *self + } } struct Baz { - a: T + a: T, } struct HasDrop { ptr: Box, - data: T + data: T, } fn main() { // Test that zero-offset works properly - let b : Baz = Baz { a: 7 }; + let b: Baz = Baz { a: 7 }; assert_eq!(b.a.get(), 7); - let b : &Baz = &b; + let b: &Baz = &b; assert_eq!(b.a.get(), 7); // Test that the field is aligned properly - let f : Foo = Foo { a: 0, b: 11 }; + let f: Foo = Foo { a: 0, b: 11 }; assert_eq!(f.b.get(), 11); - let ptr1 : *const u8 = &f.b as *const _ as *const u8; + let ptr1: *const u8 = &f.b as *const _ as *const u8; - let f : &Foo = &f; - let ptr2 : *const u8 = &f.b as *const _ as *const u8; + let f: &Foo = &f; + let ptr2: *const u8 = &f.b as *const _ as *const u8; assert_eq!(f.b.get(), 11); // The pointers should be the same assert_eq!(ptr1, ptr2); // Test that nested DSTs work properly - let f : Foo> = Foo { a: 0, b: Foo { a: 1, b: 17 }}; + let f: Foo> = Foo { a: 0, b: Foo { a: 1, b: 17 } }; assert_eq!(f.b.b.get(), 17); - let f : &Foo> = &f; + let f: &Foo> = &f; assert_eq!(f.b.b.get(), 17); // Test that get the pointer via destructuring works - let f : Foo = Foo { a: 0, b: 11 }; - let f : &Foo = &f; + let f: Foo = Foo { a: 0, b: 11 }; + let f: &Foo = &f; let &Foo { a: _, b: ref bar } = f; assert_eq!(bar.get(), 11); // Make sure that drop flags don't screw things up - let d : HasDrop> = HasDrop { - ptr: Box::new(0), - data: Baz { a: [1,2,3,4] } - }; - assert_eq!([1,2,3,4], d.data.a); + let d: HasDrop> = HasDrop { ptr: Box::new(0), data: Baz { a: [1, 2, 3, 4] } }; + assert_eq!([1, 2, 3, 4], d.data.a); - let d : &HasDrop> = &d; - assert_eq!(&[1,2,3,4], &d.data.a); + let d: &HasDrop> = &d; + assert_eq!(&[1, 2, 3, 4], &d.data.a); } diff --git a/example/example.rs b/example/example.rs index d5c122bf681ff..885e55bc76423 100644 --- a/example/example.rs +++ b/example/example.rs @@ -11,11 +11,7 @@ pub fn abc(a: u8) -> u8 { } pub fn bcd(b: bool, a: u8) -> u8 { - if b { - a * 2 - } else { - a * 3 - } + if b { a * 2 } else { a * 3 } } pub fn call() { diff --git a/example/issue-72793.rs b/example/issue-72793.rs index b1bb9b8e1e730..166b006004385 100644 --- a/example/issue-72793.rs +++ b/example/issue-72793.rs @@ -2,7 +2,9 @@ #![feature(type_alias_impl_trait)] -trait T { type Item; } +trait T { + type Item; +} type Alias<'a> = impl T; diff --git a/example/issue-91827-extern-types.rs b/example/issue-91827-extern-types.rs index 039100696331b..6f39c5edcad20 100644 --- a/example/issue-91827-extern-types.rs +++ b/example/issue-91827-extern-types.rs @@ -40,10 +40,7 @@ impl ListImpl { } } -pub static A: ListImpl = ListImpl { - len: 3, - data: [5, 6, 7], -}; +pub static A: ListImpl = ListImpl { len: 3, data: [5, 6, 7] }; pub static A_REF: &'static List = A.as_list(); pub static A_TAIL_OFFSET: isize = tail_offset(A.as_list()); diff --git a/example/mini_core.rs b/example/mini_core.rs index 73b83b89f6d91..5792ccd7cea90 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -37,13 +37,13 @@ impl, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} pub trait DispatchFromDyn {} // &T -> &U -impl<'a, T: ?Sized+Unsize, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {} +impl<'a, T: ?Sized + Unsize, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {} // &mut T -> &mut U -impl<'a, T: ?Sized+Unsize, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {} +impl<'a, T: ?Sized + Unsize, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {} // *const T -> *const U -impl, U: ?Sized> DispatchFromDyn<*const U> for *const T {} +impl, U: ?Sized> DispatchFromDyn<*const U> for *const T {} // *mut T -> *mut U -impl, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {} +impl, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {} impl, U: ?Sized> DispatchFromDyn> for Box {} #[lang = "receiver"] @@ -288,7 +288,6 @@ impl PartialEq for u32 { } } - impl PartialEq for u64 { fn eq(&self, other: &u64) -> bool { (*self) == (*other) @@ -361,7 +360,7 @@ impl PartialEq for *const T { } } -impl PartialEq for Option { +impl PartialEq for Option { fn eq(&self, other: &Self) -> bool { match (self, other) { (Some(lhs), Some(rhs)) => *lhs == *rhs, @@ -472,7 +471,11 @@ pub fn panic(_msg: &'static str) -> ! { #[track_caller] fn panic_bounds_check(index: usize, len: usize) -> ! { unsafe { - libc::printf("index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, len, index); + libc::printf( + "index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, + len, + index, + ); intrinsics::abort(); } } @@ -599,7 +602,7 @@ pub mod libc { // functions. legacy_stdio_definitions.lib which provides the printf wrapper functions as normal // symbols to link against. #[cfg_attr(unix, link(name = "c"))] - #[cfg_attr(target_env="msvc", link(name="legacy_stdio_definitions"))] + #[cfg_attr(target_env = "msvc", link(name = "legacy_stdio_definitions"))] extern "C" { pub fn printf(format: *const i8, ...) -> i32; } @@ -638,7 +641,7 @@ impl Index for [T] { } } -extern { +extern "C" { type VaListImpl; } @@ -648,23 +651,33 @@ pub struct VaList<'a>(&'a mut VaListImpl); #[rustc_builtin_macro] #[rustc_macro_transparency = "semitransparent"] -pub macro stringify($($t:tt)*) { /* compiler built-in */ } +pub macro stringify($($t:tt)*) { + /* compiler built-in */ +} #[rustc_builtin_macro] #[rustc_macro_transparency = "semitransparent"] -pub macro file() { /* compiler built-in */ } +pub macro file() { + /* compiler built-in */ +} #[rustc_builtin_macro] #[rustc_macro_transparency = "semitransparent"] -pub macro line() { /* compiler built-in */ } +pub macro line() { + /* compiler built-in */ +} #[rustc_builtin_macro] #[rustc_macro_transparency = "semitransparent"] -pub macro cfg() { /* compiler built-in */ } +pub macro cfg() { + /* compiler built-in */ +} #[rustc_builtin_macro] #[rustc_macro_transparency = "semitransparent"] -pub macro global_asm() { /* compiler built-in */ } +pub macro global_asm() { + /* compiler built-in */ +} pub static A_STATIC: u8 = 42; diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 6ad3268e70dd2..867e2a149078d 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -524,264 +524,42 @@ pub enum E1 { // Computing the discriminant used to be done using the niche type (here `u8`, // from the `bool` field of `V1`), overflowing for variants with large enough // indices (`V3` and `V4`), causing them to be interpreted as other variants. +#[rustfmt::skip] pub enum E2 { V1 { f: bool }, - /*_00*/ _01(X), - _02(X), - _03(X), - _04(X), - _05(X), - _06(X), - _07(X), - _08(X), - _09(X), - _0A(X), - _0B(X), - _0C(X), - _0D(X), - _0E(X), - _0F(X), - _10(X), - _11(X), - _12(X), - _13(X), - _14(X), - _15(X), - _16(X), - _17(X), - _18(X), - _19(X), - _1A(X), - _1B(X), - _1C(X), - _1D(X), - _1E(X), - _1F(X), - _20(X), - _21(X), - _22(X), - _23(X), - _24(X), - _25(X), - _26(X), - _27(X), - _28(X), - _29(X), - _2A(X), - _2B(X), - _2C(X), - _2D(X), - _2E(X), - _2F(X), - _30(X), - _31(X), - _32(X), - _33(X), - _34(X), - _35(X), - _36(X), - _37(X), - _38(X), - _39(X), - _3A(X), - _3B(X), - _3C(X), - _3D(X), - _3E(X), - _3F(X), - _40(X), - _41(X), - _42(X), - _43(X), - _44(X), - _45(X), - _46(X), - _47(X), - _48(X), - _49(X), - _4A(X), - _4B(X), - _4C(X), - _4D(X), - _4E(X), - _4F(X), - _50(X), - _51(X), - _52(X), - _53(X), - _54(X), - _55(X), - _56(X), - _57(X), - _58(X), - _59(X), - _5A(X), - _5B(X), - _5C(X), - _5D(X), - _5E(X), - _5F(X), - _60(X), - _61(X), - _62(X), - _63(X), - _64(X), - _65(X), - _66(X), - _67(X), - _68(X), - _69(X), - _6A(X), - _6B(X), - _6C(X), - _6D(X), - _6E(X), - _6F(X), - _70(X), - _71(X), - _72(X), - _73(X), - _74(X), - _75(X), - _76(X), - _77(X), - _78(X), - _79(X), - _7A(X), - _7B(X), - _7C(X), - _7D(X), - _7E(X), - _7F(X), - _80(X), - _81(X), - _82(X), - _83(X), - _84(X), - _85(X), - _86(X), - _87(X), - _88(X), - _89(X), - _8A(X), - _8B(X), - _8C(X), - _8D(X), - _8E(X), - _8F(X), - _90(X), - _91(X), - _92(X), - _93(X), - _94(X), - _95(X), - _96(X), - _97(X), - _98(X), - _99(X), - _9A(X), - _9B(X), - _9C(X), - _9D(X), - _9E(X), - _9F(X), - _A0(X), - _A1(X), - _A2(X), - _A3(X), - _A4(X), - _A5(X), - _A6(X), - _A7(X), - _A8(X), - _A9(X), - _AA(X), - _AB(X), - _AC(X), - _AD(X), - _AE(X), - _AF(X), - _B0(X), - _B1(X), - _B2(X), - _B3(X), - _B4(X), - _B5(X), - _B6(X), - _B7(X), - _B8(X), - _B9(X), - _BA(X), - _BB(X), - _BC(X), - _BD(X), - _BE(X), - _BF(X), - _C0(X), - _C1(X), - _C2(X), - _C3(X), - _C4(X), - _C5(X), - _C6(X), - _C7(X), - _C8(X), - _C9(X), - _CA(X), - _CB(X), - _CC(X), - _CD(X), - _CE(X), - _CF(X), - _D0(X), - _D1(X), - _D2(X), - _D3(X), - _D4(X), - _D5(X), - _D6(X), - _D7(X), - _D8(X), - _D9(X), - _DA(X), - _DB(X), - _DC(X), - _DD(X), - _DE(X), - _DF(X), - _E0(X), - _E1(X), - _E2(X), - _E3(X), - _E4(X), - _E5(X), - _E6(X), - _E7(X), - _E8(X), - _E9(X), - _EA(X), - _EB(X), - _EC(X), - _ED(X), - _EE(X), - _EF(X), - _F0(X), - _F1(X), - _F2(X), - _F3(X), - _F4(X), - _F5(X), - _F6(X), - _F7(X), - _F8(X), - _F9(X), - _FA(X), - _FB(X), - _FC(X), - _FD(X), - _FE(X), - _FF(X), + /*_00*/ _01(X), _02(X), _03(X), _04(X), _05(X), _06(X), _07(X), + _08(X), _09(X), _0A(X), _0B(X), _0C(X), _0D(X), _0E(X), _0F(X), + _10(X), _11(X), _12(X), _13(X), _14(X), _15(X), _16(X), _17(X), + _18(X), _19(X), _1A(X), _1B(X), _1C(X), _1D(X), _1E(X), _1F(X), + _20(X), _21(X), _22(X), _23(X), _24(X), _25(X), _26(X), _27(X), + _28(X), _29(X), _2A(X), _2B(X), _2C(X), _2D(X), _2E(X), _2F(X), + _30(X), _31(X), _32(X), _33(X), _34(X), _35(X), _36(X), _37(X), + _38(X), _39(X), _3A(X), _3B(X), _3C(X), _3D(X), _3E(X), _3F(X), + _40(X), _41(X), _42(X), _43(X), _44(X), _45(X), _46(X), _47(X), + _48(X), _49(X), _4A(X), _4B(X), _4C(X), _4D(X), _4E(X), _4F(X), + _50(X), _51(X), _52(X), _53(X), _54(X), _55(X), _56(X), _57(X), + _58(X), _59(X), _5A(X), _5B(X), _5C(X), _5D(X), _5E(X), _5F(X), + _60(X), _61(X), _62(X), _63(X), _64(X), _65(X), _66(X), _67(X), + _68(X), _69(X), _6A(X), _6B(X), _6C(X), _6D(X), _6E(X), _6F(X), + _70(X), _71(X), _72(X), _73(X), _74(X), _75(X), _76(X), _77(X), + _78(X), _79(X), _7A(X), _7B(X), _7C(X), _7D(X), _7E(X), _7F(X), + _80(X), _81(X), _82(X), _83(X), _84(X), _85(X), _86(X), _87(X), + _88(X), _89(X), _8A(X), _8B(X), _8C(X), _8D(X), _8E(X), _8F(X), + _90(X), _91(X), _92(X), _93(X), _94(X), _95(X), _96(X), _97(X), + _98(X), _99(X), _9A(X), _9B(X), _9C(X), _9D(X), _9E(X), _9F(X), + _A0(X), _A1(X), _A2(X), _A3(X), _A4(X), _A5(X), _A6(X), _A7(X), + _A8(X), _A9(X), _AA(X), _AB(X), _AC(X), _AD(X), _AE(X), _AF(X), + _B0(X), _B1(X), _B2(X), _B3(X), _B4(X), _B5(X), _B6(X), _B7(X), + _B8(X), _B9(X), _BA(X), _BB(X), _BC(X), _BD(X), _BE(X), _BF(X), + _C0(X), _C1(X), _C2(X), _C3(X), _C4(X), _C5(X), _C6(X), _C7(X), + _C8(X), _C9(X), _CA(X), _CB(X), _CC(X), _CD(X), _CE(X), _CF(X), + _D0(X), _D1(X), _D2(X), _D3(X), _D4(X), _D5(X), _D6(X), _D7(X), + _D8(X), _D9(X), _DA(X), _DB(X), _DC(X), _DD(X), _DE(X), _DF(X), + _E0(X), _E1(X), _E2(X), _E3(X), _E4(X), _E5(X), _E6(X), _E7(X), + _E8(X), _E9(X), _EA(X), _EB(X), _EC(X), _ED(X), _EE(X), _EF(X), + _F0(X), _F1(X), _F2(X), _F3(X), _F4(X), _F5(X), _F6(X), _F7(X), + _F8(X), _F9(X), _FA(X), _FB(X), _FC(X), _FD(X), _FE(X), _FF(X), V3, V4, diff --git a/example/mod_bench.rs b/example/mod_bench.rs index e3e8a3c2d6ab0..83eb69dd504a2 100644 --- a/example/mod_bench.rs +++ b/example/mod_bench.rs @@ -3,15 +3,15 @@ #[cfg_attr(unix, link(name = "c"))] #[cfg_attr(target_env = "msvc", link(name = "msvcrt"))] -extern {} +extern "C" {} #[panic_handler] fn panic_handler(_: &core::panic::PanicInfo) -> ! { core::intrinsics::abort(); } -#[lang="eh_personality"] -fn eh_personality(){} +#[lang = "eh_personality"] +fn eh_personality() {} // Required for rustc_codegen_llvm #[no_mangle] diff --git a/example/std_example.rs b/example/std_example.rs index e34b35d5c4a8c..c86063f60b94d 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -56,7 +56,10 @@ fn main() { assert_eq!(0b0000000000000000000000000010000010000000000000000000000000000000_0000000000100000000000000000000000001000000000000100000000000000u128.leading_zeros(), 26); assert_eq!(0b0000000000000000000000000010000000000000000000000000000000000000_0000000000000000000000000000000000001000000000000000000010000000u128.trailing_zeros(), 7); - assert_eq!(core::intrinsics::saturating_sub(0, -170141183460469231731687303715884105728i128), 170141183460469231731687303715884105727i128); + assert_eq!( + core::intrinsics::saturating_sub(0, -170141183460469231731687303715884105728i128), + 170141183460469231731687303715884105727i128 + ); std::hint::black_box(std::hint::black_box(7571400400375753350092698930310845914i128) * 10); assert!(0i128.checked_div(2i128).is_some()); @@ -113,7 +116,9 @@ fn main() { Box::pin(move |mut _task_context| { yield (); - }).as_mut().resume(0); + }) + .as_mut() + .resume(0); #[derive(Copy, Clone)] enum Nums { @@ -168,7 +173,10 @@ unsafe fn test_simd() { let (zero0, zero1) = std::mem::transmute::<_, (u64, u64)>(x); assert_eq!((zero0, zero1), (0, 0)); assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]); - assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_eq), [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff]); + assert_eq!( + std::mem::transmute::<_, [u16; 8]>(cmp_eq), + [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff] + ); assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_lt), [0, 0, 0, 0, 0, 0, 0, 0]); test_mm_slli_si128(); @@ -182,6 +190,7 @@ unsafe fn test_simd() { test_mm_extract_epi8(); test_mm_insert_epi16(); + #[rustfmt::skip] let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))); assert_eq!(mask1, 1); } @@ -343,7 +352,7 @@ fn test_checked_mul() { #[derive(PartialEq)] enum LoopState { Continue(()), - Break(()) + Break(()), } pub enum Instruction { diff --git a/example/subslice-patterns-const-eval.rs b/example/subslice-patterns-const-eval.rs index 2cb84786f56d0..3c87891666399 100644 --- a/example/subslice-patterns-const-eval.rs +++ b/example/subslice-patterns-const-eval.rs @@ -19,7 +19,9 @@ macro_rules! n { // This macro has an unused variable so that it can be repeated base on the // number of times a repeated variable (`$e` in `z`) occurs. macro_rules! zed { - ($e:expr) => { Z } + ($e:expr) => { + Z + }; } macro_rules! z { @@ -32,12 +34,14 @@ macro_rules! z { macro_rules! compare_evaluation { ($e:expr, $t:ty $(,)?) => {{ const CONST_EVAL: $t = $e; - const fn const_eval() -> $t { $e } + const fn const_eval() -> $t { + $e + } static CONST_EVAL2: $t = const_eval(); let runtime_eval = $e; assert_eq!(CONST_EVAL, runtime_eval); assert_eq!(CONST_EVAL2, runtime_eval); - }} + }}; } // Repeat `$test`, substituting the given macro variables with the given @@ -65,6 +69,7 @@ macro_rules! repeat { } } +#[rustfmt::skip] fn main() { repeat! { ($arr $Ty); n, N; z, Z: