Skip to content

Commit 5023ba0

Browse files
authored
Merge pull request #288 from JohnTitor/audit-ignore
Audit `ignore` annotations
2 parents 5de61f9 + 5e78961 commit 5023ba0

33 files changed

+128
-32
lines changed

src/aliasing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ and `output` overlap, such as `compute(&x, &mut x)`.
5656

5757
With that input, we could get this execution:
5858

59+
<!-- ignore: expanded code -->
5960
```rust,ignore
6061
// input == output == 0xabad1dea
6162
// *input == *output == 20

src/arc-mutex/arc-base.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ We'll first need a way to construct an `Arc<T>`.
1010
This is pretty simple, as we just need to box the `ArcInner<T>` and get a
1111
`NonNull<T>` pointer to it.
1212

13+
<!-- ignore: simplified code -->
1314
```rust,ignore
1415
impl<T> Arc<T> {
1516
pub fn new(data: T) -> Arc<T> {
@@ -41,6 +42,7 @@ This is okay because:
4142
if it is the only `Arc` referencing that data (which only happens in `Drop`)
4243
* We use atomics for the shared mutable reference counting
4344

45+
<!-- ignore: simplified code -->
4446
```rust,ignore
4547
unsafe impl<T: Sync + Send> Send for Arc<T> {}
4648
unsafe impl<T: Sync + Send> Sync for Arc<T> {}
@@ -61,6 +63,8 @@ as `Rc` is not thread-safe.
6163
To dereference the `NonNull<T>` pointer into a `&T`, we can call
6264
`NonNull::as_ref`. This is unsafe, unlike the typical `as_ref` function, so we
6365
must call it like this:
66+
67+
<!-- ignore: simplified code -->
6468
```rust,ignore
6569
unsafe { self.ptr.as_ref() }
6670
```
@@ -79,11 +83,15 @@ to the data inside?
7983
What we need now is an implementation of `Deref`.
8084

8185
We'll need to import the trait:
86+
87+
<!-- ignore: simplified code -->
8288
```rust,ignore
8389
use std::ops::Deref;
8490
```
8591

8692
And here's the implementation:
93+
94+
<!-- ignore: simplified code -->
8795
```rust,ignore
8896
impl<T> Deref for Arc<T> {
8997
type Target = T;
@@ -101,6 +109,8 @@ Pretty simple, eh? This simply dereferences the `NonNull` pointer to the
101109
## Code
102110

103111
Here's all the code from this section:
112+
113+
<!-- ignore: simplified code -->
104114
```rust,ignore
105115
use std::ops::Deref;
106116

src/arc-mutex/arc-clone.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ Basically, we need to:
99

1010
First, we need to get access to the `ArcInner`:
1111

12+
<!-- ignore: simplified code -->
1213
```rust,ignore
1314
let inner = unsafe { self.ptr.as_ref() };
1415
```
1516

1617
We can update the atomic reference count as follows:
1718

19+
<!-- ignore: simplified code -->
1820
```rust,ignore
1921
let old_rc = inner.rc.fetch_add(1, Ordering::???);
2022
```
@@ -30,13 +32,14 @@ ordering, see [the section on atomics](../atomics.md).
3032

3133
Thus, the code becomes this:
3234

35+
<!-- ignore: simplified code -->
3336
```rust,ignore
3437
let old_rc = inner.rc.fetch_add(1, Ordering::Relaxed);
3538
```
3639

3740
We'll need to add another import to use `Ordering`:
3841

39-
```rust,ignore
42+
```rust
4043
use std::sync::atomic::Ordering;
4144
```
4245

@@ -61,6 +64,7 @@ machines) incrementing the reference count at once. This is what we'll do.
6164

6265
It's pretty simple to implement this behavior:
6366

67+
<!-- ignore: simplified code -->
6468
```rust,ignore
6569
if old_rc >= isize::MAX as usize {
6670
std::process::abort();
@@ -69,6 +73,7 @@ if old_rc >= isize::MAX as usize {
6973

7074
Then, we need to return a new instance of the `Arc`:
7175

76+
<!-- ignore: simplified code -->
7277
```rust,ignore
7378
Self {
7479
ptr: self.ptr,
@@ -78,6 +83,7 @@ Self {
7883

7984
Now, let's wrap this all up inside the `Clone` implementation:
8085

86+
<!-- ignore: simplified code -->
8187
```rust,ignore
8288
use std::sync::atomic::Ordering;
8389

src/arc-mutex/arc-drop.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Basically, we need to:
1515

1616
First, we'll need to get access to the `ArcInner`:
1717

18+
<!-- ignore: simplified code -->
1819
```rust,ignore
1920
let inner = unsafe { self.ptr.as_ref() };
2021
```
@@ -24,6 +25,7 @@ also return if the returned value from `fetch_sub` (the value of the reference
2425
count before decrementing it) is not equal to `1` (which happens when we are not
2526
the last reference to the data).
2627

28+
<!-- ignore: simplified code -->
2729
```rust,ignore
2830
if inner.rc.fetch_sub(1, Ordering::Relaxed) != 1 {
2931
return;
@@ -63,20 +65,17 @@ implementation of `Arc`][3]:
6365

6466
To do this, we do the following:
6567

66-
```rust,ignore
67-
atomic::fence(Ordering::Acquire);
68-
```
69-
70-
We'll need to import `std::sync::atomic` itself:
71-
72-
```rust,ignore
68+
```rust
69+
# use std::sync::atomic::Ordering;
7370
use std::sync::atomic;
71+
atomic::fence(Ordering::Acquire);
7472
```
7573

7674
Finally, we can drop the data itself. We use `Box::from_raw` to drop the boxed
7775
`ArcInner<T>` and its data. This takes a `*mut T` and not a `NonNull<T>`, so we
7876
must convert using `NonNull::as_ptr`.
7977

78+
<!-- ignore: simplified code -->
8079
```rust,ignore
8180
unsafe { Box::from_raw(self.ptr.as_ptr()); }
8281
```
@@ -86,6 +85,7 @@ pointer is valid.
8685

8786
Now, let's wrap this all up inside the `Drop` implementation:
8887

88+
<!-- ignore: simplified code -->
8989
```rust,ignore
9090
impl<T> Drop for Arc<T> {
9191
fn drop(&mut self) {

src/arc-mutex/arc-layout.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ same allocation.
2222

2323
Naively, it would look something like this:
2424

25-
```rust,ignore
25+
```rust
2626
use std::sync::atomic;
2727

2828
pub struct Arc<T> {
@@ -31,7 +31,7 @@ pub struct Arc<T> {
3131

3232
pub struct ArcInner<T> {
3333
rc: atomic::AtomicUsize,
34-
data: T
34+
data: T,
3535
}
3636
```
3737

@@ -56,18 +56,18 @@ ownership of a value of `ArcInner<T>` (which itself contains some `T`).
5656

5757
With these changes we get our final structure:
5858

59-
```rust,ignore
59+
```rust
6060
use std::marker::PhantomData;
6161
use std::ptr::NonNull;
6262
use std::sync::atomic::AtomicUsize;
6363

6464
pub struct Arc<T> {
6565
ptr: NonNull<ArcInner<T>>,
66-
phantom: PhantomData<ArcInner<T>>
66+
phantom: PhantomData<ArcInner<T>>,
6767
}
6868

6969
pub struct ArcInner<T> {
7070
rc: AtomicUsize,
71-
data: T
71+
data: T,
7272
}
7373
```

src/atomics.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ exactly what we said but, you know, fast. Wouldn't that be great?
2727
Compilers fundamentally want to be able to do all sorts of complicated
2828
transformations to reduce data dependencies and eliminate dead code. In
2929
particular, they may radically change the actual order of events, or make events
30-
never occur! If we write something like
30+
never occur! If we write something like:
3131

32+
<!-- ignore: simplified code -->
3233
```rust,ignore
3334
x = 1;
3435
y = 3;
3536
x = 2;
3637
```
3738

38-
The compiler may conclude that it would be best if your program did
39+
The compiler may conclude that it would be best if your program did:
3940

41+
<!-- ignore: simplified code -->
4042
```rust,ignore
4143
x = 2;
4244
y = 3;

src/destructors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
What the language *does* provide is full-blown automatic destructors through the
44
`Drop` trait, which provides the following method:
55

6+
<!-- ignore: function header -->
67
```rust,ignore
78
fn drop(&mut self);
89
```

src/dropck.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ when we talked about `'a: 'b`, it was ok for `'a` to live _exactly_ as long as
88
gets dropped at the same time as another, right? This is why we used the
99
following desugaring of `let` statements:
1010

11+
<!-- ignore: simplified code -->
1112
```rust,ignore
1213
let x;
1314
let y;
1415
```
1516

17+
desugaring to:
18+
19+
<!-- ignore: desugared code -->
1620
```rust,ignore
1721
{
1822
let x;
@@ -29,6 +33,7 @@ definition. There are some more details about order of drop in [RFC 1857][rfc185
2933

3034
Let's do this:
3135

36+
<!-- ignore: simplified code -->
3237
```rust,ignore
3338
let tuple = (vec![], vec![]);
3439
```
@@ -259,7 +264,8 @@ lifetime `'b` and that the only uses of `T` will be moves or drops, but omit
259264
the attribute from `'a` and `U`, because we do access data with that lifetime
260265
and that type:
261266

262-
```rust,ignore
267+
```rust
268+
#![feature(dropck_eyepatch)]
263269
use std::fmt::Display;
264270

265271
struct Inspector<'a, 'b, T, U: Display>(&'a u8, &'b u8, T, U);
@@ -283,7 +289,7 @@ other avenues for such indirect access.)
283289

284290
Here is an example of invoking a callback:
285291

286-
```rust,ignore
292+
```rust
287293
struct Inspector<T>(T, &'static str, Box<for <'r> fn(&'r T) -> String>);
288294

289295
impl<T> Drop for Inspector<T> {
@@ -297,7 +303,7 @@ impl<T> Drop for Inspector<T> {
297303

298304
Here is an example of a trait method call:
299305

300-
```rust,ignore
306+
```rust
301307
use std::fmt;
302308

303309
struct Inspector<T: fmt::Display>(T, &'static str);

src/exception-safety.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ needs to be careful and consider exception safety.
3535
`Vec::push_all` is a temporary hack to get extending a Vec by a slice reliably
3636
efficient without specialization. Here's a simple implementation:
3737

38+
<!-- ignore: simplified code -->
3839
```rust,ignore
3940
impl<T: Clone> Vec<T> {
4041
fn push_all(&mut self, to_push: &[T]) {
@@ -75,7 +76,6 @@ bubble_up(heap, index):
7576
while index != 0 && heap[index] < heap[parent(index)]:
7677
heap.swap(index, parent(index))
7778
index = parent(index)
78-
7979
```
8080

8181
A literal transcription of this code to Rust is totally fine, but has an annoying
@@ -147,6 +147,7 @@ way to do this is to store the algorithm's state in a separate struct with a
147147
destructor for the "finally" logic. Whether we panic or not, that destructor
148148
will run and clean up after us.
149149

150+
<!-- ignore: simplified code -->
150151
```rust,ignore
151152
struct Hole<'a, T: 'a> {
152153
data: &'a mut [T],

src/exotic-sizes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ other is still UB).
139139

140140
The following *could* also compile:
141141

142-
```rust,ignore
142+
```rust,compile_fail
143143
enum Void {}
144144
145145
let res: Result<u32, Void> = Ok(0);

0 commit comments

Comments
 (0)