Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errors

Begin fixing all the broken doctests in `compiler/`

Begins to fix #95994.
All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are.
There are also a few that I marked `ignore` that could maybe be made to work but seem less important.
Each `ignore` has a rough "reason" for ignoring after it parentheses, with

- `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax"
- `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy.
- `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR.
- `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup.

Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful.

I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
This commit is contained in:
bors 2022-05-07 06:30:29 +00:00
commit 574830f573
116 changed files with 668 additions and 609 deletions

View file

@ -18,13 +18,13 @@
//! First upvars are stored
//! It is followed by the generator state field.
//! Then finally the MIR locals which are live across a suspension point are stored.
//!
//! ```ignore (illustrative)
//! struct Generator {
//! upvars...,
//! state: u32,
//! mir_locals...,
//! }
//!
//! ```
//! This pass computes the meaning of the state field and the MIR locals which are live
//! across a suspension point. There are however three hardcoded generator states:
//! 0 - Generator have not been resumed yet

View file

@ -14,7 +14,7 @@ pub struct MatchBranchSimplification;
///
/// For example:
///
/// ```rust
/// ```ignore (MIR)
/// bb0: {
/// switchInt(move _3) -> [42_isize: bb1, otherwise: bb2];
/// }
@ -32,7 +32,7 @@ pub struct MatchBranchSimplification;
///
/// into:
///
/// ```rust
/// ```ignore (MIR)
/// bb0: {
/// _2 = Eq(move _3, const 42_isize);
/// goto -> bb3;

View file

@ -12,7 +12,7 @@ use rustc_middle::{
/// Pass to convert `if` conditions on integrals into switches on the integral.
/// For an example, it turns something like
///
/// ```
/// ```ignore (MIR)
/// _3 = Eq(move _4, const 43i32);
/// StorageDead(_4);
/// switchInt(_3) -> [false: bb2, otherwise: bb3];
@ -20,7 +20,7 @@ use rustc_middle::{
///
/// into:
///
/// ```
/// ```ignore (MIR)
/// switchInt(_4) -> [43i32: bb3, otherwise: bb2];
/// ```
pub struct SimplifyComparisonIntegral;

View file

@ -1,10 +1,12 @@
//! The general point of the optimizations provided here is to simplify something like:
//!
//! ```rust
//! # fn foo<T, E>(x: Result<T, E>) -> Result<T, E> {
//! match x {
//! Ok(x) => Ok(x),
//! Err(x) => Err(x)
//! }
//! # }
//! ```
//!
//! into just `x`.
@ -23,7 +25,7 @@ use std::slice::Iter;
///
/// This is done by transforming basic blocks where the statements match:
///
/// ```rust
/// ```ignore (MIR)
/// _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY );
/// _TMP_2 = _LOCAL_TMP;
/// ((_LOCAL_0 as Variant).FIELD: TY) = move _TMP_2;
@ -32,7 +34,7 @@ use std::slice::Iter;
///
/// into:
///
/// ```rust
/// ```ignore (MIR)
/// _LOCAL_0 = move _LOCAL_1
/// ```
pub struct SimplifyArmIdentity;
@ -472,7 +474,7 @@ impl Visitor<'_> for LocalUseCounter {
}
/// Match on:
/// ```rust
/// ```ignore (MIR)
/// _LOCAL_INTO = ((_LOCAL_FROM as Variant).FIELD: TY);
/// ```
fn match_get_variant_field<'tcx>(
@ -492,7 +494,7 @@ fn match_get_variant_field<'tcx>(
}
/// Match on:
/// ```rust
/// ```ignore (MIR)
/// ((_LOCAL_FROM as Variant).FIELD: TY) = move _LOCAL_INTO;
/// ```
fn match_set_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local, VarField<'tcx>)> {
@ -507,7 +509,7 @@ fn match_set_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local
}
/// Match on:
/// ```rust
/// ```ignore (MIR)
/// discriminant(_LOCAL_TO_SET) = VAR_IDX;
/// ```
fn match_set_discr(stmt: &Statement<'_>) -> Option<(Local, VariantIdx)> {
@ -690,7 +692,7 @@ impl<'tcx> SimplifyBranchSameOptimizationFinder<'_, 'tcx> {
///
/// Statements can be trivially equal if the kinds match.
/// But they can also be considered equal in the following case A:
/// ```
/// ```ignore (MIR)
/// discriminant(_0) = 0; // bb1
/// _0 = move _1; // bb2
/// ```