fix most compiler/ doctests
This commit is contained in:
parent
bf611439e3
commit
7907385999
116 changed files with 666 additions and 609 deletions
|
@ -6,7 +6,7 @@
|
|||
//! is always the "expected" output from the POV of diagnostics.
|
||||
//!
|
||||
//! Examples:
|
||||
//!
|
||||
//! ```ignore (fragment)
|
||||
//! infcx.at(cause, param_env).sub(a, b)
|
||||
//! // requires that `a <: b`, with `a` considered the "expected" type
|
||||
//!
|
||||
|
@ -15,11 +15,11 @@
|
|||
//!
|
||||
//! infcx.at(cause, param_env).eq(a, b)
|
||||
//! // requires that `a == b`, with `a` considered the "expected" type
|
||||
//!
|
||||
//! ```
|
||||
//! For finer-grained control, you can also do use `trace`:
|
||||
//!
|
||||
//! ```ignore (fragment)
|
||||
//! infcx.at(...).trace(a, b).sub(&c, &d)
|
||||
//!
|
||||
//! ```
|
||||
//! This will set `a` and `b` as the "root" values for
|
||||
//! error-reporting, but actually operate on `c` and `d`. This is
|
||||
//! sometimes useful when the types of `c` and `d` are not traceable
|
||||
|
|
|
@ -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
|
||||
/// exists only one possible impl of `Trait`, and it looks like
|
||||
///
|
||||
/// impl<T> Trait<'static> for T { .. }
|
||||
///
|
||||
/// ```ignore (illustrative)
|
||||
/// impl<T> Trait<'static> for T { .. }
|
||||
/// ```
|
||||
/// then we would prepare a query result R that (among other
|
||||
/// things) includes a mapping to `'?0 := 'static`. When
|
||||
/// canonicalizing this query result R, we would leave this
|
||||
|
|
|
@ -202,7 +202,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
|
|||
///
|
||||
/// A good example of this is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// ```compile_fail,E0308
|
||||
/// #![feature(generic_const_exprs)]
|
||||
///
|
||||
/// fn bind<const N: usize>(value: [u8; N]) -> [u8; 3 + 4] {
|
||||
|
|
|
@ -889,7 +889,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
///
|
||||
/// For the following code:
|
||||
///
|
||||
/// ```no_run
|
||||
/// ```ignore (illustrative)
|
||||
/// 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:
|
||||
///
|
||||
/// ```
|
||||
/// ```compile_fail,E0308
|
||||
/// async fn make_u32() -> u32 {
|
||||
/// 22
|
||||
/// }
|
||||
|
|
|
@ -18,7 +18,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
///
|
||||
/// Consider a case where we have
|
||||
///
|
||||
/// ```no_run
|
||||
/// ```compile_fail,E0623
|
||||
/// fn foo(x: &mut Vec<&u8>, y: &u8) {
|
||||
/// x.push(y);
|
||||
/// }
|
||||
|
|
|
@ -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(_)`
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// ```compile_fail,E0623
|
||||
/// fn foo(x: &mut Vec<&u8>, y: &u8)
|
||||
/// { x.push(y); }
|
||||
/// ```
|
||||
|
|
|
@ -159,9 +159,9 @@ pub struct InferCtxtInner<'tcx> {
|
|||
/// outlive the lifetime 'a". These constraints derive from
|
||||
/// instantiated type parameters. So if you had a struct defined
|
||||
/// like
|
||||
///
|
||||
/// ```ignore (illustrative)
|
||||
/// struct Foo<T:'static> { ... }
|
||||
///
|
||||
/// ```
|
||||
/// then in some expression `let x = Foo { ... }` it will
|
||||
/// instantiate the type parameter `T` with a fresh type `$0`. At
|
||||
/// the same time, it will record a region obligation of
|
||||
|
|
|
@ -309,14 +309,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
/// the same as generating an outlives constraint on `Tc` itself.
|
||||
/// 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> {
|
||||
/// (x, y)
|
||||
/// }
|
||||
///
|
||||
/// // Equivalent to:
|
||||
/// # mod dummy { use super::*;
|
||||
/// 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`
|
||||
|
@ -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`.
|
||||
///
|
||||
/// Example:
|
||||
/// ```rust
|
||||
/// ```ignore UNSOLVED (is this a bug?)
|
||||
/// # #![feature(type_alias_impl_trait)]
|
||||
/// pub mod foo {
|
||||
/// pub mod bar {
|
||||
/// pub trait Bar { .. }
|
||||
///
|
||||
/// pub trait Bar { /* ... */ }
|
||||
/// pub type Baz = impl Bar;
|
||||
///
|
||||
/// fn f1() -> Baz { .. }
|
||||
/// # impl Bar for () {}
|
||||
/// fn f1() -> Baz { /* ... */ }
|
||||
/// }
|
||||
///
|
||||
/// fn f2() -> bar::Baz { .. }
|
||||
/// fn f2() -> bar::Baz { /* ... */ }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
|
|
|
@ -103,7 +103,7 @@ impl<'a, 'tcx> OutlivesEnvironment<'tcx> {
|
|||
///
|
||||
/// Example:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore (pseudo-rust)
|
||||
/// fn foo<T>() {
|
||||
/// callback(for<'a> |x: &'a T| {
|
||||
/// // ^^^^^^^ not legal syntax, but probably should be
|
||||
|
|
|
@ -33,9 +33,9 @@
|
|||
//! 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) {
|
||||
//! bar(x, |y| { ... })
|
||||
//! bar(x, |y| { /* ... */})
|
||||
//! // ^ closure arg
|
||||
//! }
|
||||
//! ```
|
||||
|
|
|
@ -313,7 +313,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
|
|||
///
|
||||
/// It will not, however, work for higher-ranked bounds like:
|
||||
///
|
||||
/// ```rust
|
||||
/// ```compile_fail,E0311
|
||||
/// trait Foo<'a, 'b>
|
||||
/// where for<'x> <Self as Foo<'x, 'b>>::Bar: 'x
|
||||
/// {
|
||||
|
|
|
@ -174,19 +174,19 @@ pub enum GenericKind<'tcx> {
|
|||
/// Describes the things that some `GenericKind` value `G` is known to
|
||||
/// outlive. Each variant of `VerifyBound` can be thought of as a
|
||||
/// function:
|
||||
///
|
||||
/// fn(min: Region) -> bool { .. }
|
||||
///
|
||||
/// ```ignore (pseudo-rust)
|
||||
/// fn(min: Region) -> bool { .. }
|
||||
/// ```
|
||||
/// where `true` means that the region `min` meets that `G: min`.
|
||||
/// (False means nothing.)
|
||||
///
|
||||
/// 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:
|
||||
///
|
||||
/// fn(min: Region) -> bool {
|
||||
/// ('a: min) || ('b: min)
|
||||
/// }
|
||||
///
|
||||
/// ```ignore (pseudo-rust)
|
||||
/// fn(min: Region) -> bool {
|
||||
/// ('a: min) || ('b: min)
|
||||
/// }
|
||||
/// ```
|
||||
/// This is described with an `AnyRegion('a, 'b)` node.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum VerifyBound<'tcx> {
|
||||
|
@ -194,7 +194,7 @@ pub enum VerifyBound<'tcx> {
|
|||
/// following, where `G` is the generic for which this verify
|
||||
/// bound was created:
|
||||
///
|
||||
/// ```rust
|
||||
/// ```ignore (pseudo-rust)
|
||||
/// fn(min) -> bool {
|
||||
/// if G == K {
|
||||
/// B(min)
|
||||
|
@ -218,7 +218,7 @@ pub enum VerifyBound<'tcx> {
|
|||
///
|
||||
/// So we would compile to a verify-bound like
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore (illustrative)
|
||||
/// IfEq(<T as Trait<'a>>::Item, AnyRegion('a))
|
||||
/// ```
|
||||
///
|
||||
|
@ -228,7 +228,7 @@ pub enum VerifyBound<'tcx> {
|
|||
|
||||
/// Given a region `R`, expands to the function:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore (pseudo-rust)
|
||||
/// fn(min) -> bool {
|
||||
/// R: min
|
||||
/// }
|
||||
|
@ -243,7 +243,7 @@ pub enum VerifyBound<'tcx> {
|
|||
|
||||
/// Given a set of bounds `B`, expands to the function:
|
||||
///
|
||||
/// ```rust
|
||||
/// ```ignore (pseudo-rust)
|
||||
/// fn(min) -> bool {
|
||||
/// exists (b in B) { b(min) }
|
||||
/// }
|
||||
|
@ -255,7 +255,7 @@ pub enum VerifyBound<'tcx> {
|
|||
|
||||
/// Given a set of bounds `B`, expands to the function:
|
||||
///
|
||||
/// ```rust
|
||||
/// ```ignore (pseudo-rust)
|
||||
/// fn(min) -> bool {
|
||||
/// forall (b in B) { b(min) }
|
||||
/// }
|
||||
|
|
|
@ -73,10 +73,10 @@ pub struct TypeVariableStorage<'tcx> {
|
|||
/// table exists only to help with the occurs check. In particular,
|
||||
/// we want to report constraints like these as an occurs check
|
||||
/// violation:
|
||||
///
|
||||
/// ?1 <: ?3
|
||||
/// Box<?3> <: ?1
|
||||
///
|
||||
/// ``` text
|
||||
/// ?1 <: ?3
|
||||
/// Box<?3> <: ?1
|
||||
/// ```
|
||||
/// Without this second table, what would happen in a case like
|
||||
/// this is that we would instantiate `?1` with a generalized
|
||||
/// 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
|
||||
/// variable (per the union-find algorithm), so `sub_root_var(a)
|
||||
/// == sub_root_var(b)` implies that:
|
||||
///
|
||||
/// exists X. (a <: X || X <: a) && (b <: X || X <: b)
|
||||
/// ```text
|
||||
/// exists X. (a <: X || X <: a) && (b <: X || X <: b)
|
||||
/// ```
|
||||
pub fn sub_root_var(&mut self, vid: ty::TyVid) -> ty::TyVid {
|
||||
self.sub_relations().find(vid)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue