rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Remove lazy_static dependency

Open GKFX opened this issue 1 year ago • 4 comments

Split off from rust-lang/rust#124475. The functionality of the lazy_static crate is now available in the standard library as OnceLock. Rustfmt can now use this directly and drop the dependency.

GKFX avatar Apr 28 '24 20:04 GKFX

Thanks for applying the feedback. Can you squash all of these into a single commit when you get a chance.

ytmimi avatar May 02 '24 21:05 ytmimi

Running our Diff Check Job, and assuming this passes we'll be good to go here

ytmimi avatar May 21 '24 00:05 ytmimi

🤔 hmmm the job failed when comparing the output from current HEAD (rustfmt 1.7.0-nightly (d5f1200 2024-05-01)) and your latest commit (rustfmt 1.7.0-nightly (54dfcef 2024-05-02)). Surprisingly, compiling both versions of rustfmt locally and running them produces the same output when run on these input snippets, so I'm not 100% what's going on. I'm rerunning the job.

For reference here's what the diffs looked like:

Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/rustdoc-scrape-examples-macros/src/lib.rs:8:
 
 #[macro_export]
 macro_rules! a_rules_macro {
-  ($e:expr) => { ($e, foobar::f()); }
+    ($e:expr) => {
+        ($e, foobar::f());
+    };
 }
 
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/rustdoc-scrape-examples-macros/examples/ex.rs:8:
 
 #[an_attr_macro]
 fn a() {
-  f(); // no
+    f(); // no
 }
 
 #[an_attr_macro(with_span)]
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/rustdoc-scrape-examples-macros/examples/ex.rs:15:
 fn b() {
-  f(); // yes
+    f(); // yes
 }
 
 fn c() {
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/rustdoc-scrape-examples-macros/examples/ex.rs:20:
-  a_rules_macro!(f()); // yes
+    a_rules_macro!(f()); // yes
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/rustdoc-scrape-examples-whitespace/examples/ex.rs:1:
 struct Foo;
 impl Foo {
-  fn bar() { foobar::ok(); }
+    fn bar() {
+        foobar::ok();
+    }
@ -41252,4 +41230,4 @@ Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/rustdoc-scrape-examples-macr
 fn d() {
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/rustdoc-scrape-examples-macros/examples/ex.rs:24:
-  a_rules_macro!(()); // no
+    a_rules_macro!(()); // no
 fn main() {
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/rustdoc-scrape-examples-whitespace/examples/ex.rs:7:
-  Foo::bar();
+    Foo::bar();
@ -41258,4 +41236,12 @@ Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/rustdoc-scrape-examples-macr
-fn main(){}
+fn main() {}
 
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/wasm-exceptions-nostd/src/arena_alloc.rs:14:
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/wasm-exceptions-nostd/src/lib.rs:1:
 #![no_std]
 #![crate_type = "cdylib"]
-
 // Allow a few unstable features because we create a panic
 // runtime for native wasm exceptions from scratch
-
 #![feature(core_intrinsics)]
 #![feature(lang_items)]
 #![feature(link_llvm_intrinsics)]
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/wasm-exceptions-nostd/src/lib.rs:39:
     let data = 0x1234usize as *mut u8; // Something to recognize
@ -41[26](https://github.com/rust-lang/rustfmt/actions/runs/9166837698/job/25203001180#step:4:27)3,6 +41249,31 @@ Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/wasm-exceptions-nostd/src/ar
 impl ArenaAllocator {
     pub const fn new() -> Self {
-        Self {
-            arena: UnsafeCell::new(Arena::new()),
-        }
+        Self { arena: UnsafeCell::new(Arena::new()) }
     unsafe {
-        core::intrinsics::catch_unwind(|data: *mut u8| {
-            let _log_on_drop = LogOnDrop;
+        core::intrinsics::catch_unwind(
+            |data: *mut u8| {
+                let _log_on_drop = LogOnDrop;
 
-            logging::log_str(&alloc::format!("`r#try` called with ptr {:?}", data));
-            let x = [12];
-            let _ = x[4]; // should panic
+                logging::log_str(&alloc::format!("`r#try` called with ptr {:?}", data));
+                let x = [12];
+                let _ = x[4]; // should panic
 
-            logging::log_str("This line should not be visible! :(");
-        }, data, |data, exception| {
-            let exception = *Box::from_raw(exception as *mut String);
-            logging::log_str("Caught something!");
-            logging::log_str(&alloc::format!("  data     : {:?}", data));
-            logging::log_str(&alloc::format!("  exception: {:?}", exception));
-        });
+                logging::log_str("This line should not be visible! :(");
+            },
+            data,
+            |data, exception| {
+                let exception = *Box::from_raw(exception as *mut String);
+                logging::log_str("Caught something!");
+                logging::log_str(&alloc::format!("  data     : {:?}", data));
+                logging::log_str(&alloc::format!("  exception: {:?}", exception));
+            },
+        );
@ -41[27](https://github.com/rust-lang/rustfmt/actions/runs/9166837698/job/25203001180#step:4:28)0 +41280,0 @@ Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/wasm-exceptions-nostd/src/ar
 }
@ -41272 +41[28](https://github.com/rust-lang/rustfmt/actions/runs/9166837698/job/25203001180#step:4:29)2,4 @@ Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/wasm-exceptions-nostd/src/ar
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/wasm-exceptions-nostd/src/arena_alloc.rs:42:
     logging::log_str("This program terminates correctly.");
Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/wasm-exceptions-nostd/src/panicking.rs:17:
     use alloc::boxed::Box;
     use alloc::string::ToString;
@ -[41](https://github.com/rust-lang/rustfmt/actions/runs/9166837698/job/25203001180#step:4:42)274,10 +41287,8 @@ Diff in /tmp/rust-lang-rust-EDALDBzK/tests/run-make/wasm-exceptions-nostd/src/ar
 impl Arena {
     pub const fn new() -> Self {
-        Self {
-            buf: [0x55; ARENA_SIZE],
-            allocated: 0,
-        }
+        Self { buf: [0x55; ARENA_SIZE], allocated: 0 }
     }
 
     pub unsafe fn alloc(&mut self, layout: Layout) -> *mut u8 {
-    let msg = info
-        .message()
-        .map(|msg| msg.to_string())
-        .unwrap_or("(no message)".to_string());
+    let msg = info.message().map(|msg| msg.to_string()).unwrap_or("(no message)".to_string());
     let exception = Box::new(msg.to_string());
     unsafe {
         let exception_raw = Box::into_raw(exception);

ytmimi avatar May 21 '24 01:05 ytmimi

I think this might just be an issue with the CI job, but I'll need some more time to look into it

ytmimi avatar May 21 '24 03:05 ytmimi

Seems like it was a temporary CI issue, but now the job is passing. Thanks again for your help on this!

ytmimi avatar May 31 '24 13:05 ytmimi