m-ou-se / rust-atomics-and-locks

Code examples, data structures, and links from my book, Rust Atomics and Locks.
Other
1.33k stars 120 forks source link

Redundant indents #58

Closed chengr4 closed 1 month ago

chengr4 commented 1 month ago

Type of error

Formatting error

Location of the error

At https://marabos.nl/atomics/building-arc.html#basic-reference-counting

We know the pointer will always point to a valid ArcData as long as the Arc object exists. However, this is not something the compiler knows or checks for us, so accessing the ArcData through the pointer requires unsafe code. We’ll add a private helper function to get from the Arc to the ArcData, since this is something we’ll have to do several times:

fn data(&self) -> &ArcData<T> {
        unsafe { self.ptr.as_ref() }
    }

Description of the error

Not sure whether this should be reported or not. But I saw redundant indents for

fn data(&self) -> &ArcData<T> {
        unsafe { self.ptr.as_ref() }
}

and beneath

if self.data().ref_count.fetch_add(1, Relaxed) > usize::MAX / 2 {
            std::process::abort();
}
m-ou-se commented 1 month ago

Some code blocks are indented, because they are actually snippets that are part of a larger (indented) block, such as an impl block or a function body.

For example,

    fn data(&self) -> &ArcData<T> {
        unsafe { self.ptr.as_ref() }
    }

is indented one level, because that function definition lives inside the impl Arc<T> { … } block.

chengr4 commented 1 month ago

Got it! Thanks for the explanation