Skip to content

Commit ea0c22e

Browse files
committed
Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, r=Mark-Simulacrum
enable `rust_2018_idioms` lint group for doctests With this change, `rust_2018_idioms` lint group will be enabled for compiler/libstd doctests. Resolves #106086 Resolves #99144 Signed-off-by: ozkanonur <work@onurozkan.dev>
2 parents 04c5344 + 4e7c14f commit ea0c22e

File tree

37 files changed

+125
-101
lines changed

37 files changed

+125
-101
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,20 +1477,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14771477
/// Given a function definition like:
14781478
///
14791479
/// ```rust
1480+
/// use std::fmt::Debug;
1481+
///
14801482
/// fn test<'a, T: Debug>(x: &'a T) -> impl Debug + 'a {
14811483
/// x
14821484
/// }
14831485
/// ```
14841486
///
14851487
/// we will create a TAIT definition in the HIR like
14861488
///
1487-
/// ```
1489+
/// ```rust,ignore (pseudo-Rust)
14881490
/// type TestReturn<'a, T, 'x> = impl Debug + 'x
14891491
/// ```
14901492
///
14911493
/// and return a type like `TestReturn<'static, T, 'a>`, so that the function looks like:
14921494
///
1493-
/// ```rust
1495+
/// ```rust,ignore (pseudo-Rust)
14941496
/// fn test<'a, T: Debug>(x: &'a T) -> TestReturn<'static, T, 'a>
14951497
/// ```
14961498
///

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ impl<'a> MethodDef<'a> {
10381038
/// `&self.x` because that might cause an unaligned ref. So for any trait
10391039
/// method that takes a reference, we use a local block to force a copy.
10401040
/// This requires that the field impl `Copy`.
1041-
/// ```
1041+
/// ```rust,ignore (example)
10421042
/// # struct A { x: u8, y: u8 }
10431043
/// impl PartialEq for A {
10441044
/// fn eq(&self, other: &A) -> bool {

compiler/rustc_graphviz/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
//! fn node_label(&self, n: &Nd) -> dot::LabelText<'_> {
168168
//! dot::LabelText::LabelStr(self.nodes[*n].into())
169169
//! }
170-
//! fn edge_label<'b>(&'b self, _: &Ed) -> dot::LabelText<'b> {
170+
//! fn edge_label(&self, _: &Ed<'_>) -> dot::LabelText<'_> {
171171
//! dot::LabelText::LabelStr("&sube;".into())
172172
//! }
173173
//! }
@@ -177,8 +177,8 @@
177177
//! type Edge = Ed<'a>;
178178
//! fn nodes(&self) -> dot::Nodes<'a,Nd> { (0..self.nodes.len()).collect() }
179179
//! fn edges(&'a self) -> dot::Edges<'a,Ed<'a>> { self.edges.iter().collect() }
180-
//! fn source(&self, e: &Ed) -> Nd { let & &(s,_) = e; s }
181-
//! fn target(&self, e: &Ed) -> Nd { let & &(_,t) = e; t }
180+
//! fn source(&self, e: &Ed<'_>) -> Nd { let & &(s,_) = e; s }
181+
//! fn target(&self, e: &Ed<'_>) -> Nd { let & &(_,t) = e; t }
182182
//! }
183183
//!
184184
//! # pub fn main() { render_to(&mut Vec::new()) }
@@ -226,11 +226,11 @@
226226
//! fn node_id(&'a self, n: &Nd<'a>) -> dot::Id<'a> {
227227
//! dot::Id::new(format!("N{}", n.0)).unwrap()
228228
//! }
229-
//! fn node_label<'b>(&'b self, n: &Nd<'b>) -> dot::LabelText<'b> {
229+
//! fn node_label(&self, n: &Nd<'_>) -> dot::LabelText<'_> {
230230
//! let &(i, _) = n;
231231
//! dot::LabelText::LabelStr(self.nodes[i].into())
232232
//! }
233-
//! fn edge_label<'b>(&'b self, _: &Ed<'b>) -> dot::LabelText<'b> {
233+
//! fn edge_label(&self, _: &Ed<'_>) -> dot::LabelText<'_> {
234234
//! dot::LabelText::LabelStr("&sube;".into())
235235
//! }
236236
//! }

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,21 @@ pub(super) fn compare_impl_method<'tcx>(
6060
};
6161
}
6262

