Skip to content

Commit bf9b837

Browse files
authored
Merge pull request #297 from JohnTitor/say-goodbye-to-extern-crates
Remove unnecessary `extern crate`s
2 parents f51734e + 3e8f80c commit bf9b837

File tree

3 files changed

+4
-23
lines changed

3 files changed

+4
-23
lines changed

src/ffi.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ libc = "0.2.0"
2121

2222
[libc]: https://crates.io/crates/libc
2323

24-
and add `extern crate libc;` to your crate root.
25-
2624
## Calling foreign functions
2725

2826
The following is a minimal example of calling a foreign function which will
2927
compile if snappy is installed:
3028

3129
<!-- ignore: requires libc crate -->
3230
```rust,ignore
33-
extern crate libc;
3431
use libc::size_t;
3532
3633
#[link(name = "snappy")]
@@ -64,7 +61,6 @@ The `extern` block can be extended to cover the entire snappy API:
6461

6562
<!-- ignore: requires libc crate -->
6663
```rust,ignore
67-
extern crate libc;
6864
use libc::{c_int, size_t};
6965
7066
#[link(name = "snappy")]
@@ -100,7 +96,6 @@ the allocated memory. The length is less than or equal to the capacity.
10096

10197
<!-- ignore: requires libc crate -->
10298
```rust,ignore
103-
# extern crate libc;
10499
# use libc::{c_int, size_t};
105100
# unsafe fn snappy_validate_compressed_buffer(_: *const u8, _: size_t) -> c_int { 0 }
106101
# fn main() {}
@@ -125,7 +120,6 @@ the true length after compression for setting the length.
125120

126121
<!-- ignore: requires libc crate -->
127122
```rust,ignore
128-
# extern crate libc;
129123
# use libc::{size_t, c_int};
130124
# unsafe fn snappy_compress(a: *const u8, b: size_t, c: *mut u8,
131125
# d: *mut size_t) -> c_int { 0 }
@@ -152,7 +146,6 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ
152146

153147
<!-- ignore: requires libc crate -->
154148
```rust,ignore
155-
# extern crate libc;
156149
# use libc::{size_t, c_int};
157150
# unsafe fn snappy_uncompress(compressed: *const u8,
158151
# compressed_length: size_t,
@@ -187,7 +180,6 @@ Then, we can add some tests to show how to use them.
187180

188181
<!-- ignore: requires libc crate -->
189182
```rust,ignore
190-
# extern crate libc;
191183
# use libc::{c_int, size_t};
192184
# unsafe fn snappy_compress(input: *const u8,
193185
# input_length: size_t,
@@ -208,7 +200,7 @@ Then, we can add some tests to show how to use them.
208200
# compressed_length: size_t)
209201
# -> c_int { 0 }
210202
# fn main() { }
211-
203+
#
212204
#[cfg(test)]
213205
mod tests {
214206
use super::*;
@@ -460,8 +452,6 @@ blocks with the `static` keyword:
460452

461453
<!-- ignore: requires libc crate -->
462454
```rust,ignore
463-
extern crate libc;
464-
465455
#[link(name = "readline")]
466456
extern {
467457
static rl_readline_version: libc::c_int;
@@ -479,8 +469,6 @@ them.
479469

480470
<!-- ignore: requires libc crate -->
481471
```rust,ignore
482-
extern crate libc;
483-
484472
use std::ffi::CString;
485473
use std::ptr;
486474
@@ -512,8 +500,6 @@ conventions. Rust provides a way to tell the compiler which convention to use:
512500

513501
<!-- ignore: requires libc crate -->
514502
```rust,ignore
515-
extern crate libc;
516-
517503
#[cfg(all(target_os = "win32", target_arch = "x86"))]
518504
#[link(name = "kernel32")]
519505
#[allow(non_snake_case)]
@@ -624,7 +610,6 @@ we have function pointers flying across the FFI boundary in both directions.
624610

625611
<!-- ignore: requires libc crate -->
626612
```rust,ignore
627-
extern crate libc;
628613
use libc::c_int;
629614
630615
# #[cfg(hidden)]
@@ -724,8 +709,6 @@ We can represent this in Rust with the `c_void` type:
724709
725710
<!-- ignore: requires libc crate -->
726711
```rust,ignore
727-
extern crate libc;
728-
729712
extern "C" {
730713
pub fn foo(arg: *mut libc::c_void);
731714
pub fn bar(arg: *mut libc::c_void);

src/intro.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ Topics that are within the scope of this book include: the meaning of (un)safety
3939

4040
The Rustonomicon is not a place to exhaustively describe the semantics and guarantees of every single API in the standard library, nor is it a place to exhaustively describe every feature of Rust.
4141

42+
Unless otherwise noted, Rust code in this book uses the Rust 2018 edition.
43+
4244
[trpl]: ../book/index.html
4345
[ref]: ../reference/index.html

src/panic-handler.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ fn panic(info: &PanicInfo) -> ! {
5454

5555
<!-- ignore: simplified code -->
5656
```rust,ignore
57-
5857
#![no_std]
5958
6059
use core::panic::PanicInfo;
@@ -67,9 +66,8 @@ fn panic(_info: &PanicInfo) -> ! {
6766

6867
`app` crate:
6968

70-
<!-- ignore: requires external crate -->
69+
<!-- ignore: requires the above crates -->
7170
```rust,ignore
72-
7371
#![no_std]
7472
7573
// dev profile
@@ -80,8 +78,6 @@ extern crate panic_semihosting;
8078
#[cfg(not(debug_assertions))]
8179
extern crate panic_halt;
8280
83-
// omitted: other `extern crate`s
84-
8581
fn main() {
8682
// ..
8783
}

0 commit comments

Comments
 (0)