Skip to content

Commit cede907

Browse files
committed
Auto merge of #30155 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #30129, #30134, #30136, #30144, #30150, #30153, #30154 - Failed merges:
2 parents 2f95de3 + 9823511 commit cede907

File tree

11 files changed

+54
-39
lines changed

11 files changed

+54
-39
lines changed

src/doc/book/documentation.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ Let's discuss our sample example documentation:
213213
```
214214

215215
You'll notice that you don't need a `fn main()` or anything here. `rustdoc` will
216-
automatically add a `main()` wrapper around your code, and in the right place.
217-
For example:
216+
automatically add a `main()` wrapper around your code, using heuristics to attempt
217+
to put it in the right place. For example:
218218

219219
```rust
220220
/// ```
@@ -242,11 +242,18 @@ Here's the full algorithm rustdoc uses to preprocess examples:
242242
`unused_attributes`, and `dead_code`. Small examples often trigger
243243
these lints.
244244
3. If the example does not contain `extern crate`, then `extern crate
245-
<mycrate>;` is inserted.
246-
2. Finally, if the example does not contain `fn main`, the remainder of the
247-
text is wrapped in `fn main() { your_code }`
248-
249-
Sometimes, this isn't enough, though. For example, all of these code samples
245+
<mycrate>;` is inserted (note the lack of `#[macro_use]`).
246+
4. Finally, if the example does not contain `fn main`, the remainder of the
247+
text is wrapped in `fn main() { your_code }`.
248+
249+
This generated `fn main` can be a problem! If you have `extern crate` or a `mod`
250+
statements in the example code that are referred to by `use` statements, they will
251+
fail to resolve unless you include at least `fn main() {}` to inhibit step 4.
252+
`#[macro_use] extern crate` also does not work except at the crate root, so when
253+
testing macros an explicit `main` is always required. It doesn't have to clutter
254+
up your docs, though -- keep reading!
255+
256+
Sometimes this algorithm isn't enough, though. For example, all of these code samples
250257
with `///` we've been talking about? The raw text:
251258

252259
```text
@@ -370,8 +377,8 @@ macro_rules! panic_unless {
370377

371378
You’ll note three things: we need to add our own `extern crate` line, so that
372379
we can add the `#[macro_use]` attribute. Second, we’ll need to add our own
373-
`main()` as well. Finally, a judicious use of `#` to comment out those two
374-
things, so they don’t show up in the output.
380+
`main()` as well (for reasons discussed above). Finally, a judicious use of
381+
`#` to comment out those two things, so they don’t show up in the output.
375382

376383
Another case where the use of `#` is handy is when you want to ignore
377384
error handling. Lets say you want the following,

src/doc/book/guessing-game.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,13 @@ Cargo uses the dependencies section to know what dependencies on external
357357
crates you have, and what versions you require. In this case, we’ve specified version `0.3.0`,
358358
which Cargo understands to be any release that’s compatible with this specific version.
359359
Cargo understands [Semantic Versioning][semver], which is a standard for writing version
360-
numbers. If we wanted to use only `0.3.0` exactly, we could use `=0.3.0`. If we
361-
wanted to use the latest version we could use `*`; We could use a range of
362-
versions. [Cargo’s documentation][cargodoc] contains more details.
360+
numbers. A bare number like above is actually shorthand for `^0.3.0`,
361+
meaning "anything compatible with 0.3.0".
362+
If we wanted to use only `0.3.0` exactly, we could say `rand="=0.3.0"`
363+
(note the two equal signs).
364+
And if we wanted to use the latest version we could use `*`.
365+
We could also use a range of versions.
366+
[Cargo’s documentation][cargodoc] contains more details.
363367

364368
[semver]: http://semver.org
365369
[cargodoc]: http://doc.crates.io/crates-io.html
@@ -521,11 +525,11 @@ Please input your guess.
521525
You guessed: 5
522526
```
523527

524-
Great! Next up: let’s compare our guess to the secret guess.
528+
Great! Next up: comparing our guess to the secret number.
525529

526530
# Comparing guesses
527531

528-
Now that we’ve got user input, let’s compare our guess to the random guess.
532+
Now that we’ve got user input, let’s compare our guess to the secret number.
529533
Here’s our next step, though it doesn’t quite compile yet:
530534

531535
```rust,ignore
@@ -775,7 +779,7 @@ fn main() {
775779
```
776780
777781
And try it out. But wait, didn’t we just add an infinite loop? Yup. Remember
778-
our discussion about `parse()`? If we give a non-number answer, we’ll `return`
782+
our discussion about `parse()`? If we give a non-number answer, we’ll `panic!`
779783
and quit. Observe:
780784
781785
```bash

src/librustc/middle/infer/region_inference/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ pub enum RegionResolutionError<'tcx> {
159159
/// like to indicate so to the user.
160160
/// For example, the following function
161161
/// ```
162-
/// struct Foo { bar: int }
163-
/// fn foo2<'a, 'b>(x: &'a Foo) -> &'b int {
162+
/// struct Foo { bar: isize }
163+
/// fn foo2<'a, 'b>(x: &'a Foo) -> &'b isize {
164164
/// &x.bar
165165
/// }
166166
/// ```

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15831583
let r = self.should_warn(var);
15841584
if let Some(name) = r {
15851585

1586-
// annoying: for parameters in funcs like `fn(x: int)
1586+
// annoying: for parameters in funcs like `fn(x: isize)
15871587
// {ret}`, there is only one node, so asking about
15881588
// assigned_on_exit() is not meaningful.
15891589
let is_assigned = if ln == self.s.exit_ln {

src/librustc_borrowck/borrowck/check_loans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,8 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
718718
///
719719
/// For example:
720720
///
721-
/// ```
722-
/// let a: int;
721+
/// ```ignore
722+
/// let a: isize;
723723
/// a = 10; // ok, even though a is uninitialized
724724
///
725725
/// struct Point { x: usize, y: usize }

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,9 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
486486
//! come about when variables of `&mut` type are re-borrowed,
487487
//! as in this example:
488488
//!
489-
//! fn counter<'a>(v: &'a mut Foo) -> &'a mut uint {
489+
//! struct Foo { counter: usize }
490+
//!
491+
//! fn counter<'a>(v: &'a mut Foo) -> &'a mut usize {
490492
//! &mut v.counter
491493
//! }
492494
//!

src/librustc_trans/trans/debuginfo/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
//!
6767
//! ```
6868
//! struct List {
69-
//! value: int,
69+
//! value: isize,
7070
//! tail: Option<Box<List>>,
7171
//! }
7272
//! ```

src/librustc_trans/trans/meth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
456456
/// Generate a shim function that allows an object type like `SomeTrait` to
457457
/// implement the type `SomeTrait`. Imagine a trait definition:
458458
///
459-
/// trait SomeTrait { fn get(&self) -> int; ... }
459+
/// trait SomeTrait { fn get(&self) -> isize; ... }
460460
///
461461
/// And a generic bit of code:
462462
///
@@ -468,7 +468,7 @@ fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
468468
/// What is the value of `x` when `foo` is invoked with `T=SomeTrait`?
469469
/// The answer is that it is a shim function generated by this routine:
470470
///
471-
/// fn shim(t: &SomeTrait) -> int {
471+
/// fn shim(t: &SomeTrait) -> isize {
472472
/// // ... call t.get() virtually ...
473473
/// }
474474
///

src/librustc_typeck/check/regionck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
//! There are a number of troublesome scenarios in the tests
6060
//! `region-dependent-*.rs`, but here is one example:
6161
//!
62-
//! struct Foo { i: int }
62+
//! struct Foo { i: isize }
6363
//! struct Bar { foo: Foo }
6464
//! fn get_i(x: &'a Bar) -> &'a int {
6565
//! let foo = &x.foo; // Lifetime L1
@@ -233,8 +233,8 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
233233
/// Consider this silly example:
234234
///
235235
/// ```
236-
/// fn borrow(x: &int) -> &int {x}
237-
/// fn foo(x: @int) -> int { // block: B
236+
/// fn borrow(x: &int) -> &isize {x}
237+
/// fn foo(x: @int) -> isize { // block: B
238238
/// let b = borrow(x); // region: <R0>
239239
/// *b
240240
/// }
@@ -243,7 +243,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
243243
/// Here, the region of `b` will be `<R0>`. `<R0>` is constrained to be some subregion of the
244244
/// block B and some superregion of the call. If we forced it now, we'd choose the smaller
245245
/// region (the call). But that would make the *b illegal. Since we don't resolve, the type
246-
/// of b will be `&<R0>.int` and then `*b` will require that `<R0>` be bigger than the let and
246+
/// of b will be `&<R0>.isize` and then `*b` will require that `<R0>` be bigger than the let and
247247
/// the `*b` expression, so we will effectively resolve `<R0>` to be the block B.
248248
pub fn resolve_type(&self, unresolved_ty: Ty<'tcx>) -> Ty<'tcx> {
249249
self.fcx.infcx().resolve_type_vars_if_possible(&unresolved_ty)

src/librustc_typeck/variance.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@
172172
//!
173173
//! Now imagine that I have an implementation of `ConvertTo` for `Object`:
174174
//!
175-
//! impl ConvertTo<int> for Object { ... }
175+
//! impl ConvertTo<isize> for Object { ... }
176176
//!
177177
//! And I want to call `convertAll` on an array of strings. Suppose
178178
//! further that for whatever reason I specifically supply the value of
179179
//! `String` for the type parameter `T`:
180180
//!
181181
//! let mut vector = vec!["string", ...];
182-
//! convertAll::<int, String>(vector);
182+
//! convertAll::<isize, String>(vector);
183183
//!
184184
//! Is this legal? To put another way, can we apply the `impl` for
185185
//! `Object` to the type `String`? The answer is yes, but to see why
@@ -190,25 +190,25 @@
190190
//! - It will then call the impl of `convertTo()` that is intended
191191
//! for use with objects. This has the type:
192192
//!
193-
//! fn(self: &Object) -> int
193+
//! fn(self: &Object) -> isize
194194
//!
195195
//! It is ok to provide a value for `self` of type `&String` because
196196
//! `&String <: &Object`.
197197
//!
198198
//! OK, so intuitively we want this to be legal, so let's bring this back
199199
//! to variance and see whether we are computing the correct result. We
200200
//! must first figure out how to phrase the question "is an impl for
201-
//! `Object,int` usable where an impl for `String,int` is expected?"
201+
//! `Object,isize` usable where an impl for `String,isize` is expected?"
202202
//!
203203
//! Maybe it's helpful to think of a dictionary-passing implementation of
204204
//! type classes. In that case, `convertAll()` takes an implicit parameter
205205
//! representing the impl. In short, we *have* an impl of type:
206206
//!
207-
//! V_O = ConvertTo<int> for Object
207+
//! V_O = ConvertTo<isize> for Object
208208
//!
209209
//! and the function prototype expects an impl of type:
210210
//!
211-
//! V_S = ConvertTo<int> for String
211+
//! V_S = ConvertTo<isize> for String
212212
//!
213213
//! As with any argument, this is legal if the type of the value given
214214
//! (`V_O`) is a subtype of the type expected (`V_S`). So is `V_O <: V_S`?
@@ -217,7 +217,7 @@
217217
//! covariant, it means that:
218218
//!
219219
//! V_O <: V_S iff
220-
//! int <: int
220+
//! isize <: isize
221221
//! String <: Object
222222
//!
223223
//! These conditions are satisfied and so we are happy.

src/libstd/env.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,9 @@ pub mod consts {
671671
///
672672
/// Some possible values:
673673
///
674-
/// - .so
675-
/// - .dylib
676-
/// - .dll
674+
/// - so
675+
/// - dylib
676+
/// - dll
677677
#[stable(feature = "env", since = "1.0.0")]
678678
pub const DLL_EXTENSION: &'static str = super::os::DLL_EXTENSION;
679679

@@ -682,7 +682,9 @@ pub mod consts {
682682
///
683683
/// Some possible values:
684684
///
685-
/// - exe
685+
/// - .exe
686+
/// - .nexe
687+
/// - .pexe
686688
/// - `""` (an empty string)
687689
#[stable(feature = "env", since = "1.0.0")]
688690
pub const EXE_SUFFIX: &'static str = super::os::EXE_SUFFIX;

0 commit comments

Comments
 (0)