From 7907385999b4a83d37ed31d334f3ed9ca02983a1 Mon Sep 17 00:00:00 2001 From: Elliot Roberts Date: Fri, 15 Apr 2022 15:04:34 -0700 Subject: [PATCH 01/13] fix most compiler/ doctests --- compiler/rustc_ast/src/ast.rs | 2 +- compiler/rustc_ast_lowering/src/expr.rs | 6 +- compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_ast_pretty/src/pp.rs | 10 +-- .../src/diagnostics/conflict_errors.rs | 21 +++--- .../src/diagnostics/region_errors.rs | 2 +- .../src/diagnostics/region_name.rs | 4 +- .../rustc_borrowck/src/member_constraints.rs | 6 +- .../rustc_borrowck/src/region_infer/mod.rs | 26 +++---- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- .../rustc_borrowck/src/universal_regions.rs | 8 +-- .../src/deriving/encodable.rs | 8 +-- .../src/deriving/generic/mod.rs | 15 ++-- .../rustc_builtin_macros/src/test_harness.rs | 2 +- compiler/rustc_codegen_llvm/src/back/lto.rs | 18 ++--- .../rustc_codegen_llvm/src/debuginfo/doc.md | 8 +-- compiler/rustc_data_structures/src/frozen.rs | 3 +- .../src/obligation_forest/mod.rs | 2 +- .../src/owning_ref/mod.rs | 63 ++++++---------- .../rustc_data_structures/src/tagged_ptr.rs | 3 +- .../src/transitive_relation.rs | 2 +- compiler/rustc_errors/src/lib.rs | 4 +- compiler/rustc_expand/src/mbe/macro_check.rs | 8 +-- compiler/rustc_expand/src/mbe/macro_parser.rs | 3 +- compiler/rustc_hir/src/def.rs | 1 + compiler/rustc_hir/src/hir.rs | 20 +++--- .../rustc_incremental/src/assert_dep_graph.rs | 2 +- .../src/assert_module_sources.rs | 1 + compiler/rustc_infer/src/infer/at.rs | 8 +-- .../src/infer/canonical/canonicalizer.rs | 6 +- compiler/rustc_infer/src/infer/combine.rs | 2 +- .../src/infer/error_reporting/mod.rs | 4 +- .../nice_region_error/different_lifetimes.rs | 2 +- .../nice_region_error/find_anon_type.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 4 +- .../rustc_infer/src/infer/opaque_types.rs | 24 ++++--- .../rustc_infer/src/infer/outlives/env.rs | 2 +- .../src/infer/outlives/obligations.rs | 4 +- .../rustc_infer/src/infer/outlives/verify.rs | 2 +- .../src/infer/region_constraints/mod.rs | 26 +++---- .../rustc_infer/src/infer/type_variable.rs | 13 ++-- compiler/rustc_lint_defs/src/builtin.rs | 3 +- compiler/rustc_middle/src/hir/map/mod.rs | 2 +- compiler/rustc_middle/src/infer/mod.rs | 2 +- .../src/mir/interpret/allocation.rs | 10 +-- compiler/rustc_middle/src/mir/mod.rs | 63 ++++++++-------- compiler/rustc_middle/src/mir/mono.rs | 2 +- compiler/rustc_middle/src/mir/terminator.rs | 4 +- compiler/rustc_middle/src/mir/visit.rs | 18 ++--- compiler/rustc_middle/src/traits/mod.rs | 7 +- .../src/traits/specialization_graph.rs | 1 + compiler/rustc_middle/src/ty/adjustment.rs | 2 +- compiler/rustc_middle/src/ty/adt.rs | 2 +- compiler/rustc_middle/src/ty/closure.rs | 25 ++++--- compiler/rustc_middle/src/ty/context.rs | 5 +- compiler/rustc_middle/src/ty/fold.rs | 16 ++--- .../rustc_middle/src/ty/inhabitedness/mod.rs | 7 +- compiler/rustc_middle/src/ty/instance.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 18 ++--- compiler/rustc_middle/src/ty/sty.rs | 66 ++++++++--------- compiler/rustc_middle/src/ty/subst.rs | 34 ++++----- compiler/rustc_middle/src/ty/util.rs | 2 +- compiler/rustc_middle/src/ty/walk.rs | 2 +- .../src/build/expr/as_operand.rs | 12 ++-- .../src/build/expr/as_place.rs | 4 +- .../rustc_mir_build/src/build/matches/mod.rs | 31 ++++---- compiler/rustc_mir_build/src/build/scope.rs | 16 ++--- .../src/thir/pattern/deconstruct_pat.rs | 14 ++-- .../src/thir/pattern/usefulness.rs | 37 ++++++---- compiler/rustc_mir_dataflow/src/impls/mod.rs | 72 +++++++++---------- compiler/rustc_mir_transform/src/generator.rs | 4 +- .../rustc_mir_transform/src/match_branches.rs | 4 +- .../src/simplify_comparison_integral.rs | 4 +- .../rustc_mir_transform/src/simplify_try.rs | 14 ++-- compiler/rustc_monomorphize/src/collector.rs | 5 +- compiler/rustc_parse/src/parser/attr.rs | 7 +- compiler/rustc_parse/src/parser/item.rs | 10 +-- compiler/rustc_parse/src/parser/ty.rs | 22 +++--- .../rustc_query_system/src/dep_graph/debug.rs | 6 +- compiler/rustc_resolve/src/diagnostics.rs | 26 +++---- compiler/rustc_resolve/src/late/lifetimes.rs | 4 +- compiler/rustc_span/src/hygiene.rs | 8 ++- compiler/rustc_span/src/source_map.rs | 9 +-- .../rustc_trait_selection/src/opaque_types.rs | 10 +-- .../src/traits/auto_trait.rs | 14 ++-- .../src/traits/coherence.rs | 2 +- .../src/traits/object_safety.rs | 14 ++-- .../src/traits/project.rs | 14 ++-- .../src/traits/select/confirmation.rs | 6 +- .../src/traits/select/mod.rs | 2 +- .../src/traits/specialize/mod.rs | 4 +- .../rustc_trait_selection/src/traits/wf.rs | 2 +- compiler/rustc_type_ir/src/lib.rs | 34 ++++----- compiler/rustc_typeck/src/astconv/mod.rs | 16 ++--- compiler/rustc_typeck/src/check/closure.rs | 2 +- compiler/rustc_typeck/src/check/coercion.rs | 4 +- compiler/rustc_typeck/src/check/demand.rs | 6 +- compiler/rustc_typeck/src/check/fallback.rs | 3 +- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 2 +- .../src/check/fn_ctxt/suggestions.rs | 10 +-- .../drop_ranges/cfg_build.rs | 2 +- compiler/rustc_typeck/src/check/inherited.rs | 10 +-- .../rustc_typeck/src/check/method/probe.rs | 7 +- compiler/rustc_typeck/src/check/mod.rs | 19 ++--- compiler/rustc_typeck/src/check/pat.rs | 2 +- compiler/rustc_typeck/src/check/regionck.rs | 2 +- compiler/rustc_typeck/src/check/upvar.rs | 72 ++++++++++--------- compiler/rustc_typeck/src/check/wfcheck.rs | 2 +- compiler/rustc_typeck/src/collect/type_of.rs | 2 +- .../src/constrained_generic_params.rs | 6 +- compiler/rustc_typeck/src/expr_use_visitor.rs | 7 +- .../src/impl_wf_check/min_specialization.rs | 2 +- .../rustc_typeck/src/mem_categorization.rs | 12 ++-- .../src/outlives/implicit_infer.rs | 16 ++--- .../src/outlives/outlives_bounds.rs | 6 +- .../rustc_typeck/src/variance/constraints.rs | 10 +-- 116 files changed, 666 insertions(+), 609 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index cdcd221e811a7..1e2c4f31d3df3 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -573,7 +573,7 @@ pub struct Block { pub span: Span, pub tokens: Option, /// The following *isn't* a parse error, but will cause multiple errors in following stages. - /// ``` + /// ```compile_fail /// let x = { /// foo: var /// }; diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 37ae41fabf987..8aeeeb50eb559 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -615,7 +615,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } /// Desugar `.await` into: - /// ```rust + /// ```ignore (pseudo-rust) /// match ::std::future::IntoFuture::into_future() { /// mut __awaitee => loop { /// match unsafe { ::std::future::Future::poll( @@ -1325,7 +1325,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } /// Desugar `ExprForLoop` from: `[opt_ident]: for in ` into: - /// ```rust + /// ```ignore (pseudo-rust) /// { /// let result = match IntoIterator::into_iter() { /// mut iter => { @@ -1436,7 +1436,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } /// Desugar `ExprKind::Try` from: `?` into: - /// ```rust + /// ```ignore (pseudo-rust) /// match Try::branch() { /// ControlFlow::Continue(val) => #[allow(unreachable_code)] val,, /// ControlFlow::Break(residual) => diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index d433775f85cf3..a99a155f93dd0 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -934,7 +934,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// Given an associated type constraint like one of these: /// - /// ``` + /// ```ignore (illustrative) /// T: Iterator /// ^^^^^^^^^^^ /// T: Iterator diff --git a/compiler/rustc_ast_pretty/src/pp.rs b/compiler/rustc_ast_pretty/src/pp.rs index ddce86f216538..c93022308a37d 100644 --- a/compiler/rustc_ast_pretty/src/pp.rs +++ b/compiler/rustc_ast_pretty/src/pp.rs @@ -68,20 +68,20 @@ //! will be made to flow subsequent breaks together onto lines. Inconsistent //! is the opposite. Inconsistent breaking example would be, say: //! -//! ``` +//! ```ignore (illustrative) //! foo(hello, there, good, friends) //! ``` //! //! breaking inconsistently to become //! -//! ``` +//! ```ignore (illustrative) //! foo(hello, there, //! good, friends); //! ``` //! //! whereas a consistent breaking would yield: //! -//! ``` +//! ```ignore (illustrative) //! foo(hello, //! there, //! good, @@ -153,14 +153,14 @@ enum IndentStyle { /// Vertically aligned under whatever column this block begins at. /// /// fn demo(arg1: usize, - /// arg2: usize); + /// arg2: usize) {} Visual, /// Indented relative to the indentation level of the previous line. /// /// fn demo( /// arg1: usize, /// arg2: usize, - /// ); + /// ) {} Block { offset: isize }, } diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 3b4e9e95b0e91..bbb631730d346 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -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 /// 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 /// 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 /// 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: - /// - /// ("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: /// /// ```text diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 30fe4ea8662eb..6f1c8daf42e3f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -259,7 +259,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// Report an error because the universal region `fr` was required to outlive /// `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 } /// ``` /// diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 459d4a783e40f..c4cef5710aecb 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -210,7 +210,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { /// Suppose we are trying to give a name to the lifetime of the /// reference `x`: /// - /// ``` + /// ```ignore (pseudo-rust) /// fn foo(x: &u32) { .. } /// ``` /// @@ -746,7 +746,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { /// 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`, diff --git a/compiler/rustc_borrowck/src/member_constraints.rs b/compiler/rustc_borrowck/src/member_constraints.rs index 0fe44328fd9f1..f920d9d5c3f57 100644 --- a/compiler/rustc_borrowck/src/member_constraints.rs +++ b/compiler/rustc_borrowck/src/member_constraints.rs @@ -169,7 +169,7 @@ where /// Returns the "choice regions" for a given member /// constraint. This is the `R1..Rn` from a constraint like: /// - /// ``` + /// ```text /// R0 member of [R1..Rn] /// ``` crate fn choice_regions(&self, pci: NllMemberConstraintIndex) -> &[ty::RegionVid] { @@ -195,14 +195,14 @@ where /// /// Before: /// -/// ``` +/// ```text /// target_list: A -> B -> C -> (None) /// source_list: D -> E -> F -> (None) /// ``` /// /// After: /// -/// ``` +/// ```text /// target_list: A -> B -> C -> D -> E -> F -> (None) /// ``` fn append_list( diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index cf03f34a4ec5f..b2fa16ce125af 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -436,14 +436,14 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// minimum values. /// /// For example: - /// - /// fn foo<'a, 'b>(..) where 'a: 'b - /// + /// ``` + /// fn foo<'a, 'b>( /* ... */ ) where 'a: 'b { /* ... */ } + /// ``` /// would initialize two variables like so: - /// - /// R0 = { CFG, R0 } // 'a - /// R1 = { CFG, R0, R1 } // 'b - /// + /// ```ignore (illustrative) + /// R0 = { CFG, R0 } // 'a + /// R1 = { CFG, R0, R1 } // 'b + /// ``` /// Here, R0 represents `'a`, and it contains (a) the entire CFG /// and (b) any universally quantified regions that it outlives, /// 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, /// we want to check for a case where a universally quantified /// region exceeded its bounds. Consider: - /// - /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x } - /// + /// ```compile_fail,E0312 + /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x } + /// ``` /// In this case, returning `x` requires `&'a u32 <: &'b u32` /// and hence we establish (transitively) a constraint that /// `'a: 'b`. The `propagate_constraints` code above will @@ -1366,9 +1366,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// /// /// In the canonical example - /// - /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x } - /// + /// ```compile_fail,E0312 + /// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x } + /// ``` /// 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 holds. diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index c4a190b44cbd4..4b905c23e156a 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -971,7 +971,7 @@ pub enum Locations { /// things like the type of the return slot. Consider this /// example: /// - /// ``` + /// ```compile_fail,E0515 /// fn foo<'a>(x: &'a u32) -> &'a u32 { /// let y = 22; /// return &y; // error diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index e26adba0d3002..c06fe881410ae 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -187,12 +187,12 @@ pub enum RegionClassification { /// /// Consider this example: /// - /// ``` + /// ```ignore (pseudo-rust) /// fn foo<'a, 'b>(a: &'a u32, b: &'b u32, c: &'static u32) { /// let closure = for<'x> |x: &'x u32| { .. }; - /// ^^^^^^^ pretend this were legal syntax - /// for declaring a late-bound region in - /// a closure signature + /// // ^^^^^^^ pretend this were legal syntax + /// // for declaring a late-bound region in + /// // a closure signature /// } /// ``` /// diff --git a/compiler/rustc_builtin_macros/src/deriving/encodable.rs b/compiler/rustc_builtin_macros/src/deriving/encodable.rs index c5f3a9d3379a7..6151a80a56d58 100644 --- a/compiler/rustc_builtin_macros/src/deriving/encodable.rs +++ b/compiler/rustc_builtin_macros/src/deriving/encodable.rs @@ -5,14 +5,14 @@ //! //! For example, a type like: //! -//! ``` +//! ```ignore (old code) //! #[derive(RustcEncodable, RustcDecodable)] //! struct Node { id: usize } //! ``` //! //! would generate two implementations like: //! -//! ``` +//! ```ignore (old code) //! # struct Node { id: usize } //! impl, E> Encodable for Node { //! fn encode(&self, s: &mut S) -> Result<(), E> { @@ -40,7 +40,7 @@ //! Other interesting scenarios are when the item has type parameters or //! references other non-built-in types. A type definition like: //! -//! ``` +//! ```ignore (old code) //! # #[derive(RustcEncodable, RustcDecodable)] //! # struct Span; //! #[derive(RustcEncodable, RustcDecodable)] @@ -49,7 +49,7 @@ //! //! would yield functions like: //! -//! ``` +//! ```ignore (old code) //! # #[derive(RustcEncodable, RustcDecodable)] //! # struct Span; //! # struct Spanned { node: T, span: Span } diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index f87f4726d1c69..0fd23fd281e19 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1006,9 +1006,11 @@ impl<'a> MethodDef<'a> { /// } /// } /// } - /// - /// // or if A is repr(packed) - note fields are matched by-value - /// // instead of by-reference. + /// ``` + /// or if A is repr(packed) - note fields are matched by-value + /// instead of by-reference. + /// ``` + /// # struct A { x: i32, y: i32 } /// impl PartialEq for A { /// fn eq(&self, other: &A) -> bool { /// match *self { @@ -1126,14 +1128,15 @@ impl<'a> MethodDef<'a> { /// // is equivalent to /// /// impl PartialEq for A { - /// fn eq(&self, other: &A) -> ::bool { + /// fn eq(&self, other: &A) -> bool { + /// use A::*; /// match (&*self, &*other) { /// (&A1, &A1) => true, /// (&A2(ref self_0), /// &A2(ref __arg_1_0)) => (*self_0).eq(&(*__arg_1_0)), /// _ => { - /// let __self_vi = match *self { A1(..) => 0, A2(..) => 1 }; - /// let __arg_1_vi = match *other { A1(..) => 0, A2(..) => 1 }; + /// let __self_vi = match *self { A1 => 0, A2(..) => 1 }; + /// let __arg_1_vi = match *other { A1 => 0, A2(..) => 1 }; /// false /// } /// } diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index e2553ab40cad4..db8dce804a31b 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -249,7 +249,7 @@ fn generate_test_harness( /// /// 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] /// pub fn main() { /// extern crate test; diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 5c63bd8c1bd8d..77cfdd06ef5d7 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -396,15 +396,15 @@ impl Drop for Linker<'_> { /// /// At a high level Thin LTO looks like: /// -/// 1. Prepare a "summary" of each LLVM module in question which describes -/// the values inside, cost of the values, etc. -/// 2. Merge the summaries of all modules in question into one "index" -/// 3. Perform some global analysis on this index -/// 4. For each module, use the index and analysis calculated previously to -/// perform local transformations on the module, for example inlining -/// small functions from other modules. -/// 5. Run thin-specific optimization passes over each module, and then code -/// generate everything at the end. +/// 1. Prepare a "summary" of each LLVM module in question which describes +/// the values inside, cost of the values, etc. +/// 2. Merge the summaries of all modules in question into one "index" +/// 3. Perform some global analysis on this index +/// 4. For each module, use the index and analysis calculated previously to +/// perform local transformations on the module, for example inlining +/// small functions from other modules. +/// 5. Run thin-specific optimization passes over each module, and then code +/// generate everything at the end. /// /// 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 diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/doc.md b/compiler/rustc_codegen_llvm/src/debuginfo/doc.md index 5a8976c61662b..aaec4e68c1743 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/doc.md +++ b/compiler/rustc_codegen_llvm/src/debuginfo/doc.md @@ -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 utilizing a cache. The way to get a shared metadata node when needed is thus to just call the corresponding function in this module: - - let file_metadata = file_metadata(cx, file); - +```ignore (illustrative) +let file_metadata = file_metadata(cx, file); +``` The function will take care of probing the cache for an existing node for that exact file path. @@ -63,7 +63,7 @@ struct List { will generate the following callstack with a naive DFS algorithm: -``` +```ignore (illustrative) describe(t = List) describe(t = i32) describe(t = Option>) diff --git a/compiler/rustc_data_structures/src/frozen.rs b/compiler/rustc_data_structures/src/frozen.rs index 2daf5b0414172..c81e1b124f0e5 100644 --- a/compiler/rustc_data_structures/src/frozen.rs +++ b/compiler/rustc_data_structures/src/frozen.rs @@ -23,7 +23,8 @@ //! `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: //! -//! ```rust +//! ``` +//! # struct Bar {} //! use rustc_data_structures::frozen::Frozen; //! //! struct Foo { diff --git a/compiler/rustc_data_structures/src/obligation_forest/mod.rs b/compiler/rustc_data_structures/src/obligation_forest/mod.rs index 5fe2a1fb84bd7..74f432a7967f9 100644 --- a/compiler/rustc_data_structures/src/obligation_forest/mod.rs +++ b/compiler/rustc_data_structures/src/obligation_forest/mod.rs @@ -202,7 +202,7 @@ impl Node { /// with this node. /// /// The non-`Error` state transitions are as follows. -/// ``` +/// ```text /// (Pre-creation) /// | /// | register_obligation_at() (called by process_obligations() and diff --git a/compiler/rustc_data_structures/src/owning_ref/mod.rs b/compiler/rustc_data_structures/src/owning_ref/mod.rs index e7397bf13bad4..ed5e566184f12 100644 --- a/compiler/rustc_data_structures/src/owning_ref/mod.rs +++ b/compiler/rustc_data_structures/src/owning_ref/mod.rs @@ -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 bundled together in a wrapper type that ensure that lifetime constraint: -```rust -# extern crate owning_ref; -# use owning_ref::OwningRef; +``` +# use rustc_data_structures::owning_ref::OwningRef; # fn main() { fn return_owned_and_referenced() -> OwningRef, [u8]> { let v = vec![1, 2, 3, 4]; @@ -56,8 +55,7 @@ See the documentation around `OwningHandle` for more details. ## Basics ``` -extern crate owning_ref; -use owning_ref::BoxRef; +use rustc_data_structures::owning_ref::BoxRef; fn main() { // Create an array owned by a Box. @@ -78,8 +76,7 @@ fn main() { ## Caching a reference to a struct field ``` -extern crate owning_ref; -use owning_ref::BoxRef; +use rustc_data_structures::owning_ref::BoxRef; fn main() { struct Foo { @@ -106,8 +103,7 @@ fn main() { ## Caching a reference to an entry in a vector ``` -extern crate owning_ref; -use owning_ref::VecRef; +use rustc_data_structures::owning_ref::VecRef; fn main() { 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 ``` -extern crate owning_ref; -use owning_ref::StringRef; +use rustc_data_structures::owning_ref::StringRef; fn main() { let s = StringRef::new("hello world".to_owned()) @@ -132,8 +127,7 @@ fn main() { ## Reference counted slices that share ownership of the backing storage ``` -extern crate owning_ref; -use owning_ref::RcRef; +use rustc_data_structures::owning_ref::RcRef; use std::rc::Rc; fn main() { @@ -155,8 +149,7 @@ fn main() { ## Atomic reference counted slices that share ownership of the backing storage ``` -extern crate owning_ref; -use owning_ref::ArcRef; +use rustc_data_structures::owning_ref::ArcRef; use std::sync::Arc; fn main() { @@ -188,8 +181,7 @@ fn main() { ## References into RAII locks ``` -extern crate owning_ref; -use owning_ref::RefRef; +use rustc_data_structures::owning_ref::RefRef; use std::cell::{RefCell, Ref}; 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`) ``` -extern crate owning_ref; -use owning_ref::RefMutRefMut; +use rustc_data_structures::owning_ref::RefMutRefMut; use std::cell::{RefCell, RefMut}; fn main() { @@ -326,8 +317,7 @@ impl OwningRef { /// /// # Example /// ``` - /// extern crate owning_ref; - /// use owning_ref::OwningRef; + /// use rustc_data_structures::owning_ref::OwningRef; /// /// fn main() { /// let owning_ref = OwningRef::new(Box::new(42)); @@ -362,8 +352,7 @@ impl OwningRef { /// /// # Example /// ``` - /// extern crate owning_ref; - /// use owning_ref::OwningRef; + /// use rustc_data_structures::owning_ref::OwningRef; /// /// fn main() { /// let owning_ref = OwningRef::new(Box::new([1, 2, 3, 4])); @@ -390,8 +379,7 @@ impl OwningRef { /// /// # Example /// ``` - /// extern crate owning_ref; - /// use owning_ref::OwningRef; + /// use rustc_data_structures::owning_ref::OwningRef; /// /// fn main() { /// let owning_ref = OwningRef::new(Box::new([1, 2, 3, 4])); @@ -441,8 +429,7 @@ impl OwningRef { /// /// # Example /// ``` - /// extern crate owning_ref; - /// use owning_ref::{OwningRef, Erased}; + /// use rustc_data_structures::owning_ref::{OwningRef, Erased}; /// /// fn main() { /// // N.B., using the concrete types here for explicitness. @@ -460,7 +447,7 @@ impl OwningRef { /// let owning_ref_b: OwningRef>, i32> /// = owning_ref_b.map(|a| &a[1].0); /// - /// let owning_refs: [OwningRef, i32>; 2] + /// let owning_refs: [OwningRef, i32>; 2] /// = [owning_ref_a.erase_owner(), owning_ref_b.erase_owner()]; /// /// assert_eq!(*owning_refs[0], 1); @@ -516,8 +503,7 @@ impl OwningRefMut { /// /// # Example /// ``` - /// extern crate owning_ref; - /// use owning_ref::OwningRefMut; + /// use rustc_data_structures::owning_ref::OwningRefMut; /// /// fn main() { /// let owning_ref_mut = OwningRefMut::new(Box::new(42)); @@ -552,8 +538,7 @@ impl OwningRefMut { /// /// # Example /// ``` - /// extern crate owning_ref; - /// use owning_ref::OwningRefMut; + /// use rustc_data_structures::owning_ref::OwningRefMut; /// /// fn main() { /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); @@ -580,8 +565,7 @@ impl OwningRefMut { /// /// # Example /// ``` - /// extern crate owning_ref; - /// use owning_ref::OwningRefMut; + /// use rustc_data_structures::owning_ref::OwningRefMut; /// /// fn main() { /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); @@ -608,8 +592,7 @@ impl OwningRefMut { /// /// # Example /// ``` - /// extern crate owning_ref; - /// use owning_ref::OwningRefMut; + /// use rustc_data_structures::owning_ref::OwningRefMut; /// /// fn main() { /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); @@ -638,8 +621,7 @@ impl OwningRefMut { /// /// # Example /// ``` - /// extern crate owning_ref; - /// use owning_ref::OwningRefMut; + /// use rustc_data_structures::owning_ref::OwningRefMut; /// /// fn main() { /// let owning_ref_mut = OwningRefMut::new(Box::new([1, 2, 3, 4])); @@ -689,8 +671,7 @@ impl OwningRefMut { /// /// # Example /// ``` - /// extern crate owning_ref; - /// use owning_ref::{OwningRefMut, Erased}; + /// use rustc_data_structures::owning_ref::{OwningRefMut, Erased}; /// /// fn main() { /// // N.B., using the concrete types here for explicitness. @@ -708,7 +689,7 @@ impl OwningRefMut { /// let owning_ref_mut_b: OwningRefMut>, i32> /// = owning_ref_mut_b.map_mut(|a| &mut a[1].0); /// - /// let owning_refs_mut: [OwningRefMut, i32>; 2] + /// let owning_refs_mut: [OwningRefMut, i32>; 2] /// = [owning_ref_mut_a.erase_owner(), owning_ref_mut_b.erase_owner()]; /// /// assert_eq!(*owning_refs_mut[0], 1); diff --git a/compiler/rustc_data_structures/src/tagged_ptr.rs b/compiler/rustc_data_structures/src/tagged_ptr.rs index 324a8624dd076..651bc556c9853 100644 --- a/compiler/rustc_data_structures/src/tagged_ptr.rs +++ b/compiler/rustc_data_structures/src/tagged_ptr.rs @@ -45,7 +45,8 @@ pub unsafe trait Pointer: Deref { /// case you'll need to manually figure out what the right type to pass to /// align_of is. /// - /// ```rust + /// ```ignore UNSOLVED (what to do about the Self) + /// # use std::ops::Deref; /// std::mem::align_of::<::Target>().trailing_zeros() as usize; /// ``` const BITS: usize; diff --git a/compiler/rustc_data_structures/src/transitive_relation.rs b/compiler/rustc_data_structures/src/transitive_relation.rs index 780753ed200e9..0ff64969b071c 100644 --- a/compiler/rustc_data_structures/src/transitive_relation.rs +++ b/compiler/rustc_data_structures/src/transitive_relation.rs @@ -282,7 +282,7 @@ impl TransitiveRelation { /// (where the relation is encoding the `<=` relation for the lattice). /// So e.g., if the relation is `->` and we have /// - /// ``` + /// ```text /// a -> b -> d -> f /// | ^ /// +--> c -> e ---+ diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index df41fc00714b6..f83fa68ced00d 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -100,7 +100,7 @@ pub struct CodeSuggestion { /// `foo.bar` might be replaced with `a.b` or `x.y` by replacing /// `foo` and `bar` on their own: /// - /// ``` + /// ```ignore (illustrative) /// vec![ /// Substitution { parts: vec![(0..3, "a"), (4..7, "b")] }, /// Substitution { parts: vec![(0..3, "x"), (4..7, "y")] }, @@ -109,7 +109,7 @@ pub struct CodeSuggestion { /// /// or by replacing the entire span: /// - /// ``` + /// ```ignore (illustrative) /// vec![ /// Substitution { parts: vec![(0..7, "a.b")] }, /// Substitution { parts: vec![(0..7, "x.y")] }, diff --git a/compiler/rustc_expand/src/mbe/macro_check.rs b/compiler/rustc_expand/src/mbe/macro_check.rs index 35b5e0d0f2f61..8994a2f78919f 100644 --- a/compiler/rustc_expand/src/mbe/macro_check.rs +++ b/compiler/rustc_expand/src/mbe/macro_check.rs @@ -4,7 +4,7 @@ //! //! ## Meta-variables must not be bound twice //! -//! ``` +//! ```compile_fail //! 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. /// /// Consider $i in the following example: -/// -/// ( $( $i:ident = $($j:ident),+ );* ) => { $($( $i += $j; )+)* } -/// +/// ```ignore (illustrative) +/// ( $( $i:ident = $($j:ident),+ );* ) => { $($( $i += $j; )+)* } +/// ``` /// It occurs under the Kleene stack ["*", "+"] and is bound under ["*"] only. /// /// Arguments: diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 8f260e1cdb5c8..29f354d572802 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -320,7 +320,8 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize { /// /// Then, the tree will have the following shape: /// -/// ```rust +/// ```ignore (private-internal) +/// # use NamedMatch::*; /// MatchedSeq([ /// MatchedSeq([ /// MatchedNonterminal(a), diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 324e110005717..ac33a963027f9 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -312,6 +312,7 @@ pub enum Res { /// 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`: /// ``` + /// # struct Foo; /// impl Foo { fn test() -> [u8; std::mem::size_of::()] { todo!() } } /// /// struct Bar([u8; baz::()]); diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index dfeee3f356ffb..4adfbdcf445d7 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -49,15 +49,15 @@ pub enum ParamName { /// Synthetic name generated when user elided a lifetime in an impl header. /// /// E.g., the lifetimes in cases like these: - /// - /// impl Foo for &u32 - /// impl Foo<'_> for u32 - /// + /// ```ignore (fragment) + /// impl Foo for &u32 + /// impl Foo<'_> for u32 + /// ``` /// in that case, we rewrite to - /// - /// impl<'f> Foo for &'f u32 - /// impl<'f> Foo<'f> for u32 - /// + /// ```ignore (fragment) + /// impl<'f> Foo for &'f u32 + /// impl<'f> Foo<'f> for u32 + /// ``` /// where `'f` is something like `Fresh(0)`. The indices are /// unique per impl, but not necessarily continuous. Fresh(LocalDefId), @@ -1082,7 +1082,7 @@ pub enum PatKind<'hir> { /// If `slice` exists, then `after` can be non-empty. /// /// The representation for e.g., `[a, b, .., c, d]` is: - /// ``` + /// ```ignore (illustrative) /// PatKind::Slice([Binding(a), Binding(b)], Some(Wild), [Binding(c), Binding(d)]) /// ``` Slice(&'hir [Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [Pat<'hir>]), @@ -2247,7 +2247,7 @@ pub const FN_OUTPUT_NAME: Symbol = sym::Output; /// wouldn't it be better to make the `ty` field an enum like the /// following? /// -/// ``` +/// ```ignore (pseudo-rust) /// enum TypeBindingKind { /// Equals(...), /// Binding(...), diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs index 2d06c9d8ec92c..f69ae8ebe410f 100644 --- a/compiler/rustc_incremental/src/assert_dep_graph.rs +++ b/compiler/rustc_incremental/src/assert_dep_graph.rs @@ -22,7 +22,7 @@ //! //! Example: //! -//! ``` +//! ```ignore (needs flags) //! #[rustc_if_this_changed(Hir)] //! fn foo() { } //! diff --git a/compiler/rustc_incremental/src/assert_module_sources.rs b/compiler/rustc_incremental/src/assert_module_sources.rs index 7569abfbb10e5..61b1dd8cb017c 100644 --- a/compiler/rustc_incremental/src/assert_module_sources.rs +++ b/compiler/rustc_incremental/src/assert_module_sources.rs @@ -5,6 +5,7 @@ //! The user adds annotations to the crate of the following form: //! //! ``` +//! # #![feature(rustc_attrs)] //! #![rustc_partition_reused(module="spike", cfg="rpass2")] //! #![rustc_partition_codegened(module="spike-x", cfg="rpass2")] //! ``` diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 58c309a5c52ea..39f7d30e81aca 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -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 diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 5e67c8cfa27c4..07e51afd90441 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -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 Trait<'static> for T { .. } - /// + /// ```ignore (illustrative) + /// impl 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 diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 0ca0fe33614f8..aa3f0600cccc8 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -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(value: [u8; N]) -> [u8; 3 + 4] { diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 2e50dbff51089..ccd860ce2428a 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -889,7 +889,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// /// For the following code: /// - /// ```no_run + /// ```ignore (illustrative) /// let x: Foo> = foo::>(); /// ``` /// @@ -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 /// } diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs index be9db6aa25b75..cb72cb41a7c00 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -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); /// } diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs index 9c5b944c1e987..e5ae835e81349 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -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); } /// ``` diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 6ec929f98950e..c9121f7d348ce 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -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 { ... } - /// + /// ``` /// 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 diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 78e6f3a05be66..d25484efabc5f 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -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 { /* ... */ } /// } /// ``` /// diff --git a/compiler/rustc_infer/src/infer/outlives/env.rs b/compiler/rustc_infer/src/infer/outlives/env.rs index c8236ce79c098..9ddda7b92eb5a 100644 --- a/compiler/rustc_infer/src/infer/outlives/env.rs +++ b/compiler/rustc_infer/src/infer/outlives/env.rs @@ -103,7 +103,7 @@ impl<'a, 'tcx> OutlivesEnvironment<'tcx> { /// /// Example: /// - /// ``` + /// ```ignore (pseudo-rust) /// fn foo() { /// callback(for<'a> |x: &'a T| { /// // ^^^^^^^ not legal syntax, but probably should be diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index e3312e6c6e146..19d03ffa6964a 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -33,9 +33,9 @@ //! Consider: //! //! ``` -//! fn bar(a: T, b: impl for<'a> Fn(&'a T)); +//! fn bar(a: T, b: impl for<'a> Fn(&'a T)) {} //! fn foo(x: T) { -//! bar(x, |y| { ... }) +//! bar(x, |y| { /* ... */}) //! // ^ closure arg //! } //! ``` diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index f69212c599b62..ab565d4396191 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -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> >::Bar: 'x /// { diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 4ea1c3f76c8ad..efe254387dcc9 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -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(>::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) } /// } diff --git a/compiler/rustc_infer/src/infer/type_variable.rs b/compiler/rustc_infer/src/infer/type_variable.rs index 74c440890452a..a0e2965b60512 100644 --- a/compiler/rustc_infer/src/infer/type_variable.rs +++ b/compiler/rustc_infer/src/infer/type_variable.rs @@ -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 <: ?1 - /// + /// ``` text + /// ?1 <: ?3 + /// Box <: ?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`. We would then relate `Box <: Box` @@ -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) } diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index a42e3d5d95785..092cbbccd33dc 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1109,7 +1109,8 @@ declare_lint! { /// /// ### Example /// - /// ```rust,compile_fail + /// ```compile_fail + /// #![deny(unaligned_references)] /// #[repr(packed)] /// pub struct Foo { /// field1: u64, diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index e0ed402283904..0831d7d04f5f2 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -742,7 +742,7 @@ impl<'hir> Map<'hir> { /// } /// ``` /// - /// ``` + /// ```compile_fail,E0308 /// fn foo(x: usize) -> bool { /// loop { /// true // If `get_return_block` gets passed the `id` corresponding diff --git a/compiler/rustc_middle/src/infer/mod.rs b/compiler/rustc_middle/src/infer/mod.rs index 497d3811f281b..2350a6ab15546 100644 --- a/compiler/rustc_middle/src/infer/mod.rs +++ b/compiler/rustc_middle/src/infer/mod.rs @@ -10,7 +10,7 @@ use rustc_span::Span; /// Requires that `region` must be equal to one of the regions in `choice_regions`. /// We often denote this using the syntax: /// -/// ``` +/// ```text /// R0 member of [O1..On] /// ``` #[derive(Debug, Clone, HashStable, TypeFoldable, Lift)] diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 8cfc5ed0a95d0..5564852f30539 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -770,11 +770,11 @@ impl InitMask { /// /// 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: - /// - /// 00000000|00000000 - /// ^ ^ ^ ^ - /// index: 0 7 8 15 - /// + /// ```text + /// 00000000|00000000 + /// ^ ^ ^ ^ + /// index: 0 7 8 15 + /// ``` /// Also, if not stated, assume that `is_init = true`, that is, we are searching for the first 1 bit. fn find_bit_fast( init_mask: &InitMask, diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 45999f8765897..b357a657b5981 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -737,14 +737,14 @@ pub enum BorrowKind { /// 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 /// an arm is selected. This prevents this code from compiling: - /// - /// let mut x = &Some(0); - /// match *x { - /// None => (), - /// Some(_) if { x = &None; false } => (), - /// Some(_) => (), - /// } - /// + /// ```compile_fail,E0510 + /// let mut x = &Some(0); + /// match *x { + /// None => (), + /// Some(_) if { x = &None; false } => (), + /// Some(_) => (), + /// } + /// ``` /// 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 /// 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 /// implicit closure bindings. It is needed when the closure is /// borrowing or mutating a mutable referent, e.g.: - /// - /// let x: &mut isize = ...; - /// let y = || *x += 5; - /// + /// ``` + /// let mut z = 3; + /// let x: &mut isize = &mut z; + /// let y = || *x += 5; + /// ``` /// If we were to try to translate this closure into a more explicit /// form, we'd encounter an error with the code as written: - /// - /// struct Env { x: & &mut isize } - /// let x: &mut isize = ...; - /// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn - /// fn fn_ptr(env: &mut Env) { **env.x += 5; } - /// + /// ```compile_fail,E0594 + /// struct Env<'a> { x: &'a &'a mut isize } + /// let mut z = 3; + /// 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; } + /// ``` /// This is then illegal because you cannot mutate an `&mut` found /// in an aliasable location. To solve, you'd have to translate with /// an `&mut` borrow: - /// - /// struct Env { x: &mut &mut isize } - /// let x: &mut isize = ...; - /// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x - /// fn fn_ptr(env: &mut Env) { **env.x += 5; } - /// + /// ```compile_fail,E0596 + /// struct Env<'a> { x: &'a mut &'a mut isize } + /// let mut z = 3; + /// 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; } + /// ``` /// Now the assignment to `**env.x` is legal, but creating a /// 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 @@ -1016,7 +1019,7 @@ pub struct LocalDecl<'tcx> { /// ``` /// fn foo(x: &str) { /// match { - /// match x.parse().unwrap() { + /// match x.parse::().unwrap() { /// y => y + 2 /// } /// } { @@ -1690,9 +1693,9 @@ pub enum StatementKind<'tcx> { /// Encodes a user's type ascription. These need to be preserved /// intact so that NLL can respect them. For example: - /// - /// let a: T = y; - /// + /// ```ignore (illustrative) + /// let a: T = 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: /// @@ -1985,7 +1988,7 @@ pub enum ProjectionElem { /// These indices are generated by slice patterns. Easiest to explain /// by example: /// - /// ``` + /// ```ignore (illustrative) /// [X, _, .._, _, _] => { offset: 0, min_length: 4, from_end: false }, /// [_, X, .._, _, _] => { offset: 1, min_length: 4, from_end: false }, /// [_, _, .._, X, _] => { offset: 2, min_length: 4, from_end: true }, @@ -3179,7 +3182,7 @@ impl<'tcx> ConstantKind<'tcx> { /// /// An example: /// -/// ```rust +/// ```ignore (illustrative) /// struct S<'a>((i32, &'a str), String); /// let S((_, w): (i32, &'static str), _): S = ...; /// // ------ ^^^^^^^^^^^^^^^^^^^ (1) diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index f76217d921d94..d389fa8c0ebdd 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -438,7 +438,7 @@ impl<'tcx> CodegenUnitNameBuilder<'tcx> { /// /// This function will build CGU names of the form: /// - /// ``` + /// ```text /// .[-in-](-)*[.] /// = . /// ``` diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index cc08857463d58..e6eb63fd3b2b8 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -202,7 +202,7 @@ pub enum TerminatorKind<'tcx> { /// This assignment occurs both in the unwind and the regular code paths. The semantics are best /// explained by the elaboration: /// - /// ``` + /// ```ignore (MIR) /// BB0 { /// DropAndReplace(P <- V, goto BB1, unwind BB2) /// } @@ -210,7 +210,7 @@ pub enum TerminatorKind<'tcx> { /// /// becomes /// - /// ``` + /// ```ignore (MIR) /// BB0 { /// Drop(P, goto BB1, unwind BB2) /// } diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 45b1ad6df8226..350bdfdadb258 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -29,7 +29,7 @@ //! //! For example, the `super_basic_block_data` method begins like this: //! -//! ```rust +//! ```ignore (pseudo-rust) //! fn super_basic_block_data(&mut self, //! block: BasicBlock, //! data: & $($mutability)? BasicBlockData<'tcx>) { @@ -1170,10 +1170,10 @@ pub enum NonMutatingUseContext { AddressOf, /// 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: - /// - /// z = x.y; - /// f(&x.y); - /// + /// ```ignore (illustrative) + /// z = x.y; + /// f(&x.y); + /// ``` Projection, } @@ -1199,10 +1199,10 @@ pub enum MutatingUseContext { AddressOf, /// 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: - /// - /// x.y = ...; - /// f(&mut x.y); - /// + /// ```ignore (illustrative) + /// x.y = ...; + /// f(&mut x.y); + /// ``` Projection, /// Retagging, a "Stacked Borrows" shadow state operation Retag, diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 7c3d08b26bf54..ffde1294ec655 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -47,7 +47,8 @@ pub enum Reveal { /// impl. Concretely, that means that the following example will /// fail to compile: /// - /// ``` + /// ```compile_fail,E0308 + /// #![feature(specialization)] /// trait Assoc { /// type Output; /// } @@ -57,7 +58,7 @@ pub enum Reveal { /// } /// /// fn main() { - /// let <() as Assoc>::Output = true; + /// let x: <() as Assoc>::Output = true; /// } /// ``` UserFacing, @@ -515,7 +516,7 @@ pub type SelectionResult<'tcx, T> = Result, SelectionError<'tcx>>; /// 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). /// -/// ``` +/// ```ignore (illustrative) /// impl Clone for Option { ... } // Impl_1 /// impl Clone for Box { ... } // Impl_2 /// impl Clone for i32 { ... } // Impl_3 diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs index c43ec048c3f99..ce13825b01696 100644 --- a/compiler/rustc_middle/src/traits/specialization_graph.rs +++ b/compiler/rustc_middle/src/traits/specialization_graph.rs @@ -180,6 +180,7 @@ pub struct LeafDef { /// Example: /// /// ``` + /// #![feature(specialization)] /// trait Tr { /// fn assoc(&self); /// } diff --git a/compiler/rustc_middle/src/ty/adjustment.rs b/compiler/rustc_middle/src/ty/adjustment.rs index 2676b7ab521d8..d9332f6896af6 100644 --- a/compiler/rustc_middle/src/ty/adjustment.rs +++ b/compiler/rustc_middle/src/ty/adjustment.rs @@ -59,7 +59,7 @@ pub enum PointerCast { /// sized struct to a dynamically sized one. E.g., `&[i32; 4]` -> `&[i32]` is /// represented by: /// -/// ``` +/// ```ignore (illustrative) /// Deref(None) -> [i32; 4], /// Borrow(AutoBorrow::Ref) -> &[i32; 4], /// Unsize -> &[i32], diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index fc6710f07e37b..2e4c16e39eb96 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -82,7 +82,7 @@ bitflags! { /// /// is essentially represented with [`Ty`] as the following pseudocode: /// -/// ``` +/// ```ignore (illustrative) /// struct S { x } /// ``` /// diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs index 3bddf7fb6ffc4..c88cac30a1927 100644 --- a/compiler/rustc_middle/src/ty/closure.rs +++ b/compiler/rustc_middle/src/ty/closure.rs @@ -293,7 +293,7 @@ pub struct CaptureInfo { /// let mut t = (0,1); /// /// let c = || { - /// println!("{t}"); // L1 + /// println!("{t:?}"); // L1 /// t.1 = 4; // L2 /// }; /// ``` @@ -309,7 +309,7 @@ pub struct CaptureInfo { /// let x = 5; /// /// let c = || { - /// let _ = x + /// let _ = x; /// }; /// ``` /// @@ -373,17 +373,19 @@ pub enum BorrowKind { /// 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; /// ``` /// /// If we were to try to translate this closure into a more explicit /// form, we'd encounter an error with the code as written: /// - /// ``` - /// struct Env { x: & &mut isize } - /// let x: &mut isize = ...; - /// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn + /// ```compile_fail,E0594 + /// struct Env<'a> { x: &'a &'a mut isize } + /// let mut z = 3; + /// 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; } /// ``` /// @@ -391,10 +393,11 @@ pub enum BorrowKind { /// in an aliasable location. To solve, you'd have to translate with /// an `&mut` borrow: /// - /// ``` - /// struct Env { x: &mut &mut isize } - /// let x: &mut isize = ...; - /// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x + /// ```compile_fail,E0596 + /// struct Env<'a> { x: &'a mut &'a mut isize } + /// let mut z = 3; + /// 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; } /// ``` /// diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 30fe3ffa7e3c4..cf9f229779ff8 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -455,12 +455,13 @@ pub struct TypeckResults<'tcx> { /// # Example /// /// ```rust + /// # use std::fmt::Debug; /// fn foo(x: &u32) -> impl Debug { *x } /// ``` /// /// The function signature here would be: /// - /// ``` + /// ```ignore (illustrative) /// for<'a> fn(&'a u32) -> Foo /// ``` /// @@ -469,7 +470,7 @@ pub struct TypeckResults<'tcx> { /// /// The *liberated* form of this would be /// - /// ``` + /// ```ignore (illustrative) /// fn(&'a u32) -> u32 /// ``` /// diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 075928c889d83..896a8280551d2 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -41,7 +41,7 @@ //! //! 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: -//! ``` +//! ```text //! s.visit_with(visitor) calls //! - s.super_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 /// binder or one outer to it, it appears free. Example: /// - /// ``` - /// for<'a> fn(for<'b> fn(), T) - /// ^ ^ ^ ^ - /// | | | | here, would be shifted in 1 - /// | | | here, would be shifted in 2 - /// | | here, would be `INNERMOST` shifted in by 1 - /// | here, initially, binder would be `INNERMOST` + /// ```ignore (illustrative) + /// for<'a> fn(for<'b> fn(), T) + /// // ^ ^ ^ ^ + /// // | | | | here, would be shifted in 1 + /// // | | | here, would be shifted in 2 + /// // | | here, would be `INNERMOST` shifted in by 1 + /// // | here, initially, binder would be `INNERMOST` /// ``` /// /// You see that, initially, *any* bound value is free, diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index 226456588e75d..b8088766cca68 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -56,7 +56,9 @@ impl<'tcx> TyCtxt<'tcx> { /// Checks whether a type is visibly uninhabited from a particular module. /// /// # Example - /// ```rust + /// ``` + /// #![feature(never_type)] + /// # fn main() {} /// enum Void {} /// mod a { /// pub mod b { @@ -67,6 +69,7 @@ impl<'tcx> TyCtxt<'tcx> { /// } /// /// mod c { + /// use super::Void; /// pub struct AlsoSecretlyUninhabited { /// _priv: Void, /// } @@ -84,7 +87,7 @@ impl<'tcx> TyCtxt<'tcx> { /// contain `Foo`. /// /// # Example - /// ```rust + /// ```ignore (illustrative) /// let foo_result: Result = ... ; /// let Ok(t) = foo_result; /// ``` diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 00b3639a99776..03d3a4a8c5f3c 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -337,7 +337,7 @@ impl<'tcx> Instance<'tcx> { /// Returns `Ok(None)` if we cannot resolve `Instance` to a specific instance. /// For example, in a context like this, /// - /// ``` + /// ```ignore (illustrative) /// fn foo(t: T) { ... } /// ``` /// diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index ec416722c214e..0ad1775d3b54e 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1012,9 +1012,9 @@ impl<'tcx> Predicate<'tcx> { /// their values. /// /// Example: -/// -/// struct Foo> { ... } -/// +/// ```ignore (illustrative) +/// struct Foo> { ... } +/// ``` /// Here, the `GenericPredicates` for `Foo` would contain a list of bounds like /// `[[], [U:Bar]]`. Now if there were some particular reference /// like `Foo`, then the `InstantiatedPredicates` would be `[[], @@ -1072,9 +1072,9 @@ pub struct OpaqueHiddenType<'tcx> { /// The type variable that represents the value of the opaque type /// that we require. In other words, after we compile this function, /// we will be created a constraint like: - /// - /// Foo<'a, T> = ?C - /// + /// ```ignore (pseudo-rust) + /// Foo<'a, T> = ?C + /// ``` /// where `?C` is the value of this type variable. =) It may /// naturally refer to the type and lifetime parameters in scope /// in this function, though ultimately it should only reference @@ -1115,7 +1115,7 @@ rustc_index::newtype_index! { /// /// To make this more concrete, consider this program: /// - /// ``` + /// ```ignore (illustrative) /// struct Foo { } /// fn bar(x: T) { /// let y: for<'a> fn(&'a u8, Foo) = ...; @@ -1154,7 +1154,7 @@ impl UniverseIndex { /// corresponds to entering a `forall` quantifier. So, for /// example, suppose we have this type in universe `U`: /// - /// ``` + /// ```ignore (illustrative) /// for<'a> fn(&'a u32) /// ``` /// @@ -1941,7 +1941,7 @@ pub enum ImplOverlapKind { /// 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: /// - /// ``` + /// ```compile_fail,(E0119) /// trait Trait {} /// impl Trait for dyn Send + Sync {} /// impl Trait for dyn Sync + Send {} diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 1509de0e93070..a2e19761d93e8 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -187,12 +187,14 @@ pub enum TyKind<'tcx> { /// Looking at the following example, the witness for this generator /// may end up as something like `for<'a> [Vec, &'a Vec]`: /// - /// ```rust + /// ```ignore UNSOLVED (ask @compiler-errors, should this error? can we just swap the yields?) + /// #![feature(generators)] /// |a| { /// let x = &vec![3]; /// yield a; /// yield x[0]; /// } + /// # ; /// ``` GeneratorWitness(Binder<'tcx, &'tcx List>>), @@ -276,9 +278,9 @@ impl<'tcx> TyKind<'tcx> { static_assert_size!(TyKind<'_>, 32); /// A closure can be modeled as a struct that looks like: -/// -/// struct Closure<'l0...'li, T0...Tj, CK, CS, U>(...U); -/// +/// ```ignore (illustrative) +/// struct Closure<'l0...'li, T0...Tj, CK, CS, U>(...U); +/// ``` /// where: /// /// - '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`). /// /// So, for example, given this function: -/// -/// fn foo<'a, T>(data: &'a mut T) { -/// do(|| data.count += 1) -/// } -/// +/// ```ignore (illustrative) +/// fn foo<'a, T>(data: &'a mut T) { +/// do(|| data.count += 1) +/// } +/// ``` /// the type of the closure would be something like: -/// -/// struct Closure<'a, T, U>(...U); -/// +/// ```ignore (illustrative) +/// struct Closure<'a, T, U>(...U); +/// ``` /// 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, /// 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 /// instances with the expected upvar types: -/// -/// impl<'b, 'a, T> FnMut() for Closure<'a, T, (&'b mut &'a mut T,)> { -/// ... -/// } -/// +/// ```ignore (illustrative) +/// 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 /// and thus knows full well that `data` has type `&'b mut &'a mut T`. /// (Here, I am assuming that `data` is mut-borrowed.) @@ -760,9 +762,9 @@ impl<'tcx> UpvarSubsts<'tcx> { } /// An inline const is modeled like -/// -/// const InlineConst<'l0...'li, T0...Tj, R>: R; -/// +/// ```ignore (illustrative) +/// const InlineConst<'l0...'li, T0...Tj, R>: R; +/// ``` /// where: /// /// - 'l0...'li and T0...Tj are the generic parameters @@ -936,9 +938,9 @@ impl<'tcx> List>> { /// A complete reference to a trait. These take numerous guises in syntax, /// but perhaps the most recognizable form is in a where-clause: -/// -/// T: Foo -/// +/// ```ignore (illustrative) +/// T: Foo +/// ``` /// 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, /// and `U` as parameter 1. @@ -1012,9 +1014,9 @@ impl<'tcx> PolyTraitRef<'tcx> { /// An existential reference to a trait, where `Self` is erased. /// For example, the trait object `Trait<'a, 'b, X, Y>` is: -/// -/// exists T. T: Trait<'a, 'b, X, Y> -/// +/// ```ignore (illustrative) +/// exists T. T: Trait<'a, 'b, X, Y> +/// ``` /// The substitutions don't include the erased `Self`, only trait /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above). #[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 /// -/// ``` +/// ```text /// static ----------+-----...------+ (greatest) /// | | | /// 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. /// For example, consider the regions in this snippet of code: /// - /// ``` + /// ```ignore (illustrative) /// 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 - /// ^^ ^^ ^ anonymous, late-bound - /// | early-bound, appears in where-clauses - /// late-bound, appears only in fn args + /// // ^^ ^^ ^ anonymous, late-bound + /// // | early-bound, appears in where-clauses + /// // late-bound, appears only in fn args /// {..} /// } /// ``` diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 46b938ea93baa..5063420e975d1 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -687,17 +687,17 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> { /// /// ``` /// type Func = 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 - /// - /// for<'a> fn(fn(&'a i32)) - /// ^~ ^~ ^~~ - /// | | | - /// | | DebruijnIndex of 2 - /// Binders - /// + /// ```ignore (illustrative) + /// for<'a> fn(fn(&'a i32)) + /// // ^~ ^~ ^~~ + /// // | | | + /// // | | DebruijnIndex of 2 + /// // Binders + /// ``` /// 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 /// 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,fn(A)); - /// type MetaFuncTuple = for<'a> fn(FuncTuple<&'a i32>) + /// type MetaFuncTuple = for<'a> fn(FuncTuple<&'a i32>); /// ``` /// /// Here the final type will be: - /// - /// for<'a> fn((&'a i32, fn(&'a i32))) - /// ^~~ ^~~ - /// | | - /// DebruijnIndex of 1 | - /// DebruijnIndex of 2 - /// + /// ```ignore (illustrative) + /// for<'a> fn((&'a i32, fn(&'a i32))) + /// // ^~~ ^~~ + /// // | | + /// // DebruijnIndex of 1 | + /// // DebruijnIndex of 2 + /// ``` /// 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 /// 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 /// example, in this code: /// -/// ``` +/// ```ignore (illustrative) /// struct Foo { } /// impl Foo { fn method() { } } /// ``` diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 918fe49e8e3fc..40e449cf10efc 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -975,7 +975,7 @@ impl<'tcx> ExplicitSelf<'tcx> { /// /// Examples: /// - /// ``` + /// ```ignore (illustrative) /// impl<'a> Foo for &'a T { /// // Legal declarations: /// fn method1(self: &&'a T); // ExplicitSelf::ByReference diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index 9f57e1a977a93..09946f02448d6 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -34,7 +34,7 @@ impl<'tcx> TypeWalker<'tcx> { /// /// Example: Imagine you are walking `Foo, usize>`. /// - /// ``` + /// ```ignore (illustrative) /// let mut iter: TypeWalker = ...; /// iter.next(); // yields Foo /// iter.next(); // yields Bar diff --git a/compiler/rustc_mir_build/src/build/expr/as_operand.rs b/compiler/rustc_mir_build/src/build/expr/as_operand.rs index b627b0763a286..7358fa6286367 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_operand.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_operand.rs @@ -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 /// 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) { foo(*p); } + /// fn bar(box_p: Box) { foo(*box_p); } /// ``` /// /// 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 /// 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 /// `*tmp0`: /// - /// ```rust + /// ```ignore (illustrative) /// let tmp0 = box_p; call foo(*tmp0) /// ``` /// diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index 3b3120cf04b7f..fa1bb0622bd11 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -37,7 +37,7 @@ crate enum PlaceBase { /// /// Consider the following example /// ```rust - /// let t = (10, (10, (10, 10))); + /// let t = (((10, 10), 10), 10); /// /// let c = || { /// 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 /// - /// ``` + /// ```ignore (illustrative) /// * Field(0) /// * Field(0) /// * Field(0) diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index d45ae19752e8c..8594d0806bbdd 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -1032,11 +1032,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// exhaustive match, consider: /// /// ``` + /// # fn foo(x: (bool, bool)) { /// match x { /// (true, true) => (), /// (_, false) => (), /// (false, true) => (), /// } + /// # } /// ``` /// /// 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: /// - /// ```rust + /// ```ignore (illustrative) /// ... /// Some(x) if cond1 => ... /// Some(x) => ... @@ -1481,11 +1483,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// ``` /// # let (x, y, z) = (true, true, true); /// match (x, y, z) { - /// (true, _, true) => true, // (0) - /// (_, true, _) => true, // (1) - /// (false, false, _) => false, // (2) - /// (true, _, false) => false, // (3) + /// (true , _ , true ) => true, // (0) + /// (_ , true , _ ) => true, // (1) + /// (false, false, _ ) => false, // (2) + /// (true , _ , false) => false, // (3) /// } + /// # ; /// ``` /// /// 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 /// is trivially NP-complete: /// - /// ```rust - /// match (var0, var1, var2, var3, ...) { - /// (true, _, _, false, true, ...) => false, - /// (_, true, true, false, _, ...) => false, - /// (false, _, false, false, _, ...) => false, - /// ... - /// _ => true - /// } + /// ```ignore (illustrative) + /// match (var0, var1, var2, var3, ...) { + /// (true , _ , _ , false, true, ...) => false, + /// (_ , true, true , false, _ , ...) => false, + /// (false, _ , false, false, _ , ...) => false, + /// ... + /// _ => true + /// } /// ``` /// /// 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 /// in very common situations - for example [#29740]: /// - /// ```rust + /// ```ignore (illustrative) /// match x { /// "foo" if foo_guard => ..., /// "bar" if bar_guard => ..., diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index d96534fe3e0a8..465bd62406efe 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -803,16 +803,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// scope (which can be larger or smaller). /// /// Consider: - /// - /// let x = foo(bar(X, Y)); - /// + /// ```ignore (illustrative) + /// let x = foo(bar(X, Y)); + /// ``` /// We wish to pop the storage for X and Y after `bar()` is /// called, not after the whole `let` is completed. /// /// As another example, if the second argument diverges: - /// - /// foo(Box::new(2), panic!()) - /// + /// ```ignore (illustrative) + /// foo(Box::new(2), panic!()) + /// ``` /// We would allocate the box but then free it on the unwinding /// path; we would also emit a free on the 'success' path from /// 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: /// - /// ```rust + /// ```ignore (illustrative) /// foo(bar(), ...) /// ``` /// @@ -955,7 +955,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// dropped). However, if no unwind occurs, then `_X` will be /// unconditionally consumed by the `call`: /// - /// ``` + /// ```ignore (illustrative) /// bb { /// ... /// _R = CALL(foo, _X, ...) diff --git a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs index 72f0d07c260ca..60eead69a1b05 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs @@ -13,7 +13,7 @@ //! Instead of listing all those constructors (which is intractable), we group those value //! constructors together as much as possible. Example: //! -//! ``` +//! ```compile_fail,E0004 //! match (0, false) { //! (0 ..=100, true) => {} // `p_1` //! (50..=150, false) => {} // `p_2` @@ -344,13 +344,13 @@ enum IntBorder { /// straddles the boundary of one of the inputs. /// /// The following input: -/// ``` +/// ```text /// |-------------------------| // `self` /// |------| |----------| |----| /// |-------| |-------| /// ``` /// would be iterated over as follows: -/// ``` +/// ```text /// ||---|--||-|---|---|---|--| /// ``` #[derive(Debug, Clone)] @@ -492,14 +492,17 @@ impl Slice { /// /// Let's look at an example, where we are trying to split the last pattern: /// ``` +/// # fn foo(x: &[bool]) { /// match x { /// [true, true, ..] => {} /// [.., false, false] => {} /// [..] => {} /// } +/// # } /// ``` /// Here are the results of specialization for the first few lengths: /// ``` +/// # fn foo(x: &[bool]) { match x { /// // length 0 /// [] => {} /// // length 1 @@ -520,6 +523,8 @@ impl Slice { /// [true, true, _, _, _ ] => {} /// [_, _, _, false, false] => {} /// [_, _, _, _, _ ] => {} +/// # _ => {} +/// # }} /// ``` /// /// 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 /// `extract_pattern_arguments` we fill some of the entries, and the result is /// `[Some(0), _, _, _]`. -/// ```rust +/// ```compile_fail,E0004 +/// # fn foo() -> [Option; 4] { [None; 4] } /// let x: [Option; 4] = foo(); /// match x { /// [Some(0), ..] => {} diff --git a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs index 687b2e23c9fcb..4e96cfd9bbd50 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs @@ -35,23 +35,27 @@ //! 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: //! ```rust +//! # fn foo(x: Option) { //! match x { -//! Some(_) => ..., -//! 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(_)` above +//! Some(_) => {}, +//! 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(_)` above //! } +//! # } //! ``` //! //! 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` //! are used to tell the user which values are missing. -//! ```rust +//! ```compile_fail,E0004 +//! # fn foo(x: Option) { //! match x { -//! Some(0) => ..., -//! None => ..., +//! Some(0) => {}, +//! None => {}, //! // not exhaustive: `_` is useful because it matches `Some(1)` //! } +//! # } //! ``` //! //! 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. //! //! Let's take the following example: -//! ``` +//! ```compile_fail,E0004 +//! # enum Enum { Variant1(()), Variant2(Option, u32)} +//! # fn foo(x: Enum) { //! match x { //! Enum::Variant1(_) => {} // `p1` //! Enum::Variant2(None, 0) => {} // `p2` //! Enum::Variant2(Some(_), 0) => {} // `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 //! `(v0, v1)` is a witness of usefulness of `q'` in the following reduced match: //! -//! ``` +//! ```compile_fail,E0004 +//! # fn foo(x: (Option, u32)) { //! match x { //! (None, 0) => {} // `p2'` //! (Some(_), 0) => {} // `q'` //! } +//! # } //! ``` //! //! 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]`. //! Here's a sequence of specializations of a list of pattern-stacks, to illustrate what's //! happening: -//! ``` +//! ```ignore (illustrative) //! [Enum::Variant1(_)] //! [Enum::Variant2(None, 0)] //! [Enum::Variant2(Some(_), 0)] @@ -234,7 +243,7 @@ //! - We return the concatenation of all the witnesses found, if any. //! //! Example: -//! ``` +//! ```ignore (illustrative) //! [Some(true)] // p_1 //! [None] // p_2 //! [Some(_)] // q @@ -659,13 +668,15 @@ enum ArmType { /// /// For example, if we are constructing a witness for the match against /// -/// ``` +/// ```compile_fail,E0004 +/// # #![feature(type_ascription)] /// struct Pair(Option<(u32, u32)>, bool); -/// +/// # fn foo(p: Pair) { /// match (p: Pair) { /// Pair(None, _) => {} /// Pair(_, false) => {} /// } +/// # } /// ``` /// /// We'll perform the following steps: diff --git a/compiler/rustc_mir_dataflow/src/impls/mod.rs b/compiler/rustc_mir_dataflow/src/impls/mod.rs index d90ead3228c2d..c9722a6df77db 100644 --- a/compiler/rustc_mir_dataflow/src/impls/mod.rs +++ b/compiler/rustc_mir_dataflow/src/impls/mod.rs @@ -37,21 +37,21 @@ pub use self::storage_liveness::{MaybeRequiresStorage, MaybeStorageLive}; /// /// ```rust /// struct S; -/// fn foo(pred: bool) { // maybe-init: -/// // {} -/// let a = S; let b = S; let c; let d; // {a, b} +/// fn foo(pred: bool) { // maybe-init: +/// // {} +/// let a = S; let mut b = S; let c; let d; // {a, b} /// /// if pred { -/// drop(a); // { b} -/// b = S; // { b} +/// drop(a); // { b} +/// b = S; // { b} /// /// } else { -/// drop(b); // {a} -/// d = S; // {a, d} +/// drop(b); // {a} +/// 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 /// struct S; -/// fn foo(pred: bool) { // maybe-uninit: -/// // {a, b, c, d} -/// let a = S; let b = S; let c; let d; // { c, d} +/// fn foo(pred: bool) { // maybe-uninit: +/// // {a, b, c, d} +/// let a = S; let mut b = S; let c; let d; // { c, d} /// /// if pred { -/// drop(a); // {a, c, d} -/// b = S; // {a, c, d} +/// drop(a); // {a, c, d} +/// b = S; // {a, c, d} /// /// } else { -/// drop(b); // { b, c, d} -/// d = S; // { b, c } +/// drop(b); // { b, c, d} +/// 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 /// struct S; -/// fn foo(pred: bool) { // definite-init: -/// // { } -/// let a = S; let b = S; let c; let d; // {a, b } +/// fn foo(pred: bool) { // definite-init: +/// // { } +/// let a = S; let mut b = S; let c; let d; // {a, b } /// /// if pred { -/// drop(a); // { b, } -/// b = S; // { b, } +/// drop(a); // { b, } +/// b = S; // { b, } /// /// } else { -/// drop(b); // {a, } -/// d = S; // {a, d} +/// drop(b); // {a, } +/// d = S; // {a, d} /// -/// } // { } +/// } // { } /// -/// c = S; // { c } +/// c = S; // { c } /// } /// ``` /// @@ -210,21 +210,21 @@ impl<'a, 'tcx> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> { /// /// ```rust /// struct S; -/// fn foo(pred: bool) { // ever-init: -/// // { } -/// let a = S; let b = S; let c; let d; // {a, b } +/// fn foo(pred: bool) { // ever-init: +/// // { } +/// let a = S; let mut b = S; let c; let d; // {a, b } /// /// if pred { -/// drop(a); // {a, b, } -/// b = S; // {a, b, } +/// drop(a); // {a, b, } +/// b = S; // {a, b, } /// /// } else { -/// drop(b); // {a, b, } -/// d = S; // {a, b, d } +/// drop(b); // {a, b, } +/// 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> { diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index 144ea0ec61931..d5d4bfa255bd9 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -18,13 +18,13 @@ //! First upvars are stored //! It is followed by the generator state field. //! Then finally the MIR locals which are live across a suspension point are stored. -//! +//! ```ignore (illustrative) //! struct Generator { //! upvars..., //! state: u32, //! mir_locals..., //! } -//! +//! ``` //! This pass computes the meaning of the state field and the MIR locals which are live //! across a suspension point. There are however three hardcoded generator states: //! 0 - Generator have not been resumed yet diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index 3c14a324c36ff..7cd7d26328a1a 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -14,7 +14,7 @@ pub struct MatchBranchSimplification; /// /// For example: /// -/// ```rust +/// ```ignore (MIR) /// bb0: { /// switchInt(move _3) -> [42_isize: bb1, otherwise: bb2]; /// } @@ -32,7 +32,7 @@ pub struct MatchBranchSimplification; /// /// into: /// -/// ```rust +/// ```ignore (MIR) /// bb0: { /// _2 = Eq(move _3, const 42_isize); /// goto -> bb3; diff --git a/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs b/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs index da683a33651d6..bbfaace7041ec 100644 --- a/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs +++ b/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs @@ -12,7 +12,7 @@ use rustc_middle::{ /// Pass to convert `if` conditions on integrals into switches on the integral. /// For an example, it turns something like /// -/// ``` +/// ```ignore (MIR) /// _3 = Eq(move _4, const 43i32); /// StorageDead(_4); /// switchInt(_3) -> [false: bb2, otherwise: bb3]; @@ -20,7 +20,7 @@ use rustc_middle::{ /// /// into: /// -/// ``` +/// ```ignore (MIR) /// switchInt(_4) -> [43i32: bb3, otherwise: bb2]; /// ``` pub struct SimplifyComparisonIntegral; diff --git a/compiler/rustc_mir_transform/src/simplify_try.rs b/compiler/rustc_mir_transform/src/simplify_try.rs index ce4b45062e8de..b3d45c7a22155 100644 --- a/compiler/rustc_mir_transform/src/simplify_try.rs +++ b/compiler/rustc_mir_transform/src/simplify_try.rs @@ -1,10 +1,12 @@ //! The general point of the optimizations provided here is to simplify something like: //! //! ```rust +//! # fn foo(x: Result) -> Result { //! match x { //! Ok(x) => Ok(x), //! Err(x) => Err(x) //! } +//! # } //! ``` //! //! into just `x`. @@ -23,7 +25,7 @@ use std::slice::Iter; /// /// This is done by transforming basic blocks where the statements match: /// -/// ```rust +/// ```ignore (MIR) /// _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY ); /// _TMP_2 = _LOCAL_TMP; /// ((_LOCAL_0 as Variant).FIELD: TY) = move _TMP_2; @@ -32,7 +34,7 @@ use std::slice::Iter; /// /// into: /// -/// ```rust +/// ```ignore (MIR) /// _LOCAL_0 = move _LOCAL_1 /// ``` pub struct SimplifyArmIdentity; @@ -472,7 +474,7 @@ impl Visitor<'_> for LocalUseCounter { } /// Match on: -/// ```rust +/// ```ignore (MIR) /// _LOCAL_INTO = ((_LOCAL_FROM as Variant).FIELD: TY); /// ``` fn match_get_variant_field<'tcx>( @@ -492,7 +494,7 @@ fn match_get_variant_field<'tcx>( } /// Match on: -/// ```rust +/// ```ignore (MIR) /// ((_LOCAL_FROM as Variant).FIELD: TY) = move _LOCAL_INTO; /// ``` fn match_set_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local, VarField<'tcx>)> { @@ -507,7 +509,7 @@ fn match_set_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local } /// Match on: -/// ```rust +/// ```ignore (MIR) /// discriminant(_LOCAL_TO_SET) = VAR_IDX; /// ``` fn match_set_discr(stmt: &Statement<'_>) -> Option<(Local, VariantIdx)> { @@ -690,7 +692,7 @@ impl<'tcx> SimplifyBranchSameOptimizationFinder<'_, 'tcx> { /// /// Statements can be trivially equal if the kinds match. /// But they can also be considered equal in the following case A: - /// ``` + /// ```ignore (MIR) /// discriminant(_0) = 0; // bb1 /// _0 = move _1; // bb2 /// ``` diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 0e0a4fbc21556..39040ab77bc51 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -91,12 +91,13 @@ //! another function. It suffices to just take a reference in order to introduce //! an edge. Consider the following example: //! -//! ```rust +//! ``` +//! # use core::fmt::Display; //! fn print_val(x: T) { //! println!("{}", x); //! } //! -//! fn call_fn(f: &Fn(i32), x: i32) { +//! fn call_fn(f: &dyn Fn(i32), x: i32) { //! f(x); //! } //! diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index 358b01df3b983..2f90a7c54aba6 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -371,9 +371,10 @@ impl<'a> Parser<'a> { } /// Matches the following grammar (per RFC 1559). - /// - /// meta_item : PATH ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ; - /// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ; + /// ```ebnf + /// meta_item : PATH ( '=' 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> { let nt_meta = match self.token.kind { token::Interpolated(ref nt) => match **nt { diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 10f1daf112951..56757c1d90351 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -485,7 +485,7 @@ impl<'a> Parser<'a> { /// Parses an implementation item. /// - /// ``` + /// ```ignore (illustrative) /// impl<'a, T> 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. - /// ``` + /// ```ebnf /// "impl" GENERICS "const"? "!"? TYPE "for"? (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: - /// ``` + /// ```ebnf /// TypeAlias = "type" Ident Generics {":" GenericBounds}? {"=" Ty}? ";" ; /// ``` /// The `"type"` has already been eaten. @@ -930,7 +930,7 @@ impl<'a> Parser<'a> { /// /// # Examples /// - /// ``` + /// ```ignore (illustrative) /// extern crate foo; /// extern crate bar as foo; /// ``` @@ -1630,7 +1630,7 @@ impl<'a> Parser<'a> { /// Parses a declarative macro 2.0 definition. /// The `macro` keyword has already been parsed. - /// ``` + /// ```ebnf /// MacBody = "{" TOKEN_STREAM "}" ; /// MacParams = "(" TOKEN_STREAM ")" ; /// DeclMac = "macro" Ident MacParams? MacBody ; diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 9e771a8af1a4e..b0439a5987afa 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -52,7 +52,7 @@ pub(super) enum RecoverQuestionMark { /// Signals whether parsing a type should recover `->`. /// /// More specifically, when parsing a function like: -/// ```rust +/// ```compile_fail /// fn foo() => u8 { 0 } /// fn bar(): u8 { 0 } /// ``` @@ -499,12 +499,12 @@ impl<'a> Parser<'a> { } /// Parses a function pointer type (`TyKind::BareFn`). - /// ``` - /// [unsafe] [extern "ABI"] fn (S) -> T - /// ^~~~~^ ^~~~^ ^~^ ^ - /// | | | | - /// | | | Return type - /// Function Style ABI Parameter types + /// ```ignore (illustrative) + /// [unsafe] [extern "ABI"] fn (S) -> T + /// // ^~~~~^ ^~~~^ ^~^ ^ + /// // | | | | + /// // | | | Return type + /// // Function Style ABI Parameter types /// ``` /// We actually parse `FnHeader FnDecl`, but we error on `const` and `async` qualifiers. fn parse_ty_bare_fn( @@ -707,7 +707,7 @@ impl<'a> Parser<'a> { } /// Parses a bound according to the grammar: - /// ``` + /// ```ebnf /// BOUND = TY_BOUND | LT_BOUND /// ``` fn parse_generic_bound(&mut self) -> PResult<'a, Result> { @@ -729,7 +729,7 @@ impl<'a> Parser<'a> { } /// Parses a lifetime ("outlives") bound, e.g. `'a`, according to: - /// ``` + /// ```ebnf /// LT_BOUND = LIFETIME /// ``` fn parse_generic_lt_bound( @@ -787,7 +787,7 @@ impl<'a> Parser<'a> { /// /// If no modifiers are present, this does not consume any tokens. /// - /// ``` + /// ```ebnf /// TY_BOUND_MODIFIERS = ["~const"] ["?"] /// ``` fn parse_ty_bound_modifiers(&mut self) -> PResult<'a, BoundModifiers> { @@ -807,7 +807,7 @@ impl<'a> Parser<'a> { } /// Parses a type bound according to: - /// ``` + /// ```ebnf /// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN) /// TY_BOUND_NOPAREN = [TY_BOUND_MODIFIERS] [for] SIMPLE_PATH /// ``` diff --git a/compiler/rustc_query_system/src/dep_graph/debug.rs b/compiler/rustc_query_system/src/dep_graph/debug.rs index a544ac2c343ae..f9f3169af69c9 100644 --- a/compiler/rustc_query_system/src/dep_graph/debug.rs +++ b/compiler/rustc_query_system/src/dep_graph/debug.rs @@ -7,9 +7,9 @@ use std::error::Error; /// A dep-node filter goes from a user-defined string to a query over /// nodes. Right now the format is like this: -/// -/// x & y & z -/// +/// ```ignore (illustrative) +/// x & y & z +/// ``` /// where the format-string of the dep-node must contain `x`, `y`, and /// `z`. #[derive(Debug)] diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index e0a83ba8c0d4a..555a3382acfe9 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -2273,16 +2273,16 @@ impl<'a, 'b> ImportResolver<'a, 'b> { /// Given a `binding_span` of a binding within a use statement: /// -/// ``` +/// ```ignore (illustrative) /// use foo::{a, b, c}; -/// ^ +/// // ^ /// ``` /// /// then return the span until the next binding or the end of the statement: /// -/// ``` +/// ```ignore (illustrative) /// use foo::{a, b, c}; -/// ^^^ +/// // ^^^ /// ``` fn find_span_of_binding_until_next_binding( sess: &Session, @@ -2326,14 +2326,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 /// binding. /// -/// ``` +/// ```ignore (illustrative) /// use foo::a::{a, b, c}; -/// ^^--- binding span -/// | -/// returned span +/// // ^^--- binding span +/// // | +/// // returned span /// /// use foo::{a, b, c}; -/// --- binding span +/// // --- binding span /// ``` fn extend_span_to_previous_binding(sess: &Session, binding_span: Span) -> Option { let source_map = sess.source_map(); @@ -2369,15 +2369,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 /// it is a nested use tree. /// -/// ``` +/// ```ignore (illustrative) /// use foo::a::{b, c}; -/// ^^^^^^^^^^ // false +/// // ^^^^^^^^^^ -- false /// /// use foo::{a, b, c}; -/// ^^^^^^^^^^ // true +/// // ^^^^^^^^^^ -- true /// /// use foo::{a, b::{c, d}}; -/// ^^^^^^^^^^^^^^^ // true +/// // ^^^^^^^^^^^^^^^ -- true /// ``` fn find_span_immediately_after_crate_name( sess: &Session, diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 787536d2a38ed..0db0b9d67d409 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -401,7 +401,7 @@ pub fn provide(providers: &mut ty::query::Providers) { /// The reason for this separate call is to resolve what would otherwise /// be a cycle. Consider this example: /// -/// ```rust +/// ```ignore UNSOLVED (maybe @jackh726 knows what lifetime parameter to give Sub) /// trait Base<'a> { /// type BaseItem; /// } @@ -2552,7 +2552,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { /// Returns all the late-bound vars that come into scope from supertrait HRTBs, based on the /// associated type name and starting trait. /// For example, imagine we have - /// ```rust + /// ```ignore (illustrative) /// trait Foo<'a, 'b> { /// type As; /// } diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index 3889639b50f45..687d7471b25b2 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -686,7 +686,7 @@ impl SyntaxContext { /// context up one macro definition level. That is, if we have a nested macro /// definition as follows: /// - /// ```rust + /// ```ignore (illustrative) /// macro_rules! f { /// macro_rules! g { /// ... @@ -710,6 +710,7 @@ impl SyntaxContext { /// For example, consider the following three resolutions of `f`: /// /// ```rust + /// #![feature(decl_macro)] /// mod foo { pub fn f() {} } // `f`'s `SyntaxContext` is empty. /// m!(f); /// macro m($f:ident) { @@ -746,7 +747,8 @@ impl SyntaxContext { /// via a glob import with the given `SyntaxContext`. /// For example: /// - /// ```rust + /// ```compile_fail,E0425 + /// #![feature(decl_macro)] /// m!(f); /// macro m($i:ident) { /// mod foo { @@ -786,7 +788,7 @@ impl SyntaxContext { /// Undo `glob_adjust` if possible: /// - /// ```rust + /// ```ignore (illustrative) /// if let Some(privacy_checking_scope) = self.reverse_glob_adjust(expansion, glob_ctxt) { /// assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope)); /// } diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 460b5c18fc1b4..505c0af953af1 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -1058,10 +1058,11 @@ impl SourceMap { /// 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. - /// - /// v output - /// mac!(); - /// ^^^^^^ input + /// ```ignore (illustrative) + /// // v output + /// mac!(); + /// // ^^^^^^ input + /// ``` pub fn mac_call_stmt_semi_span(&self, mac_call: Span) -> Option { 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)?)); diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 4b949ff8b95de..5bd49dd21e73c 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -22,11 +22,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// (*), computes the "definition type" for an opaque type /// definition -- that is, the inferred value of `Foo1<'x>` or /// `Foo2<'x>` that we would conceptually use in its definition: - /// - /// type Foo1<'x> = impl Bar<'x> = AAA; <-- this type AAA - /// type Foo2<'x> = impl Bar<'x> = BBB; <-- or this type BBB - /// fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. } - /// + /// ```ignore (illustrative) + /// type Foo1<'x> = impl Bar<'x> = AAA; // <-- this type AAA + /// type Foo2<'x> = impl Bar<'x> = BBB; // <-- or this type BBB + /// fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. } + /// ``` /// 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 /// purpose of this function is to do that translation. diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index d95512bb88f36..79e9635f90ef6 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -255,9 +255,9 @@ impl<'tcx> AutoTraitFinder<'tcx> { /// `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 /// like this: - /// - /// impl Send for Foo where T: IntoIterator - /// + /// ```ignore (illustrative) + /// impl Send for Foo 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`. /// @@ -420,10 +420,10 @@ impl<'tcx> AutoTraitFinder<'tcx> { /// two trait predicates that differ only in their region parameters: /// one containing a HRTB lifetime parameter, and one containing a 'normal' /// lifetime parameter. For example: - /// - /// T as MyTrait<'a> - /// T as MyTrait<'static> - /// + /// ```ignore (illustrative) + /// T as MyTrait<'a> + /// T as MyTrait<'static> + /// ``` /// If we put both of these predicates in our computed `ParamEnv`, we'll /// confuse `SelectionContext`, since it will (correctly) view both as being applicable. /// diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 40c3f4047ae6e..24110d30a8456 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -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 /// write both a conditional blanket impl and a specific impl, we need to /// make sure they do not overlap. For example, if we write -/// ``` +/// ```ignore (illustrative) /// impl IntoIterator for Vec /// impl IntoIterator for T /// ``` diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index b39310d12942d..e1b6ed92269ca 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -595,7 +595,7 @@ fn object_ty_for_trait<'tcx>( /// - let `Receiver` be the type of the `self` argument, i.e `Self`, `&Self`, `Rc`, /// - require the following bound: /// -/// ``` +/// ```ignore (not-rust) /// Receiver[Self => T]: DispatchFromDyn 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 /// `Self: Unsize` and `U: Trait + ?Sized`, and use `U` in place of `dyn Trait`. /// Written as a chalk-style query: -/// -/// forall (U: Trait + ?Sized) { -/// if (Self: Unsize) { -/// Receiver: DispatchFromDyn U]> -/// } +/// ```ignore (not-rust) +/// forall (U: Trait + ?Sized) { +/// if (Self: Unsize) { +/// Receiver: DispatchFromDyn U]> /// } -/// +/// } +/// ``` /// for `self: &'a mut Self`, this means `&'a mut Self: DispatchFromDyn<&'a mut U>` /// for `self: Rc`, this means `Rc: DispatchFromDyn>` /// for `self: Pin>`, this means `Pin>: DispatchFromDyn>>` diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index c7a61cbe25a1a..be4d734b964b8 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -158,9 +158,9 @@ pub(super) enum ProjectAndUnifyResult<'tcx> { } /// Evaluates constraints of the form: -/// -/// for<...> ::U == V -/// +/// ```ignore (not-rust) +/// for<...> ::U == V +/// ``` /// If successful, this may result in additional obligations. Also returns /// 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: -/// -/// ::U == V -/// +/// ```ignore (not-rust) +/// ::U == V +/// ``` /// If successful, this may result in additional obligations. /// /// 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 <::FooT as Bar>::BarT, we may find /// that the definition of `Foo` has some clues: /// -/// ``` +/// ```ignore (illustrative) /// trait Foo { /// type FooT : Bar /// } diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index b97ab39d991fe..771a3072af5d9 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -712,9 +712,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { /// and we desugared it so that the type of the expression is /// `Closure`, and `Closure` expects `i32` as argument. Then it /// is "as if" the compiler generated this impl: - /// - /// impl Fn(i32) for Closure { ... } - /// + /// ```ignore (illustrative) + /// impl Fn(i32) for Closure { ... } + /// ``` /// Now imagine our obligation is `Closure: Fn(usize)`. So far /// we have matched the self type `Closure`. At this point we'll /// compare the `i32` to `usize` and generate an error. diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index e69bf6eca90ef..612091d5ab7de 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1933,7 +1933,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { /// /// Here are some (simple) examples: /// - /// ``` + /// ```ignore (illustrative) /// (i32, u32) -> [i32, u32] /// Foo where struct Foo { x: i32, y: u32 } -> [i32, u32] /// Bar where struct Bar { x: T, y: u32 } -> [i32, u32] diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index 328e0d2e0e90a..49c8c56083f08 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -52,7 +52,7 @@ pub struct OverlapError { /// /// For example, consider the following scenario: /// -/// ```rust +/// ```ignore (illustrative) /// trait Foo { ... } /// impl Foo for (T, U) { ... } // target impl /// impl 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" /// an argument indirectly: /// -/// ```rust +/// ```ignore (illustrative) /// impl<'a, I, T: 'a> Iterator for Cloned /// where I: Iterator, T: Clone /// ``` diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index b4ed5b95b1047..de0ade64247df 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -170,7 +170,7 @@ struct WfPredicates<'a, 'tcx> { /// predicates. This is a kind of hack to address #43784. The /// underlying problem in that issue was a trait structure like: /// -/// ``` +/// ```ignore (illustrative) /// trait Foo: Copy { } /// trait Bar: Foo { } /// impl Foo for T { } diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index b015e40b6836f..c63e9c31d535c 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -122,16 +122,16 @@ rustc_index::newtype_index! { /// A [De Bruijn index][dbi] is a standard means of representing /// regions (and perhaps later types) in a higher-ranked setting. In /// particular, imagine a type like this: - /// - /// for<'a> fn(for<'b> fn(&'b isize, &'a isize), &'a char) - /// ^ ^ | | | - /// | | | | | - /// | +------------+ 0 | | - /// | | | - /// +----------------------------------+ 1 | - /// | | - /// +----------------------------------------------+ 0 - /// + /// ```ignore (illustrative) + /// for<'a> fn(for<'b> fn(&'b isize, &'a isize), &'a char) + /// // ^ ^ | | | + /// // | | | | | + /// // | +------------+ 0 | | + /// // | | | + /// // +----------------------------------+ 1 | + /// // | | + /// // +----------------------------------------------+ 0 + /// ``` /// 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 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 /// when moving a region out from inside binders: /// - /// ``` + /// ```ignore (illustrative) /// for<'a> fn(for<'b> for<'c> fn(&'a u32), _) /// // Binder: D3 D2 D1 ^^ /// ``` @@ -471,9 +471,9 @@ impl Variance { /// variance with which the argument appears. /// /// Example 1: - /// - /// *mut Vec - /// + /// ```ignore (illustrative) + /// *mut Vec + /// ``` /// Here, the "ambient" variance starts as covariant. `*mut T` is /// invariant with respect to `T`, so the variance in which the /// `Vec` appears is `Covariant.xform(Invariant)`, which @@ -483,9 +483,9 @@ impl Variance { /// (again) in `Invariant`. /// /// Example 2: - /// - /// fn(*const Vec, *mut Vec, *mut Vec dyn AstConv<'tcx> + 'o { /// /// Example: /// - /// ``` - /// T: std::ops::Index - /// ^1 ^^^^^^^^^^^^^^2 ^^^^3 ^^^^^^^^^^^4 + /// ```ignore (illustrative) + /// T: std::ops::Index + /// // ^1 ^^^^^^^^^^^^^^2 ^^^^3 ^^^^^^^^^^^4 /// ``` /// /// 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 /// - /// ``` + /// ```ignore (illustrative) /// as Iterable>::Iter::<'a> /// ``` /// @@ -756,7 +756,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { /// /// Example: /// - /// ``` + /// ```ignore (illustrative) /// poly_trait_ref = Iterator /// self_ty = Foo /// ``` @@ -1021,10 +1021,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { /// /// Example: /// - /// ``` + /// ```ignore (illustrative) /// fn foo() { } - /// ^ ^^^^^^^^^ ast_bounds - /// param_ty + /// // ^ ^^^^^^^^^ ast_bounds + /// // param_ty /// ``` /// /// The `sized_by_default` parameter indicates if, in this context, the `param_ty` should be diff --git a/compiler/rustc_typeck/src/check/closure.rs b/compiler/rustc_typeck/src/check/closure.rs index 320be9b44d441..50e55bdc4af30 100644 --- a/compiler/rustc_typeck/src/check/closure.rs +++ b/compiler/rustc_typeck/src/check/closure.rs @@ -371,7 +371,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// /// # Examples /// - /// ``` + /// ```ignore (illustrative) /// fn with_closure(_: F) /// where F: Fn(&u32) -> &u32 { .. } /// diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs index b44baf83cbe1e..c563d57ed96bb 100644 --- a/compiler/rustc_typeck/src/check/coercion.rs +++ b/compiler/rustc_typeck/src/check/coercion.rs @@ -21,7 +21,7 @@ //! When inferring the generic arguments of functions, the argument //! order is relevant, which can lead to the following edge case: //! -//! ```rust +//! ```ignore (illustrative) //! fn foo(a: T, b: T) { //! // ... //! } @@ -1210,7 +1210,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// /// Example: /// -/// ``` +/// ```ignore (illustrative) /// let mut coerce = CoerceMany::new(expected_ty); /// for expr in exprs { /// let expr_ty = fcx.check_expr_with_expectation(expr, expected); diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index f377cf3678e40..bfd2c32fd7e3c 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -439,7 +439,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Identify some cases where `as_ref()` would be appropriate and suggest it. /// /// Given the following code: - /// ``` + /// ```compile_fail,E0308 /// struct Foo; /// fn takes_ref(_: &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. /// /// It only checks for `Option` and `Result` and won't work with - /// ``` + /// ```ignore (illustrative) /// opt.map(|param| { takes_ref(param) }); /// ``` 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 /// provide them useful help. For example: /// - /// ``` + /// ```compile_fail,E0308 /// fn some_fn(s: &str) {} /// /// let x = "hey!".to_owned(); diff --git a/compiler/rustc_typeck/src/check/fallback.rs b/compiler/rustc_typeck/src/check/fallback.rs index 8513231782407..15788f410f195 100644 --- a/compiler/rustc_typeck/src/check/fallback.rs +++ b/compiler/rustc_typeck/src/check/fallback.rs @@ -144,6 +144,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { /// code. The most common case is something like this: /// /// ```rust + /// # fn foo() -> i32 { 4 } /// match foo() { /// 22 => Default::default(), // call this type `?D` /// _ => return, // return has type `!` @@ -168,7 +169,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { /// fallback to use based on whether there is a coercion pattern /// like this: /// - /// ``` + /// ```ignore (not-rust) /// ?Diverging -> ?V /// ?NonDiverging -> ?V /// ?V != ?NonDiverging diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 616aa11f00a6b..d7a817f67e0cd 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -1467,7 +1467,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// A common error is to add an extra semicolon: /// - /// ``` + /// ```compile_fail,E0308 /// fn foo() -> usize { /// 22; /// } diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index 681d1e37f86f1..ecb0004c33434 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -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 /// the ctor would successfully solve the type mismatch and if so, suggest it: - /// ``` + /// ```compile_fail,E0308 /// fn foo(x: usize) -> usize { x } /// 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., /// - /// ``` + /// ```compile_fail,E0308 + /// # fn bar_that_returns_u32() -> u32 { 4 } /// fn foo() { /// 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: /// - /// ``` + /// ```compile_fail,E0308 + /// # fn bar_that_returns_u32() -> u32 { 4 } /// fn foo() { /// 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 /// 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` - /// ``` + /// ```compile_fail,E0308 /// fn cant_name_it u32>() -> T { /// || 3 /// } diff --git a/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs b/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs index 721f251650f54..df8db0da64482 100644 --- a/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs +++ b/compiler/rustc_typeck/src/check/generator_interior/drop_ranges/cfg_build.rs @@ -71,7 +71,7 @@ pub(super) fn build_control_flow_graph<'tcx>( /// ``` /// /// Rule 3: -/// ```rust +/// ```compile_fail,E0382 /// let mut a = (vec![0], vec![0]); /// drop(a); /// a.1 = vec![1]; diff --git a/compiler/rustc_typeck/src/check/inherited.rs b/compiler/rustc_typeck/src/check/inherited.rs index 62ca728868b45..5cd63cae8ad9b 100644 --- a/compiler/rustc_typeck/src/check/inherited.rs +++ b/compiler/rustc_typeck/src/check/inherited.rs @@ -17,11 +17,11 @@ use std::cell::RefCell; use std::ops::Deref; /// Closures defined within the function. For example: -/// -/// fn foo() { -/// bar(move|| { ... }) -/// } -/// +/// ```ignore (illustrative) +/// fn foo() { +/// bar(move|| { ... }) +/// } +/// ``` /// Here, the function `foo()` and the closure passed to /// `bar()` will each have their own `FnCtxt`, but they will /// share the inherited fields. diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index e04cc42b6d7e5..a46be244e39a0 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -200,8 +200,9 @@ pub struct Pick<'tcx> { pub import_ids: SmallVec<[LocalDefId; 1]>, /// Indicates that the source expression should be autoderef'd N times - /// - /// A = expr | *expr | **expr | ... + /// ```ignore (not-rust) + /// A = expr | *expr | **expr | ... + /// ``` pub autoderefs: usize, /// Indicates that we want to add an autoref (and maybe also unsize it), or if the receiver is @@ -1631,7 +1632,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { /// /// Example (`src/test/ui/method-two-trait-defer-resolution-1.rs`): /// - /// ``` + /// ```ignore (illustrative) /// trait Foo { ... } /// impl Foo for Vec { ... } /// impl Foo for Vec { ... } diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 76c955d6f690d..e82a454e30d4d 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -891,16 +891,19 @@ fn report_unexpected_variant_res(tcx: TyCtxt<'_>, res: Res, span: Span) { /// Tupling means that all call-side arguments are packed into a tuple and /// passed as a single parameter. For example, if tupling is enabled, this /// function: -/// -/// fn f(x: (isize, isize)) -/// +/// ``` +/// fn f(x: (isize, isize)) {} +/// ``` /// Can be called as: -/// -/// f(1, 2); -/// +/// ```ignore UNSOLVED (can this be done in user code?) +/// # fn f(x: (isize, isize)) {} +/// f(1, 2); +/// ``` /// Instead of: -/// -/// f((1, 2)); +/// ``` +/// # fn f(x: (isize, isize)) {} +/// f((1, 2)); +/// ``` #[derive(Clone, Eq, PartialEq)] enum TupleArgumentsFlag { DontTupleArguments, diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 356763fab5e3b..5eba95b495dd7 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -1894,7 +1894,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// /// Syntactically, these look like `[pat_0, ..., pat_n]`. /// Semantically, we are type checking a pattern with structure: - /// ``` + /// ```ignore (not-rust) /// [before_0, ..., before_n, (slice, after_0, ... after_n)?] /// ``` /// The type of `slice`, if it is present, depends on the `expected` type. diff --git a/compiler/rustc_typeck/src/check/regionck.rs b/compiler/rustc_typeck/src/check/regionck.rs index e37e83e748733..20456cc427c52 100644 --- a/compiler/rustc_typeck/src/check/regionck.rs +++ b/compiler/rustc_typeck/src/check/regionck.rs @@ -269,7 +269,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { /// /// Consider this silly example: /// - /// ``` + /// ```ignore UNSOLVED (does replacing @i32 with Box preserve the desired semantics for the example?) /// fn borrow(x: &i32) -> &i32 {x} /// fn foo(x: @i32) -> i32 { // block: B /// let b = borrow(x); // region: diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 9dbb813293263..cac9899ecd4b2 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -5,9 +5,9 @@ //! immutable "borrow kind" (see `ty::BorrowKind` for details) and then //! "escalating" the kind as needed. The borrow kind proceeds according to //! the following lattice: -//! -//! ty::ImmBorrow -> ty::UniqueImmBorrow -> ty::MutBorrow -//! +//! ```ignore (not-rust) +//! ty::ImmBorrow -> ty::UniqueImmBorrow -> ty::MutBorrow +//! ``` //! So, for example, if we see an assignment `x = 5` to an upvar `x`, we //! will promote its borrow kind to mutable borrow. If we see an `&mut x` //! we'll do the same. Naturally, this applies not just to the upvar, but @@ -447,16 +447,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// the existing min_capture map that is stored in TypeckResults. /// /// Eg: - /// ```rust,no_run + /// ``` + /// #[derive(Debug)] /// struct Point { x: i32, y: i32 } /// - /// let s: String; // hir_id_s - /// let mut p: Point; // his_id_p + /// let s = String::from("s"); // hir_id_s + /// let mut p = Point { x: 2, y: -2 }; // his_id_p /// let c = || { - /// println!("{s}"); // L1 + /// println!("{s:?}"); // L1 /// p.x += 10; // L2 /// println!("{}" , p.y); // L3 - /// println!("{p}"); // L4 + /// println!("{p:?}"); // L4 /// drop(s); // L5 /// }; /// ``` @@ -465,7 +466,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// /// InferBorrowKind results in a structure like this: /// - /// ```text + /// ```ignore (illustrative) /// { /// Place(base: hir_id_s, projections: [], ....) -> { /// capture_kind_expr: hir_id_L5, @@ -490,7 +491,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// ``` /// /// After the min capture analysis, we get: - /// ```text + /// ```ignore (illustrative) /// { /// hir_id_s -> [ /// Place(base: hir_id_s, projections: [], ....) -> { @@ -1281,27 +1282,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// - Ty(place): Type of place /// - `(a, b)`: Represents the function parameters `base_path_ty` and `captured_by_move_projs` /// respectively. - /// ``` + /// ```ignore (illustrative) /// (Ty(w), [ &[p, x], &[c] ]) - /// | - /// ---------------------------- - /// | | - /// v v + /// // | + /// // ---------------------------- + /// // | | + /// // v v /// (Ty(w.p), [ &[x] ]) (Ty(w.c), [ &[] ]) // I(1) - /// | | - /// v v + /// // | | + /// // v v /// (Ty(w.p), [ &[x] ]) false - /// | - /// | - /// ------------------------------- - /// | | - /// v v + /// // | + /// // | + /// // ------------------------------- + /// // | | + /// // v v /// (Ty((w.p).x), [ &[] ]) (Ty((w.p).y), []) // IMP 2 - /// | | - /// v v + /// // | | + /// // v v /// false NeedsSignificantDrop(Ty(w.p.y)) - /// | - /// v + /// // | + /// // v /// true /// ``` /// @@ -1319,7 +1320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// /// Consider another example: /// - /// ```rust + /// ```ignore (pseudo-rust) /// struct X; /// impl Drop for X {} /// @@ -1724,14 +1725,14 @@ struct InferBorrowKind<'a, 'tcx> { /// s.str2 via a MutableBorrow /// /// ```rust,no_run - /// struct SomeStruct { str1: String, str2: String } + /// struct SomeStruct { str1: String, str2: String }; /// /// // Assume that the HirId for the variable definition is `V1` - /// let mut s = SomeStruct { str1: format!("s1"), str2: format!("s2") } + /// let mut s = SomeStruct { str1: format!("s1"), str2: format!("s2") }; /// /// let fix_s = |new_s2| { /// // Assume that the HirId for the expression `s.str1` is `E1` - /// println!("Updating SomeStruct with str1=", s.str1); + /// println!("Updating SomeStruct with str1={0}", s.str1); /// // Assume that the HirId for the expression `*s.str2` is `E2` /// s.str2 = new_s2; /// }; @@ -1739,7 +1740,7 @@ struct InferBorrowKind<'a, 'tcx> { /// /// For closure `fix_s`, (at a high level) the map contains /// - /// ``` + /// ```ignore (illustrative) /// Place { V1, [ProjectionKind::Field(Index=0, Variant=0)] } : CaptureKind { E1, ImmutableBorrow } /// Place { V1, [ProjectionKind::Field(Index=1, Variant=0)] } : CaptureKind { E2, MutableBorrow } /// ``` @@ -2067,7 +2068,7 @@ fn migration_suggestion_for_2229( /// Consider the following example /// ```rust,no_run /// struct Point { x: i32, y: i32 } -/// let mut p: Point { x: 10, y: 10 }; +/// let mut p = Point { x: 10, y: 10 }; /// /// let c = || { /// p.x += 10; @@ -2213,7 +2214,10 @@ fn determine_place_ancestry_relation<'tcx>( /// /// Reason we only drop the last deref is because of the following edge case: /// -/// ```rust +/// ``` +/// # struct A { field_of_a: Box } +/// # struct B {} +/// # struct C<'a>(&'a i32); /// struct MyStruct<'a> { /// a: &'static A, /// b: B, @@ -2221,7 +2225,7 @@ fn determine_place_ancestry_relation<'tcx>( /// } /// /// fn foo<'a, 'b>(m: &'a MyStruct<'b>) -> impl FnMut() + 'static { -/// let c = || drop(&*m.a.field_of_a); +/// || drop(&*m.a.field_of_a) /// // Here we really do want to capture `*m.a` because that outlives `'static` /// /// // If we capture `m`, then the closure no longer outlives `'static' diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index ec2b7c13ff33c..829485367e0a4 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -37,7 +37,7 @@ use std::ops::ControlFlow; /// Helper type of a temporary returned by `.for_item(...)`. /// This is necessary because we can't write the following bound: /// -/// ```rust +/// ```ignore (illustrative) /// F: for<'b, 'tcx> where 'tcx FnOnce(FnCtxt<'b, 'tcx>) /// ``` struct CheckWfFcxBuilder<'tcx> { diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 495b8d3b4eeb3..5bb3f92e2f80b 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -531,7 +531,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { /// In particular, definitions of opaque types can only use other generics as arguments, /// and they cannot repeat an argument. Example: /// -/// ```rust +/// ```ignore (illustrative) /// type Foo = impl Bar; /// /// // Okay -- `Foo` is applied to two distinct, generic types. diff --git a/compiler/rustc_typeck/src/constrained_generic_params.rs b/compiler/rustc_typeck/src/constrained_generic_params.rs index 909c99adab5d2..d406d08cd9508 100644 --- a/compiler/rustc_typeck/src/constrained_generic_params.rs +++ b/compiler/rustc_typeck/src/constrained_generic_params.rs @@ -109,9 +109,9 @@ pub fn identify_constrained_generic_params<'tcx>( /// constrained before it is used, if that is possible, and add the /// parameters so constrained to `input_parameters`. For example, /// imagine the following impl: -/// -/// impl> Trait for U -/// +/// ```ignore (illustrative) +/// impl> Trait for U +/// ``` /// The impl's predicates are collected from left to right. Ignoring /// the implicit `Sized` bounds, these are /// * T: Debug diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index 2bcf2d3b2ed71..e69ba99dcef42 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -698,12 +698,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { /// In the following example the closures `c` only captures `p.x` even though `incr` /// is a capture of the nested closure /// - /// ```rust,ignore(cannot-test-this-because-pseudo-code) - /// let p = ..; + /// ``` + /// struct P { x: i32 } + /// let mut p = P { x: 4 }; /// let c = || { /// let incr = 10; /// let nested = || p.x += incr; - /// } + /// }; /// ``` /// /// - When reporting the Place back to the Delegate, ensure that the UpvarId uses the enclosing diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs index 6cef3e9d9409e..22db15f4d4e8e 100644 --- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs @@ -29,7 +29,7 @@ //! //! Suppose we have the following always applicable impl: //! -//! ```rust +//! ```ignore (illustrative) //! impl SpecExtend for std::vec::IntoIter { /* specialized impl */ } //! impl> SpecExtend for I { /* default impl */ } //! ``` diff --git a/compiler/rustc_typeck/src/mem_categorization.rs b/compiler/rustc_typeck/src/mem_categorization.rs index 85e9a670ffbf1..3d7b6593a6455 100644 --- a/compiler/rustc_typeck/src/mem_categorization.rs +++ b/compiler/rustc_typeck/src/mem_categorization.rs @@ -9,12 +9,12 @@ //! expressions of the following forms (the actual enum has many more //! possibilities, naturally, but they are all variants of these base //! forms): -//! -//! E = rvalue // some computed rvalue -//! | x // address of a local variable or argument -//! | *E // deref of a ptr -//! | E.comp // access to an interior component -//! +//! ```ignore (not-rust) +//! E = rvalue // some computed rvalue +//! | x // address of a local variable or argument +//! | *E // deref of a ptr +//! | E.comp // access to an interior component +//! ``` //! Imagine a routine ToAddr(Expr) that evaluates an expression and returns an //! address where the result is to be found. If Expr is a place, then this //! is the address of the place. If `Expr` is an rvalue, this is the address of diff --git a/compiler/rustc_typeck/src/outlives/implicit_infer.rs b/compiler/rustc_typeck/src/outlives/implicit_infer.rs index 6f842c6e71a5b..b2cf64393a402 100644 --- a/compiler/rustc_typeck/src/outlives/implicit_infer.rs +++ b/compiler/rustc_typeck/src/outlives/implicit_infer.rs @@ -211,15 +211,15 @@ fn insert_required_predicates_to_be_wf<'tcx>( /// We also have to check the explicit predicates /// declared on the type. +/// ```ignore (illustrative) +/// struct Foo<'a, T> { +/// field1: Bar +/// } /// -/// struct Foo<'a, T> { -/// field1: Bar -/// } -/// -/// struct Bar where U: 'static, U: Foo { -/// ... -/// } -/// +/// struct Bar where U: 'static, U: Foo { +/// ... +/// } +/// ``` /// Here, we should fetch the explicit predicates, which /// will give us `U: 'static` and `U: Foo`. The latter we /// can ignore, but we will want to process `U: 'static`, diff --git a/compiler/rustc_typeck/src/outlives/outlives_bounds.rs b/compiler/rustc_typeck/src/outlives/outlives_bounds.rs index 435df9c00f466..87f844fafe67f 100644 --- a/compiler/rustc_typeck/src/outlives/outlives_bounds.rs +++ b/compiler/rustc_typeck/src/outlives/outlives_bounds.rs @@ -26,9 +26,9 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { /// calling that fn, and hence the *callee* can assume that its /// argument types are well-formed. This may imply certain relationships /// between generic parameters. For example: - /// - /// fn foo<'a,T>(x: &'a T) - /// + /// ``` + /// fn foo<'a,T>(x: &'a T) {} + /// ``` /// can only be called with a `'a` and `T` such that `&'a T` is WF. /// For `&'a T` to be WF, `T: 'a` must hold. So we can assume `T: 'a`. /// diff --git a/compiler/rustc_typeck/src/variance/constraints.rs b/compiler/rustc_typeck/src/variance/constraints.rs index 76755de4964e1..81d3dfae626fe 100644 --- a/compiler/rustc_typeck/src/variance/constraints.rs +++ b/compiler/rustc_typeck/src/variance/constraints.rs @@ -34,11 +34,11 @@ pub struct Constraint<'a> { /// To build constraints, we visit one item (type, trait) at a time /// and look at its contents. So e.g., if we have -/// -/// struct Foo { -/// b: Bar -/// } -/// +/// ```ignore (illustrative) +/// struct Foo { +/// b: Bar +/// } +/// ``` /// then while we are visiting `Bar`, the `CurrentItem` would have /// the `DefId` and the start of `Foo`'s inferreds. pub struct CurrentItem { From e62663492b2773d50e37a70420f41e758d5af722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Mon, 2 May 2022 00:00:00 +0000 Subject: [PATCH 02/13] Collect function instance used in `global_asm!` sym operand The constants used in SymFn operands have FnDef type, so the type of the constant identifies the function. --- compiler/rustc_monomorphize/src/collector.rs | 9 +++------ src/test/assembly/asm/global_asm.rs | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 1828aecb375c4..18f32b04fadca 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -445,12 +445,9 @@ fn collect_items_rec<'tcx>( // depend on any other items. } hir::InlineAsmOperand::SymFn { anon_const } => { - let def_id = tcx.hir().body_owner_def_id(anon_const.body).to_def_id(); - if let Ok(val) = tcx.const_eval_poly(def_id) { - rustc_data_structures::stack::ensure_sufficient_stack(|| { - collect_const_value(tcx, val, &mut neighbors); - }); - } + let fn_ty = + tcx.typeck_body(anon_const.body).node_type(anon_const.hir_id); + visit_fn_use(tcx, fn_ty, false, *op_sp, &mut neighbors); } hir::InlineAsmOperand::SymStatic { path: _, def_id } => { let instance = Instance::mono(tcx, *def_id); diff --git a/src/test/assembly/asm/global_asm.rs b/src/test/assembly/asm/global_asm.rs index b76ce7ac387fa..4cf73b40faf0b 100644 --- a/src/test/assembly/asm/global_asm.rs +++ b/src/test/assembly/asm/global_asm.rs @@ -2,6 +2,7 @@ // only-linux // assembly-output: emit-asm // compile-flags: -C llvm-args=--x86-asm-syntax=intel +// compile-flags: -C symbol-mangling-version=v0 #![feature(asm_const, asm_sym)] #![crate_type = "rlib"] @@ -24,3 +25,7 @@ global_asm!("movl ${}, %ecx", const 5, options(att_syntax)); global_asm!("call {}", sym my_func); // CHECK: lea rax, [rip + MY_STATIC] global_asm!("lea rax, [rip + {}]", sym MY_STATIC); +// CHECK: call _RNvCsiubXh4Yz005_10global_asm6foobar +global_asm!("call {}", sym foobar); +// CHECK: _RNvCsiubXh4Yz005_10global_asm6foobar: +fn foobar() { loop {} } From 13b45aa6c66c8075acc95ea94d8c5cbc24a3a203 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 4 May 2022 15:39:18 +0200 Subject: [PATCH 03/13] Add rotation animation on settings button when loading --- src/librustdoc/html/static/css/rustdoc.css | 12 ++++++++++++ src/librustdoc/html/static/js/main.js | 2 +- src/librustdoc/html/static/js/settings.js | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 81c12be8e83c0..12059e0b9c4b5 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1401,6 +1401,18 @@ pre.rust { cursor: pointer; } +@keyframes rotating { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} +#settings-menu.rotate img { + animation: rotating 2s linear infinite; +} + #help-button { font-family: "Fira Sans", Arial, sans-serif; text-align: center; diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 1dfd9c762c46e..1f41d62bde346 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -300,8 +300,8 @@ function loadCss(cssFileName) { document.head.append(script); } - getSettingsButton().onclick = event => { + addClass(getSettingsButton(), "rotate"); event.preventDefault(); loadScript(window.settingsJS); }; diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js index 43b24245ab2e8..04c64cbb54846 100644 --- a/src/librustdoc/html/static/js/settings.js +++ b/src/librustdoc/html/static/js/settings.js @@ -272,5 +272,6 @@ if (!isSettingsPage) { switchDisplayedElement(settingsMenu); } + removeClass(getSettingsButton(), "rotate"); }, 0); })(); From cb131d2b4a1a56676c5f21bcf74ab373900eca2f Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 5 May 2022 20:03:34 +0900 Subject: [PATCH 04/13] Add a regression test for #64173 and #66152 --- .../lifetimes/issue-64173-unused-lifetimes.rs | 19 ++++++++++ .../issue-64173-unused-lifetimes.stderr | 35 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/test/ui/lifetimes/issue-64173-unused-lifetimes.rs create mode 100644 src/test/ui/lifetimes/issue-64173-unused-lifetimes.stderr diff --git a/src/test/ui/lifetimes/issue-64173-unused-lifetimes.rs b/src/test/ui/lifetimes/issue-64173-unused-lifetimes.rs new file mode 100644 index 0000000000000..8080dd7dc34db --- /dev/null +++ b/src/test/ui/lifetimes/issue-64173-unused-lifetimes.rs @@ -0,0 +1,19 @@ +use std::mem::size_of; + +struct Foo<'s> { //~ ERROR: parameter `'s` is never used + array: [(); size_of::<&Self>()], + //~^ ERROR: generic `Self` types are currently not permitted in anonymous constants +} + +// The below is taken from https://github.com/rust-lang/rust/issues/66152#issuecomment-550275017 +// as the root cause seems the same. + +const fn foo() -> usize { + 0 +} + +struct Bar<'a> { //~ ERROR: parameter `'a` is never used + beta: [(); foo::<&'a ()>()], //~ ERROR: a non-static lifetime is not allowed in a `const` +} + +fn main() {} diff --git a/src/test/ui/lifetimes/issue-64173-unused-lifetimes.stderr b/src/test/ui/lifetimes/issue-64173-unused-lifetimes.stderr new file mode 100644 index 0000000000000..a487cbea5371b --- /dev/null +++ b/src/test/ui/lifetimes/issue-64173-unused-lifetimes.stderr @@ -0,0 +1,35 @@ +error[E0658]: a non-static lifetime is not allowed in a `const` + --> $DIR/issue-64173-unused-lifetimes.rs:16:23 + | +LL | beta: [(); foo::<&'a ()>()], + | ^^ + | + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable + +error: generic `Self` types are currently not permitted in anonymous constants + --> $DIR/issue-64173-unused-lifetimes.rs:4:28 + | +LL | array: [(); size_of::<&Self>()], + | ^^^^ + +error[E0392]: parameter `'s` is never used + --> $DIR/issue-64173-unused-lifetimes.rs:3:12 + | +LL | struct Foo<'s> { + | ^^ unused parameter + | + = help: consider removing `'s`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0392]: parameter `'a` is never used + --> $DIR/issue-64173-unused-lifetimes.rs:15:12 + | +LL | struct Bar<'a> { + | ^^ unused parameter + | + = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0392, E0658. +For more information about an error, try `rustc --explain E0392`. From 6c8a2d4715ffc5e8ce8b1aec613c091f0198eaea Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 30 Apr 2022 13:05:40 -0700 Subject: [PATCH 05/13] rustdoc: when running a function-signature search, tweak the tab bar --- src/librustdoc/html/static/css/rustdoc.css | 5 +++ src/librustdoc/html/static/js/search.js | 25 +++++++-------- .../search-tab-change-title-fn-sig.goml | 32 +++++++++++++++++++ ...rch-tab-selection-if-current-is-empty.goml | 23 ------------- 4 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml delete mode 100644 src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 81c12be8e83c0..9999c68860715 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1333,6 +1333,11 @@ pre.rust { border-top: 2px solid; } +#titles > button:first-child:last-child { + margin-right: 1px; + width: calc(100% - 1px); +} + #titles > button:not(:last-child) { margin-right: 1px; width: calc(33.3% - 1px); diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 60ad431ba7a99..f93f21af817a0 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1407,18 +1407,12 @@ window.initSearch = rawSearchIndex => { for (i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) { row = searchIndex[i]; in_returned = checkReturned(row, elem, parsedQuery.typeFilter); - addIntoResults(results_returned, row.id, i, -1, in_returned); + addIntoResults(results_others, row.id, i, -1, in_returned); } } } else if (parsedQuery.foundElems > 0) { - let container = results_others; - // In the special case where only a "returned" information is available, we want to - // put the information into the "results_returned" dict. - if (parsedQuery.returned.length !== 0 && parsedQuery.elems.length === 0) { - container = results_returned; - } for (i = 0, nSearchWords = searchWords.length; i < nSearchWords; ++i) { - handleArgs(searchIndex[i], i, container); + handleArgs(searchIndex[i], i, results_others); } } } @@ -1723,12 +1717,17 @@ window.initSearch = rawSearchIndex => { `${typeFilter} in ${crates} `; if (results.query.error !== null) { output += `

Query parser error: "${results.query.error}".

`; + } else if (results.query.foundElems <= 1 && results.query.returned.length === 0) { + output += `
` + + makeTabHeader(0, "In Names", ret_others[1]) + + makeTabHeader(1, "In Parameters", ret_in_args[1]) + + makeTabHeader(2, "In Return Types", ret_returned[1]) + + "
"; + } else { + output += '
' + + makeTabHeader(0, "In Function Signature", ret_others[1]) + + "
"; } - output += `
` + - makeTabHeader(0, "In Names", ret_others[1]) + - makeTabHeader(1, "In Parameters", ret_in_args[1]) + - makeTabHeader(2, "In Return Types", ret_returned[1]) + - "
"; const resultsElem = document.createElement("div"); resultsElem.id = "results"; diff --git a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml new file mode 100644 index 0000000000000..3269305331b19 --- /dev/null +++ b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml @@ -0,0 +1,32 @@ +// Checks that the search tab results work correctly with function signature syntax +// First, try a search-by-name +goto: file://|DOC_PATH|/test_docs/index.html +write: (".search-input", "Foo") +// Waiting for the search results to appear... +wait-for: "#titles" +assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +assert-text: ("#titles > button:nth-of-type(1)", "In Names", CONTAINS) + +// Now try search-by-return +goto: file://|DOC_PATH|/test_docs/index.html +write: (".search-input", "-> String") +// Waiting for the search results to appear... +wait-for: "#titles" +assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", CONTAINS) + +// Try with a search-by-return with no results +goto: file://|DOC_PATH|/test_docs/index.html +write: (".search-input", "-> Something") +// Waiting for the search results to appear... +wait-for: "#titles" +assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", CONTAINS) + +// Try with a search-by-return with no results +goto: file://|DOC_PATH|/test_docs/index.html +write: (".search-input", "usize pattern") +// Waiting for the search results to appear... +wait-for: "#titles" +assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", CONTAINS) diff --git a/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml b/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml deleted file mode 100644 index 52b3ceae7b115..0000000000000 --- a/src/test/rustdoc-gui/search-tab-selection-if-current-is-empty.goml +++ /dev/null @@ -1,23 +0,0 @@ -// Checks that the first non-empty search result tab is selected if the default/currently selected -// one is empty. -goto: file://|DOC_PATH|/test_docs/index.html -write: (".search-input", "Foo") -// Waiting for the search results to appear... -wait-for: "#titles" -assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) - -// To go back to the original "state" -goto: file://|DOC_PATH|/test_docs/index.html -write: (".search-input", "-> String") -// Waiting for the search results to appear... -wait-for: "#titles" -// With this search, only the last tab shouldn't be empty so it should be selected. -assert-attribute: ("#titles > button:nth-of-type(3)", {"class": "selected"}) - -// To go back to the original "state" -goto: file://|DOC_PATH|/test_docs/index.html -write: (".search-input", "-> Something") -// Waiting for the search results to appear... -wait-for: "#titles" -// With this search, all the tabs are empty so the first one should remain selected. -assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) From 345a580e8d19c59cdd7d6ab5889311d2f07d7931 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 1 May 2022 15:40:46 -0700 Subject: [PATCH 06/13] Use STARTS_WITH, since it's more specific Co-Authored-By: Guillaume Gomez --- src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml index 3269305331b19..3cf34c2f43210 100644 --- a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml +++ b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml @@ -5,7 +5,7 @@ write: (".search-input", "Foo") // Waiting for the search results to appear... wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Names", CONTAINS) +assert-text: ("#titles > button:nth-of-type(1)", "In Names", STARTS_WITH) // Now try search-by-return goto: file://|DOC_PATH|/test_docs/index.html @@ -13,7 +13,7 @@ write: (".search-input", "-> String") // Waiting for the search results to appear... wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", CONTAINS) +assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH) // Try with a search-by-return with no results goto: file://|DOC_PATH|/test_docs/index.html @@ -21,7 +21,7 @@ write: (".search-input", "-> Something") // Waiting for the search results to appear... wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", CONTAINS) +assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH) // Try with a search-by-return with no results goto: file://|DOC_PATH|/test_docs/index.html @@ -29,4 +29,4 @@ write: (".search-input", "usize pattern") // Waiting for the search results to appear... wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", CONTAINS) +assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH) From 21a121332b4c5e2302c46956564879c447d555b2 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 2 May 2022 09:45:32 -0700 Subject: [PATCH 07/13] rustdoc: change the "In Function Signatures" to context-sensitive * If it's just `-> a`, use "In Function Return Types" * If it's just `a b`, use "In Function Parameters" * Otherwise, still use "In Function Signatures" --- src/librustdoc/html/static/js/search.js | 6 +++++- .../search-tab-change-title-fn-sig.goml | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index f93f21af817a0..2468d39ebc702 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1724,8 +1724,12 @@ window.initSearch = rawSearchIndex => { makeTabHeader(2, "In Return Types", ret_returned[1]) + ""; } else { + const signatureTabTitle = + results.query.elems.length === 0 ? "In Function Return Types" : + results.query.returned.length === 0 ? "In Function Parameters" : + "In Function Signatures"; output += '
' + - makeTabHeader(0, "In Function Signature", ret_others[1]) + + makeTabHeader(0, signatureTabTitle, ret_others[1]) + "
"; } diff --git a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml index 3cf34c2f43210..fc6b0696bf0db 100644 --- a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml +++ b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml @@ -13,7 +13,7 @@ write: (".search-input", "-> String") // Waiting for the search results to appear... wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH) +assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH) // Try with a search-by-return with no results goto: file://|DOC_PATH|/test_docs/index.html @@ -21,12 +21,20 @@ write: (".search-input", "-> Something") // Waiting for the search results to appear... wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH) +assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH) -// Try with a search-by-return with no results +// Try with a search-by-parameter goto: file://|DOC_PATH|/test_docs/index.html write: (".search-input", "usize pattern") // Waiting for the search results to appear... wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) -assert-text: ("#titles > button:nth-of-type(1)", "In Function Signature", STARTS_WITH) +assert-text: ("#titles > button:nth-of-type(1)", "In Function Parameters", STARTS_WITH) + +// Try with a search-by-parameter-and-return +goto: file://|DOC_PATH|/test_docs/index.html +write: (".search-input", "pattern -> str") +// Waiting for the search results to appear... +wait-for: "#titles" +assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +assert-text: ("#titles > button:nth-of-type(1)", "In Function Signatures", STARTS_WITH) From 8b2147b4970a06377defd142fa932d2264d2aa5d Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 2 May 2022 15:50:01 -0700 Subject: [PATCH 08/13] rustdoc: fix keyboard shortcuts and console log on search page --- src/librustdoc/html/static/js/search.js | 36 ++++++++++++------- .../search-tab-change-title-fn-sig.goml | 20 +++++++++++ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 2468d39ebc702..2bb850f994d0d 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -43,26 +43,33 @@ const TY_KEYWORD = itemTypes.indexOf("keyword"); // In the search display, allows to switch between tabs. function printTab(nb) { - if (nb === 0 || nb === 1 || nb === 2) { - searchState.currentTab = nb; - } - let nb_copy = nb; + let iter = 0; + let foundCurrentTab = false; + let foundCurrentResultSet = false; onEachLazy(document.getElementById("titles").childNodes, elem => { - if (nb_copy === 0) { + if (nb === iter) { addClass(elem, "selected"); + foundCurrentTab = true; } else { removeClass(elem, "selected"); } - nb_copy -= 1; + iter += 1; }); + iter = 0; onEachLazy(document.getElementById("results").childNodes, elem => { - if (nb === 0) { + if (nb === iter) { addClass(elem, "active"); + foundCurrentResultSet = true; } else { removeClass(elem, "active"); } - nb -= 1; + iter += 1; }); + if (foundCurrentTab && foundCurrentResultSet) { + searchState.currentTab = nb; + } else if (nb != 0) { + printTab(0); + } } /** @@ -1731,6 +1738,7 @@ window.initSearch = rawSearchIndex => { output += '
' + makeTabHeader(0, signatureTabTitle, ret_others[1]) + "
"; + currentTab = 0; } const resultsElem = document.createElement("div"); @@ -1746,12 +1754,16 @@ window.initSearch = rawSearchIndex => { } search.appendChild(resultsElem); // Reset focused elements. - searchState.focusedByTab = [null, null, null]; searchState.showResults(search); const elems = document.getElementById("titles").childNodes; - elems[0].onclick = () => { printTab(0); }; - elems[1].onclick = () => { printTab(1); }; - elems[2].onclick = () => { printTab(2); }; + searchState.focusedByTab = []; + let i = 0; + for (const elem of elems) { + const j = i; + elem.onclick = () => { printTab(j); }; + searchState.focusedByTab.push(null); + i += 1; + } printTab(currentTab); } diff --git a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml index fc6b0696bf0db..7bc837bfaeb68 100644 --- a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml +++ b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml @@ -6,6 +6,16 @@ write: (".search-input", "Foo") wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) assert-text: ("#titles > button:nth-of-type(1)", "In Names", STARTS_WITH) +// Use left-right keys +press-key: "ArrowDown" +press-key: "ArrowRight" +wait-for-attribute: ("#titles > button:nth-of-type(2)", {"class": "selected"}) +press-key: "ArrowRight" +wait-for-attribute: ("#titles > button:nth-of-type(3)", {"class": "selected"}) +press-key: "ArrowRight" +wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +press-key: "ArrowLeft" +wait-for-attribute: ("#titles > button:nth-of-type(3)", {"class": "selected"}) // Now try search-by-return goto: file://|DOC_PATH|/test_docs/index.html @@ -14,6 +24,16 @@ write: (".search-input", "-> String") wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH) +// Use left-right keys +press-key: "ArrowDown" +press-key: "ArrowRight" +wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +press-key: "ArrowRight" +wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +press-key: "ArrowRight" +wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) +press-key: "ArrowLeft" +wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) // Try with a search-by-return with no results goto: file://|DOC_PATH|/test_docs/index.html From 75790fabedbb2abd0a9ec30b65655398c89c10e1 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 3 May 2022 09:20:22 -0700 Subject: [PATCH 09/13] rustdoc: add test case assertions for ArrowDown highlight first result --- src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml index 7bc837bfaeb68..763927f9d0fe9 100644 --- a/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml +++ b/src/test/rustdoc-gui/search-tab-change-title-fn-sig.goml @@ -6,8 +6,10 @@ write: (".search-input", "Foo") wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) assert-text: ("#titles > button:nth-of-type(1)", "In Names", STARTS_WITH) +assert: "input.search-input:focus" // Use left-right keys press-key: "ArrowDown" +assert: "#results > .search-results.active > a:nth-of-type(1):focus" press-key: "ArrowRight" wait-for-attribute: ("#titles > button:nth-of-type(2)", {"class": "selected"}) press-key: "ArrowRight" @@ -24,8 +26,10 @@ write: (".search-input", "-> String") wait-for: "#titles" assert-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) assert-text: ("#titles > button:nth-of-type(1)", "In Function Return Types", STARTS_WITH) +assert: "input.search-input:focus" // Use left-right keys press-key: "ArrowDown" +assert: "#results > .search-results.active > a:nth-of-type(1):focus" press-key: "ArrowRight" wait-for-attribute: ("#titles > button:nth-of-type(1)", {"class": "selected"}) press-key: "ArrowRight" From 4c183cd2d41abfe22b20ff1c9d5a1bb712ef1d71 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 3 May 2022 09:20:45 -0700 Subject: [PATCH 10/13] rustdoc: fix JS error when rendering parse error --- src/librustdoc/html/static/js/search.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 2bb850f994d0d..e755d27f73784 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1724,6 +1724,10 @@ window.initSearch = rawSearchIndex => { `${typeFilter} in ${crates} `; if (results.query.error !== null) { output += `

Query parser error: "${results.query.error}".

`; + output += '
' + + makeTabHeader(0, "In Names", ret_others[1]) + + "
"; + currentTab = 0; } else if (results.query.foundElems <= 1 && results.query.returned.length === 0) { output += `
` + makeTabHeader(0, "In Names", ret_others[1]) + From 87b6326d672f5d40b14460bdedebf4f69288fb6a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 5 May 2022 20:19:40 +0200 Subject: [PATCH 11/13] Improve settings loading strategy by loading CSS and JS at the same time to prevent the style to be applied afterwards on slow connections --- src/librustdoc/html/static/js/main.js | 3 +++ src/librustdoc/html/static/js/settings.js | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 1dfd9c762c46e..a6b64cd54af86 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -303,6 +303,9 @@ function loadCss(cssFileName) { getSettingsButton().onclick = event => { event.preventDefault(); + // Sending request for the CSS and the JS files at the same time so it will + // hopefully be loaded when the JS will generate the settings content. + loadCss("settings"); loadScript(window.settingsJS); }; diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js index 43b24245ab2e8..ac483dbb41973 100644 --- a/src/librustdoc/html/static/js/settings.js +++ b/src/librustdoc/html/static/js/settings.js @@ -3,7 +3,7 @@ /* eslint prefer-const: "error" */ /* eslint prefer-arrow-callback: "error" */ // Local js definitions: -/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme, loadCss */ +/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme */ /* global addClass, removeClass, onEach, onEachLazy, NOT_DISPLAYED_ID */ /* global MAIN_ID, getVar, getSettingsButton, switchDisplayedElement, getNotDisplayedElem */ @@ -207,9 +207,6 @@ }, ]; - // First, we add the settings.css file. - loadCss("settings"); - // Then we build the DOM. const el = document.createElement("section"); el.id = "settings"; From 2ed38cdbdd3670790aaf3d48ab2bbdf10dad290b Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 6 May 2022 07:28:06 +0900 Subject: [PATCH 12/13] Add `track_caller` to `DefId::expect_local()` --- compiler/rustc_span/src/def_id.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index d5f806308cf41..6b529d5e0837b 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -279,6 +279,7 @@ impl DefId { } #[inline] + #[track_caller] pub fn expect_local(self) -> LocalDefId { self.as_local().unwrap_or_else(|| panic!("DefId::expect_local: `{:?}` isn't local", self)) } From 30309db9722699743f54026b2837ef6a217c0b9d Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Tue, 3 May 2022 19:17:57 -0700 Subject: [PATCH 13/13] Put the 2229 migration errors in alphabetical order Looks like they were in FxHash order before, so it might just be luck that this used to be consistent across different word lengths. --- compiler/rustc_typeck/src/check/upvar.rs | 4 ++++ .../2229_closure_analysis/migrations/auto_traits.stderr | 2 +- .../migrations/mir_calls_to_shims.stderr | 2 +- .../2229_closure_analysis/migrations/multi_diagnostics.stderr | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 9dbb813293263..c1d4bb92173da 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -914,6 +914,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { reasons.auto_traits.extend(auto_trait_reasons); reasons.drop_order = drop_order; + // `auto_trait_reasons` are in hashset order, so sort them to put the + // diagnostics we emit later in a cross-platform-consistent order. + reasons.auto_traits.sort_unstable(); + reasons } diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr index ee4907bb755cc..a8367766ae1cf 100644 --- a/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr +++ b/src/test/ui/closures/2229_closure_analysis/migrations/auto_traits.stderr @@ -29,8 +29,8 @@ error: changes to closure capture in Rust 2021 will affect which traits the clos LL | thread::spawn(move || unsafe { | ^^^^^^^^^^^^^^ | | - | in Rust 2018, this closure implements `Sync` as `fptr` implements `Sync`, but in Rust 2021, this closure will no longer implement `Sync` because `fptr` is not fully captured and `fptr.0.0` does not implement `Sync` | in Rust 2018, this closure implements `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` because `fptr` is not fully captured and `fptr.0.0` does not implement `Send` + | in Rust 2018, this closure implements `Sync` as `fptr` implements `Sync`, but in Rust 2021, this closure will no longer implement `Sync` because `fptr` is not fully captured and `fptr.0.0` does not implement `Sync` ... LL | *fptr.0.0 = 20; | --------- in Rust 2018, this closure captures all of `fptr`, but in Rust 2021, it will only capture `fptr.0.0` diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr index 6594ec316532a..2648b00435b31 100644 --- a/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr +++ b/src/test/ui/closures/2229_closure_analysis/migrations/mir_calls_to_shims.stderr @@ -4,8 +4,8 @@ error: changes to closure capture in Rust 2021 will affect which traits the clos LL | let result = panic::catch_unwind(move || { | ^^^^^^^ | | - | in Rust 2018, this closure implements `UnwindSafe` as `f` implements `UnwindSafe`, but in Rust 2021, this closure will no longer implement `UnwindSafe` because `f` is not fully captured and `f.0` does not implement `UnwindSafe` | in Rust 2018, this closure implements `RefUnwindSafe` as `f` implements `RefUnwindSafe`, but in Rust 2021, this closure will no longer implement `RefUnwindSafe` because `f` is not fully captured and `f.0` does not implement `RefUnwindSafe` + | in Rust 2018, this closure implements `UnwindSafe` as `f` implements `UnwindSafe`, but in Rust 2021, this closure will no longer implement `UnwindSafe` because `f` is not fully captured and `f.0` does not implement `UnwindSafe` ... LL | f.0() | --- in Rust 2018, this closure captures all of `f`, but in Rust 2021, it will only capture `f.0` diff --git a/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr b/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr index 0008f1b2c07ed..483eae6bb4b1f 100644 --- a/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr +++ b/src/test/ui/closures/2229_closure_analysis/migrations/multi_diagnostics.stderr @@ -94,8 +94,8 @@ error: changes to closure capture in Rust 2021 will affect which traits the clos LL | thread::spawn(move || unsafe { | ^^^^^^^^^^^^^^ | | - | in Rust 2018, this closure implements `Sync` as `fptr1` implements `Sync`, but in Rust 2021, this closure will no longer implement `Sync` because `fptr1` is not fully captured and `fptr1.0.0` does not implement `Sync` | in Rust 2018, this closure implements `Send` as `fptr1` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` because `fptr1` is not fully captured and `fptr1.0.0` does not implement `Send` + | in Rust 2018, this closure implements `Sync` as `fptr1` implements `Sync`, but in Rust 2021, this closure will no longer implement `Sync` because `fptr1` is not fully captured and `fptr1.0.0` does not implement `Sync` | in Rust 2018, this closure implements `Send` as `fptr2` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` because `fptr2` is not fully captured and `fptr2.0` does not implement `Send` ... LL | *fptr1.0.0 = 20;