Skip to content

Commit 966e4b3

Browse files
committed
Use functions returning ! in tests
1 parent a9d8264 commit 966e4b3

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

src/expressions/block-expr.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,49 @@ assert_eq!(5, five);
6666
r[expr.block.type.diverging]
6767
A block is itself considered to be [diverging](../divergence.md) if all reachable control flow paths contain a [diverging expression](../divergence.md#r-divergence.diverging-expressions), unless that expression is a place expression that is not read from.
6868

69-
```rust
70-
# #![ feature(never_type) ]
69+
```rust,no_run
7170
# fn make<T>() -> T { loop {} }
72-
let no_control_flow: ! = {
71+
fn no_control_flow() -> ! {
7372
// There are no conditional statements, so this entire block is diverging.
7473
loop {}
75-
};
74+
}
7675
77-
let control_flow_diverging: ! = {
76+
fn control_flow_diverging() -> ! {
7877
// All paths are diverging, so this entire block is diverging.
7978
if true {
8079
loop {}
8180
} else {
8281
loop {}
8382
}
84-
};
83+
}
8584
86-
let control_flow_not_diverging: () = {
85+
fn control_flow_not_diverging() -> () {
8786
// Some paths are not diverging, so this entire block is not diverging.
8887
if true {
8988
()
9089
} else {
9190
loop {}
9291
}
93-
};
92+
}
9493
9594
struct Foo {
9695
x: !,
9796
}
9897
99-
let foo = Foo { x: make() };
100-
let diverging_place_not_read: () = {
98+
fn diverging_place_read() -> () {
99+
let foo = Foo { x: make() };
100+
let _: ! = {
101+
// A read of a place expression produces a diverging block
102+
let _x = foo.x;
103+
};
104+
}
105+
fn diverging_place_not_read() -> () {
106+
let foo = Foo { x: make() };
101107
let _: () = {
102108
// Asssignment to `_` means the place is not read
103109
let _ = foo.x;
104110
};
105-
};
111+
}
106112
```
107113

108114
r[expr.block.value]

src/expressions/if-expr.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,24 @@ assert_eq!(y, "Bigger");
7676
r[expr.if.diverging]
7777
An `if` expression diverges if either the condition expression diverges or if all arms diverge.
7878

79-
```rust
80-
# #![ feature(never_type) ]
81-
// Diverges because the condition expression diverges
82-
let x: ! = if { loop {}; true } {
83-
()
84-
} else {
85-
()
86-
};
79+
```rust,no_run
80+
fn diverging_condition() -> ! {
81+
// Diverges because the condition expression diverges
82+
if { loop {}; true } {
83+
()
84+
} else {
85+
()
86+
}
87+
}
8788
88-
let x: ! = if true {
89-
loop {}
90-
} else {
91-
loop {}
92-
};
89+
fn diverging_arms() -> ! {
90+
// Diverges because all arms diverge
91+
if true {
92+
loop {}
93+
} else {
94+
loop {}
95+
}
96+
}
9397
```
9498

9599
r[expr.if.let]

0 commit comments

Comments
 (0)