Skip to content

Commit 2f7d6a5

Browse files
committed
Merge pull request #30950 from brson/beta-next
Beta next
2 parents 92f74c4 + fa3cc83 commit 2f7d6a5

14 files changed

+322
-128
lines changed

mk/main.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CFG_RELEASE_NUM=1.6.0
1818
# An optional number to put after the label, e.g. '.2' -> '-beta.2'
1919
# NB Make sure it starts with a dot to conform to semver pre-release
2020
# versions (section 9)
21-
CFG_PRERELEASE_VERSION=.2
21+
CFG_PRERELEASE_VERSION=.3
2222

2323
# Append a version-dependent hash to each library, so we can install different
2424
# versions in the same place

src/doc/book/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* [FFI](ffi.md)
5555
* [Borrow and AsRef](borrow-and-asref.md)
5656
* [Release Channels](release-channels.md)
57+
* [Using Rust without the standard library](using-rust-without-the-standard-library.md)
5758
* [Nightly Rust](nightly-rust.md)
5859
* [Compiler Plugins](compiler-plugins.md)
5960
* [Inline Assembly](inline-assembly.md)

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, just 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 extra lang item here which 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-
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/librustc/lint/builtin.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ declare_lint! {
127127
"unit struct or enum variant erroneously allowed to match via path::ident(..)"
128128
}
129129

130+
declare_lint! {
131+
pub RAW_POINTER_DERIVE,
132+
Warn,
133+
"uses of #[derive] with raw pointers are rarely correct"
134+
}
135+
130136
/// Does nothing as a lint pass, but registers some `Lint`s
131137
/// which are used by other parts of the compiler.
132138
#[derive(Copy, Clone)]
@@ -152,7 +158,8 @@ impl LintPass for HardwiredLints {
152158
TRIVIAL_CASTS,
153159
TRIVIAL_NUMERIC_CASTS,
154160
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
155-
CONST_ERR
161+
CONST_ERR,
162+
RAW_POINTER_DERIVE
156163
)
157164
}
158165
}

0 commit comments

Comments
 (0)