63-
/// This function is best explained by example. Consider a trait:
63+
/// This function is best explained by example. Consider a trait with it's implementation:
6464
///
65-
/// trait Trait<'t, T> {
66-
/// // `trait_m`
67-
/// fn method<'a, M>(t: &'t T, m: &'a M) -> Self;
68-
/// }
65+
/// ```rust
66+
/// trait Trait<'t, T> {
67+
/// // `trait_m`
68+
/// fn method<'a, M>(t: &'t T, m: &'a M) -> Self;
69+
/// }
6970
///
70-
/// And an impl:
71+
/// struct Foo;
7172
///
72-
/// impl<'i, 'j, U> Trait<'j, &'i U> for Foo {
73-
/// // `impl_m`
74-
/// fn method<'b, N>(t: &'j &'i U, m: &'b N) -> Foo;
75-
/// }
73+
/// impl<'i, 'j, U> Trait<'j, &'i U> for Foo {
74+
/// // `impl_m`
75+
/// fn method<'b, N>(t: &'j &'i U, m: &'b N) -> Foo { Foo }
76+
/// }
77+
/// ```
7678
///
7779
/// We wish to decide if those two method types are compatible.
7880
/// 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>(
8284
/// type parameters to impl type parameters. This is taken from the
8385
/// impl trait reference:
8486
///
85-
/// trait_to_impl_substs = {'t => 'j, T => &'i U, Self => Foo}
87+
/// ```rust,ignore (pseudo-Rust)
88+
/// trait_to_impl_substs = {'t => 'j, T => &'i U, Self => Foo}
89+
/// ```
8690
///
8791
/// We create a mapping `dummy_substs` that maps from the impl type
8892
/// parameters to fresh types and regions. For type parameters,
@@ -91,13 +95,17 @@ pub(super) fn compare_impl_method<'tcx>(
9195
/// regions (Note: but only early-bound regions, i.e., those
9296
/// declared on the impl or used in type parameter bounds).
9397
///
94-
/// impl_to_placeholder_substs = {'i => 'i0, U => U0, N => N0 }
98+
/// ```rust,ignore (pseudo-Rust)
99+
/// impl_to_placeholder_substs = {'i => 'i0, U => U0, N => N0 }
100+
/// ```
95101
///
96102
/// Now we can apply `placeholder_substs` to the type of the impl method
97103
/// to yield a new function type in terms of our fresh, placeholder
98104
/// types:
99105
///
100-
/// <'b> fn(t: &'i0 U0, m: &'b) -> Foo
106+
/// ```rust,ignore (pseudo-Rust)
107+
/// <'b> fn(t: &'i0 U0, m: &'b) -> Foo
108+
/// ```
101109
///
102110
/// We now want to extract and substitute the type of the *trait*
103111
/// method and compare it. To do so, we must create a compound
@@ -106,11 +114,15 @@ pub(super) fn compare_impl_method<'tcx>(
106114
/// type parameters. We extend the mapping to also include
107115
/// the method parameters.
108116
///
109-
/// trait_to_placeholder_substs = { T => &'i0 U0, Self => Foo, M => N0 }
117+
/// ```rust,ignore (pseudo-Rust)
118+
/// trait_to_placeholder_substs = { T => &'i0 U0, Self => Foo, M => N0 }
119+
/// ```
110120
///
111121
/// Applying this to the trait method type yields:
112122
///
113-
/// <'a> fn(t: &'i0 U0, m: &'a) -> Foo
123+
/// ```rust,ignore (pseudo-Rust)
124+
/// <'a> fn(t: &'i0 U0, m: &'a) -> Foo
125+
/// ```
114126
///
115127
/// This type is also the same but the name of the bound region (`'a`
116128
/// vs `'b`). However, the normal subtyping rules on fn types handle
@@ -1163,7 +1175,7 @@ fn compare_self_type<'tcx>(
11631175
/// as the number of generics on the respective assoc item in the trait definition.
11641176
///
11651177
/// For example this code emits the errors in the following code:
1166-
/// ```
1178+
/// ```rust,compile_fail
11671179
/// trait Trait {
11681180
/// fn foo();
11691181
/// type Assoc<T>;
@@ -1547,7 +1559,7 @@ fn compare_synthetic_generics<'tcx>(
15471559
/// the same kind as the respective generic parameter in the trait def.
15481560
///
15491561
/// For example all 4 errors in the following code are emitted here:
1550-
/// ```
1562+
/// ```rust,ignore (pseudo-Rust)
15511563
/// trait Foo {
15521564
/// fn foo<const N: u8>();
15531565
/// type bar<const N: u8>;

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ fn is_late_bound_map(
19231923
/// handles cycle detection as we go through the query system.
19241924
///
19251925
/// This is necessary in the first place for the following case:
1926-
/// ```
1926+
/// ```rust,ignore (pseudo-Rust)
19271927
/// type Alias<'a, T> = <T as Trait<'a>>::Assoc;
19281928
/// fn foo<'a>(_: Alias<'a, ()>) -> Alias<'a, ()> { ... }
19291929
/// ```

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum TypeAnnotationNeeded {
3131
/// ```
3232
E0282,
3333
/// An implementation cannot be chosen unambiguously because of lack of information.
34-
/// ```compile_fail,E0283
34+
/// ```compile_fail,E0790
3535
/// let _ = Default::default();
3636
/// ```
3737
E0283,

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2121
///
2222
/// Consider a case where we have
2323
///
24-
/// ```compile_fail,E0623
24+
/// ```compile_fail
2525
/// fn foo(x: &mut Vec<&u8>, y: &u8) {
2626
/// x.push(y);
2727
/// }

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::ty::{self, Region, TyCtxt};
1414
/// br - the bound region corresponding to the above region which is of type `BrAnon(_)`
1515
///
1616
/// # Example
17-
/// ```compile_fail,E0623
17+
/// ```compile_fail
1818
/// fn foo(x: &mut Vec<&u8>, y: &u8)
1919
/// { x.push(y); }
2020
/// ```

compiler/rustc_infer/src/infer/outlives/test_type_match.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ use crate::infer::region_constraints::VerifyIfEq;
1313

1414
/// Given a "verify-if-eq" type test like:
1515
///
16-
/// exists<'a...> {
17-
/// verify_if_eq(some_type, bound_region)
18-
/// }
16+
/// ```rust,ignore (pseudo-Rust)
17+
/// exists<'a...> {
18+
/// verify_if_eq(some_type, bound_region)
19+
/// }
20+
/// ```
1921
///
2022
/// and the type `test_ty` that the type test is being tested against,
2123
/// returns:

compiler/rustc_infer/src/infer/outlives/verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
277277
///
278278
/// It will not, however, work for higher-ranked bounds like:
279279
///
280-
/// ```compile_fail,E0311
280+
/// ```ignore(this does compile today, previously was marked as `compile_fail,E0311`)
281281
/// trait Foo<'a, 'b>
282282
/// where for<'x> <Self as Foo<'x, 'b>>::Bar: 'x
283283
/// {

0 commit comments

Comments
 (0)