Skip to content

Commit 4a9c58c

Browse files
committed
Auto merge of #51369 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 7 pull requests Successful merges: - #50852 (Add doc comment to hiding portions of code example) - #51183 (Update rustdoc book to suggest using Termination trait instead of hidden ‘foo’ function) - #51255 (Fix confusing error message for sub_instant) - #51256 (Fix crate-name option in rustdoc) - #51308 (Check array indices in constant propagation) - #51343 (test: Ignore some problematic tests on sparc and sparc64) - #51358 (Tests that #39963 is fixed on MIR borrowck) Failed merges:
2 parents 90f34b5 + d011150 commit 4a9c58c

33 files changed

+141
-48
lines changed

src/doc/rustdoc/src/documentation-tests.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ from your example, but are important to make the tests work. Consider
7979
an example block that looks like this:
8080

8181
```text
82-
/// Some documentation.
83-
# fn foo() {}
82+
/// /// Some documentation.
83+
/// # fn foo() {} // this function will be hidden
84+
/// println!("Hello, World!");
8485
```
8586

8687
It will render like this:
8788

8889
```rust
8990
/// Some documentation.
9091
# fn foo() {}
92+
println!("Hello, World!");
9193
```
9294

9395
Yes, that's right: you can add lines that start with `# `, and they will
@@ -168,37 +170,56 @@ By repeating all parts of the example, you can ensure that your example still
168170
compiles, while only showing the parts that are relevant to that part of your
169171
explanation.
170172
171-
Another case where the use of `#` is handy is when you want to ignore
172-
error handling. Lets say you want the following,
173+
174+
## Using `?` in doc tests
175+
176+
When writing an example, it is rarely useful to include a complete error
177+
handling, as it would add significant amounts of boilerplate code. Instead, you
178+
may want the following:
173179
174180
```ignore
181+
/// ```
175182
/// use std::io;
176183
/// let mut input = String::new();
177184
/// io::stdin().read_line(&mut input)?;
185+
/// ```
178186
```
179187

180-
The problem is that `?` returns a `Result<T, E>` and test functions
181-
don't return anything so this will give a mismatched types error.
188+
The problem is that `?` returns a `Result<T, E>` and test functions don't
189+
return anything, so this will give a mismatched types error.
190+
191+
You can get around this limitation by manually adding a `main` that returns
192+
`Result<T, E>`, because `Result<T, E>` implements the `Termination` trait:
182193

183194
```ignore
184195
/// A doc test using ?
185196
///
186197
/// ```
187198
/// use std::io;
188-
/// # fn foo() -> io::Result<()> {
199+
///
200+
/// fn main() -> io::Result<()> {
201+
/// let mut input = String::new();
202+
/// io::stdin().read_line(&mut input)?;
203+
/// Ok(())
204+
/// }
205+
/// ```
206+
```
207+
208+
Together with the `# ` from the section above, you arrive at a solution that
209+
appears to the reader as the initial idea but works with doc tests:
210+
211+
```ignore
212+
/// ```
213+
/// use std::io;
214+
/// # fn main() -> io::Result<()> {
189215
/// let mut input = String::new();
190216
/// io::stdin().read_line(&mut input)?;
191217
/// # Ok(())
192218
/// # }
193219
/// ```
194-
# fn foo() {}
195220
```
196221

197-
You can get around this by wrapping the code in a function. This catches
198-
and swallows the `Result<T, E>` when running tests on the docs. This
199-
pattern appears regularly in the standard library.
200-
201-
### Documenting macros
222+
## Documenting macros
202223

203224
Here’s an example of documenting a macro:
204225

src/librustc_mir/transform/const_prop.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,6 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> {
240240
) -> Option<Const<'tcx>> {
241241
let span = source_info.span;
242242
match *rvalue {
243-
// No need to overwrite an already evaluated constant
244-
Rvalue::Use(Operand::Constant(box Constant {
245-
literal: Literal::Value {
246-
value: &ty::Const {
247-
val: ConstVal::Value(_),
248-
..
249-
},
250-
},
251-
..
252-
})) => None,
253243
// This branch exists for the sanity type check
254244
Rvalue::Use(Operand::Constant(ref c)) => {
255245
assert_eq!(c.ty, place_ty);

src/librustdoc/core.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ pub fn run_core(search_paths: SearchPaths,
230230

231231
let krate = panictry!(driver::phase_1_parse_input(control, &sess, &input));
232232

233-
let name = ::rustc_codegen_utils::link::find_crate_name(Some(&sess), &krate.attrs, &input);
233+
let name = match crate_name {
234+
Some(ref crate_name) => crate_name.clone(),
235+
None => ::rustc_codegen_utils::link::find_crate_name(Some(&sess), &krate.attrs, &input),
236+
};
234237

235238
let mut crate_loader = CrateLoader::new(&sess, &cstore, &name);
236239

src/libstd/sys/redox/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl Instant {
144144

145145
pub fn sub_instant(&self, other: &Instant) -> Duration {
146146
self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
147-
panic!("other was less than the current instant")
147+
panic!("specified instant was later than self")
148148
})
149149
}
150150

src/libstd/sys/unix/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ mod inner {
289289

290290
pub fn sub_instant(&self, other: &Instant) -> Duration {
291291
self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
292-
panic!("other was less than the current instant")
292+
panic!("specified instant was later than self")
293293
})
294294
}
295295

src/test/codegen/abi-main-signature-16bit-c-int.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// ignore-powerpc64
2323
// ignore-s390x
2424
// ignore-sparc
25+
// ignore-sparc64
2526
// ignore-wasm32
2627
// ignore-x86
2728
// ignore-x86_64

src/test/codegen/fastcall-inreg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// ignore-r600
3030
// ignore-amdgcn
3131
// ignore-sparc
32+
// ignore-sparc64
3233
// ignore-sparcv9
3334
// ignore-sparcel
3435
// ignore-s390x

src/test/codegen/repr-transparent-aggregates-2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// ignore-asmjs
1515
// ignore-mips64
1616
// ignore-s390x
17+
// ignore-sparc
18+
// ignore-sparc64
1719
// ignore-wasm
1820
// ignore-x86
1921
// ignore-x86_64

src/test/codegen/stack-probes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// ignore-mips64
1515
// ignore-powerpc
1616
// ignore-s390x
17+
// ignore-sparc
18+
// ignore-sparc64
1719
// ignore-wasm
1820
// ignore-emscripten
1921
// ignore-windows

src/test/codegen/x86_mmx.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// ignore-emscripten
1414
// ignore-mips
1515
// ignore-mips64
16+
// ignore-sparc
17+
// ignore-sparc64
1618
// compile-flags: -O
1719

1820
#![feature(repr_simd)]

0 commit comments

Comments
 (0)