diff options
| author | ozkanonur <work@onurozkan.dev> | 2023-05-07 00:12:29 +0300 |
|---|---|---|
| committer | ozkanonur <work@onurozkan.dev> | 2023-05-07 00:12:29 +0300 |
| commit | 4e7c14fe9f03dd0189f954bd9cb97c3c513e7eed (patch) | |
| tree | fa8a777bab81cc492a0df4d8bd6d40efc17d2ae4 /compiler | |
| parent | 8b8110e1469d459a196f6feb60d82dec48c3cfc2 (diff) | |
| download | rust-4e7c14fe9f03dd0189f954bd9cb97c3c513e7eed.tar.gz rust-4e7c14fe9f03dd0189f954bd9cb97c3c513e7eed.zip | |
enable `rust_2018_idioms` for doctests
Signed-off-by: ozkanonur <work@onurozkan.dev>
Diffstat (limited to 'compiler')
12 files changed, 54 insertions, 35 deletions
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index d07355a4154..8a511d8b5fb 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1474,6 +1474,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// Given a function definition like: /// /// ```rust + /// use std::fmt::Debug; + /// /// fn test<'a, T: Debug>(x: &'a T) -> impl Debug + 'a { /// x /// } @@ -1481,13 +1483,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// /// we will create a TAIT definition in the HIR like /// - /// ``` + /// ```rust,ignore (pseudo-Rust) /// type TestReturn<'a, T, 'x> = impl Debug + 'x /// ``` /// /// and return a type like `TestReturn<'static, T, 'a>`, so that the function looks like: /// - /// ```rust + /// ```rust,ignore (pseudo-Rust) /// fn test<'a, T: Debug>(x: &'a T) -> TestReturn<'static, T, 'a> /// ``` /// diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index e5a00331588..caced3d6447 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1038,7 +1038,7 @@ impl<'a> MethodDef<'a> { /// `&self.x` because that might cause an unaligned ref. So for any trait /// method that takes a reference, we use a local block to force a copy. /// This requires that the field impl `Copy`. - /// ``` + /// ```rust,ignore (example) /// # struct A { x: u8, y: u8 } /// impl PartialEq for A { /// fn eq(&self, other: &A) -> bool { diff --git a/compiler/rustc_graphviz/src/lib.rs b/compiler/rustc_graphviz/src/lib.rs index b70a55e8953..5d86d895817 100644 --- a/compiler/rustc_graphviz/src/lib.rs +++ b/compiler/rustc_graphviz/src/lib.rs @@ -167,7 +167,7 @@ //! fn node_label(&self, n: &Nd) -> dot::LabelText<'_> { //! dot::LabelText::LabelStr(self.nodes[*n].into()) //! } -//! fn edge_label<'b>(&'b self, _: &Ed) -> dot::LabelText<'b> { +//! fn edge_label(&self, _: &Ed<'_>) -> dot::LabelText<'_> { //! dot::LabelText::LabelStr("⊆".into()) //! } //! } @@ -177,8 +177,8 @@ //! type Edge = Ed<'a>; //! fn nodes(&self) -> dot::Nodes<'a,Nd> { (0..self.nodes.len()).collect() } //! fn edges(&'a self) -> dot::Edges<'a,Ed<'a>> { self.edges.iter().collect() } -//! fn source(&self, e: &Ed) -> Nd { let & &(s,_) = e; s } -//! fn target(&self, e: &Ed) -> Nd { let & &(_,t) = e; t } +//! fn source(&self, e: &Ed<'_>) -> Nd { let & &(s,_) = e; s } +//! fn target(&self, e: &Ed<'_>) -> Nd { let & &(_,t) = e; t } //! } //! //! # pub fn main() { render_to(&mut Vec::new()) } @@ -226,11 +226,11 @@ //! fn node_id(&'a self, n: &Nd<'a>) -> dot::Id<'a> { //! dot::Id::new(format!("N{}", n.0)).unwrap() //! } -//! fn node_label<'b>(&'b self, n: &Nd<'b>) -> dot::LabelText<'b> { +//! fn node_label(&self, n: &Nd<'_>) -> dot::LabelText<'_> { //! let &(i, _) = n; //! dot::LabelText::LabelStr(self.nodes[i].into()) //! } -//! fn edge_label<'b>(&'b self, _: &Ed<'b>) -> dot::LabelText<'b> { +//! fn edge_label(&self, _: &Ed<'_>) -> dot::LabelText<'_> { //! dot::LabelText::LabelStr("⊆".into()) //! } //! } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 48214b899a4..b956ed50073 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -60,19 +60,21 @@ pub(super) fn compare_impl_method<'tcx>( }; } -/// This function is best explained by example. Consider a trait: +/// This function is best explained by example. Consider a trait with it's implementation: /// -/// trait Trait<'t, T> { -/// // `trait_m` -/// fn method<'a, M>(t: &'t T, m: &'a M) -> Self; -/// } +/// ```rust +/// trait Trait<'t, T> { +/// // `trait_m` +/// fn method<'a, M>(t: &'t T, m: &'a M) -> Self; +/// } /// -/// And an impl: +/// struct Foo; /// -/// impl<'i, 'j, U> Trait<'j, &'i U> for Foo { -/// // `impl_m` -/// fn method<'b, N>(t: &'j &'i U, m: &'b N) -> Foo; -/// } +/// impl<'i, 'j, U> Trait<'j, &'i U> for Foo { +/// // `impl_m` +/// fn method<'b, N>(t: &'j &'i U, m: &'b N) -> Foo { Foo } +/// } +/// ``` /// /// We wish to decide if those two method types are compatible. /// For this we have to show that, assuming the bounds of the impl hold, the @@ -82,7 +84,9 @@ pub(super) fn compare_impl_method<'tcx>( /// type parameters to impl type parameters. This is taken from the /// impl trait reference: /// -/// trait_to_impl_substs = {'t => 'j, T => &'i U, Self => Foo} +/// ```rust,ignore (pseudo-Rust) +/// trait_to_impl_substs = {'t => 'j, T => &'i U, Self => Foo} +/// ``` /// /// We create a mapping `dummy_substs` that maps from the impl type /// parameters to fresh types and regions. For type parameters, @@ -91,13 +95,17 @@ pub(super) fn compare_impl_method<'tcx>( /// regions (Note: but only early-bound regions, i.e., those /// declared on the impl or used in type parameter bounds). /// -/// impl_to_placeholder_substs = {'i => 'i0, U => U0, N => N0 } +/// ```rust,ignore (pseudo-Rust) +/// impl_to_placeholder_substs = {'i => 'i0, U => U0, N => N0 } +/// ``` /// /// Now we can apply `placeholder_substs` to the type of the impl method /// to yield a new function type in terms of our fresh, placeholder /// types: /// -/// <'b> fn(t: &'i0 U0, m: &'b) -> Foo +/// ```rust,ignore (pseudo-Rust) +/// <'b> fn(t: &'i0 U0, m: &'b) -> Foo +/// ``` /// /// We now want to extract and substitute the type of the *trait* /// method and compare it. To do so, we must create a compound @@ -106,11 +114,15 @@ pub(super) fn compare_impl_method<'tcx>( /// type parameters. We extend the mapping to also include /// the method parameters. /// -/// trait_to_placeholder_substs = { T => &'i0 U0, Self => Foo, M => N0 } +/// ```rust,ignore (pseudo-Rust) +/// trait_to_placeholder_substs = { T => &'i0 U0, Self => Foo, M => N0 } +/// ``` /// /// Applying this to the trait method type yields: /// -/// <'a> fn(t: &'i0 U0, m: &'a) -> Foo +/// ```rust,ignore (pseudo-Rust) +/// <'a> fn(t: &'i0 U0, m: &'a) -> Foo +/// ``` /// /// This type is also the same but the name of the bound region (`'a` /// vs `'b`). However, the normal subtyping rules on fn types handle @@ -1163,7 +1175,7 @@ fn compare_self_type<'tcx>( /// as the number of generics on the respective assoc item in the trait definition. /// /// For example this code emits the errors in the following code: -/// ``` +/// ```rust,compile_fail /// trait Trait { /// fn foo(); /// type Assoc<T>; @@ -1547,7 +1559,7 @@ fn compare_synthetic_generics<'tcx>( /// the same kind as the respective generic parameter in the trait def. /// /// For example all 4 errors in the following code are emitted here: -/// ``` +/// ```rust,ignore (pseudo-Rust) /// trait Foo { /// fn foo<const N: u8>(); /// type bar<const N: u8>; diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 1c496f867a0..f17caba5787 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -1913,7 +1913,7 @@ fn is_late_bound_map( /// handles cycle detection as we go through the query system. /// /// This is necessary in the first place for the following case: - /// ``` + /// ```rust,ignore (pseudo-Rust) /// type Alias<'a, T> = <T as Trait<'a>>::Assoc; /// fn foo<'a>(_: Alias<'a, ()>) -> Alias<'a, ()> { ... } /// ``` diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 58e3159a4e2..5000b0139df 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -31,7 +31,7 @@ pub enum TypeAnnotationNeeded { /// ``` E0282, /// An implementation cannot be chosen unambiguously because of lack of information. - /// ```compile_fail,E0283 + /// ```compile_fail,E0790 /// let _ = Default::default(); /// ``` E0283, 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 da0271a345e..1a60bab18db 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 @@ -21,7 +21,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { /// /// Consider a case where we have /// - /// ```compile_fail,E0623 + /// ```compile_fail /// 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 fec04af2313..0df417d0950 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 +/// ```compile_fail /// fn foo(x: &mut Vec<&u8>, y: &u8) /// { x.push(y); } /// ``` diff --git a/compiler/rustc_infer/src/infer/outlives/test_type_match.rs b/compiler/rustc_infer/src/infer/outlives/test_type_match.rs index 01f900f050e..75ce0f83fd6 100644 --- a/compiler/rustc_infer/src/infer/outlives/test_type_match.rs +++ b/compiler/rustc_infer/src/infer/outlives/test_type_match.rs @@ -13,9 +13,11 @@ use crate::infer::region_constraints::VerifyIfEq; /// Given a "verify-if-eq" type test like: /// -/// exists<'a...> { -/// verify_if_eq(some_type, bound_region) -/// } +/// ```rust,ignore (pseudo-Rust) +/// exists<'a...> { +/// verify_if_eq(some_type, bound_region) +/// } +/// ``` /// /// and the type `test_ty` that the type test is being tested against, /// returns: diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index e1cb53bc71d..4b59059010f 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -277,7 +277,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { /// /// It will not, however, work for higher-ranked bounds like: /// - /// ```compile_fail,E0311 + /// ```ignore(this does compile today, previously was marked as `compile_fail,E0311`) /// trait Foo<'a, 'b> /// where for<'x> <Self as Foo<'x, 'b>>::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 6692cd1d389..c7a307b89e4 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -217,7 +217,7 @@ pub enum VerifyBound<'tcx> { /// and supplies a bound if it ended up being relevant. It's used in situations /// like this: /// -/// ```rust +/// ```rust,ignore (pseudo-Rust) /// fn foo<'a, 'b, T: SomeTrait<'a>> /// where /// <T as SomeTrait<'a>>::Item: 'b @@ -232,7 +232,7 @@ pub enum VerifyBound<'tcx> { /// In the [`VerifyBound`], this struct is enclosed in `Binder` to account /// for cases like /// -/// ```rust +/// ```rust,ignore (pseudo-Rust) /// where for<'a> <T as SomeTrait<'a>::Item: 'a /// ``` /// diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index b223b8c137a..814513cbd6d 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -333,6 +333,7 @@ declare_lint! { /// /// ```rust,compile_fail /// #![deny(unused_extern_crates)] + /// #![deny(warnings)] /// extern crate proc_macro; /// ``` /// @@ -1667,6 +1668,7 @@ declare_lint! { /// /// ```rust,compile_fail /// #![deny(elided_lifetimes_in_paths)] + /// #![deny(warnings)] /// struct Foo<'a> { /// x: &'a u32 /// } @@ -2158,6 +2160,7 @@ declare_lint! { /// ```rust,compile_fail /// # #![allow(unused)] /// #![deny(explicit_outlives_requirements)] + /// #![deny(warnings)] /// /// struct SharedRef<'a, T> /// where |
