1
Fork 0

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

@ -573,7 +573,7 @@ pub struct Block {
pub span: Span, pub span: Span,
pub tokens: Option<LazyTokenStream>, pub tokens: Option<LazyTokenStream>,
/// The following *isn't* a parse error, but will cause multiple errors in following stages. /// The following *isn't* a parse error, but will cause multiple errors in following stages.
/// ``` /// ```compile_fail
/// let x = { /// let x = {
/// foo: var /// foo: var
/// }; /// };

View file

@ -616,7 +616,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
/// Desugar `<expr>.await` into: /// Desugar `<expr>.await` into:
/// ```rust /// ```ignore (pseudo-rust)
/// match ::std::future::IntoFuture::into_future(<expr>) { /// match ::std::future::IntoFuture::into_future(<expr>) {
/// mut __awaitee => loop { /// mut __awaitee => loop {
/// match unsafe { ::std::future::Future::poll( /// match unsafe { ::std::future::Future::poll(
@ -1363,7 +1363,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
/// Desugar `ExprForLoop` from: `[opt_ident]: for <pat> in <head> <body>` into: /// Desugar `ExprForLoop` from: `[opt_ident]: for <pat> in <head> <body>` into:
/// ```rust /// ```ignore (pseudo-rust)
/// { /// {
/// let result = match IntoIterator::into_iter(<head>) { /// let result = match IntoIterator::into_iter(<head>) {
/// mut iter => { /// mut iter => {
@ -1474,7 +1474,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
/// Desugar `ExprKind::Try` from: `<expr>?` into: /// Desugar `ExprKind::Try` from: `<expr>?` into:
/// ```rust /// ```ignore (pseudo-rust)
/// match Try::branch(<expr>) { /// match Try::branch(<expr>) {
/// ControlFlow::Continue(val) => #[allow(unreachable_code)] val,, /// ControlFlow::Continue(val) => #[allow(unreachable_code)] val,,
/// ControlFlow::Break(residual) => /// ControlFlow::Break(residual) =>

View file

@ -920,7 +920,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// Given an associated type constraint like one of these: /// Given an associated type constraint like one of these:
/// ///
/// ``` /// ```ignore (illustrative)
/// T: Iterator<Item: Debug> /// T: Iterator<Item: Debug>
/// ^^^^^^^^^^^ /// ^^^^^^^^^^^
/// T: Iterator<Item = Debug> /// T: Iterator<Item = Debug>

View file

@ -68,20 +68,20 @@
//! will be made to flow subsequent breaks together onto lines. Inconsistent //! will be made to flow subsequent breaks together onto lines. Inconsistent
//! is the opposite. Inconsistent breaking example would be, say: //! is the opposite. Inconsistent breaking example would be, say:
//! //!
//! ``` //! ```ignore (illustrative)
//! foo(hello, there, good, friends) //! foo(hello, there, good, friends)
//! ``` //! ```
//! //!
//! breaking inconsistently to become //! breaking inconsistently to become
//! //!
//! ``` //! ```ignore (illustrative)
//! foo(hello, there, //! foo(hello, there,
//! good, friends); //! good, friends);
//! ``` //! ```
//! //!
//! whereas a consistent breaking would yield: //! whereas a consistent breaking would yield:
//! //!
//! ``` //! ```ignore (illustrative)
//! foo(hello, //! foo(hello,
//! there, //! there,
//! good, //! good,
@ -153,14 +153,14 @@ enum IndentStyle {
/// Vertically aligned under whatever column this block begins at. /// Vertically aligned under whatever column this block begins at.
/// ///
/// fn demo(arg1: usize, /// fn demo(arg1: usize,
/// arg2: usize); /// arg2: usize) {}
Visual, Visual,
/// Indented relative to the indentation level of the previous line. /// Indented relative to the indentation level of the previous line.
/// ///
/// fn demo( /// fn demo(
/// arg1: usize, /// arg1: usize,
/// arg2: usize, /// arg2: usize,
/// ); /// ) {}
Block { offset: isize }, Block { offset: isize },
} }

View file

@ -896,20 +896,23 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// ///
/// In the simplest case, where there are no unions involved, if a mutable borrow of `x` is /// In the simplest case, where there are no unions involved, if a mutable borrow of `x` is
/// attempted while a shared borrow is live, then this function will return: /// attempted while a shared borrow is live, then this function will return:
/// /// ```
/// ("x", "", "") /// ("x", "", "")
/// /// # ;
/// ```
/// In the simple union case, if a mutable borrow of a union field `x.z` is attempted while /// In the simple union case, if a mutable borrow of a union field `x.z` is attempted while
/// a shared borrow of another field `x.y`, then this function will return: /// a shared borrow of another field `x.y`, then this function will return:
/// /// ```
/// ("x", "x.z", "x.y") /// ("x", "x.z", "x.y")
/// /// # ;
/// ```
/// In the more complex union case, where the union is a field of a struct, then if a mutable /// In the more complex union case, where the union is a field of a struct, then if a mutable
/// borrow of a union field in a struct `x.u.z` is attempted while a shared borrow of /// borrow of a union field in a struct `x.u.z` is attempted while a shared borrow of
/// another field `x.u.y`, then this function will return: /// another field `x.u.y`, then this function will return:
/// /// ```
/// ("x.u", "x.u.z", "x.u.y") /// ("x.u", "x.u.z", "x.u.y")
/// /// # ;
/// ```
/// This is used when creating error messages like below: /// This is used when creating error messages like below:
/// ///
/// ```text /// ```text

View file

@ -259,7 +259,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
/// Report an error because the universal region `fr` was required to outlive /// Report an error because the universal region `fr` was required to outlive
/// `outlived_fr` but it is not known to do so. For example: /// `outlived_fr` but it is not known to do so. For example:
/// ///
/// ``` /// ```compile_fail,E0312
/// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x } /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x }
/// ``` /// ```
/// ///

View file

@ -210,7 +210,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
/// Suppose we are trying to give a name to the lifetime of the /// Suppose we are trying to give a name to the lifetime of the
/// reference `x`: /// reference `x`:
/// ///
/// ``` /// ```ignore (pseudo-rust)
/// fn foo(x: &u32) { .. } /// fn foo(x: &u32) { .. }
/// ``` /// ```
/// ///
@ -746,7 +746,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
/// e.g. given the function: /// e.g. given the function:
/// ///
/// ``` /// ```
/// async fn foo() -> i32 {} /// async fn foo() -> i32 { 2 }
/// ``` /// ```
/// ///
/// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements `Future<Output=i32>`, /// this function, given the lowered return type of `foo`, an [`OpaqueDef`] that implements `Future<Output=i32>`,

View file

@ -169,7 +169,7 @@ where
/// Returns the "choice regions" for a given member /// Returns the "choice regions" for a given member
/// constraint. This is the `R1..Rn` from a constraint like: /// constraint. This is the `R1..Rn` from a constraint like:
/// ///
/// ``` /// ```text
/// R0 member of [R1..Rn] /// R0 member of [R1..Rn]
/// ``` /// ```
crate fn choice_regions(&self, pci: NllMemberConstraintIndex) -> &[ty::RegionVid] { crate fn choice_regions(&self, pci: NllMemberConstraintIndex) -> &[ty::RegionVid] {
@ -195,14 +195,14 @@ where
/// ///
/// Before: /// Before:
/// ///
/// ``` /// ```text
/// target_list: A -> B -> C -> (None) /// target_list: A -> B -> C -> (None)
/// source_list: D -> E -> F -> (None) /// source_list: D -> E -> F -> (None)
/// ``` /// ```
/// ///
/// After: /// After:
/// ///
/// ``` /// ```text
/// target_list: A -> B -> C -> D -> E -> F -> (None) /// target_list: A -> B -> C -> D -> E -> F -> (None)
/// ``` /// ```
fn append_list( fn append_list(

View file

@ -436,14 +436,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// minimum values. /// minimum values.
/// ///
/// For example: /// For example:
/// /// ```
/// fn foo<'a, 'b>(..) where 'a: 'b /// fn foo<'a, 'b>( /* ... */ ) where 'a: 'b { /* ... */ }
/// /// ```
/// would initialize two variables like so: /// would initialize two variables like so:
/// /// ```ignore (illustrative)
/// R0 = { CFG, R0 } // 'a /// R0 = { CFG, R0 } // 'a
/// R1 = { CFG, R0, R1 } // 'b /// R1 = { CFG, R0, R1 } // 'b
/// /// ```
/// Here, R0 represents `'a`, and it contains (a) the entire CFG /// Here, R0 represents `'a`, and it contains (a) the entire CFG
/// and (b) any universally quantified regions that it outlives, /// and (b) any universally quantified regions that it outlives,
/// which in this case is just itself. R1 (`'b`) in contrast also /// which in this case is just itself. R1 (`'b`) in contrast also
@ -1310,9 +1310,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// whether any of the constraints were too strong. In particular, /// whether any of the constraints were too strong. In particular,
/// we want to check for a case where a universally quantified /// we want to check for a case where a universally quantified
/// region exceeded its bounds. Consider: /// region exceeded its bounds. Consider:
/// /// ```compile_fail,E0312
/// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x } /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x }
/// /// ```
/// In this case, returning `x` requires `&'a u32 <: &'b u32` /// In this case, returning `x` requires `&'a u32 <: &'b u32`
/// and hence we establish (transitively) a constraint that /// and hence we establish (transitively) a constraint that
/// `'a: 'b`. The `propagate_constraints` code above will /// `'a: 'b`. The `propagate_constraints` code above will
@ -1366,9 +1366,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// <https://smallcultfollowing.com/babysteps/blog/2019/01/17/polonius-and-region-errors/> /// <https://smallcultfollowing.com/babysteps/blog/2019/01/17/polonius-and-region-errors/>
/// ///
/// In the canonical example /// In the canonical example
/// /// ```compile_fail,E0312
/// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x } /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x }
/// /// ```
/// returning `x` requires `&'a u32 <: &'b u32` and hence we establish (transitively) a /// returning `x` requires `&'a u32 <: &'b u32` and hence we establish (transitively) a
/// constraint that `'a: 'b`. It is an error that we have no evidence that this /// constraint that `'a: 'b`. It is an error that we have no evidence that this
/// constraint holds. /// constraint holds.

View file

@ -971,7 +971,7 @@ pub enum Locations {
/// things like the type of the return slot. Consider this /// things like the type of the return slot. Consider this
/// example: /// example:
/// ///
/// ``` /// ```compile_fail,E0515
/// fn foo<'a>(x: &'a u32) -> &'a u32 { /// fn foo<'a>(x: &'a u32) -> &'a u32 {
/// let y = 22; /// let y = 22;
/// return &y; // error /// return &y; // error

View file

@ -187,12 +187,12 @@ pub enum RegionClassification {
/// ///
/// Consider this example: /// Consider this example:
/// ///
/// ``` /// ```ignore (pseudo-rust)
/// fn foo<'a, 'b>(a: &'a u32, b: &'b u32, c: &'static u32) { /// fn foo<'a, 'b>(a: &'a u32, b: &'b u32, c: &'static u32) {
/// let closure = for<'x> |x: &'x u32| { .. }; /// let closure = for<'x> |x: &'x u32| { .. };
/// ^^^^^^^ pretend this were legal syntax /// // ^^^^^^^ pretend this were legal syntax
/// for declaring a late-bound region in /// // for declaring a late-bound region in
/// a closure signature /// // a closure signature
/// } /// }
/// ``` /// ```
/// ///

View file

@ -5,14 +5,14 @@
//! //!
//! For example, a type like: //! For example, a type like:
//! //!
//! ``` //! ```ignore (old code)
//! #[derive(RustcEncodable, RustcDecodable)] //! #[derive(RustcEncodable, RustcDecodable)]
//! struct Node { id: usize } //! struct Node { id: usize }
//! ``` //! ```
//! //!
//! would generate two implementations like: //! would generate two implementations like:
//! //!
//! ``` //! ```ignore (old code)
//! # struct Node { id: usize } //! # struct Node { id: usize }
//! impl<S: Encoder<E>, E> Encodable<S, E> for Node { //! impl<S: Encoder<E>, E> Encodable<S, E> for Node {
//! fn encode(&self, s: &mut S) -> Result<(), E> { //! fn encode(&self, s: &mut S) -> Result<(), E> {
@ -40,7 +40,7 @@
//! Other interesting scenarios are when the item has type parameters or //! Other interesting scenarios are when the item has type parameters or
//! references other non-built-in types. A type definition like: //! references other non-built-in types. A type definition like:
//! //!
//! ``` //! ```ignore (old code)
//! # #[derive(RustcEncodable, RustcDecodable)] //! # #[derive(RustcEncodable, RustcDecodable)]
//! # struct Span; //! # struct Span;
//! #[derive(RustcEncodable, RustcDecodable)] //! #[derive(RustcEncodable, RustcDecodable)]
@ -49,7 +49,7 @@
//! //!
//! would yield functions like: //! would yield functions like:
//! //!
//! ``` //! ```ignore (old code)
//! # #[derive(RustcEncodable, RustcDecodable)] //! # #[derive(RustcEncodable, RustcDecodable)]
//! # struct Span; //! # struct Span;
//! # struct Spanned<T> { node: T, span: Span } //! # struct Spanned<T> { node: T, span: Span }

View file

@ -1006,9 +1006,11 @@ impl<'a> MethodDef<'a> {
/// } /// }
/// } /// }
/// } /// }
/// /// ```
/// // or if A is repr(packed) - note fields are matched by-value /// or if A is repr(packed) - note fields are matched by-value
/// // instead of by-reference. /// instead of by-reference.
/// ```
/// # struct A { x: i32, y: i32 }
/// impl PartialEq for A { /// impl PartialEq for A {
/// fn eq(&self, other: &A) -> bool { /// fn eq(&self, other: &A) -> bool {
/// match *self { /// match *self {
@ -1126,14 +1128,15 @@ impl<'a> MethodDef<'a> {
/// // is equivalent to /// // is equivalent to
/// ///
/// impl PartialEq for A { /// impl PartialEq for A {
/// fn eq(&self, other: &A) -> ::bool { /// fn eq(&self, other: &A) -> bool {
/// use A::*;
/// match (&*self, &*other) { /// match (&*self, &*other) {
/// (&A1, &A1) => true, /// (&A1, &A1) => true,
/// (&A2(ref self_0), /// (&A2(ref self_0),
/// &A2(ref __arg_1_0)) => (*self_0).eq(&(*__arg_1_0)), /// &A2(ref __arg_1_0)) => (*self_0).eq(&(*__arg_1_0)),
/// _ => { /// _ => {
/// let __self_vi = match *self { A1(..) => 0, A2(..) => 1 }; /// let __self_vi = match *self { A1 => 0, A2(..) => 1 };
/// let __arg_1_vi = match *other { A1(..) => 0, A2(..) => 1 }; /// let __arg_1_vi = match *other { A1 => 0, A2(..) => 1 };
/// false /// false
/// } /// }
/// } /// }

View file

@ -249,7 +249,7 @@ fn generate_test_harness(
/// ///
/// By default this expands to /// By default this expands to
/// ///
/// ``` /// ```ignore UNSOLVED (I think I still need guidance for this one. Is it correct? Do we try to make it run? How do we nicely fill it out?)
/// #[rustc_main] /// #[rustc_main]
/// pub fn main() { /// pub fn main() {
/// extern crate test; /// extern crate test;

View file

@ -394,15 +394,15 @@ impl Drop for Linker<'_> {
/// ///
/// At a high level Thin LTO looks like: /// At a high level Thin LTO looks like:
/// ///
/// 1. Prepare a "summary" of each LLVM module in question which describes /// 1. Prepare a "summary" of each LLVM module in question which describes
/// the values inside, cost of the values, etc. /// the values inside, cost of the values, etc.
/// 2. Merge the summaries of all modules in question into one "index" /// 2. Merge the summaries of all modules in question into one "index"
/// 3. Perform some global analysis on this index /// 3. Perform some global analysis on this index
/// 4. For each module, use the index and analysis calculated previously to /// 4. For each module, use the index and analysis calculated previously to
/// perform local transformations on the module, for example inlining /// perform local transformations on the module, for example inlining
/// small functions from other modules. /// small functions from other modules.
/// 5. Run thin-specific optimization passes over each module, and then code /// 5. Run thin-specific optimization passes over each module, and then code
/// generate everything at the end. /// generate everything at the end.
/// ///
/// The summary for each module is intended to be quite cheap, and the global /// The summary for each module is intended to be quite cheap, and the global
/// index is relatively quite cheap to create as well. As a result, the goal of /// index is relatively quite cheap to create as well. As a result, the goal of

View file

@ -27,9 +27,9 @@ The module is thus driven from an outside client with functions like
Internally the module will try to reuse already created metadata by Internally the module will try to reuse already created metadata by
utilizing a cache. The way to get a shared metadata node when needed is utilizing a cache. The way to get a shared metadata node when needed is
thus to just call the corresponding function in this module: thus to just call the corresponding function in this module:
```ignore (illustrative)
let file_metadata = file_metadata(cx, file); let file_metadata = file_metadata(cx, file);
```
The function will take care of probing the cache for an existing node for The function will take care of probing the cache for an existing node for
that exact file path. that exact file path.
@ -63,7 +63,7 @@ struct List {
will generate the following callstack with a naive DFS algorithm: will generate the following callstack with a naive DFS algorithm:
``` ```ignore (illustrative)
describe(t = List) describe(t = List)
describe(t = i32) describe(t = i32)
describe(t = Option<Box<List>>) describe(t = Option<Box<List>>)

View file

@ -23,7 +23,8 @@
//! `computed` does not change accidentally (e.g. somebody might accidentally call //! `computed` does not change accidentally (e.g. somebody might accidentally call
//! `foo.computed.mutate()`). This is what `Frozen` is for. We can do the following: //! `foo.computed.mutate()`). This is what `Frozen` is for. We can do the following:
//! //!
//! ```rust //! ```
//! # struct Bar {}
//! use rustc_data_structures::frozen::Frozen; //! use rustc_data_structures::frozen::Frozen;
//! //!
//! struct Foo { //! struct Foo {

View file

@ -202,7 +202,7 @@ impl<O> Node<O> {
/// with this node. /// with this node.
/// ///
/// The non-`Error` state transitions are as follows. /// The non-`Error` state transitions are as follows.
/// ``` /// ```text
/// (Pre-creation) /// (Pre-creation)
/// | /// |
/// | register_obligation_at() (called by process_obligations() and /// | register_obligation_at() (called by process_obligations() and

View file

@ -25,9 +25,8 @@ of the reference because the backing allocation of the vector does not change.
This library enables this safe usage by keeping the owner and the reference This library enables this safe usage by keeping the owner and the reference
bundled together in a wrapper type that ensure that lifetime constraint: bundled together in a wrapper type that ensure that lifetime constraint:
```rust ```
# extern crate owning_ref; # use rustc_data_structures::owning_ref::OwningRef;
# use owning_ref::OwningRef;
# fn main() { # fn main() {
fn return_owned_and_referenced() -> OwningRef<Vec<u8>, [u8]> { fn return_owned_and_referenced() -> OwningRef<Vec<u8>, [u8]> {
let v = vec![1, 2, 3, 4]; let v = vec![1, 2, 3, 4];
@ -56,8 +55,7 @@ See the documentation around `OwningHandle` for more details.
## Basics ## Basics
``` ```
extern crate owning_ref; use rustc_data_structures::owning_ref::BoxRef;
use owning_ref::BoxRef;
fn main() { fn main() {
// Create an array owned by a Box. // Create an array owned by a Box.
@ -78,8 +76,7 @@ fn main() {
## Caching a reference to a struct field ## Caching a reference to a struct field
``` ```
extern crate owning_ref; use rustc_data_structures::owning_ref::BoxRef;
use owning_ref::BoxRef;
fn main() { fn main() {
struct Foo { struct Foo {
@ -106,8 +103,7 @@ fn main() {
## Caching a reference to an entry in a vector ## Caching a reference to an entry in a vector
``` ```
extern crate owning_ref; use rustc_data_structures::owning_ref::VecRef;
use owning_ref::VecRef;
fn main() { fn main() {
let v = VecRef::new(vec![1, 2, 3, 4, 5]).map(|v| &v[3]); let v = VecRef::new(vec![1, 2, 3, 4, 5]).map(|v| &v[3]);
@ -118,8 +114,7 @@ fn main() {
## Caching a subslice of a String ## Caching a subslice of a String
``` ```
extern crate owning_ref; use rustc_data_structures::owning_ref::StringRef;
use owning_ref::StringRef;
fn main() { fn main() {
let s = StringRef::new("hello world".to_owned()) let s = StringRef::new("hello world".to_owned())
@ -132,8 +127,7 @@ fn main() {
## Reference counted slices that share ownership of the backing storage ## Reference counted slices that share ownership of the backing storage
``` ```
extern crate owning_ref; use rustc_data_structures::owning_ref::RcRef;
use owning_ref::RcRef;
use std::rc::Rc; use std::rc::Rc;
fn main() { fn main() {
@ -155,8 +149,7 @@ fn main() {
## Atomic reference counted slices that share ownership of the backing storage ## Atomic reference counted slices that share ownership of the backing storage
``` ```
extern crate owning_ref; use rustc_data_structures::owning_ref::ArcRef;
use owning_ref::ArcRef;
use std::sync::Arc; use std::sync::Arc;
fn main() { fn main() {
@ -188,8 +181,7 @@ fn main() {
## References into RAII locks ## References into RAII locks
``` ```
extern crate owning_ref; use rustc_data_structures::owning_ref::RefRef;
use owning_ref::RefRef;
use std::cell::{RefCell, Ref}; use std::cell::{RefCell, Ref};
fn main() { fn main() {
@ -219,8 +211,7 @@ When the owned container implements `DerefMut`, it is also possible to make
a _mutable owning reference_. (e.g., with `Box`, `RefMut`, `MutexGuard`) a _mutable owning reference_. (e.g., with `Box`, `RefMut`, `MutexGuard`)
``` ```
extern crate owning_ref; use rustc_data_structures::owning_ref::RefMutRefMut;
use owning_ref::RefMutRefMut;
use std::cell::{RefCell, RefMut}; use std::cell::{RefCell, RefMut};
fn main() { fn main() {
@ -326,8 +317,7 @@ impl<O, T: ?Sized> OwningRef<O, T> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate owning_ref; /// use rustc_data_structures::owning_ref::OwningRef;
/// use owning_ref::OwningRef;
/// ///
/// fn main() { /// fn main() {
/// let owning_ref = OwningRef::new(Box::new(42)); /// let owning_ref = OwningRef::new(Box::new(42));
@ -362,8 +352,7 @@ impl<O, T: ?Sized> OwningRef<O, T> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate owning_ref; /// use rustc_data_structures::owning_ref::OwningRef;
/// use owning_ref::OwningRef;
/// ///
/// fn main() { /// fn main() {
/// let owning_ref = OwningRef::new(Box::new([1, 2, 3, 4])); /// let owning_ref = OwningRef::new(Box::new([1, 2, 3, 4]));
@ -390,8 +379,7 @@ impl<O, T: ?Sized> OwningRef<O, T> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate owning_ref; /// use rustc_data_structures::owning_ref::OwningRef;
/// use owning_ref::OwningRef;
/// ///
/// fn main() { /// fn main() {
/// let owning_ref = OwningRef::new(Box::new([1, 2, 3, 4])); /// let owning_ref = OwningRef::new(Box::new([1, 2, 3, 4]));
@ -441,8 +429,7 @@ impl<O, T: ?Sized> OwningRef<O, T> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate owning_ref; /// use rustc_data_structures::owning_ref::{OwningRef, Erased};
/// use owning_ref::{OwningRef, Erased};
/// ///
/// fn main() { /// fn main() {
/// // N.B., using the concrete types here for explicitness. /// // N.B., using the concrete types here for explicitness.
@ -460,7 +447,7 @@ impl<O, T: ?Sized> OwningRef<O, T> {
/// let owning_ref_b: OwningRef<Box<Vec<(i32, bool)>>, i32> /// let owning_ref_b: OwningRef<Box<Vec<(i32, bool)>>, i32>
/// = owning_ref_b.map(|a| &a[1].0); /// = owning_ref_b.map(|a| &a[1].0);
/// ///
/// let owning_refs: [OwningRef<Box<Erased>, i32>; 2] /// let owning_refs: [OwningRef<Box<dyn Erased>, i32>; 2]
/// = [owning_ref_a.erase_owner(), owning_ref_b.erase_owner()]; /// = [owning_ref_a.erase_owner(), owning_ref_b.erase_owner()];
/// ///
/// assert_eq!(*owning_refs[0], 1); /// assert_eq!(*owning_refs[0], 1);
@ -516,8 +503,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate owning_ref; /// use rustc_data_structures::owning_ref::OwningRefMut;
/// use owning_ref::OwningRefMut;
/// ///
/// fn main() { /// fn main() {
/// let owning_ref_mut = OwningRefMut::new(Box::new(42)); /// let owning_ref_mut = OwningRefMut::new(Box::new(42));
@ -552,8 +538,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate owning_ref; /// use rustc_data_structures::owning_ref::OwningRefMut;
/// use owning_ref::OwningRefMut;
/// ///
/// fn main() { /// fn main() {
/// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4]));
@ -580,8 +565,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate owning_ref; /// use rustc_data_structures::owning_ref::OwningRefMut;
/// use owning_ref::OwningRefMut;
/// ///
/// fn main() { /// fn main() {
/// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4]));
@ -608,8 +592,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate owning_ref; /// use rustc_data_structures::owning_ref::OwningRefMut;
/// use owning_ref::OwningRefMut;
/// ///
/// fn main() { /// fn main() {
/// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4]));
@ -638,8 +621,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate owning_ref; /// use rustc_data_structures::owning_ref::OwningRefMut;
/// use owning_ref::OwningRefMut;
/// ///
/// fn main() { /// fn main() {
/// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4]));
@ -689,8 +671,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
/// ///
/// # Example /// # Example
/// ``` /// ```
/// extern crate owning_ref; /// use rustc_data_structures::owning_ref::{OwningRefMut, Erased};
/// use owning_ref::{OwningRefMut, Erased};
/// ///
/// fn main() { /// fn main() {
/// // N.B., using the concrete types here for explicitness. /// // N.B., using the concrete types here for explicitness.
@ -708,7 +689,7 @@ impl<O, T: ?Sized> OwningRefMut<O, T> {
/// let owning_ref_mut_b: OwningRefMut<Box<Vec<(i32, bool)>>, i32> /// let owning_ref_mut_b: OwningRefMut<Box<Vec<(i32, bool)>>, i32>
/// = owning_ref_mut_b.map_mut(|a| &mut a[1].0); /// = owning_ref_mut_b.map_mut(|a| &mut a[1].0);
/// ///
/// let owning_refs_mut: [OwningRefMut<Box<Erased>, i32>; 2] /// let owning_refs_mut: [OwningRefMut<Box<dyn Erased>, i32>; 2]
/// = [owning_ref_mut_a.erase_owner(), owning_ref_mut_b.erase_owner()]; /// = [owning_ref_mut_a.erase_owner(), owning_ref_mut_b.erase_owner()];
/// ///
/// assert_eq!(*owning_refs_mut[0], 1); /// assert_eq!(*owning_refs_mut[0], 1);

View file

@ -45,7 +45,8 @@ pub unsafe trait Pointer: Deref {
/// case you'll need to manually figure out what the right type to pass to /// case you'll need to manually figure out what the right type to pass to
/// align_of is. /// align_of is.
/// ///
/// ```rust /// ```ignore UNSOLVED (what to do about the Self)
/// # use std::ops::Deref;
/// std::mem::align_of::<<Self as Deref>::Target>().trailing_zeros() as usize; /// std::mem::align_of::<<Self as Deref>::Target>().trailing_zeros() as usize;
/// ``` /// ```
const BITS: usize; const BITS: usize;

View file

@ -282,7 +282,7 @@ impl<T: Eq + Hash + Copy> TransitiveRelation<T> {
/// (where the relation is encoding the `<=` relation for the lattice). /// (where the relation is encoding the `<=` relation for the lattice).
/// So e.g., if the relation is `->` and we have /// So e.g., if the relation is `->` and we have
/// ///
/// ``` /// ```text
/// a -> b -> d -> f /// a -> b -> d -> f
/// | ^ /// | ^
/// +--> c -> e ---+ /// +--> c -> e ---+

View file

@ -100,7 +100,7 @@ pub struct CodeSuggestion {
/// `foo.bar` might be replaced with `a.b` or `x.y` by replacing /// `foo.bar` might be replaced with `a.b` or `x.y` by replacing
/// `foo` and `bar` on their own: /// `foo` and `bar` on their own:
/// ///
/// ``` /// ```ignore (illustrative)
/// vec![ /// vec![
/// Substitution { parts: vec![(0..3, "a"), (4..7, "b")] }, /// Substitution { parts: vec![(0..3, "a"), (4..7, "b")] },
/// Substitution { parts: vec![(0..3, "x"), (4..7, "y")] }, /// Substitution { parts: vec![(0..3, "x"), (4..7, "y")] },
@ -109,7 +109,7 @@ pub struct CodeSuggestion {
/// ///
/// or by replacing the entire span: /// or by replacing the entire span:
/// ///
/// ``` /// ```ignore (illustrative)
/// vec![ /// vec![
/// Substitution { parts: vec![(0..7, "a.b")] }, /// Substitution { parts: vec![(0..7, "a.b")] },
/// Substitution { parts: vec![(0..7, "x.y")] }, /// Substitution { parts: vec![(0..7, "x.y")] },

View file

@ -4,7 +4,7 @@
//! //!
//! ## Meta-variables must not be bound twice //! ## Meta-variables must not be bound twice
//! //!
//! ``` //! ```compile_fail
//! macro_rules! foo { ($x:tt $x:tt) => { $x }; } //! macro_rules! foo { ($x:tt $x:tt) => { $x }; }
//! ``` //! ```
//! //!
@ -604,9 +604,9 @@ fn check_ops_is_prefix(
/// Kleene operators of its binder as a prefix. /// Kleene operators of its binder as a prefix.
/// ///
/// Consider $i in the following example: /// Consider $i in the following example:
/// /// ```ignore (illustrative)
/// ( $( $i:ident = $($j:ident),+ );* ) => { $($( $i += $j; )+)* } /// ( $( $i:ident = $($j:ident),+ );* ) => { $($( $i += $j; )+)* }
/// /// ```
/// It occurs under the Kleene stack ["*", "+"] and is bound under ["*"] only. /// It occurs under the Kleene stack ["*", "+"] and is bound under ["*"] only.
/// ///
/// Arguments: /// Arguments:

View file

@ -320,7 +320,8 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize {
/// ///
/// Then, the tree will have the following shape: /// Then, the tree will have the following shape:
/// ///
/// ```rust /// ```ignore (private-internal)
/// # use NamedMatch::*;
/// MatchedSeq([ /// MatchedSeq([
/// MatchedSeq([ /// MatchedSeq([
/// MatchedNonterminal(a), /// MatchedNonterminal(a),

View file

@ -312,6 +312,7 @@ pub enum Res<Id = hir::HirId> {
/// HACK(min_const_generics): self types also have an optional requirement to **not** mention /// HACK(min_const_generics): self types also have an optional requirement to **not** mention
/// any generic parameters to allow the following with `min_const_generics`: /// any generic parameters to allow the following with `min_const_generics`:
/// ``` /// ```
/// # struct Foo;
/// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] { todo!() } } /// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] { todo!() } }
/// ///
/// struct Bar([u8; baz::<Self>()]); /// struct Bar([u8; baz::<Self>()]);

View file

@ -49,15 +49,15 @@ pub enum ParamName {
/// Synthetic name generated when user elided a lifetime in an impl header. /// Synthetic name generated when user elided a lifetime in an impl header.
/// ///
/// E.g., the lifetimes in cases like these: /// E.g., the lifetimes in cases like these:
/// /// ```ignore (fragment)
/// impl Foo for &u32 /// impl Foo for &u32
/// impl Foo<'_> for u32 /// impl Foo<'_> for u32
/// /// ```
/// in that case, we rewrite to /// in that case, we rewrite to
/// /// ```ignore (fragment)
/// impl<'f> Foo for &'f u32 /// impl<'f> Foo for &'f u32
/// impl<'f> Foo<'f> for u32 /// impl<'f> Foo<'f> for u32
/// /// ```
/// where `'f` is something like `Fresh(0)`. The indices are /// where `'f` is something like `Fresh(0)`. The indices are
/// unique per impl, but not necessarily continuous. /// unique per impl, but not necessarily continuous.
Fresh(LocalDefId), Fresh(LocalDefId),
@ -1082,7 +1082,7 @@ pub enum PatKind<'hir> {
/// If `slice` exists, then `after` can be non-empty. /// If `slice` exists, then `after` can be non-empty.
/// ///
/// The representation for e.g., `[a, b, .., c, d]` is: /// The representation for e.g., `[a, b, .., c, d]` is:
/// ``` /// ```ignore (illustrative)
/// PatKind::Slice([Binding(a), Binding(b)], Some(Wild), [Binding(c), Binding(d)]) /// PatKind::Slice([Binding(a), Binding(b)], Some(Wild), [Binding(c), Binding(d)])
/// ``` /// ```
Slice(&'hir [Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [Pat<'hir>]), Slice(&'hir [Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [Pat<'hir>]),
@ -2244,7 +2244,7 @@ pub const FN_OUTPUT_NAME: Symbol = sym::Output;
/// wouldn't it be better to make the `ty` field an enum like the /// wouldn't it be better to make the `ty` field an enum like the
/// following? /// following?
/// ///
/// ``` /// ```ignore (pseudo-rust)
/// enum TypeBindingKind { /// enum TypeBindingKind {
/// Equals(...), /// Equals(...),
/// Binding(...), /// Binding(...),

View file

@ -22,7 +22,7 @@
//! //!
//! Example: //! Example:
//! //!
//! ``` //! ```ignore (needs flags)
//! #[rustc_if_this_changed(Hir)] //! #[rustc_if_this_changed(Hir)]
//! fn foo() { } //! fn foo() { }
//! //!

View file

@ -5,6 +5,7 @@
//! The user adds annotations to the crate of the following form: //! The user adds annotations to the crate of the following form:
//! //!
//! ``` //! ```
//! # #![feature(rustc_attrs)]
//! #![rustc_partition_reused(module="spike", cfg="rpass2")] //! #![rustc_partition_reused(module="spike", cfg="rpass2")]
//! #![rustc_partition_codegened(module="spike-x", cfg="rpass2")] //! #![rustc_partition_codegened(module="spike-x", cfg="rpass2")]
//! ``` //! ```

View file

@ -6,7 +6,7 @@
//! is always the "expected" output from the POV of diagnostics. //! is always the "expected" output from the POV of diagnostics.
//! //!
//! Examples: //! Examples:
//! //! ```ignore (fragment)
//! infcx.at(cause, param_env).sub(a, b) //! infcx.at(cause, param_env).sub(a, b)
//! // requires that `a <: b`, with `a` considered the "expected" type //! // requires that `a <: b`, with `a` considered the "expected" type
//! //!
@ -15,11 +15,11 @@
//! //!
//! infcx.at(cause, param_env).eq(a, b) //! infcx.at(cause, param_env).eq(a, b)
//! // requires that `a == b`, with `a` considered the "expected" type //! // requires that `a == b`, with `a` considered the "expected" type
//! //! ```
//! For finer-grained control, you can also do use `trace`: //! For finer-grained control, you can also do use `trace`:
//! //! ```ignore (fragment)
//! infcx.at(...).trace(a, b).sub(&c, &d) //! infcx.at(...).trace(a, b).sub(&c, &d)
//! //! ```
//! This will set `a` and `b` as the "root" values for //! This will set `a` and `b` as the "root" values for
//! error-reporting, but actually operate on `c` and `d`. This is //! error-reporting, but actually operate on `c` and `d`. This is
//! sometimes useful when the types of `c` and `d` are not traceable //! sometimes useful when the types of `c` and `d` are not traceable

View file

@ -87,9 +87,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
/// ///
/// with a mapping M that maps `'?0` to `'static`. But if we found that there /// with a mapping M that maps `'?0` to `'static`. But if we found that there
/// exists only one possible impl of `Trait`, and it looks like /// exists only one possible impl of `Trait`, and it looks like
/// /// ```ignore (illustrative)
/// impl<T> Trait<'static> for T { .. } /// impl<T> Trait<'static> for T { .. }
/// /// ```
/// then we would prepare a query result R that (among other /// then we would prepare a query result R that (among other
/// things) includes a mapping to `'?0 := 'static`. When /// things) includes a mapping to `'?0 := 'static`. When
/// canonicalizing this query result R, we would leave this /// canonicalizing this query result R, we would leave this

View file

@ -202,7 +202,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
/// ///
/// A good example of this is the following: /// A good example of this is the following:
/// ///
/// ```rust /// ```compile_fail,E0308
/// #![feature(generic_const_exprs)] /// #![feature(generic_const_exprs)]
/// ///
/// fn bind<const N: usize>(value: [u8; N]) -> [u8; 3 + 4] { /// fn bind<const N: usize>(value: [u8; N]) -> [u8; 3 + 4] {

View file

@ -889,7 +889,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// ///
/// For the following code: /// For the following code:
/// ///
/// ```no_run /// ```ignore (illustrative)
/// let x: Foo<Bar<Qux>> = foo::<Bar<Qux>>(); /// let x: Foo<Bar<Qux>> = foo::<Bar<Qux>>();
/// ``` /// ```
/// ///
@ -1872,7 +1872,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// A possible error is to forget to add `.await` when using futures: /// A possible error is to forget to add `.await` when using futures:
/// ///
/// ``` /// ```compile_fail,E0308
/// async fn make_u32() -> u32 { /// async fn make_u32() -> u32 {
/// 22 /// 22
/// } /// }

View file

@ -18,7 +18,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
/// ///
/// Consider a case where we have /// Consider a case where we have
/// ///
/// ```no_run /// ```compile_fail,E0623
/// fn foo(x: &mut Vec<&u8>, y: &u8) { /// fn foo(x: &mut Vec<&u8>, y: &u8) {
/// x.push(y); /// x.push(y);
/// } /// }

View file

@ -14,7 +14,7 @@ use rustc_middle::ty::{self, Region, TyCtxt};
/// br - the bound region corresponding to the above region which is of type `BrAnon(_)` /// br - the bound region corresponding to the above region which is of type `BrAnon(_)`
/// ///
/// # Example /// # Example
/// ``` /// ```compile_fail,E0623
/// fn foo(x: &mut Vec<&u8>, y: &u8) /// fn foo(x: &mut Vec<&u8>, y: &u8)
/// { x.push(y); } /// { x.push(y); }
/// ``` /// ```

View file

@ -159,9 +159,9 @@ pub struct InferCtxtInner<'tcx> {
/// outlive the lifetime 'a". These constraints derive from /// outlive the lifetime 'a". These constraints derive from
/// instantiated type parameters. So if you had a struct defined /// instantiated type parameters. So if you had a struct defined
/// like /// like
/// /// ```ignore (illustrative)
/// struct Foo<T:'static> { ... } /// struct Foo<T:'static> { ... }
/// /// ```
/// then in some expression `let x = Foo { ... }` it will /// then in some expression `let x = Foo { ... }` it will
/// instantiate the type parameter `T` with a fresh type `$0`. At /// instantiate the type parameter `T` with a fresh type `$0`. At
/// the same time, it will record a region obligation of /// the same time, it will record a region obligation of

View file

@ -309,14 +309,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// the same as generating an outlives constraint on `Tc` itself. /// the same as generating an outlives constraint on `Tc` itself.
/// For example, if we had a function like this: /// For example, if we had a function like this:
/// ///
/// ```rust /// ```
/// # #![feature(type_alias_impl_trait)]
/// # fn main() {}
/// # trait Foo<'a> {}
/// # impl<'a, T> Foo<'a> for (&'a u32, T) {}
/// fn foo<'a, T>(x: &'a u32, y: T) -> impl Foo<'a> { /// fn foo<'a, T>(x: &'a u32, y: T) -> impl Foo<'a> {
/// (x, y) /// (x, y)
/// } /// }
/// ///
/// // Equivalent to: /// // Equivalent to:
/// # mod dummy { use super::*;
/// type FooReturn<'a, T> = impl Foo<'a>; /// type FooReturn<'a, T> = impl Foo<'a>;
/// fn foo<'a, T>(..) -> FooReturn<'a, T> { .. } /// fn foo<'a, T>(x: &'a u32, y: T) -> FooReturn<'a, T> {
/// (x, y)
/// }
/// # }
/// ``` /// ```
/// ///
/// then the hidden type `Tc` would be `(&'0 u32, T)` (where `'0` /// then the hidden type `Tc` would be `(&'0 u32, T)` (where `'0`
@ -602,17 +610,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// Returns `true` if `opaque_hir_id` is a sibling or a child of a sibling of `def_id`. /// Returns `true` if `opaque_hir_id` is a sibling or a child of a sibling of `def_id`.
/// ///
/// Example: /// Example:
/// ```rust /// ```ignore UNSOLVED (is this a bug?)
/// # #![feature(type_alias_impl_trait)]
/// pub mod foo { /// pub mod foo {
/// pub mod bar { /// pub mod bar {
/// pub trait Bar { .. } /// pub trait Bar { /* ... */ }
///
/// pub type Baz = impl Bar; /// pub type Baz = impl Bar;
/// ///
/// fn f1() -> Baz { .. } /// # impl Bar for () {}
/// fn f1() -> Baz { /* ... */ }
/// } /// }
/// /// fn f2() -> bar::Baz { /* ... */ }
/// fn f2() -> bar::Baz { .. }
/// } /// }
/// ``` /// ```
/// ///

View file

@ -103,7 +103,7 @@ impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
/// ///
/// Example: /// Example:
/// ///
/// ``` /// ```ignore (pseudo-rust)
/// fn foo<T>() { /// fn foo<T>() {
/// callback(for<'a> |x: &'a T| { /// callback(for<'a> |x: &'a T| {
/// // ^^^^^^^ not legal syntax, but probably should be /// // ^^^^^^^ not legal syntax, but probably should be

View file

@ -33,9 +33,9 @@
//! Consider: //! Consider:
//! //!
//! ``` //! ```
//! fn bar<T>(a: T, b: impl for<'a> Fn(&'a T)); //! fn bar<T>(a: T, b: impl for<'a> Fn(&'a T)) {}
//! fn foo<T>(x: T) { //! fn foo<T>(x: T) {
//! bar(x, |y| { ... }) //! bar(x, |y| { /* ... */})
//! // ^ closure arg //! // ^ closure arg
//! } //! }
//! ``` //! ```

View file

@ -313,7 +313,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
/// ///
/// It will not, however, work for higher-ranked bounds like: /// It will not, however, work for higher-ranked bounds like:
/// ///
/// ```rust /// ```compile_fail,E0311
/// trait Foo<'a, 'b> /// trait Foo<'a, 'b>
/// where for<'x> <Self as Foo<'x, 'b>>::Bar: 'x /// where for<'x> <Self as Foo<'x, 'b>>::Bar: 'x
/// { /// {

View file

@ -174,19 +174,19 @@ pub enum GenericKind<'tcx> {
/// Describes the things that some `GenericKind` value `G` is known to /// Describes the things that some `GenericKind` value `G` is known to
/// outlive. Each variant of `VerifyBound` can be thought of as a /// outlive. Each variant of `VerifyBound` can be thought of as a
/// function: /// function:
/// /// ```ignore (pseudo-rust)
/// fn(min: Region) -> bool { .. } /// fn(min: Region) -> bool { .. }
/// /// ```
/// where `true` means that the region `min` meets that `G: min`. /// where `true` means that the region `min` meets that `G: min`.
/// (False means nothing.) /// (False means nothing.)
/// ///
/// So, for example, if we have the type `T` and we have in scope that /// So, for example, if we have the type `T` and we have in scope that
/// `T: 'a` and `T: 'b`, then the verify bound might be: /// `T: 'a` and `T: 'b`, then the verify bound might be:
/// /// ```ignore (pseudo-rust)
/// fn(min: Region) -> bool { /// fn(min: Region) -> bool {
/// ('a: min) || ('b: min) /// ('a: min) || ('b: min)
/// } /// }
/// /// ```
/// This is described with an `AnyRegion('a, 'b)` node. /// This is described with an `AnyRegion('a, 'b)` node.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum VerifyBound<'tcx> { pub enum VerifyBound<'tcx> {
@ -194,7 +194,7 @@ pub enum VerifyBound<'tcx> {
/// following, where `G` is the generic for which this verify /// following, where `G` is the generic for which this verify
/// bound was created: /// bound was created:
/// ///
/// ```rust /// ```ignore (pseudo-rust)
/// fn(min) -> bool { /// fn(min) -> bool {
/// if G == K { /// if G == K {
/// B(min) /// B(min)
@ -218,7 +218,7 @@ pub enum VerifyBound<'tcx> {
/// ///
/// So we would compile to a verify-bound like /// So we would compile to a verify-bound like
/// ///
/// ``` /// ```ignore (illustrative)
/// IfEq(<T as Trait<'a>>::Item, AnyRegion('a)) /// IfEq(<T as Trait<'a>>::Item, AnyRegion('a))
/// ``` /// ```
/// ///
@ -228,7 +228,7 @@ pub enum VerifyBound<'tcx> {
/// Given a region `R`, expands to the function: /// Given a region `R`, expands to the function:
/// ///
/// ``` /// ```ignore (pseudo-rust)
/// fn(min) -> bool { /// fn(min) -> bool {
/// R: min /// R: min
/// } /// }
@ -243,7 +243,7 @@ pub enum VerifyBound<'tcx> {
/// Given a set of bounds `B`, expands to the function: /// Given a set of bounds `B`, expands to the function:
/// ///
/// ```rust /// ```ignore (pseudo-rust)
/// fn(min) -> bool { /// fn(min) -> bool {
/// exists (b in B) { b(min) } /// exists (b in B) { b(min) }
/// } /// }
@ -255,7 +255,7 @@ pub enum VerifyBound<'tcx> {
/// Given a set of bounds `B`, expands to the function: /// Given a set of bounds `B`, expands to the function:
/// ///
/// ```rust /// ```ignore (pseudo-rust)
/// fn(min) -> bool { /// fn(min) -> bool {
/// forall (b in B) { b(min) } /// forall (b in B) { b(min) }
/// } /// }

View file

@ -73,10 +73,10 @@ pub struct TypeVariableStorage<'tcx> {
/// table exists only to help with the occurs check. In particular, /// table exists only to help with the occurs check. In particular,
/// we want to report constraints like these as an occurs check /// we want to report constraints like these as an occurs check
/// violation: /// violation:
/// /// ``` text
/// ?1 <: ?3 /// ?1 <: ?3
/// Box<?3> <: ?1 /// Box<?3> <: ?1
/// /// ```
/// Without this second table, what would happen in a case like /// Without this second table, what would happen in a case like
/// this is that we would instantiate `?1` with a generalized /// this is that we would instantiate `?1` with a generalized
/// type like `Box<?6>`. We would then relate `Box<?3> <: Box<?6>` /// type like `Box<?6>`. We would then relate `Box<?3> <: Box<?6>`
@ -287,8 +287,9 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
/// related via equality or subtyping will yield the same root /// related via equality or subtyping will yield the same root
/// variable (per the union-find algorithm), so `sub_root_var(a) /// variable (per the union-find algorithm), so `sub_root_var(a)
/// == sub_root_var(b)` implies that: /// == sub_root_var(b)` implies that:
/// /// ```text
/// exists X. (a <: X || X <: a) && (b <: X || X <: b) /// exists X. (a <: X || X <: a) && (b <: X || X <: b)
/// ```
pub fn sub_root_var(&mut self, vid: ty::TyVid) -> ty::TyVid { pub fn sub_root_var(&mut self, vid: ty::TyVid) -> ty::TyVid {
self.sub_relations().find(vid) self.sub_relations().find(vid)
} }

View file

@ -1109,7 +1109,8 @@ declare_lint! {
/// ///
/// ### Example /// ### Example
/// ///
/// ```rust,compile_fail /// ```compile_fail
/// #![deny(unaligned_references)]
/// #[repr(packed)] /// #[repr(packed)]
/// pub struct Foo { /// pub struct Foo {
/// field1: u64, /// field1: u64,

View file

@ -737,7 +737,7 @@ impl<'hir> Map<'hir> {
/// } /// }
/// ``` /// ```
/// ///
/// ``` /// ```compile_fail,E0308
/// fn foo(x: usize) -> bool { /// fn foo(x: usize) -> bool {
/// loop { /// loop {
/// true // If `get_return_block` gets passed the `id` corresponding /// true // If `get_return_block` gets passed the `id` corresponding

View file

@ -10,7 +10,7 @@ use rustc_span::Span;
/// Requires that `region` must be equal to one of the regions in `choice_regions`. /// Requires that `region` must be equal to one of the regions in `choice_regions`.
/// We often denote this using the syntax: /// We often denote this using the syntax:
/// ///
/// ``` /// ```text
/// R0 member of [O1..On] /// R0 member of [O1..On]
/// ``` /// ```
#[derive(Debug, Clone, HashStable, TypeFoldable, Lift)] #[derive(Debug, Clone, HashStable, TypeFoldable, Lift)]

View file

@ -770,11 +770,11 @@ impl InitMask {
/// ///
/// Note that all examples below are written with 8 (instead of 64) bit blocks for simplicity, /// Note that all examples below are written with 8 (instead of 64) bit blocks for simplicity,
/// and with the least significant bit (and lowest block) first: /// and with the least significant bit (and lowest block) first:
/// /// ```text
/// 00000000|00000000 /// 00000000|00000000
/// ^ ^ ^ ^ /// ^ ^ ^ ^
/// index: 0 7 8 15 /// index: 0 7 8 15
/// /// ```
/// Also, if not stated, assume that `is_init = true`, that is, we are searching for the first 1 bit. /// Also, if not stated, assume that `is_init = true`, that is, we are searching for the first 1 bit.
fn find_bit_fast( fn find_bit_fast(
init_mask: &InitMask, init_mask: &InitMask,

View file

@ -737,14 +737,14 @@ pub enum BorrowKind {
/// This is used when lowering matches: when matching on a place we want to /// This is used when lowering matches: when matching on a place we want to
/// ensure that place have the same value from the start of the match until /// ensure that place have the same value from the start of the match until
/// an arm is selected. This prevents this code from compiling: /// an arm is selected. This prevents this code from compiling:
/// /// ```compile_fail,E0510
/// let mut x = &Some(0); /// let mut x = &Some(0);
/// match *x { /// match *x {
/// None => (), /// None => (),
/// Some(_) if { x = &None; false } => (), /// Some(_) if { x = &None; false } => (),
/// Some(_) => (), /// Some(_) => (),
/// } /// }
/// /// ```
/// This can't be a shared borrow because mutably borrowing (*x as Some).0 /// This can't be a shared borrow because mutably borrowing (*x as Some).0
/// should not prevent `if let None = x { ... }`, for example, because the /// should not prevent `if let None = x { ... }`, for example, because the
/// mutating `(*x as Some).0` can't affect the discriminant of `x`. /// mutating `(*x as Some).0` can't affect the discriminant of `x`.
@ -755,27 +755,30 @@ pub enum BorrowKind {
/// cannot currently be expressed by the user and is used only in /// cannot currently be expressed by the user and is used only in
/// implicit closure bindings. It is needed when the closure is /// implicit closure bindings. It is needed when the closure is
/// borrowing or mutating a mutable referent, e.g.: /// borrowing or mutating a mutable referent, e.g.:
/// /// ```
/// let x: &mut isize = ...; /// let mut z = 3;
/// let y = || *x += 5; /// let x: &mut isize = &mut z;
/// /// let y = || *x += 5;
/// ```
/// If we were to try to translate this closure into a more explicit /// If we were to try to translate this closure into a more explicit
/// form, we'd encounter an error with the code as written: /// form, we'd encounter an error with the code as written:
/// /// ```compile_fail,E0594
/// struct Env { x: & &mut isize } /// struct Env<'a> { x: &'a &'a mut isize }
/// let x: &mut isize = ...; /// let mut z = 3;
/// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn /// let x: &mut isize = &mut z;
/// fn fn_ptr(env: &mut Env) { **env.x += 5; } /// let y = (&mut Env { x: &x }, fn_ptr); // Closure is pair of env and fn
/// /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
/// ```
/// This is then illegal because you cannot mutate an `&mut` found /// This is then illegal because you cannot mutate an `&mut` found
/// in an aliasable location. To solve, you'd have to translate with /// in an aliasable location. To solve, you'd have to translate with
/// an `&mut` borrow: /// an `&mut` borrow:
/// /// ```compile_fail,E0596
/// struct Env { x: &mut &mut isize } /// struct Env<'a> { x: &'a mut &'a mut isize }
/// let x: &mut isize = ...; /// let mut z = 3;
/// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x /// let x: &mut isize = &mut z;
/// fn fn_ptr(env: &mut Env) { **env.x += 5; } /// let y = (&mut Env { x: &mut x }, fn_ptr); // changed from &x to &mut x
/// /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
/// ```
/// Now the assignment to `**env.x` is legal, but creating a /// Now the assignment to `**env.x` is legal, but creating a
/// mutable pointer to `x` is not because `x` is not mutable. We /// mutable pointer to `x` is not because `x` is not mutable. We
/// could fix this by declaring `x` as `let mut x`. This is ok in /// could fix this by declaring `x` as `let mut x`. This is ok in
@ -1016,7 +1019,7 @@ pub struct LocalDecl<'tcx> {
/// ``` /// ```
/// fn foo(x: &str) { /// fn foo(x: &str) {
/// match { /// match {
/// match x.parse().unwrap() { /// match x.parse::<u32>().unwrap() {
/// y => y + 2 /// y => y + 2
/// } /// }
/// } { /// } {
@ -1692,9 +1695,9 @@ pub enum StatementKind<'tcx> {
/// Encodes a user's type ascription. These need to be preserved /// Encodes a user's type ascription. These need to be preserved
/// intact so that NLL can respect them. For example: /// intact so that NLL can respect them. For example:
/// /// ```ignore (illustrative)
/// let a: T = y; /// let a: T = y;
/// /// ```
/// The effect of this annotation is to relate the type `T_y` of the place `y` /// The effect of this annotation is to relate the type `T_y` of the place `y`
/// to the user-given type `T`. The effect depends on the specified variance: /// to the user-given type `T`. The effect depends on the specified variance:
/// ///
@ -1987,7 +1990,7 @@ pub enum ProjectionElem<V, T> {
/// These indices are generated by slice patterns. Easiest to explain /// These indices are generated by slice patterns. Easiest to explain
/// by example: /// by example:
/// ///
/// ``` /// ```ignore (illustrative)
/// [X, _, .._, _, _] => { offset: 0, min_length: 4, from_end: false }, /// [X, _, .._, _, _] => { offset: 0, min_length: 4, from_end: false },
/// [_, X, .._, _, _] => { offset: 1, min_length: 4, from_end: false }, /// [_, X, .._, _, _] => { offset: 1, min_length: 4, from_end: false },
/// [_, _, .._, X, _] => { offset: 2, min_length: 4, from_end: true }, /// [_, _, .._, X, _] => { offset: 2, min_length: 4, from_end: true },
@ -3175,7 +3178,7 @@ impl<'tcx> ConstantKind<'tcx> {
/// ///
/// An example: /// An example:
/// ///
/// ```rust /// ```ignore (illustrative)
/// struct S<'a>((i32, &'a str), String); /// struct S<'a>((i32, &'a str), String);
/// let S((_, w): (i32, &'static str), _): S = ...; /// let S((_, w): (i32, &'static str), _): S = ...;
/// // ------ ^^^^^^^^^^^^^^^^^^^ (1) /// // ------ ^^^^^^^^^^^^^^^^^^^ (1)

View file

@ -438,7 +438,7 @@ impl<'tcx> CodegenUnitNameBuilder<'tcx> {
/// ///
/// This function will build CGU names of the form: /// This function will build CGU names of the form:
/// ///
/// ``` /// ```text
/// <crate-name>.<crate-disambiguator>[-in-<local-crate-id>](-<component>)*[.<special-suffix>] /// <crate-name>.<crate-disambiguator>[-in-<local-crate-id>](-<component>)*[.<special-suffix>]
/// <local-crate-id> = <local-crate-name>.<local-crate-disambiguator> /// <local-crate-id> = <local-crate-name>.<local-crate-disambiguator>
/// ``` /// ```

View file

@ -202,7 +202,7 @@ pub enum TerminatorKind<'tcx> {
/// This assignment occurs both in the unwind and the regular code paths. The semantics are best /// This assignment occurs both in the unwind and the regular code paths. The semantics are best
/// explained by the elaboration: /// explained by the elaboration:
/// ///
/// ``` /// ```ignore (MIR)
/// BB0 { /// BB0 {
/// DropAndReplace(P <- V, goto BB1, unwind BB2) /// DropAndReplace(P <- V, goto BB1, unwind BB2)
/// } /// }
@ -210,7 +210,7 @@ pub enum TerminatorKind<'tcx> {
/// ///
/// becomes /// becomes
/// ///
/// ``` /// ```ignore (MIR)
/// BB0 { /// BB0 {
/// Drop(P, goto BB1, unwind BB2) /// Drop(P, goto BB1, unwind BB2)
/// } /// }

View file

@ -29,7 +29,7 @@
//! //!
//! For example, the `super_basic_block_data` method begins like this: //! For example, the `super_basic_block_data` method begins like this:
//! //!
//! ```rust //! ```ignore (pseudo-rust)
//! fn super_basic_block_data(&mut self, //! fn super_basic_block_data(&mut self,
//! block: BasicBlock, //! block: BasicBlock,
//! data: & $($mutability)? BasicBlockData<'tcx>) { //! data: & $($mutability)? BasicBlockData<'tcx>) {
@ -1170,10 +1170,10 @@ pub enum NonMutatingUseContext {
AddressOf, AddressOf,
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place. /// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
/// For example, the projection `x.y` is not marked as a mutation in these cases: /// For example, the projection `x.y` is not marked as a mutation in these cases:
/// /// ```ignore (illustrative)
/// z = x.y; /// z = x.y;
/// f(&x.y); /// f(&x.y);
/// /// ```
Projection, Projection,
} }
@ -1199,10 +1199,10 @@ pub enum MutatingUseContext {
AddressOf, AddressOf,
/// Used as base for another place, e.g., `x` in `x.y`. Could potentially mutate the place. /// Used as base for another place, e.g., `x` in `x.y`. Could potentially mutate the place.
/// For example, the projection `x.y` is marked as a mutation in these cases: /// For example, the projection `x.y` is marked as a mutation in these cases:
/// /// ```ignore (illustrative)
/// x.y = ...; /// x.y = ...;
/// f(&mut x.y); /// f(&mut x.y);
/// /// ```
Projection, Projection,
/// Retagging, a "Stacked Borrows" shadow state operation /// Retagging, a "Stacked Borrows" shadow state operation
Retag, Retag,

View file

@ -47,7 +47,8 @@ pub enum Reveal {
/// impl. Concretely, that means that the following example will /// impl. Concretely, that means that the following example will
/// fail to compile: /// fail to compile:
/// ///
/// ``` /// ```compile_fail,E0308
/// #![feature(specialization)]
/// trait Assoc { /// trait Assoc {
/// type Output; /// type Output;
/// } /// }
@ -57,7 +58,7 @@ pub enum Reveal {
/// } /// }
/// ///
/// fn main() { /// fn main() {
/// let <() as Assoc>::Output = true; /// let x: <() as Assoc>::Output = true;
/// } /// }
/// ``` /// ```
UserFacing, UserFacing,
@ -515,7 +516,7 @@ pub type SelectionResult<'tcx, T> = Result<Option<T>, SelectionError<'tcx>>;
/// For example, the obligation may be satisfied by a specific impl (case A), /// For example, the obligation may be satisfied by a specific impl (case A),
/// or it may be relative to some bound that is in scope (case B). /// or it may be relative to some bound that is in scope (case B).
/// ///
/// ``` /// ```ignore (illustrative)
/// impl<T:Clone> Clone<T> for Option<T> { ... } // Impl_1 /// impl<T:Clone> Clone<T> for Option<T> { ... } // Impl_1
/// impl<T:Clone> Clone<T> for Box<T> { ... } // Impl_2 /// impl<T:Clone> Clone<T> for Box<T> { ... } // Impl_2
/// impl Clone for i32 { ... } // Impl_3 /// impl Clone for i32 { ... } // Impl_3

View file

@ -180,6 +180,7 @@ pub struct LeafDef {
/// Example: /// Example:
/// ///
/// ``` /// ```
/// #![feature(specialization)]
/// trait Tr { /// trait Tr {
/// fn assoc(&self); /// fn assoc(&self);
/// } /// }

View file

@ -59,7 +59,7 @@ pub enum PointerCast {
/// sized struct to a dynamically sized one. E.g., `&[i32; 4]` -> `&[i32]` is /// sized struct to a dynamically sized one. E.g., `&[i32; 4]` -> `&[i32]` is
/// represented by: /// represented by:
/// ///
/// ``` /// ```ignore (illustrative)
/// Deref(None) -> [i32; 4], /// Deref(None) -> [i32; 4],
/// Borrow(AutoBorrow::Ref) -> &[i32; 4], /// Borrow(AutoBorrow::Ref) -> &[i32; 4],
/// Unsize -> &[i32], /// Unsize -> &[i32],

View file

@ -82,7 +82,7 @@ bitflags! {
/// ///
/// is essentially represented with [`Ty`] as the following pseudocode: /// is essentially represented with [`Ty`] as the following pseudocode:
/// ///
/// ``` /// ```ignore (illustrative)
/// struct S { x } /// struct S { x }
/// ``` /// ```
/// ///

View file

@ -293,7 +293,7 @@ pub struct CaptureInfo {
/// let mut t = (0,1); /// let mut t = (0,1);
/// ///
/// let c = || { /// let c = || {
/// println!("{t}"); // L1 /// println!("{t:?}"); // L1
/// t.1 = 4; // L2 /// t.1 = 4; // L2
/// }; /// };
/// ``` /// ```
@ -309,7 +309,7 @@ pub struct CaptureInfo {
/// let x = 5; /// let x = 5;
/// ///
/// let c = || { /// let c = || {
/// let _ = x /// let _ = x;
/// }; /// };
/// ``` /// ```
/// ///
@ -373,17 +373,19 @@ pub enum BorrowKind {
/// is borrowing or mutating a mutable referent, e.g.: /// is borrowing or mutating a mutable referent, e.g.:
/// ///
/// ``` /// ```
/// let x: &mut isize = ...; /// let mut z = 3;
/// let x: &mut isize = &mut z;
/// let y = || *x += 5; /// let y = || *x += 5;
/// ``` /// ```
/// ///
/// If we were to try to translate this closure into a more explicit /// If we were to try to translate this closure into a more explicit
/// form, we'd encounter an error with the code as written: /// form, we'd encounter an error with the code as written:
/// ///
/// ``` /// ```compile_fail,E0594
/// struct Env { x: & &mut isize } /// struct Env<'a> { x: &'a &'a mut isize }
/// let x: &mut isize = ...; /// let mut z = 3;
/// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn /// let x: &mut isize = &mut z;
/// let y = (&mut Env { x: &x }, fn_ptr); // Closure is pair of env and fn
/// fn fn_ptr(env: &mut Env) { **env.x += 5; } /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
/// ``` /// ```
/// ///
@ -391,10 +393,11 @@ pub enum BorrowKind {
/// in an aliasable location. To solve, you'd have to translate with /// in an aliasable location. To solve, you'd have to translate with
/// an `&mut` borrow: /// an `&mut` borrow:
/// ///
/// ``` /// ```compile_fail,E0596
/// struct Env { x: &mut &mut isize } /// struct Env<'a> { x: &'a mut &'a mut isize }
/// let x: &mut isize = ...; /// let mut z = 3;
/// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x /// let x: &mut isize = &mut z;
/// let y = (&mut Env { x: &mut x }, fn_ptr); // changed from &x to &mut x
/// fn fn_ptr(env: &mut Env) { **env.x += 5; } /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
/// ``` /// ```
/// ///

View file

@ -455,12 +455,13 @@ pub struct TypeckResults<'tcx> {
/// # Example /// # Example
/// ///
/// ```rust /// ```rust
/// # use std::fmt::Debug;
/// fn foo(x: &u32) -> impl Debug { *x } /// fn foo(x: &u32) -> impl Debug { *x }
/// ``` /// ```
/// ///
/// The function signature here would be: /// The function signature here would be:
/// ///
/// ``` /// ```ignore (illustrative)
/// for<'a> fn(&'a u32) -> Foo /// for<'a> fn(&'a u32) -> Foo
/// ``` /// ```
/// ///
@ -469,7 +470,7 @@ pub struct TypeckResults<'tcx> {
/// ///
/// The *liberated* form of this would be /// The *liberated* form of this would be
/// ///
/// ``` /// ```ignore (illustrative)
/// fn(&'a u32) -> u32 /// fn(&'a u32) -> u32
/// ``` /// ```
/// ///

View file

@ -41,7 +41,7 @@
//! //!
//! For example, if you have `struct S(Ty, U)` where `S: TypeFoldable` and `U: //! For example, if you have `struct S(Ty, U)` where `S: TypeFoldable` and `U:
//! TypeFoldable`, and an instance `S(ty, u)`, it would be visited like so: //! TypeFoldable`, and an instance `S(ty, u)`, it would be visited like so:
//! ``` //! ```text
//! s.visit_with(visitor) calls //! s.visit_with(visitor) calls
//! - s.super_visit_with(visitor) calls //! - s.super_visit_with(visitor) calls
//! - ty.visit_with(visitor) calls //! - ty.visit_with(visitor) calls
@ -486,13 +486,13 @@ impl<'tcx> TyCtxt<'tcx> {
/// traversed. If we encounter a bound region bound by this /// traversed. If we encounter a bound region bound by this
/// binder or one outer to it, it appears free. Example: /// binder or one outer to it, it appears free. Example:
/// ///
/// ``` /// ```ignore (illustrative)
/// for<'a> fn(for<'b> fn(), T) /// for<'a> fn(for<'b> fn(), T)
/// ^ ^ ^ ^ /// // ^ ^ ^ ^
/// | | | | here, would be shifted in 1 /// // | | | | here, would be shifted in 1
/// | | | here, would be shifted in 2 /// // | | | here, would be shifted in 2
/// | | here, would be `INNERMOST` shifted in by 1 /// // | | here, would be `INNERMOST` shifted in by 1
/// | here, initially, binder would be `INNERMOST` /// // | here, initially, binder would be `INNERMOST`
/// ``` /// ```
/// ///
/// You see that, initially, *any* bound value is free, /// You see that, initially, *any* bound value is free,

View file

@ -56,7 +56,9 @@ impl<'tcx> TyCtxt<'tcx> {
/// Checks whether a type is visibly uninhabited from a particular module. /// Checks whether a type is visibly uninhabited from a particular module.
/// ///
/// # Example /// # Example
/// ```rust /// ```
/// #![feature(never_type)]
/// # fn main() {}
/// enum Void {} /// enum Void {}
/// mod a { /// mod a {
/// pub mod b { /// pub mod b {
@ -67,6 +69,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// } /// }
/// ///
/// mod c { /// mod c {
/// use super::Void;
/// pub struct AlsoSecretlyUninhabited { /// pub struct AlsoSecretlyUninhabited {
/// _priv: Void, /// _priv: Void,
/// } /// }
@ -84,7 +87,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// contain `Foo`. /// contain `Foo`.
/// ///
/// # Example /// # Example
/// ```rust /// ```ignore (illustrative)
/// let foo_result: Result<T, Foo> = ... ; /// let foo_result: Result<T, Foo> = ... ;
/// let Ok(t) = foo_result; /// let Ok(t) = foo_result;
/// ``` /// ```

View file

@ -337,7 +337,7 @@ impl<'tcx> Instance<'tcx> {
/// Returns `Ok(None)` if we cannot resolve `Instance` to a specific instance. /// Returns `Ok(None)` if we cannot resolve `Instance` to a specific instance.
/// For example, in a context like this, /// For example, in a context like this,
/// ///
/// ``` /// ```ignore (illustrative)
/// fn foo<T: Debug>(t: T) { ... } /// fn foo<T: Debug>(t: T) { ... }
/// ``` /// ```
/// ///

View file

@ -1030,9 +1030,9 @@ impl<'tcx> Predicate<'tcx> {
/// their values. /// their values.
/// ///
/// Example: /// Example:
/// /// ```ignore (illustrative)
/// struct Foo<T, U: Bar<T>> { ... } /// struct Foo<T, U: Bar<T>> { ... }
/// /// ```
/// Here, the `GenericPredicates` for `Foo` would contain a list of bounds like /// Here, the `GenericPredicates` for `Foo` would contain a list of bounds like
/// `[[], [U:Bar<T>]]`. Now if there were some particular reference /// `[[], [U:Bar<T>]]`. Now if there were some particular reference
/// like `Foo<isize,usize>`, then the `InstantiatedPredicates` would be `[[], /// like `Foo<isize,usize>`, then the `InstantiatedPredicates` would be `[[],
@ -1090,9 +1090,9 @@ pub struct OpaqueHiddenType<'tcx> {
/// The type variable that represents the value of the opaque type /// The type variable that represents the value of the opaque type
/// that we require. In other words, after we compile this function, /// that we require. In other words, after we compile this function,
/// we will be created a constraint like: /// we will be created a constraint like:
/// /// ```ignore (pseudo-rust)
/// Foo<'a, T> = ?C /// Foo<'a, T> = ?C
/// /// ```
/// where `?C` is the value of this type variable. =) It may /// where `?C` is the value of this type variable. =) It may
/// naturally refer to the type and lifetime parameters in scope /// naturally refer to the type and lifetime parameters in scope
/// in this function, though ultimately it should only reference /// in this function, though ultimately it should only reference
@ -1133,7 +1133,7 @@ rustc_index::newtype_index! {
/// ///
/// To make this more concrete, consider this program: /// To make this more concrete, consider this program:
/// ///
/// ``` /// ```ignore (illustrative)
/// struct Foo { } /// struct Foo { }
/// fn bar<T>(x: T) { /// fn bar<T>(x: T) {
/// let y: for<'a> fn(&'a u8, Foo) = ...; /// let y: for<'a> fn(&'a u8, Foo) = ...;
@ -1172,7 +1172,7 @@ impl UniverseIndex {
/// corresponds to entering a `forall` quantifier. So, for /// corresponds to entering a `forall` quantifier. So, for
/// example, suppose we have this type in universe `U`: /// example, suppose we have this type in universe `U`:
/// ///
/// ``` /// ```ignore (illustrative)
/// for<'a> fn(&'a u32) /// for<'a> fn(&'a u32)
/// ``` /// ```
/// ///
@ -1959,7 +1959,7 @@ pub enum ImplOverlapKind {
/// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied /// The widely-used version 0.1.0 of the crate `traitobject` had accidentally relied
/// that difference, making what reduces to the following set of impls: /// that difference, making what reduces to the following set of impls:
/// ///
/// ``` /// ```compile_fail,(E0119)
/// trait Trait {} /// trait Trait {}
/// impl Trait for dyn Send + Sync {} /// impl Trait for dyn Send + Sync {}
/// impl Trait for dyn Sync + Send {} /// impl Trait for dyn Sync + Send {}

View file

@ -187,12 +187,14 @@ pub enum TyKind<'tcx> {
/// Looking at the following example, the witness for this generator /// Looking at the following example, the witness for this generator
/// may end up as something like `for<'a> [Vec<i32>, &'a Vec<i32>]`: /// may end up as something like `for<'a> [Vec<i32>, &'a Vec<i32>]`:
/// ///
/// ```rust /// ```ignore UNSOLVED (ask @compiler-errors, should this error? can we just swap the yields?)
/// #![feature(generators)]
/// |a| { /// |a| {
/// let x = &vec![3]; /// let x = &vec![3];
/// yield a; /// yield a;
/// yield x[0]; /// yield x[0];
/// } /// }
/// # ;
/// ``` /// ```
GeneratorWitness(Binder<'tcx, &'tcx List<Ty<'tcx>>>), GeneratorWitness(Binder<'tcx, &'tcx List<Ty<'tcx>>>),
@ -276,9 +278,9 @@ impl<'tcx> TyKind<'tcx> {
static_assert_size!(TyKind<'_>, 32); static_assert_size!(TyKind<'_>, 32);
/// A closure can be modeled as a struct that looks like: /// A closure can be modeled as a struct that looks like:
/// /// ```ignore (illustrative)
/// struct Closure<'l0...'li, T0...Tj, CK, CS, U>(...U); /// struct Closure<'l0...'li, T0...Tj, CK, CS, U>(...U);
/// /// ```
/// where: /// where:
/// ///
/// - 'l0...'li and T0...Tj are the generic parameters /// - 'l0...'li and T0...Tj are the generic parameters
@ -295,25 +297,25 @@ static_assert_size!(TyKind<'_>, 32);
/// and the up-var has the type `Foo`, then that field of U will be `&Foo`). /// and the up-var has the type `Foo`, then that field of U will be `&Foo`).
/// ///
/// So, for example, given this function: /// So, for example, given this function:
/// /// ```ignore (illustrative)
/// fn foo<'a, T>(data: &'a mut T) { /// fn foo<'a, T>(data: &'a mut T) {
/// do(|| data.count += 1) /// do(|| data.count += 1)
/// } /// }
/// /// ```
/// the type of the closure would be something like: /// the type of the closure would be something like:
/// /// ```ignore (illustrative)
/// struct Closure<'a, T, U>(...U); /// struct Closure<'a, T, U>(...U);
/// /// ```
/// Note that the type of the upvar is not specified in the struct. /// Note that the type of the upvar is not specified in the struct.
/// You may wonder how the impl would then be able to use the upvar, /// You may wonder how the impl would then be able to use the upvar,
/// if it doesn't know it's type? The answer is that the impl is /// if it doesn't know it's type? The answer is that the impl is
/// (conceptually) not fully generic over Closure but rather tied to /// (conceptually) not fully generic over Closure but rather tied to
/// instances with the expected upvar types: /// instances with the expected upvar types:
/// /// ```ignore (illustrative)
/// impl<'b, 'a, T> FnMut() for Closure<'a, T, (&'b mut &'a mut T,)> { /// impl<'b, 'a, T> FnMut() for Closure<'a, T, (&'b mut &'a mut T,)> {
/// ... /// ...
/// } /// }
/// /// ```
/// You can see that the *impl* fully specified the type of the upvar /// You can see that the *impl* fully specified the type of the upvar
/// and thus knows full well that `data` has type `&'b mut &'a mut T`. /// and thus knows full well that `data` has type `&'b mut &'a mut T`.
/// (Here, I am assuming that `data` is mut-borrowed.) /// (Here, I am assuming that `data` is mut-borrowed.)
@ -760,9 +762,9 @@ impl<'tcx> UpvarSubsts<'tcx> {
} }
/// An inline const is modeled like /// An inline const is modeled like
/// /// ```ignore (illustrative)
/// const InlineConst<'l0...'li, T0...Tj, R>: R; /// const InlineConst<'l0...'li, T0...Tj, R>: R;
/// /// ```
/// where: /// where:
/// ///
/// - 'l0...'li and T0...Tj are the generic parameters /// - 'l0...'li and T0...Tj are the generic parameters
@ -936,9 +938,9 @@ impl<'tcx> List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>> {
/// A complete reference to a trait. These take numerous guises in syntax, /// A complete reference to a trait. These take numerous guises in syntax,
/// but perhaps the most recognizable form is in a where-clause: /// but perhaps the most recognizable form is in a where-clause:
/// /// ```ignore (illustrative)
/// T: Foo<U> /// T: Foo<U>
/// /// ```
/// This would be represented by a trait-reference where the `DefId` is the /// This would be represented by a trait-reference where the `DefId` is the
/// `DefId` for the trait `Foo` and the substs define `T` as parameter 0, /// `DefId` for the trait `Foo` and the substs define `T` as parameter 0,
/// and `U` as parameter 1. /// and `U` as parameter 1.
@ -1012,9 +1014,9 @@ impl<'tcx> PolyTraitRef<'tcx> {
/// An existential reference to a trait, where `Self` is erased. /// An existential reference to a trait, where `Self` is erased.
/// For example, the trait object `Trait<'a, 'b, X, Y>` is: /// For example, the trait object `Trait<'a, 'b, X, Y>` is:
/// /// ```ignore (illustrative)
/// exists T. T: Trait<'a, 'b, X, Y> /// exists T. T: Trait<'a, 'b, X, Y>
/// /// ```
/// The substitutions don't include the erased `Self`, only trait /// The substitutions don't include the erased `Self`, only trait
/// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above). /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above).
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
@ -1434,7 +1436,7 @@ impl<'tcx> fmt::Debug for Region<'tcx> {
/// ///
/// In general, the region lattice looks like /// In general, the region lattice looks like
/// ///
/// ``` /// ```text
/// static ----------+-----...------+ (greatest) /// static ----------+-----...------+ (greatest)
/// | | | /// | | |
/// early-bound and | | /// early-bound and | |
@ -1780,14 +1782,14 @@ impl<'tcx> Region<'tcx> {
/// Given an early-bound or free region, returns the `DefId` where it was bound. /// Given an early-bound or free region, returns the `DefId` where it was bound.
/// For example, consider the regions in this snippet of code: /// For example, consider the regions in this snippet of code:
/// ///
/// ``` /// ```ignore (illustrative)
/// impl<'a> Foo { /// impl<'a> Foo {
/// ^^ -- early bound, declared on an impl /// // ^^ -- early bound, declared on an impl
/// ///
/// fn bar<'b, 'c>(x: &self, y: &'b u32, z: &'c u64) where 'static: 'c /// fn bar<'b, 'c>(x: &self, y: &'b u32, z: &'c u64) where 'static: 'c
/// ^^ ^^ ^ anonymous, late-bound /// // ^^ ^^ ^ anonymous, late-bound
/// | early-bound, appears in where-clauses /// // | early-bound, appears in where-clauses
/// late-bound, appears only in fn args /// // late-bound, appears only in fn args
/// {..} /// {..}
/// } /// }
/// ``` /// ```

View file

@ -687,17 +687,17 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
/// ///
/// ``` /// ```
/// type Func<A> = fn(A); /// type Func<A> = fn(A);
/// type MetaFunc = for<'a> fn(Func<&'a i32>) /// type MetaFunc = for<'a> fn(Func<&'a i32>);
/// ``` /// ```
/// ///
/// The type `MetaFunc`, when fully expanded, will be /// The type `MetaFunc`, when fully expanded, will be
/// /// ```ignore (illustrative)
/// for<'a> fn(fn(&'a i32)) /// for<'a> fn(fn(&'a i32))
/// ^~ ^~ ^~~ /// // ^~ ^~ ^~~
/// | | | /// // | | |
/// | | DebruijnIndex of 2 /// // | | DebruijnIndex of 2
/// Binders /// // Binders
/// /// ```
/// Here the `'a` lifetime is bound in the outer function, but appears as an argument of the /// Here the `'a` lifetime is bound in the outer function, but appears as an argument of the
/// inner one. Therefore, that appearance will have a DebruijnIndex of 2, because we must skip /// inner one. Therefore, that appearance will have a DebruijnIndex of 2, because we must skip
/// over the inner binder (remember that we count De Bruijn indices from 1). However, in the /// over the inner binder (remember that we count De Bruijn indices from 1). However, in the
@ -709,17 +709,17 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
/// ///
/// ``` /// ```
/// type FuncTuple<A> = (A,fn(A)); /// type FuncTuple<A> = (A,fn(A));
/// type MetaFuncTuple = for<'a> fn(FuncTuple<&'a i32>) /// type MetaFuncTuple = for<'a> fn(FuncTuple<&'a i32>);
/// ``` /// ```
/// ///
/// Here the final type will be: /// Here the final type will be:
/// /// ```ignore (illustrative)
/// for<'a> fn((&'a i32, fn(&'a i32))) /// for<'a> fn((&'a i32, fn(&'a i32)))
/// ^~~ ^~~ /// // ^~~ ^~~
/// | | /// // | |
/// DebruijnIndex of 1 | /// // DebruijnIndex of 1 |
/// DebruijnIndex of 2 /// // DebruijnIndex of 2
/// /// ```
/// As indicated in the diagram, here the same type `&'a i32` is substituted once, but in the /// As indicated in the diagram, here the same type `&'a i32` is substituted once, but in the
/// first case we do not increase the De Bruijn index and in the second case we do. The reason /// first case we do not increase the De Bruijn index and in the second case we do. The reason
/// is that only in the second case have we passed through a fn binder. /// is that only in the second case have we passed through a fn binder.
@ -767,7 +767,7 @@ pub struct UserSubsts<'tcx> {
/// sometimes needed to constrain the type parameters on the impl. For /// sometimes needed to constrain the type parameters on the impl. For
/// example, in this code: /// example, in this code:
/// ///
/// ``` /// ```ignore (illustrative)
/// struct Foo<T> { } /// struct Foo<T> { }
/// impl<A> Foo<A> { fn method() { } } /// impl<A> Foo<A> { fn method() { } }
/// ``` /// ```

View file

@ -973,7 +973,7 @@ impl<'tcx> ExplicitSelf<'tcx> {
/// ///
/// Examples: /// Examples:
/// ///
/// ``` /// ```ignore (illustrative)
/// impl<'a> Foo for &'a T { /// impl<'a> Foo for &'a T {
/// // Legal declarations: /// // Legal declarations:
/// fn method1(self: &&'a T); // ExplicitSelf::ByReference /// fn method1(self: &&'a T); // ExplicitSelf::ByReference

View file

@ -34,7 +34,7 @@ impl<'tcx> TypeWalker<'tcx> {
/// ///
/// Example: Imagine you are walking `Foo<Bar<i32>, usize>`. /// Example: Imagine you are walking `Foo<Bar<i32>, usize>`.
/// ///
/// ``` /// ```ignore (illustrative)
/// let mut iter: TypeWalker = ...; /// let mut iter: TypeWalker = ...;
/// iter.next(); // yields Foo /// iter.next(); // yields Foo
/// iter.next(); // yields Bar<i32> /// iter.next(); // yields Bar<i32>

View file

@ -42,15 +42,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// We tweak the handling of parameters of unsized type slightly to avoid the need to create a /// We tweak the handling of parameters of unsized type slightly to avoid the need to create a
/// local variable of unsized type. For example, consider this program: /// local variable of unsized type. For example, consider this program:
/// ///
/// ```rust /// ```
/// fn foo(p: dyn Debug) { ... } /// #![feature(unsized_locals, unsized_fn_params)]
/// # use core::fmt::Debug;
/// fn foo(p: dyn Debug) { dbg!(p); }
/// ///
/// fn bar(box_p: Box<dyn Debug>) { foo(*p); } /// fn bar(box_p: Box<dyn Debug>) { foo(*box_p); }
/// ``` /// ```
/// ///
/// Ordinarily, for sized types, we would compile the call `foo(*p)` like so: /// Ordinarily, for sized types, we would compile the call `foo(*p)` like so:
/// ///
/// ```rust /// ```ignore (illustrative)
/// let tmp0 = *box_p; // tmp0 would be the operand returned by this function call /// let tmp0 = *box_p; // tmp0 would be the operand returned by this function call
/// foo(tmp0) /// foo(tmp0)
/// ``` /// ```
@ -60,7 +62,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// that we create *stores the entire box*, and the parameter to the call itself will be /// that we create *stores the entire box*, and the parameter to the call itself will be
/// `*tmp0`: /// `*tmp0`:
/// ///
/// ```rust /// ```ignore (illustrative)
/// let tmp0 = box_p; call foo(*tmp0) /// let tmp0 = box_p; call foo(*tmp0)
/// ``` /// ```
/// ///

View file

@ -37,7 +37,7 @@ crate enum PlaceBase {
/// ///
/// Consider the following example /// Consider the following example
/// ```rust /// ```rust
/// let t = (10, (10, (10, 10))); /// let t = (((10, 10), 10), 10);
/// ///
/// let c = || { /// let c = || {
/// println!("{}", t.0.0.0); /// println!("{}", t.0.0.0);
@ -45,7 +45,7 @@ crate enum PlaceBase {
/// ``` /// ```
/// Here the THIR expression for `t.0.0.0` will be something like /// Here the THIR expression for `t.0.0.0` will be something like
/// ///
/// ``` /// ```ignore (illustrative)
/// * Field(0) /// * Field(0)
/// * Field(0) /// * Field(0)
/// * Field(0) /// * Field(0)

View file

@ -1032,11 +1032,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// exhaustive match, consider: /// exhaustive match, consider:
/// ///
/// ``` /// ```
/// # fn foo(x: (bool, bool)) {
/// match x { /// match x {
/// (true, true) => (), /// (true, true) => (),
/// (_, false) => (), /// (_, false) => (),
/// (false, true) => (), /// (false, true) => (),
/// } /// }
/// # }
/// ``` /// ```
/// ///
/// For this match, we check if `x.0` matches `true` (for the first /// For this match, we check if `x.0` matches `true` (for the first
@ -1157,7 +1159,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// ///
/// For example, if we have something like this: /// For example, if we have something like this:
/// ///
/// ```rust /// ```ignore (illustrative)
/// ... /// ...
/// Some(x) if cond1 => ... /// Some(x) if cond1 => ...
/// Some(x) => ... /// Some(x) => ...
@ -1481,11 +1483,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// ``` /// ```
/// # let (x, y, z) = (true, true, true); /// # let (x, y, z) = (true, true, true);
/// match (x, y, z) { /// match (x, y, z) {
/// (true, _, true) => true, // (0) /// (true , _ , true ) => true, // (0)
/// (_, true, _) => true, // (1) /// (_ , true , _ ) => true, // (1)
/// (false, false, _) => false, // (2) /// (false, false, _ ) => false, // (2)
/// (true, _, false) => false, // (3) /// (true , _ , false) => false, // (3)
/// } /// }
/// # ;
/// ``` /// ```
/// ///
/// In that case, after we test on `x`, there are 2 overlapping candidate /// In that case, after we test on `x`, there are 2 overlapping candidate
@ -1502,14 +1505,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// with precisely the reachable arms being reachable - but that problem /// with precisely the reachable arms being reachable - but that problem
/// is trivially NP-complete: /// is trivially NP-complete:
/// ///
/// ```rust /// ```ignore (illustrative)
/// match (var0, var1, var2, var3, ...) { /// match (var0, var1, var2, var3, ...) {
/// (true, _, _, false, true, ...) => false, /// (true , _ , _ , false, true, ...) => false,
/// (_, true, true, false, _, ...) => false, /// (_ , true, true , false, _ , ...) => false,
/// (false, _, false, false, _, ...) => false, /// (false, _ , false, false, _ , ...) => false,
/// ... /// ...
/// _ => true /// _ => true
/// } /// }
/// ``` /// ```
/// ///
/// Here the last arm is reachable only if there is an assignment to /// Here the last arm is reachable only if there is an assignment to
@ -1520,7 +1523,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// our simplistic treatment of constants and guards would make it occur /// our simplistic treatment of constants and guards would make it occur
/// in very common situations - for example [#29740]: /// in very common situations - for example [#29740]:
/// ///
/// ```rust /// ```ignore (illustrative)
/// match x { /// match x {
/// "foo" if foo_guard => ..., /// "foo" if foo_guard => ...,
/// "bar" if bar_guard => ..., /// "bar" if bar_guard => ...,

View file

@ -803,16 +803,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// scope (which can be larger or smaller). /// scope (which can be larger or smaller).
/// ///
/// Consider: /// Consider:
/// /// ```ignore (illustrative)
/// let x = foo(bar(X, Y)); /// let x = foo(bar(X, Y));
/// /// ```
/// We wish to pop the storage for X and Y after `bar()` is /// We wish to pop the storage for X and Y after `bar()` is
/// called, not after the whole `let` is completed. /// called, not after the whole `let` is completed.
/// ///
/// As another example, if the second argument diverges: /// As another example, if the second argument diverges:
/// /// ```ignore (illustrative)
/// foo(Box::new(2), panic!()) /// foo(Box::new(2), panic!())
/// /// ```
/// We would allocate the box but then free it on the unwinding /// We would allocate the box but then free it on the unwinding
/// path; we would also emit a free on the 'success' path from /// path; we would also emit a free on the 'success' path from
/// panic, but that will turn out to be removed as dead-code. /// panic, but that will turn out to be removed as dead-code.
@ -944,7 +944,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// ///
/// Example: when compiling the call to `foo` here: /// Example: when compiling the call to `foo` here:
/// ///
/// ```rust /// ```ignore (illustrative)
/// foo(bar(), ...) /// foo(bar(), ...)
/// ``` /// ```
/// ///
@ -955,7 +955,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// dropped). However, if no unwind occurs, then `_X` will be /// dropped). However, if no unwind occurs, then `_X` will be
/// unconditionally consumed by the `call`: /// unconditionally consumed by the `call`:
/// ///
/// ``` /// ```ignore (illustrative)
/// bb { /// bb {
/// ... /// ...
/// _R = CALL(foo, _X, ...) /// _R = CALL(foo, _X, ...)

View file

@ -13,7 +13,7 @@
//! Instead of listing all those constructors (which is intractable), we group those value //! Instead of listing all those constructors (which is intractable), we group those value
//! constructors together as much as possible. Example: //! constructors together as much as possible. Example:
//! //!
//! ``` //! ```compile_fail,E0004
//! match (0, false) { //! match (0, false) {
//! (0 ..=100, true) => {} // `p_1` //! (0 ..=100, true) => {} // `p_1`
//! (50..=150, false) => {} // `p_2` //! (50..=150, false) => {} // `p_2`
@ -344,13 +344,13 @@ enum IntBorder {
/// straddles the boundary of one of the inputs. /// straddles the boundary of one of the inputs.
/// ///
/// The following input: /// The following input:
/// ``` /// ```text
/// |-------------------------| // `self` /// |-------------------------| // `self`
/// |------| |----------| |----| /// |------| |----------| |----|
/// |-------| |-------| /// |-------| |-------|
/// ``` /// ```
/// would be iterated over as follows: /// would be iterated over as follows:
/// ``` /// ```text
/// ||---|--||-|---|---|---|--| /// ||---|--||-|---|---|---|--|
/// ``` /// ```
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -492,14 +492,17 @@ impl Slice {
/// ///
/// Let's look at an example, where we are trying to split the last pattern: /// Let's look at an example, where we are trying to split the last pattern:
/// ``` /// ```
/// # fn foo(x: &[bool]) {
/// match x { /// match x {
/// [true, true, ..] => {} /// [true, true, ..] => {}
/// [.., false, false] => {} /// [.., false, false] => {}
/// [..] => {} /// [..] => {}
/// } /// }
/// # }
/// ``` /// ```
/// Here are the results of specialization for the first few lengths: /// Here are the results of specialization for the first few lengths:
/// ``` /// ```
/// # fn foo(x: &[bool]) { match x {
/// // length 0 /// // length 0
/// [] => {} /// [] => {}
/// // length 1 /// // length 1
@ -520,6 +523,8 @@ impl Slice {
/// [true, true, _, _, _ ] => {} /// [true, true, _, _, _ ] => {}
/// [_, _, _, false, false] => {} /// [_, _, _, false, false] => {}
/// [_, _, _, _, _ ] => {} /// [_, _, _, _, _ ] => {}
/// # _ => {}
/// # }}
/// ``` /// ```
/// ///
/// If we went above length 5, we would simply be inserting more columns full of wildcards in the /// If we went above length 5, we would simply be inserting more columns full of wildcards in the
@ -1128,7 +1133,8 @@ impl<'tcx> SplitWildcard<'tcx> {
/// In the following example `Fields::wildcards` returns `[_, _, _, _]`. Then in /// In the following example `Fields::wildcards` returns `[_, _, _, _]`. Then in
/// `extract_pattern_arguments` we fill some of the entries, and the result is /// `extract_pattern_arguments` we fill some of the entries, and the result is
/// `[Some(0), _, _, _]`. /// `[Some(0), _, _, _]`.
/// ```rust /// ```compile_fail,E0004
/// # fn foo() -> [Option<u8>; 4] { [None; 4] }
/// let x: [Option<u8>; 4] = foo(); /// let x: [Option<u8>; 4] = foo();
/// match x { /// match x {
/// [Some(0), ..] => {} /// [Some(0), ..] => {}

View file

@ -35,23 +35,27 @@
//! This is enough to compute reachability: a pattern in a `match` expression is reachable iff it //! This is enough to compute reachability: a pattern in a `match` expression is reachable iff it
//! is useful w.r.t. the patterns above it: //! is useful w.r.t. the patterns above it:
//! ```rust //! ```rust
//! # fn foo(x: Option<i32>) {
//! match x { //! match x {
//! Some(_) => ..., //! Some(_) => {},
//! None => ..., // reachable: `None` is matched by this but not the branch above //! None => {}, // reachable: `None` is matched by this but not the branch above
//! Some(0) => ..., // unreachable: all the values this matches are already matched by //! Some(0) => {}, // unreachable: all the values this matches are already matched by
//! // `Some(_)` above //! // `Some(_)` above
//! } //! }
//! # }
//! ``` //! ```
//! //!
//! This is also enough to compute exhaustiveness: a match is exhaustive iff the wildcard `_` //! This is also enough to compute exhaustiveness: a match is exhaustive iff the wildcard `_`
//! pattern is _not_ useful w.r.t. the patterns in the match. The values returned by `usefulness` //! pattern is _not_ useful w.r.t. the patterns in the match. The values returned by `usefulness`
//! are used to tell the user which values are missing. //! are used to tell the user which values are missing.
//! ```rust //! ```compile_fail,E0004
//! # fn foo(x: Option<i32>) {
//! match x { //! match x {
//! Some(0) => ..., //! Some(0) => {},
//! None => ..., //! None => {},
//! // not exhaustive: `_` is useful because it matches `Some(1)` //! // not exhaustive: `_` is useful because it matches `Some(1)`
//! } //! }
//! # }
//! ``` //! ```
//! //!
//! The entrypoint of this file is the [`compute_match_usefulness`] function, which computes //! The entrypoint of this file is the [`compute_match_usefulness`] function, which computes
@ -120,12 +124,15 @@
//! say from knowing only the first constructor of our candidate value. //! say from knowing only the first constructor of our candidate value.
//! //!
//! Let's take the following example: //! Let's take the following example:
//! ``` //! ```compile_fail,E0004
//! # enum Enum { Variant1(()), Variant2(Option<bool>, u32)}
//! # fn foo(x: Enum) {
//! match x { //! match x {
//! Enum::Variant1(_) => {} // `p1` //! Enum::Variant1(_) => {} // `p1`
//! Enum::Variant2(None, 0) => {} // `p2` //! Enum::Variant2(None, 0) => {} // `p2`
//! Enum::Variant2(Some(_), 0) => {} // `q` //! Enum::Variant2(Some(_), 0) => {} // `q`
//! } //! }
//! # }
//! ``` //! ```
//! //!
//! We can easily see that if our candidate value `v` starts with `Variant1` it will not match `q`. //! We can easily see that if our candidate value `v` starts with `Variant1` it will not match `q`.
@ -133,11 +140,13 @@
//! and `v1`. In fact, such a `v` will be a witness of usefulness of `q` exactly when the tuple //! and `v1`. In fact, such a `v` will be a witness of usefulness of `q` exactly when the tuple
//! `(v0, v1)` is a witness of usefulness of `q'` in the following reduced match: //! `(v0, v1)` is a witness of usefulness of `q'` in the following reduced match:
//! //!
//! ``` //! ```compile_fail,E0004
//! # fn foo(x: (Option<bool>, u32)) {
//! match x { //! match x {
//! (None, 0) => {} // `p2'` //! (None, 0) => {} // `p2'`
//! (Some(_), 0) => {} // `q'` //! (Some(_), 0) => {} // `q'`
//! } //! }
//! # }
//! ``` //! ```
//! //!
//! This motivates a new step in computing usefulness, that we call _specialization_. //! This motivates a new step in computing usefulness, that we call _specialization_.
@ -150,7 +159,7 @@
//! like a stack. We note a pattern-stack simply with `[p_1 ... p_n]`. //! like a stack. We note a pattern-stack simply with `[p_1 ... p_n]`.
//! Here's a sequence of specializations of a list of pattern-stacks, to illustrate what's //! Here's a sequence of specializations of a list of pattern-stacks, to illustrate what's
//! happening: //! happening:
//! ``` //! ```ignore (illustrative)
//! [Enum::Variant1(_)] //! [Enum::Variant1(_)]
//! [Enum::Variant2(None, 0)] //! [Enum::Variant2(None, 0)]
//! [Enum::Variant2(Some(_), 0)] //! [Enum::Variant2(Some(_), 0)]
@ -234,7 +243,7 @@
//! - We return the concatenation of all the witnesses found, if any. //! - We return the concatenation of all the witnesses found, if any.
//! //!
//! Example: //! Example:
//! ``` //! ```ignore (illustrative)
//! [Some(true)] // p_1 //! [Some(true)] // p_1
//! [None] // p_2 //! [None] // p_2
//! [Some(_)] // q //! [Some(_)] // q
@ -659,13 +668,15 @@ enum ArmType {
/// ///
/// For example, if we are constructing a witness for the match against /// For example, if we are constructing a witness for the match against
/// ///
/// ``` /// ```compile_fail,E0004
/// # #![feature(type_ascription)]
/// struct Pair(Option<(u32, u32)>, bool); /// struct Pair(Option<(u32, u32)>, bool);
/// /// # fn foo(p: Pair) {
/// match (p: Pair) { /// match (p: Pair) {
/// Pair(None, _) => {} /// Pair(None, _) => {}
/// Pair(_, false) => {} /// Pair(_, false) => {}
/// } /// }
/// # }
/// ``` /// ```
/// ///
/// We'll perform the following steps: /// We'll perform the following steps:

View file

@ -37,21 +37,21 @@ pub use self::storage_liveness::{MaybeRequiresStorage, MaybeStorageLive};
/// ///
/// ```rust /// ```rust
/// struct S; /// struct S;
/// fn foo(pred: bool) { // maybe-init: /// fn foo(pred: bool) { // maybe-init:
/// // {} /// // {}
/// let a = S; let b = S; let c; let d; // {a, b} /// let a = S; let mut b = S; let c; let d; // {a, b}
/// ///
/// if pred { /// if pred {
/// drop(a); // { b} /// drop(a); // { b}
/// b = S; // { b} /// b = S; // { b}
/// ///
/// } else { /// } else {
/// drop(b); // {a} /// drop(b); // {a}
/// d = S; // {a, d} /// d = S; // {a, d}
/// ///
/// } // {a, b, d} /// } // {a, b, d}
/// ///
/// c = S; // {a, b, c, d} /// c = S; // {a, b, c, d}
/// } /// }
/// ``` /// ```
/// ///
@ -90,21 +90,21 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'tcx> {
/// ///
/// ```rust /// ```rust
/// struct S; /// struct S;
/// fn foo(pred: bool) { // maybe-uninit: /// fn foo(pred: bool) { // maybe-uninit:
/// // {a, b, c, d} /// // {a, b, c, d}
/// let a = S; let b = S; let c; let d; // { c, d} /// let a = S; let mut b = S; let c; let d; // { c, d}
/// ///
/// if pred { /// if pred {
/// drop(a); // {a, c, d} /// drop(a); // {a, c, d}
/// b = S; // {a, c, d} /// b = S; // {a, c, d}
/// ///
/// } else { /// } else {
/// drop(b); // { b, c, d} /// drop(b); // { b, c, d}
/// d = S; // { b, c } /// d = S; // { b, c }
/// ///
/// } // {a, b, c, d} /// } // {a, b, c, d}
/// ///
/// c = S; // {a, b, d} /// c = S; // {a, b, d}
/// } /// }
/// ``` /// ```
/// ///
@ -155,21 +155,21 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'a, 'tcx> {
/// ///
/// ```rust /// ```rust
/// struct S; /// struct S;
/// fn foo(pred: bool) { // definite-init: /// fn foo(pred: bool) { // definite-init:
/// // { } /// // { }
/// let a = S; let b = S; let c; let d; // {a, b } /// let a = S; let mut b = S; let c; let d; // {a, b }
/// ///
/// if pred { /// if pred {
/// drop(a); // { b, } /// drop(a); // { b, }
/// b = S; // { b, } /// b = S; // { b, }
/// ///
/// } else { /// } else {
/// drop(b); // {a, } /// drop(b); // {a, }
/// d = S; // {a, d} /// d = S; // {a, d}
/// ///
/// } // { } /// } // { }
/// ///
/// c = S; // { c } /// c = S; // { c }
/// } /// }
/// ``` /// ```
/// ///
@ -210,21 +210,21 @@ impl<'a, 'tcx> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> {
/// ///
/// ```rust /// ```rust
/// struct S; /// struct S;
/// fn foo(pred: bool) { // ever-init: /// fn foo(pred: bool) { // ever-init:
/// // { } /// // { }
/// let a = S; let b = S; let c; let d; // {a, b } /// let a = S; let mut b = S; let c; let d; // {a, b }
/// ///
/// if pred { /// if pred {
/// drop(a); // {a, b, } /// drop(a); // {a, b, }
/// b = S; // {a, b, } /// b = S; // {a, b, }
/// ///
/// } else { /// } else {
/// drop(b); // {a, b, } /// drop(b); // {a, b, }
/// d = S; // {a, b, d } /// d = S; // {a, b, d }
/// ///
/// } // {a, b, d } /// } // {a, b, d }
/// ///
/// c = S; // {a, b, c, d } /// c = S; // {a, b, c, d }
/// } /// }
/// ``` /// ```
pub struct EverInitializedPlaces<'a, 'tcx> { pub struct EverInitializedPlaces<'a, 'tcx> {

View file

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

View file

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

View file

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

View file

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

View file

@ -91,12 +91,13 @@
//! another function. It suffices to just take a reference in order to introduce //! another function. It suffices to just take a reference in order to introduce
//! an edge. Consider the following example: //! an edge. Consider the following example:
//! //!
//! ```rust //! ```
//! # use core::fmt::Display;
//! fn print_val<T: Display>(x: T) { //! fn print_val<T: Display>(x: T) {
//! println!("{}", x); //! println!("{}", x);
//! } //! }
//! //!
//! fn call_fn(f: &Fn(i32), x: i32) { //! fn call_fn(f: &dyn Fn(i32), x: i32) {
//! f(x); //! f(x);
//! } //! }
//! //!

View file

@ -371,9 +371,10 @@ impl<'a> Parser<'a> {
} }
/// Matches the following grammar (per RFC 1559). /// Matches the following grammar (per RFC 1559).
/// /// ```ebnf
/// meta_item : PATH ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ; /// meta_item : PATH ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ;
/// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ; /// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
/// ```
pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> { pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> {
let nt_meta = match self.token.kind { let nt_meta = match self.token.kind {
token::Interpolated(ref nt) => match **nt { token::Interpolated(ref nt) => match **nt {

View file

@ -485,7 +485,7 @@ impl<'a> Parser<'a> {
/// Parses an implementation item. /// Parses an implementation item.
/// ///
/// ``` /// ```ignore (illustrative)
/// impl<'a, T> TYPE { /* impl items */ } /// impl<'a, T> TYPE { /* impl items */ }
/// impl<'a, T> TRAIT for TYPE { /* impl items */ } /// impl<'a, T> TRAIT for TYPE { /* impl items */ }
/// impl<'a, T> !TRAIT for TYPE { /* impl items */ } /// impl<'a, T> !TRAIT for TYPE { /* impl items */ }
@ -493,7 +493,7 @@ impl<'a> Parser<'a> {
/// ``` /// ```
/// ///
/// We actually parse slightly more relaxed grammar for better error reporting and recovery. /// We actually parse slightly more relaxed grammar for better error reporting and recovery.
/// ``` /// ```ebnf
/// "impl" GENERICS "const"? "!"? TYPE "for"? (TYPE | "..") ("where" PREDICATES)? "{" BODY "}" /// "impl" GENERICS "const"? "!"? TYPE "for"? (TYPE | "..") ("where" PREDICATES)? "{" BODY "}"
/// "impl" GENERICS "const"? "!"? TYPE ("where" PREDICATES)? "{" BODY "}" /// "impl" GENERICS "const"? "!"? TYPE ("where" PREDICATES)? "{" BODY "}"
/// ``` /// ```
@ -806,7 +806,7 @@ impl<'a> Parser<'a> {
} }
/// Parses a `type` alias with the following grammar: /// Parses a `type` alias with the following grammar:
/// ``` /// ```ebnf
/// TypeAlias = "type" Ident Generics {":" GenericBounds}? {"=" Ty}? ";" ; /// TypeAlias = "type" Ident Generics {":" GenericBounds}? {"=" Ty}? ";" ;
/// ``` /// ```
/// The `"type"` has already been eaten. /// The `"type"` has already been eaten.
@ -930,7 +930,7 @@ impl<'a> Parser<'a> {
/// ///
/// # Examples /// # Examples
/// ///
/// ``` /// ```ignore (illustrative)
/// extern crate foo; /// extern crate foo;
/// extern crate bar as foo; /// extern crate bar as foo;
/// ``` /// ```
@ -1630,7 +1630,7 @@ impl<'a> Parser<'a> {
/// Parses a declarative macro 2.0 definition. /// Parses a declarative macro 2.0 definition.
/// The `macro` keyword has already been parsed. /// The `macro` keyword has already been parsed.
/// ``` /// ```ebnf
/// MacBody = "{" TOKEN_STREAM "}" ; /// MacBody = "{" TOKEN_STREAM "}" ;
/// MacParams = "(" TOKEN_STREAM ")" ; /// MacParams = "(" TOKEN_STREAM ")" ;
/// DeclMac = "macro" Ident MacParams? MacBody ; /// DeclMac = "macro" Ident MacParams? MacBody ;

View file

@ -52,7 +52,7 @@ pub(super) enum RecoverQuestionMark {
/// Signals whether parsing a type should recover `->`. /// Signals whether parsing a type should recover `->`.
/// ///
/// More specifically, when parsing a function like: /// More specifically, when parsing a function like:
/// ```rust /// ```compile_fail
/// fn foo() => u8 { 0 } /// fn foo() => u8 { 0 }
/// fn bar(): u8 { 0 } /// fn bar(): u8 { 0 }
/// ``` /// ```
@ -499,12 +499,12 @@ impl<'a> Parser<'a> {
} }
/// Parses a function pointer type (`TyKind::BareFn`). /// Parses a function pointer type (`TyKind::BareFn`).
/// ``` /// ```ignore (illustrative)
/// [unsafe] [extern "ABI"] fn (S) -> T /// [unsafe] [extern "ABI"] fn (S) -> T
/// ^~~~~^ ^~~~^ ^~^ ^ /// // ^~~~~^ ^~~~^ ^~^ ^
/// | | | | /// // | | | |
/// | | | Return type /// // | | | Return type
/// Function Style ABI Parameter types /// // Function Style ABI Parameter types
/// ``` /// ```
/// We actually parse `FnHeader FnDecl`, but we error on `const` and `async` qualifiers. /// We actually parse `FnHeader FnDecl`, but we error on `const` and `async` qualifiers.
fn parse_ty_bare_fn( fn parse_ty_bare_fn(
@ -707,7 +707,7 @@ impl<'a> Parser<'a> {
} }
/// Parses a bound according to the grammar: /// Parses a bound according to the grammar:
/// ``` /// ```ebnf
/// BOUND = TY_BOUND | LT_BOUND /// BOUND = TY_BOUND | LT_BOUND
/// ``` /// ```
fn parse_generic_bound(&mut self) -> PResult<'a, Result<GenericBound, Span>> { fn parse_generic_bound(&mut self) -> PResult<'a, Result<GenericBound, Span>> {
@ -729,7 +729,7 @@ impl<'a> Parser<'a> {
} }
/// Parses a lifetime ("outlives") bound, e.g. `'a`, according to: /// Parses a lifetime ("outlives") bound, e.g. `'a`, according to:
/// ``` /// ```ebnf
/// LT_BOUND = LIFETIME /// LT_BOUND = LIFETIME
/// ``` /// ```
fn parse_generic_lt_bound( fn parse_generic_lt_bound(
@ -787,7 +787,7 @@ impl<'a> Parser<'a> {
/// ///
/// If no modifiers are present, this does not consume any tokens. /// If no modifiers are present, this does not consume any tokens.
/// ///
/// ``` /// ```ebnf
/// TY_BOUND_MODIFIERS = ["~const"] ["?"] /// TY_BOUND_MODIFIERS = ["~const"] ["?"]
/// ``` /// ```
fn parse_ty_bound_modifiers(&mut self) -> PResult<'a, BoundModifiers> { fn parse_ty_bound_modifiers(&mut self) -> PResult<'a, BoundModifiers> {
@ -807,7 +807,7 @@ impl<'a> Parser<'a> {
} }
/// Parses a type bound according to: /// Parses a type bound according to:
/// ``` /// ```ebnf
/// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN) /// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN)
/// TY_BOUND_NOPAREN = [TY_BOUND_MODIFIERS] [for<LT_PARAM_DEFS>] SIMPLE_PATH /// TY_BOUND_NOPAREN = [TY_BOUND_MODIFIERS] [for<LT_PARAM_DEFS>] SIMPLE_PATH
/// ``` /// ```

View file

@ -7,9 +7,9 @@ use std::error::Error;
/// A dep-node filter goes from a user-defined string to a query over /// A dep-node filter goes from a user-defined string to a query over
/// nodes. Right now the format is like this: /// nodes. Right now the format is like this:
/// /// ```ignore (illustrative)
/// x & y & z /// x & y & z
/// /// ```
/// where the format-string of the dep-node must contain `x`, `y`, and /// where the format-string of the dep-node must contain `x`, `y`, and
/// `z`. /// `z`.
#[derive(Debug)] #[derive(Debug)]

View file

@ -2270,16 +2270,16 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
/// Given a `binding_span` of a binding within a use statement: /// Given a `binding_span` of a binding within a use statement:
/// ///
/// ``` /// ```ignore (illustrative)
/// use foo::{a, b, c}; /// use foo::{a, b, c};
/// ^ /// // ^
/// ``` /// ```
/// ///
/// then return the span until the next binding or the end of the statement: /// then return the span until the next binding or the end of the statement:
/// ///
/// ``` /// ```ignore (illustrative)
/// use foo::{a, b, c}; /// use foo::{a, b, c};
/// ^^^ /// // ^^^
/// ``` /// ```
fn find_span_of_binding_until_next_binding( fn find_span_of_binding_until_next_binding(
sess: &Session, sess: &Session,
@ -2323,14 +2323,14 @@ fn find_span_of_binding_until_next_binding(
/// Given a `binding_span`, return the span through to the comma or opening brace of the previous /// Given a `binding_span`, return the span through to the comma or opening brace of the previous
/// binding. /// binding.
/// ///
/// ``` /// ```ignore (illustrative)
/// use foo::a::{a, b, c}; /// use foo::a::{a, b, c};
/// ^^--- binding span /// // ^^--- binding span
/// | /// // |
/// returned span /// // returned span
/// ///
/// use foo::{a, b, c}; /// use foo::{a, b, c};
/// --- binding span /// // --- binding span
/// ``` /// ```
fn extend_span_to_previous_binding(sess: &Session, binding_span: Span) -> Option<Span> { fn extend_span_to_previous_binding(sess: &Session, binding_span: Span) -> Option<Span> {
let source_map = sess.source_map(); let source_map = sess.source_map();
@ -2366,15 +2366,15 @@ fn extend_span_to_previous_binding(sess: &Session, binding_span: Span) -> Option
/// Given a `use_span` of a binding within a use statement, returns the highlighted span and if /// Given a `use_span` of a binding within a use statement, returns the highlighted span and if
/// it is a nested use tree. /// it is a nested use tree.
/// ///
/// ``` /// ```ignore (illustrative)
/// use foo::a::{b, c}; /// use foo::a::{b, c};
/// ^^^^^^^^^^ // false /// // ^^^^^^^^^^ -- false
/// ///
/// use foo::{a, b, c}; /// use foo::{a, b, c};
/// ^^^^^^^^^^ // true /// // ^^^^^^^^^^ -- true
/// ///
/// use foo::{a, b::{c, d}}; /// use foo::{a, b::{c, d}};
/// ^^^^^^^^^^^^^^^ // true /// // ^^^^^^^^^^^^^^^ -- true
/// ``` /// ```
fn find_span_immediately_after_crate_name( fn find_span_immediately_after_crate_name(
sess: &Session, sess: &Session,

View file

@ -401,7 +401,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
/// The reason for this separate call is to resolve what would otherwise /// The reason for this separate call is to resolve what would otherwise
/// be a cycle. Consider this example: /// be a cycle. Consider this example:
/// ///
/// ```rust /// ```ignore UNSOLVED (maybe @jackh726 knows what lifetime parameter to give Sub)
/// trait Base<'a> { /// trait Base<'a> {
/// type BaseItem; /// type BaseItem;
/// } /// }
@ -2546,7 +2546,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
/// Returns all the late-bound vars that come into scope from supertrait HRTBs, based on the /// Returns all the late-bound vars that come into scope from supertrait HRTBs, based on the
/// associated type name and starting trait. /// associated type name and starting trait.
/// For example, imagine we have /// For example, imagine we have
/// ```rust /// ```ignore (illustrative)
/// trait Foo<'a, 'b> { /// trait Foo<'a, 'b> {
/// type As; /// type As;
/// } /// }

View file

@ -686,7 +686,7 @@ impl SyntaxContext {
/// context up one macro definition level. That is, if we have a nested macro /// context up one macro definition level. That is, if we have a nested macro
/// definition as follows: /// definition as follows:
/// ///
/// ```rust /// ```ignore (illustrative)
/// macro_rules! f { /// macro_rules! f {
/// macro_rules! g { /// macro_rules! g {
/// ... /// ...
@ -710,6 +710,7 @@ impl SyntaxContext {
/// For example, consider the following three resolutions of `f`: /// For example, consider the following three resolutions of `f`:
/// ///
/// ```rust /// ```rust
/// #![feature(decl_macro)]
/// mod foo { pub fn f() {} } // `f`'s `SyntaxContext` is empty. /// mod foo { pub fn f() {} } // `f`'s `SyntaxContext` is empty.
/// m!(f); /// m!(f);
/// macro m($f:ident) { /// macro m($f:ident) {
@ -746,7 +747,8 @@ impl SyntaxContext {
/// via a glob import with the given `SyntaxContext`. /// via a glob import with the given `SyntaxContext`.
/// For example: /// For example:
/// ///
/// ```rust /// ```compile_fail,E0425
/// #![feature(decl_macro)]
/// m!(f); /// m!(f);
/// macro m($i:ident) { /// macro m($i:ident) {
/// mod foo { /// mod foo {
@ -786,7 +788,7 @@ impl SyntaxContext {
/// Undo `glob_adjust` if possible: /// Undo `glob_adjust` if possible:
/// ///
/// ```rust /// ```ignore (illustrative)
/// if let Some(privacy_checking_scope) = self.reverse_glob_adjust(expansion, glob_ctxt) { /// if let Some(privacy_checking_scope) = self.reverse_glob_adjust(expansion, glob_ctxt) {
/// assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope)); /// assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope));
/// } /// }

View file

@ -1058,10 +1058,11 @@ impl SourceMap {
/// Tries to find the span of the semicolon of a macro call statement. /// Tries to find the span of the semicolon of a macro call statement.
/// The input must be the *call site* span of a statement from macro expansion. /// The input must be the *call site* span of a statement from macro expansion.
/// /// ```ignore (illustrative)
/// v output /// // v output
/// mac!(); /// mac!();
/// ^^^^^^ input /// // ^^^^^^ input
/// ```
pub fn mac_call_stmt_semi_span(&self, mac_call: Span) -> Option<Span> { pub fn mac_call_stmt_semi_span(&self, mac_call: Span) -> Option<Span> {
let span = self.span_extend_while(mac_call, char::is_whitespace).ok()?; let span = self.span_extend_while(mac_call, char::is_whitespace).ok()?;
let span = span.shrink_to_hi().with_hi(BytePos(span.hi().0.checked_add(1)?)); let span = span.shrink_to_hi().with_hi(BytePos(span.hi().0.checked_add(1)?));

View file

@ -22,11 +22,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
/// (*), computes the "definition type" for an opaque type /// (*), computes the "definition type" for an opaque type
/// definition -- that is, the inferred value of `Foo1<'x>` or /// definition -- that is, the inferred value of `Foo1<'x>` or
/// `Foo2<'x>` that we would conceptually use in its definition: /// `Foo2<'x>` that we would conceptually use in its definition:
/// /// ```ignore (illustrative)
/// type Foo1<'x> = impl Bar<'x> = AAA; <-- this type AAA /// type Foo1<'x> = impl Bar<'x> = AAA; // <-- this type AAA
/// type Foo2<'x> = impl Bar<'x> = BBB; <-- or this type BBB /// type Foo2<'x> = impl Bar<'x> = BBB; // <-- or this type BBB
/// fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. } /// fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. }
/// /// ```
/// Note that these values are defined in terms of a distinct set of /// Note that these values are defined in terms of a distinct set of
/// generic parameters (`'x` instead of `'a`) from C1 or C2. The main /// generic parameters (`'x` instead of `'a`) from C1 or C2. The main
/// purpose of this function is to do that translation. /// purpose of this function is to do that translation.

View file

@ -255,9 +255,9 @@ impl<'tcx> AutoTraitFinder<'tcx> {
/// `FulfillmentContext` will drive `SelectionContext` to consider that impl before giving up. /// `FulfillmentContext` will drive `SelectionContext` to consider that impl before giving up.
/// If we were to rely on `FulfillmentContext`s decision, we might end up synthesizing an impl /// If we were to rely on `FulfillmentContext`s decision, we might end up synthesizing an impl
/// like this: /// like this:
/// /// ```ignore (illustrative)
/// impl<T> Send for Foo<T> where T: IntoIterator /// impl<T> Send for Foo<T> where T: IntoIterator
/// /// ```
/// While it might be technically true that Foo implements Send where `T: IntoIterator`, /// While it might be technically true that Foo implements Send where `T: IntoIterator`,
/// the bound is overly restrictive - it's really only necessary that `T: Iterator`. /// the bound is overly restrictive - it's really only necessary that `T: Iterator`.
/// ///
@ -420,10 +420,10 @@ impl<'tcx> AutoTraitFinder<'tcx> {
/// two trait predicates that differ only in their region parameters: /// two trait predicates that differ only in their region parameters:
/// one containing a HRTB lifetime parameter, and one containing a 'normal' /// one containing a HRTB lifetime parameter, and one containing a 'normal'
/// lifetime parameter. For example: /// lifetime parameter. For example:
/// /// ```ignore (illustrative)
/// T as MyTrait<'a> /// T as MyTrait<'a>
/// T as MyTrait<'static> /// T as MyTrait<'static>
/// /// ```
/// If we put both of these predicates in our computed `ParamEnv`, we'll /// If we put both of these predicates in our computed `ParamEnv`, we'll
/// confuse `SelectionContext`, since it will (correctly) view both as being applicable. /// confuse `SelectionContext`, since it will (correctly) view both as being applicable.
/// ///

View file

@ -547,7 +547,7 @@ pub fn orphan_check(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Result<(), OrphanChe
/// 2. They ground negative reasoning for coherence. If a user wants to /// 2. They ground negative reasoning for coherence. If a user wants to
/// write both a conditional blanket impl and a specific impl, we need to /// write both a conditional blanket impl and a specific impl, we need to
/// make sure they do not overlap. For example, if we write /// make sure they do not overlap. For example, if we write
/// ``` /// ```ignore (illustrative)
/// impl<T> IntoIterator for Vec<T> /// impl<T> IntoIterator for Vec<T>
/// impl<T: Iterator> IntoIterator for T /// impl<T: Iterator> IntoIterator for T
/// ``` /// ```

View file

@ -595,7 +595,7 @@ fn object_ty_for_trait<'tcx>(
/// - let `Receiver` be the type of the `self` argument, i.e `Self`, `&Self`, `Rc<Self>`, /// - let `Receiver` be the type of the `self` argument, i.e `Self`, `&Self`, `Rc<Self>`,
/// - require the following bound: /// - require the following bound:
/// ///
/// ``` /// ```ignore (not-rust)
/// Receiver[Self => T]: DispatchFromDyn<Receiver[Self => dyn Trait]> /// Receiver[Self => T]: DispatchFromDyn<Receiver[Self => dyn Trait]>
/// ``` /// ```
/// ///
@ -621,13 +621,13 @@ fn object_ty_for_trait<'tcx>(
/// Instead, we fudge a little by introducing a new type parameter `U` such that /// Instead, we fudge a little by introducing a new type parameter `U` such that
/// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`. /// `Self: Unsize<U>` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`.
/// Written as a chalk-style query: /// Written as a chalk-style query:
/// /// ```ignore (not-rust)
/// forall (U: Trait + ?Sized) { /// forall (U: Trait + ?Sized) {
/// if (Self: Unsize<U>) { /// if (Self: Unsize<U>) {
/// Receiver: DispatchFromDyn<Receiver[Self => U]> /// Receiver: DispatchFromDyn<Receiver[Self => U]>
/// }
/// } /// }
/// /// }
/// ```
/// for `self: &'a mut Self`, this means `&'a mut Self: DispatchFromDyn<&'a mut U>` /// for `self: &'a mut Self`, this means `&'a mut Self: DispatchFromDyn<&'a mut U>`
/// for `self: Rc<Self>`, this means `Rc<Self>: DispatchFromDyn<Rc<U>>` /// for `self: Rc<Self>`, this means `Rc<Self>: DispatchFromDyn<Rc<U>>`
/// for `self: Pin<Box<Self>>`, this means `Pin<Box<Self>>: DispatchFromDyn<Pin<Box<U>>>` /// for `self: Pin<Box<Self>>`, this means `Pin<Box<Self>>: DispatchFromDyn<Pin<Box<U>>>`

View file

@ -158,9 +158,9 @@ pub(super) enum ProjectAndUnifyResult<'tcx> {
} }
/// Evaluates constraints of the form: /// Evaluates constraints of the form:
/// /// ```ignore (not-rust)
/// for<...> <T as Trait>::U == V /// for<...> <T as Trait>::U == V
/// /// ```
/// If successful, this may result in additional obligations. Also returns /// If successful, this may result in additional obligations. Also returns
/// the projection cache key used to track these additional obligations. /// the projection cache key used to track these additional obligations.
/// ///
@ -224,9 +224,9 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
} }
/// Evaluates constraints of the form: /// Evaluates constraints of the form:
/// /// ```ignore (not-rust)
/// <T as Trait>::U == V /// <T as Trait>::U == V
/// /// ```
/// If successful, this may result in additional obligations. /// If successful, this may result in additional obligations.
/// ///
/// See [poly_project_and_unify_type] for an explanation of the return value. /// See [poly_project_and_unify_type] for an explanation of the return value.
@ -1258,7 +1258,7 @@ fn assemble_candidates_from_param_env<'cx, 'tcx>(
/// In the case of a nested projection like <<A as Foo>::FooT as Bar>::BarT, we may find /// In the case of a nested projection like <<A as Foo>::FooT as Bar>::BarT, we may find
/// that the definition of `Foo` has some clues: /// that the definition of `Foo` has some clues:
/// ///
/// ``` /// ```ignore (illustrative)
/// trait Foo { /// trait Foo {
/// type FooT : Bar<BarT=i32> /// type FooT : Bar<BarT=i32>
/// } /// }

View file

@ -712,9 +712,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
/// and we desugared it so that the type of the expression is /// and we desugared it so that the type of the expression is
/// `Closure`, and `Closure` expects `i32` as argument. Then it /// `Closure`, and `Closure` expects `i32` as argument. Then it
/// is "as if" the compiler generated this impl: /// is "as if" the compiler generated this impl:
/// /// ```ignore (illustrative)
/// impl Fn(i32) for Closure { ... } /// impl Fn(i32) for Closure { ... }
/// /// ```
/// Now imagine our obligation is `Closure: Fn(usize)`. So far /// Now imagine our obligation is `Closure: Fn(usize)`. So far
/// we have matched the self type `Closure`. At this point we'll /// we have matched the self type `Closure`. At this point we'll
/// compare the `i32` to `usize` and generate an error. /// compare the `i32` to `usize` and generate an error.

View file

@ -1891,7 +1891,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
/// ///
/// Here are some (simple) examples: /// Here are some (simple) examples:
/// ///
/// ``` /// ```ignore (illustrative)
/// (i32, u32) -> [i32, u32] /// (i32, u32) -> [i32, u32]
/// Foo where struct Foo { x: i32, y: u32 } -> [i32, u32] /// Foo where struct Foo { x: i32, y: u32 } -> [i32, u32]
/// Bar<i32> where struct Bar<T> { x: T, y: u32 } -> [i32, u32] /// Bar<i32> where struct Bar<T> { x: T, y: u32 } -> [i32, u32]

View file

@ -52,7 +52,7 @@ pub struct OverlapError {
/// ///
/// For example, consider the following scenario: /// For example, consider the following scenario:
/// ///
/// ```rust /// ```ignore (illustrative)
/// trait Foo { ... } /// trait Foo { ... }
/// impl<T, U> Foo for (T, U) { ... } // target impl /// impl<T, U> Foo for (T, U) { ... } // target impl
/// impl<V> Foo for (V, V) { ... } // source impl /// impl<V> Foo for (V, V) { ... } // source impl
@ -64,7 +64,7 @@ pub struct OverlapError {
/// where-clauses add some trickiness here, because they can be used to "define" /// where-clauses add some trickiness here, because they can be used to "define"
/// an argument indirectly: /// an argument indirectly:
/// ///
/// ```rust /// ```ignore (illustrative)
/// impl<'a, I, T: 'a> Iterator for Cloned<I> /// impl<'a, I, T: 'a> Iterator for Cloned<I>
/// where I: Iterator<Item = &'a T>, T: Clone /// where I: Iterator<Item = &'a T>, T: Clone
/// ``` /// ```

View file

@ -170,7 +170,7 @@ struct WfPredicates<'a, 'tcx> {
/// predicates. This is a kind of hack to address #43784. The /// predicates. This is a kind of hack to address #43784. The
/// underlying problem in that issue was a trait structure like: /// underlying problem in that issue was a trait structure like:
/// ///
/// ``` /// ```ignore (illustrative)
/// trait Foo: Copy { } /// trait Foo: Copy { }
/// trait Bar: Foo { } /// trait Bar: Foo { }
/// impl<T: Bar> Foo for T { } /// impl<T: Bar> Foo for T { }

View file

@ -122,16 +122,16 @@ rustc_index::newtype_index! {
/// A [De Bruijn index][dbi] is a standard means of representing /// A [De Bruijn index][dbi] is a standard means of representing
/// regions (and perhaps later types) in a higher-ranked setting. In /// regions (and perhaps later types) in a higher-ranked setting. In
/// particular, imagine a type like this: /// particular, imagine a type like this:
/// /// ```ignore (illustrative)
/// for<'a> fn(for<'b> fn(&'b isize, &'a isize), &'a char) /// for<'a> fn(for<'b> fn(&'b isize, &'a isize), &'a char)
/// ^ ^ | | | /// // ^ ^ | | |
/// | | | | | /// // | | | | |
/// | +------------+ 0 | | /// // | +------------+ 0 | |
/// | | | /// // | | |
/// +----------------------------------+ 1 | /// // +----------------------------------+ 1 |
/// | | /// // | |
/// +----------------------------------------------+ 0 /// // +----------------------------------------------+ 0
/// /// ```
/// In this type, there are two binders (the outer fn and the inner /// In this type, there are two binders (the outer fn and the inner
/// fn). We need to be able to determine, for any given region, which /// fn). We need to be able to determine, for any given region, which
/// fn type it is bound by, the inner or the outer one. There are /// fn type it is bound by, the inner or the outer one. There are
@ -203,7 +203,7 @@ impl DebruijnIndex {
/// it will now be bound at INNERMOST. This is an appropriate thing to do /// it will now be bound at INNERMOST. This is an appropriate thing to do
/// when moving a region out from inside binders: /// when moving a region out from inside binders:
/// ///
/// ``` /// ```ignore (illustrative)
/// for<'a> fn(for<'b> for<'c> fn(&'a u32), _) /// for<'a> fn(for<'b> for<'c> fn(&'a u32), _)
/// // Binder: D3 D2 D1 ^^ /// // Binder: D3 D2 D1 ^^
/// ``` /// ```
@ -471,9 +471,9 @@ impl Variance {
/// variance with which the argument appears. /// variance with which the argument appears.
/// ///
/// Example 1: /// Example 1:
/// /// ```ignore (illustrative)
/// *mut Vec<i32> /// *mut Vec<i32>
/// /// ```
/// Here, the "ambient" variance starts as covariant. `*mut T` is /// Here, the "ambient" variance starts as covariant. `*mut T` is
/// invariant with respect to `T`, so the variance in which the /// invariant with respect to `T`, so the variance in which the
/// `Vec<i32>` appears is `Covariant.xform(Invariant)`, which /// `Vec<i32>` appears is `Covariant.xform(Invariant)`, which
@ -483,9 +483,9 @@ impl Variance {
/// (again) in `Invariant`. /// (again) in `Invariant`.
/// ///
/// Example 2: /// Example 2:
/// /// ```ignore (illustrative)
/// fn(*const Vec<i32>, *mut Vec<i32) /// fn(*const Vec<i32>, *mut Vec<i32)
/// /// ```
/// The ambient variance is covariant. A `fn` type is /// The ambient variance is covariant. A `fn` type is
/// contravariant with respect to its parameters, so the variance /// contravariant with respect to its parameters, so the variance
/// within which both pointer types appear is /// within which both pointer types appear is

View file

@ -294,9 +294,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// ///
/// Example: /// Example:
/// ///
/// ``` /// ```ignore (illustrative)
/// T: std::ops::Index<usize, Output = u32> /// T: std::ops::Index<usize, Output = u32>
/// ^1 ^^^^^^^^^^^^^^2 ^^^^3 ^^^^^^^^^^^4 /// // ^1 ^^^^^^^^^^^^^^2 ^^^^3 ^^^^^^^^^^^4
/// ``` /// ```
/// ///
/// 1. The `self_ty` here would refer to the type `T`. /// 1. The `self_ty` here would refer to the type `T`.
@ -310,7 +310,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// ///
/// For (generic) associated types /// For (generic) associated types
/// ///
/// ``` /// ```ignore (illustrative)
/// <Vec<u8> as Iterable<u8>>::Iter::<'a> /// <Vec<u8> as Iterable<u8>>::Iter::<'a>
/// ``` /// ```
/// ///
@ -756,7 +756,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// ///
/// Example: /// Example:
/// ///
/// ``` /// ```ignore (illustrative)
/// poly_trait_ref = Iterator<Item = u32> /// poly_trait_ref = Iterator<Item = u32>
/// self_ty = Foo /// self_ty = Foo
/// ``` /// ```
@ -1021,10 +1021,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// ///
/// Example: /// Example:
/// ///
/// ``` /// ```ignore (illustrative)
/// fn foo<T: Bar + Baz>() { } /// fn foo<T: Bar + Baz>() { }
/// ^ ^^^^^^^^^ ast_bounds /// // ^ ^^^^^^^^^ ast_bounds
/// param_ty /// // param_ty
/// ``` /// ```
/// ///
/// The `sized_by_default` parameter indicates if, in this context, the `param_ty` should be /// The `sized_by_default` parameter indicates if, in this context, the `param_ty` should be

View file

@ -371,7 +371,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// ///
/// # Examples /// # Examples
/// ///
/// ``` /// ```ignore (illustrative)
/// fn with_closure<F>(_: F) /// fn with_closure<F>(_: F)
/// where F: Fn(&u32) -> &u32 { .. } /// where F: Fn(&u32) -> &u32 { .. }
/// ///

View file

@ -21,7 +21,7 @@
//! When inferring the generic arguments of functions, the argument //! When inferring the generic arguments of functions, the argument
//! order is relevant, which can lead to the following edge case: //! order is relevant, which can lead to the following edge case:
//! //!
//! ```rust //! ```ignore (illustrative)
//! fn foo<T>(a: T, b: T) { //! fn foo<T>(a: T, b: T) {
//! // ... //! // ...
//! } //! }
@ -1210,7 +1210,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// ///
/// Example: /// Example:
/// ///
/// ``` /// ```ignore (illustrative)
/// let mut coerce = CoerceMany::new(expected_ty); /// let mut coerce = CoerceMany::new(expected_ty);
/// for expr in exprs { /// for expr in exprs {
/// let expr_ty = fcx.check_expr_with_expectation(expr, expected); /// let expr_ty = fcx.check_expr_with_expectation(expr, expected);

View file

@ -439,7 +439,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Identify some cases where `as_ref()` would be appropriate and suggest it. /// Identify some cases where `as_ref()` would be appropriate and suggest it.
/// ///
/// Given the following code: /// Given the following code:
/// ``` /// ```compile_fail,E0308
/// struct Foo; /// struct Foo;
/// fn takes_ref(_: &Foo) {} /// fn takes_ref(_: &Foo) {}
/// let ref opt = Some(Foo); /// let ref opt = Some(Foo);
@ -449,7 +449,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Suggest using `opt.as_ref().map(|param| takes_ref(param));` instead. /// Suggest using `opt.as_ref().map(|param| takes_ref(param));` instead.
/// ///
/// It only checks for `Option` and `Result` and won't work with /// It only checks for `Option` and `Result` and won't work with
/// ``` /// ```ignore (illustrative)
/// opt.map(|param| { takes_ref(param) }); /// opt.map(|param| { takes_ref(param) });
/// ``` /// ```
fn can_use_as_ref(&self, expr: &hir::Expr<'_>) -> Option<(Span, &'static str, String)> { fn can_use_as_ref(&self, expr: &hir::Expr<'_>) -> Option<(Span, &'static str, String)> {
@ -566,7 +566,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// This function is used to determine potential "simple" improvements or users' errors and /// This function is used to determine potential "simple" improvements or users' errors and
/// provide them useful help. For example: /// provide them useful help. For example:
/// ///
/// ``` /// ```compile_fail,E0308
/// fn some_fn(s: &str) {} /// fn some_fn(s: &str) {}
/// ///
/// let x = "hey!".to_owned(); /// let x = "hey!".to_owned();

View file

@ -144,6 +144,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
/// code. The most common case is something like this: /// code. The most common case is something like this:
/// ///
/// ```rust /// ```rust
/// # fn foo() -> i32 { 4 }
/// match foo() { /// match foo() {
/// 22 => Default::default(), // call this type `?D` /// 22 => Default::default(), // call this type `?D`
/// _ => return, // return has type `!` /// _ => return, // return has type `!`
@ -168,7 +169,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
/// fallback to use based on whether there is a coercion pattern /// fallback to use based on whether there is a coercion pattern
/// like this: /// like this:
/// ///
/// ``` /// ```ignore (not-rust)
/// ?Diverging -> ?V /// ?Diverging -> ?V
/// ?NonDiverging -> ?V /// ?NonDiverging -> ?V
/// ?V != ?NonDiverging /// ?V != ?NonDiverging

View file

@ -1475,7 +1475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// A common error is to add an extra semicolon: /// A common error is to add an extra semicolon:
/// ///
/// ``` /// ```compile_fail,E0308
/// fn foo() -> usize { /// fn foo() -> usize {
/// 22; /// 22;
/// } /// }

View file

@ -72,7 +72,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// When encountering an fn-like ctor that needs to unify with a value, check whether calling /// When encountering an fn-like ctor that needs to unify with a value, check whether calling
/// the ctor would successfully solve the type mismatch and if so, suggest it: /// the ctor would successfully solve the type mismatch and if so, suggest it:
/// ``` /// ```compile_fail,E0308
/// fn foo(x: usize) -> usize { x } /// fn foo(x: usize) -> usize { x }
/// let x: usize = foo; // suggest calling the `foo` function: `foo(42)` /// let x: usize = foo; // suggest calling the `foo` function: `foo(42)`
/// ``` /// ```
@ -463,7 +463,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// A common error is to forget to add a semicolon at the end of a block, e.g., /// A common error is to forget to add a semicolon at the end of a block, e.g.,
/// ///
/// ``` /// ```compile_fail,E0308
/// # fn bar_that_returns_u32() -> u32 { 4 }
/// fn foo() { /// fn foo() {
/// bar_that_returns_u32() /// bar_that_returns_u32()
/// } /// }
@ -504,7 +505,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// A possible error is to forget to add a return type that is needed: /// A possible error is to forget to add a return type that is needed:
/// ///
/// ``` /// ```compile_fail,E0308
/// # fn bar_that_returns_u32() -> u32 { 4 }
/// fn foo() { /// fn foo() {
/// bar_that_returns_u32() /// bar_that_returns_u32()
/// } /// }
@ -569,7 +571,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// check whether the return type is a generic type with a trait bound /// check whether the return type is a generic type with a trait bound
/// only suggest this if the generic param is not present in the arguments /// only suggest this if the generic param is not present in the arguments
/// if this is true, hint them towards changing the return type to `impl Trait` /// if this is true, hint them towards changing the return type to `impl Trait`
/// ``` /// ```compile_fail,E0308
/// fn cant_name_it<T: Fn() -> u32>() -> T { /// fn cant_name_it<T: Fn() -> u32>() -> T {
/// || 3 /// || 3
/// } /// }

Some files were not shown because too many files have changed in this diff Show more