Skip to content

Commit 2fb0c5e

Browse files
committed
Auto merge of #30916 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #30712, #30895, #30902, #30903, #30909, #30910, #30911, #30912, #30914 - Failed merges:
2 parents c12c42d + 6ab39ff commit 2fb0c5e

File tree

9 files changed

+76
-101
lines changed

9 files changed

+76
-101
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ labels to triage issues:
174174
* Yellow, **A**-prefixed labels state which **area** of the project an issue
175175
relates to.
176176

177-
* Magenta, **B**-prefixed labels identify bugs which **belong** elsewhere.
177+
* Magenta, **B**-prefixed labels identify bugs which are **blockers**.
178178

179179
* Green, **E**-prefixed labels explain the level of **experience** necessary
180180
to fix the issue.

src/doc/book/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* [FFI](ffi.md)
5252
* [Borrow and AsRef](borrow-and-asref.md)
5353
* [Release Channels](release-channels.md)
54+
* [Using Rust without the standard library](using-rust-without-the-standard-library.md)
5455
* [Nightly Rust](nightly-rust.md)
5556
* [Compiler Plugins](compiler-plugins.md)
5657
* [Inline Assembly](inline-assembly.md)

src/doc/book/error-handling.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,10 @@ To convert this to proper error handling, we need to do the following:
17951795
Let's try it:
17961796

17971797
```rust,ignore
1798+
use std::error::Error;
1799+
1800+
// The rest of the code before this is unchanged
1801+
17981802
fn search<P: AsRef<Path>>
17991803
(file_path: P, city: &str)
18001804
-> Result<Vec<PopulationCount>, Box<Error+Send+Sync>> {
@@ -1903,8 +1907,13 @@ let city = if !matches.free.is_empty() {
19031907
return;
19041908
};
19051909
1906-
for pop in search(&data_file, &city) {
1907-
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
1910+
match search(&data_file, &city) {
1911+
Ok(pops) => {
1912+
for pop in pops {
1913+
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
1914+
}
1915+
}
1916+
Err(err) => println!("{}", err)
19081917
}
19091918
...
19101919
```
@@ -1927,6 +1936,10 @@ that it is generic on some type parameter `R` that satisfies
19271936
`io::Read`. Another way is to use trait objects:
19281937

19291938
```rust,ignore
1939+
use std::io;
1940+
1941+
// The rest of the code before this is unchanged
1942+
19301943
fn search<P: AsRef<Path>>
19311944
(file_path: &Option<P>, city: &str)
19321945
-> Result<Vec<PopulationCount>, Box<Error+Send+Sync>> {

src/doc/book/no-stdlib.md

+10-89
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
% No stdlib
22

3-
By default, `std` is linked to every Rust crate. In some contexts,
4-
this is undesirable, and can be avoided with the `#![no_std]`
5-
attribute attached to the crate.
3+
Rust’s standard library provides a lot of useful functionality, but assumes
4+
support for various features of its host system: threads, networking, heap
5+
allocation, and others. There are systems that do not have these features,
6+
however, and Rust can work with those too! To do so, we tell Rust that we
7+
don’t want to use the standard library via an attribute: `#![no_std]`.
8+
9+
> Note: This feature is technically stable, but there are some caveats. For
10+
> one, you can build a `#![no_std]` _library_ on stable, but not a _binary_.
11+
> For details on libraries without the standard library, see [the chapter on
12+
> `#![no_std]`](using-rust-without-the-standard-library.html)
613
714
Obviously there's more to life than just libraries: one can use
815
`#[no_std]` with an executable, controlling the entry point is
@@ -77,89 +84,3 @@ personality function (see the
7784
information), but crates which do not trigger a panic can be assured
7885
that this function is never called. The second function, `panic_fmt`, is
7986
also used by the failure mechanisms of the compiler.
80-
81-
## Using libcore
82-
83-
> **Note**: the core library's structure is unstable, and it is recommended to
84-
> use the standard library instead wherever possible.
85-
86-
With the above techniques, we've got a bare-metal executable running some Rust
87-
code. There is a good deal of functionality provided by the standard library,
88-
however, that is necessary to be productive in Rust. If the standard library is
89-
not sufficient, then [libcore](../core/index.html) is designed to be used
90-
instead.
91-
92-
The core library has very few dependencies and is much more portable than the
93-
standard library itself. Additionally, the core library has most of the
94-
necessary functionality for writing idiomatic and effective Rust code. When
95-
using `#![no_std]`, Rust will automatically inject the `core` crate, like
96-
we do for `std` when we’re using it.
97-
98-
As an example, here is a program that will calculate the dot product of two
99-
vectors provided from C, using idiomatic Rust practices.
100-
101-
```rust
102-
# #![feature(libc)]
103-
#![feature(lang_items)]
104-
#![feature(start)]
105-
#![feature(raw)]
106-
#![no_std]
107-
108-
extern crate libc;
109-
110-
use core::mem;
111-
112-
#[no_mangle]
113-
pub extern fn dot_product(a: *const u32, a_len: u32,
114-
b: *const u32, b_len: u32) -> u32 {
115-
use core::raw::Slice;
116-
117-
// Convert the provided arrays into Rust slices.
118-
// The core::raw module guarantees that the Slice
119-
// structure has the same memory layout as a &[T]
120-
// slice.
121-
//
122-
// This is an unsafe operation because the compiler
123-
// cannot tell the pointers are valid.
124-
let (a_slice, b_slice): (&[u32], &[u32]) = unsafe {
125-
mem::transmute((
126-
Slice { data: a, len: a_len as usize },
127-
Slice { data: b, len: b_len as usize },
128-
))
129-
};
130-
131-
// Iterate over the slices, collecting the result
132-
let mut ret = 0;
133-
for (i, j) in a_slice.iter().zip(b_slice.iter()) {
134-
ret += (*i) * (*j);
135-
}
136-
return ret;
137-
}
138-
139-
#[lang = "panic_fmt"]
140-
extern fn panic_fmt(args: &core::fmt::Arguments,
141-
file: &str,
142-
line: u32) -> ! {
143-
loop {}
144-
}
145-
146-
#[lang = "eh_personality"] extern fn eh_personality() {}
147-
# #[start] fn start(argc: isize, argv: *const *const u8) -> isize { 0 }
148-
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
149-
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
150-
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
151-
# fn main() {}
152-
```
153-
154-
Note that there is one lang item here whose signature differs from the examples
155-
above, `panic_fmt`. This must be defined by consumers of libcore because the
156-
core library declares panics, but it does not define it. The `panic_fmt`
157-
lang item is this crate's definition of panic, and it must be guaranteed to
158-
never return.
159-
160-
As can be seen in this example, the core library is intended to provide the
161-
power of Rust in all circumstances, regardless of platform requirements. Further
162-
libraries, such as liballoc, add functionality to libcore which make other
163-
platform-specific assumptions, but continue to be more portable than the
164-
standard library itself.
165-

