From c42314b09b0226309add750ec00f4eeff7f736ac Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 29 Jul 2021 06:29:46 +0900 Subject: [PATCH 1/2] Remove unnecessary `extern crate`s --- src/ffi.md | 19 +------------------ src/panic-handler.md | 6 +----- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/ffi.md b/src/ffi.md index 8012bbc..825be5a 100644 --- a/src/ffi.md +++ b/src/ffi.md @@ -21,8 +21,6 @@ libc = "0.2.0" [libc]: https://crates.io/crates/libc -and add `extern crate libc;` to your crate root. - ## Calling foreign functions The following is a minimal example of calling a foreign function which will @@ -30,7 +28,6 @@ compile if snappy is installed: ```rust,ignore -extern crate libc; use libc::size_t; #[link(name = "snappy")] @@ -64,7 +61,6 @@ The `extern` block can be extended to cover the entire snappy API: ```rust,ignore -extern crate libc; use libc::{c_int, size_t}; #[link(name = "snappy")] @@ -100,7 +96,6 @@ the allocated memory. The length is less than or equal to the capacity. ```rust,ignore -# extern crate libc; # use libc::{c_int, size_t}; # unsafe fn snappy_validate_compressed_buffer(_: *const u8, _: size_t) -> c_int { 0 } # fn main() {} @@ -125,7 +120,6 @@ the true length after compression for setting the length. ```rust,ignore -# extern crate libc; # use libc::{size_t, c_int}; # unsafe fn snappy_compress(a: *const u8, b: size_t, c: *mut u8, # d: *mut size_t) -> c_int { 0 } @@ -152,7 +146,6 @@ format and `snappy_uncompressed_length` will retrieve the exact buffer size requ ```rust,ignore -# extern crate libc; # use libc::{size_t, c_int}; # unsafe fn snappy_uncompress(compressed: *const u8, # compressed_length: size_t, @@ -187,7 +180,6 @@ Then, we can add some tests to show how to use them. ```rust,ignore -# extern crate libc; # use libc::{c_int, size_t}; # unsafe fn snappy_compress(input: *const u8, # input_length: size_t, @@ -208,7 +200,7 @@ Then, we can add some tests to show how to use them. # compressed_length: size_t) # -> c_int { 0 } # fn main() { } - +# #[cfg(test)] mod tests { use super::*; @@ -460,8 +452,6 @@ blocks with the `static` keyword: ```rust,ignore -extern crate libc; - #[link(name = "readline")] extern { static rl_readline_version: libc::c_int; @@ -479,8 +469,6 @@ them. ```rust,ignore -extern crate libc; - use std::ffi::CString; use std::ptr; @@ -512,8 +500,6 @@ conventions. Rust provides a way to tell the compiler which convention to use: ```rust,ignore -extern crate libc; - #[cfg(all(target_os = "win32", target_arch = "x86"))] #[link(name = "kernel32")] #[allow(non_snake_case)] @@ -624,7 +610,6 @@ we have function pointers flying across the FFI boundary in both directions. ```rust,ignore -extern crate libc; use libc::c_int; # #[cfg(hidden)] @@ -724,8 +709,6 @@ We can represent this in Rust with the `c_void` type: ```rust,ignore -extern crate libc; - extern "C" { pub fn foo(arg: *mut libc::c_void); pub fn bar(arg: *mut libc::c_void); diff --git a/src/panic-handler.md b/src/panic-handler.md index 3b48dba..cd3ce95 100644 --- a/src/panic-handler.md +++ b/src/panic-handler.md @@ -54,7 +54,6 @@ fn panic(info: &PanicInfo) -> ! { ```rust,ignore - #![no_std] use core::panic::PanicInfo; @@ -67,9 +66,8 @@ fn panic(_info: &PanicInfo) -> ! { `app` crate: - + ```rust,ignore - #![no_std] // dev profile @@ -80,8 +78,6 @@ extern crate panic_semihosting; #[cfg(not(debug_assertions))] extern crate panic_halt; -// omitted: other `extern crate`s - fn main() { // .. } From 3e8f80c6ccc35113fa955b64a6465e6c8afc0d80 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 29 Jul 2021 06:30:07 +0900 Subject: [PATCH 2/2] Note that this book is edition 2018 --- src/intro.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/intro.md b/src/intro.md index 5ada80e..c6ca90f 100644 --- a/src/intro.md +++ b/src/intro.md @@ -39,5 +39,7 @@ Topics that are within the scope of this book include: the meaning of (un)safety 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. +Unless otherwise noted, Rust code in this book uses the Rust 2018 edition. + [trpl]: ../book/index.html [ref]: ../reference/index.html