Skip to content

Commit 0f66e31

Browse files
committed
Rollup merge of rust-lang#22295 - steveklabnik:gh9980, r=alexcrichton
Fixes rust-lang#9980
2 parents db4a167 + ece19bf commit 0f66e31

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/doc/trpl/ffi.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ fn main() {
420420
```
421421

422422
Alternatively, you may need to alter global state provided by a foreign
423-
interface. To do this, statics can be declared with `mut` so rust can mutate
423+
interface. To do this, statics can be declared with `mut` so we can mutate
424424
them.
425425

426426
```no_run
@@ -436,12 +436,19 @@ extern {
436436
437437
fn main() {
438438
let prompt = CString::from_slice(b"[my-awesome-shell] $");
439-
unsafe { rl_prompt = prompt.as_ptr(); }
440-
// get a line, process it
441-
unsafe { rl_prompt = ptr::null(); }
439+
unsafe {
440+
rl_prompt = prompt.as_ptr();
441+
442+
println!("{}", rl_prompt);
443+
444+
rl_prompt = ptr::null();
445+
}
442446
}
443447
```
444448

449+
Note that all interaction with a `static mut` is unsafe, both reading and
450+
writing. Dealing with global mutable state requires a great deal of care.
451+
445452
# Foreign calling conventions
446453

447454
Most foreign code exposes a C ABI, and Rust uses the platform's C calling convention by default when

0 commit comments

Comments
 (0)