Skip to content

Commit b6449eb

Browse files
committed
Rollup merge of #28753 - steveklabnik:gh28572, r=alexcrichton
This is part of #28572, but doesn't complete it. Amongst other things, this patch: * Increases consistency in the way feature flags are used with other docs. * Removes the ignores, which is nice: we actually had some syntax errors in the examples 😭. * Mentions #![no_core] Realistically, this document used to be in the order of least to most: nothing, then adding core. But with the changes in RFC 1184, this is backwards: it now shows stuff that uses core from the beginning. In the future, I'd like to revamp this to go from 'most to least', but I'd like to see the discussion in #27701 goes before I write more.
2 parents 1c788d0 + 4632ad8 commit b6449eb

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/doc/trpl/no-stdlib.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ By default, `std` is linked to every Rust crate. In some contexts,
44
this is undesirable, and can be avoided with the `#![no_std]`
55
attribute attached to the crate.
66

7-
```ignore
8-
// a minimal library
9-
#![crate_type="lib"]
10-
#![feature(no_std)]
11-
#![no_std]
12-
# // fn main() {} tricked you, rustdoc!
13-
```
14-
157
Obviously there's more to life than just libraries: one can use
168
`#[no_std]` with an executable, controlling the entry point is
179
possible in two ways: the `#[start]` attribute, or overriding the
@@ -21,7 +13,10 @@ The function marked `#[start]` is passed the command line parameters
2113
in the same format as C:
2214

2315
```rust
24-
#![feature(lang_items, start, no_std, libc)]
16+
# #![feature(libc)]
17+
#![feature(lang_items)]
18+
#![feature(start)]
19+
#![feature(no_std)]
2520
#![no_std]
2621

2722
// Pull in the system libc library for what crt0.o likely requires
@@ -47,11 +42,13 @@ with `#![no_main]` and then create the appropriate symbol with the
4742
correct ABI and the correct name, which requires overriding the
4843
compiler's name mangling too:
4944

50-
```ignore
45+
```rust
46+
# #![feature(libc)]
5147
#![feature(no_std)]
48+
#![feature(lang_items)]
49+
#![feature(start)]
5250
#![no_std]
5351
#![no_main]
54-
#![feature(lang_items, start)]
5552

5653
extern crate libc;
5754

@@ -92,19 +89,24 @@ instead.
9289

9390
The core library has very few dependencies and is much more portable than the
9491
standard library itself. Additionally, the core library has most of the
95-
necessary functionality for writing idiomatic and effective Rust code.
92+
necessary functionality for writing idiomatic and effective Rust code. When
93+
using `#![no_std]`, Rust will automatically inject the `core` crate, just like
94+
we do for `std` when we’re using it.
9695

9796
As an example, here is a program that will calculate the dot product of two
9897
vectors provided from C, using idiomatic Rust practices.
9998

100-
```ignore
101-
#![feature(lang_items, start, no_std, core, libc)]
99+
```rust
100+
# #![feature(libc)]
101+
#![feature(lang_items)]
102+
#![feature(start)]
103+
#![feature(no_std)]
104+
#![feature(core)]
105+
#![feature(core_slice_ext)]
106+
#![feature(raw)]
102107
#![no_std]
103108

104-
# extern crate libc;
105-
extern crate core;
106-
107-
use core::prelude::*;
109+
extern crate libc;
108110

109111
use core::mem;
110112

0 commit comments

Comments
 (0)