Skip to content

Commit d1da991

Browse files
authored
Work around a rust-analyzer bug (#855)
1 parent a6793e7 commit d1da991

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/loom.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,15 @@ pub use std::{thread, thread_local};
160160
pub mod cell {
161161
pub use std::cell::*;
162162

163-
#[derive(Debug)]
164163
pub(crate) struct UnsafeCell<T>(core::cell::UnsafeCell<T>);
165164

165+
// this is not derived because it confuses rust-analyzer ... https://github.com/rust-lang/rust-analyzer/issues/19755
166+
impl<T: std::fmt::Debug> std::fmt::Debug for UnsafeCell<T> {
167+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
168+
f.debug_tuple("UnsafeCell").field(&self.0).finish()
169+
}
170+
}
171+
166172
impl<T> UnsafeCell<T> {
167173
pub const fn new(data: T) -> UnsafeCell<T> {
168174
UnsafeCell(core::cell::UnsafeCell::new(data))
@@ -216,9 +222,23 @@ pub mod sync {
216222
}
217223

218224
/// A wrapper around parking-lot's `Condvar` to mirror loom's API.
219-
#[derive(Default, Debug)]
220225
pub struct Condvar(parking_lot::Condvar);
221226

227+
// this is not derived because it confuses rust-analyzer ... https://github.com/rust-lang/rust-analyzer/issues/19755
228+
#[allow(clippy::derivable_impls)]
229+
impl Default for Condvar {
230+
fn default() -> Self {
231+
Self(Default::default())
232+
}
233+
}
234+
235+
// this is not derived because it confuses rust-analyzer ... https://github.com/rust-lang/rust-analyzer/issues/19755
236+
impl std::fmt::Debug for Condvar {
237+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
238+
f.debug_tuple("Condvar").field(&self.0).finish()
239+
}
240+
}
241+
222242
impl Condvar {
223243
pub fn wait<'a, T>(&self, mut guard: MutexGuard<'a, T>) -> MutexGuard<'a, T> {
224244
self.0.wait(&mut guard);

0 commit comments

Comments
 (0)