src/doc/book/the-stack-and-the-heap.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ After `italic()` is over, its frame is deallocated, leaving only `bold()` and
185185
| **3** | **c**|**1** |
186186
| **2** | **b**|**100**|
187187
| **1** | **a**| **5** |
188-
| 0 | x | 42 |
188+
| 0 | x | 42 |
189189

190190
And then `bold()` ends, leaving only `main()`:
191191

@@ -554,8 +554,8 @@ Managing the memory for the stack is trivial: The machine
554554
increments or decrements a single value, the so-called “stack pointer”.
555555
Managing memory for the heap is non-trivial: heap-allocated memory is freed at
556556
arbitrary points, and each block of heap-allocated memory can be of arbitrary
557-
size, the memory manager must generally work much harder to identify memory for
558-
reuse.
557+
size, so the memory manager must generally work much harder to
558+
identify memory for reuse.
559559

560560
If you’d like to dive into this topic in greater detail, [this paper][wilson]
561561
is a great introduction.
@@ -579,4 +579,3 @@ comes at the cost of either significant runtime support (e.g. in the form of a
579579
garbage collector) or significant programmer effort (in the form of explicit
580580
memory management calls that require verification not provided by the Rust
581581
compiler).
582-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
% Using Rust Without the Standard Library
2+
3+
Rust’s standard library provides a lot of useful functionality, but assumes
4+
support for various features of its host system: threads, networking, heap
5+
allocation, and others. There are systems that do not have these features,
6+
however, and Rust can work with those too! To do so, we tell Rust that we
7+
don’t want to use the standard library via an attribute: `#![no_std]`.
8+
9+
> Note: This feature is technically stable, but there are some caveats. For
10+
> one, you can build a `#![no_std]` _library_ on stable, but not a _binary_.
11+
> For details on binaries without the standard library, see [the nightly
12+
> chapter on `#![no_std]`](no-stdlib.html)
13+
14+
To use `#![no_std]`, add a it to your crate root:
15+
16+
```rust
17+
#![no_std]
18+
19+
fn plus_one(x: i32) -> i32 {
20+
x + 1
21+
}
22+
```
23+
24+
Much of the functionality that’s exposed in the standard library is also
25+
available via the [`core` crate](../core/). When we’re using the standard
26+
library, Rust automatically brings `std` into scope, allowing you to use
27+
its features without an explicit import. By the same token, when using
28+
`!#[no_std]`, Rust will bring `core` into scope for you, as well as [its
29+
prelude](../core/prelude/v1/). This means that a lot of code will Just Work:
30+
31+
```rust
32+
#![no_std]
33+
34+
fn may_fail(failure: bool) -> Result<(), &'static str> {
35+
if failure {
36+
Err("this didn’t work!")
37+
} else {
38+
Ok(())
39+
}
40+
}
41+
```

src/liballoc/boxed.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ impl<T: ?Sized> Drop for IntermediateBox<T> {
222222
}
223223

224224
impl<T> Box<T> {
225-
/// Allocates memory on the heap and then moves `x` into it.
225+
/// Allocates memory on the heap and then places `x` into it.
226226
///
227227
/// # Examples
228228
///
229229
/// ```
230-
/// let x = Box::new(5);
230+
/// let five = Box::new(5);
231231
/// ```
232232
#[stable(feature = "rust1", since = "1.0.0")]
233233
#[inline(always)]
@@ -266,7 +266,7 @@ impl<T: ?Sized> Box<T> {
266266
/// # Examples
267267
///
268268
/// ```
269-
/// let seventeen = Box::new(17u32);
269+
/// let seventeen = Box::new(17);
270270
/// let raw = Box::into_raw(seventeen);
271271
/// let boxed_again = unsafe { Box::from_raw(raw) };
272272
/// ```

src/libcore/mem.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn size_of<T>() -> usize {
130130
unsafe { intrinsics::size_of::<T>() }
131131
}
132132

133-
/// Returns the size of the type that `val` points to in bytes.
133+
/// Returns the size of the given value in bytes.
134134
///
135135
/// # Examples
136136
///

src/libstd/num/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod cmath {
6262
pub fn hypotf(x: c_float, y: c_float) -> c_float;
6363
}
6464

65-
// See the comments in `core::float::Float::floor` for why MSVC is special
65+
// See the comments in the `floor` function for why MSVC is special
6666
// here.
6767
#[cfg(not(target_env = "msvc"))]
6868
extern {

0 commit comments

Comments
 (0)