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

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+4-2
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
///

Diff for: compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+1-1
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 {

Diff for: compiler/rustc_graphviz/src/lib.rs

+5-5
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
//! }

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+29-17
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>;

Diff for: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
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
/// ```

Diff for: compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+1-1
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,

Diff for: compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs

+1-1
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
/// }

Diff for: compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs

+1-1
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
/// ```

Diff for: compiler/rustc_infer/src/infer/outlives/test_type_match.rs

+5-3
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:

Diff for: compiler/rustc_infer/src/infer/outlives/verify.rs

+1-1
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
/// {

Diff for: compiler/rustc_infer/src/infer/region_constraints/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub enum VerifyBound<'tcx> {
217217
/// and supplies a bound if it ended up being relevant. It's used in situations
218218
/// like this:
219219
///
220-
/// ```rust
220+
/// ```rust,ignore (pseudo-Rust)
221221
/// fn foo<'a, 'b, T: SomeTrait<'a>>
222222
/// where
223223
/// <T as SomeTrait<'a>>::Item: 'b
@@ -232,7 +232,7 @@ pub enum VerifyBound<'tcx> {
232232
/// In the [`VerifyBound`], this struct is enclosed in `Binder` to account
233233
/// for cases like
234234
///
235-
/// ```rust
235+
/// ```rust,ignore (pseudo-Rust)
236236
/// where for<'a> <T as SomeTrait<'a>::Item: 'a
237237
/// ```
238238
///

Diff for: compiler/rustc_lint_defs/src/builtin.rs

+3
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ declare_lint! {
333333
///
334334
/// ```rust,compile_fail
335335
/// #![deny(unused_extern_crates)]
336+
/// #![deny(warnings)]
336337
/// extern crate proc_macro;
337338
/// ```
338339
///
@@ -1667,6 +1668,7 @@ declare_lint! {
16671668
///
16681669
/// ```rust,compile_fail
16691670
/// #![deny(elided_lifetimes_in_paths)]
1671+
/// #![deny(warnings)]
16701672
/// struct Foo<'a> {
16711673
/// x: &'a u32
16721674
/// }
@@ -2158,6 +2160,7 @@ declare_lint! {
21582160
/// ```rust,compile_fail
21592161
/// # #![allow(unused)]
21602162
/// #![deny(explicit_outlives_requirements)]
2163+
/// #![deny(warnings)]
21612164
///
21622165
/// struct SharedRef<'a, T>
21632166
/// where

Diff for: library/alloc/src/borrow.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ where
115115
/// ```
116116
/// use std::borrow::Cow;
117117
///
118-
/// fn abs_all(input: &mut Cow<[i32]>) {
118+
/// fn abs_all(input: &mut Cow<'_, [i32]>) {
119119
/// for i in 0..input.len() {
120120
/// let v = input[i];
121121
/// if v < 0 {
@@ -145,7 +145,7 @@ where
145145
/// ```
146146
/// use std::borrow::Cow;
147147
///
148-
/// struct Items<'a, X: 'a> where [X]: ToOwned<Owned = Vec<X>> {
148+
/// struct Items<'a, X> where [X]: ToOwned<Owned = Vec<X>> {
149149
/// values: Cow<'a, [X]>,
150150
/// }
151151
///
@@ -267,7 +267,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
267267
///
268268
/// assert_eq!(
269269
/// cow,
270-
/// Cow::Owned(String::from("FOO")) as Cow<str>
270+
/// Cow::Owned(String::from("FOO")) as Cow<'_, str>
271271
/// );
272272
/// ```
273273
#[stable(feature = "rust1", since = "1.0.0")]
@@ -311,7 +311,7 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
311311
/// use std::borrow::Cow;
312312
///
313313
/// let s = "Hello world!";
314-
/// let cow: Cow<str> = Cow::Owned(String::from(s));
314+
/// let cow: Cow<'_, str> = Cow::Owned(String::from(s));
315315
///
316316
/// assert_eq!(
317317
/// cow.into_owned(),

Diff for: library/alloc/src/fmt.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@
363363
//! # use std::fmt;
364364
//! # struct Foo; // our custom type
365365
//! # impl fmt::Display for Foo {
366-
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
366+
//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
367367
//! # write!(f, "testing, testing")
368368
//! # } }
369369
//! ```
@@ -399,7 +399,7 @@
399399
//! }
400400
//!
401401
//! impl fmt::Display for Vector2D {
402-
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
402+
//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
403403
//! // The `f` value implements the `Write` trait, which is what the
404404
//! // write! macro is expecting. Note that this formatting ignores the
405405
//! // various flags provided to format strings.
@@ -410,7 +410,7 @@
410410
//! // Different traits allow different forms of output of a type. The meaning
411411
//! // of this format is to print the magnitude of a vector.
412412
//! impl fmt::Binary for Vector2D {
413-
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
413+
//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
414414
//! let magnitude = (self.x * self.x + self.y * self.y) as f64;
415415
//! let magnitude = magnitude.sqrt();
416416
//!
@@ -517,7 +517,7 @@
517517
//! let mut some_writer = io::stdout();
518518
//! write!(&mut some_writer, "{}", format_args!("print with a {}", "macro"));
519519
//!
520-
//! fn my_fmt_fn(args: fmt::Arguments) {
520+
//! fn my_fmt_fn(args: fmt::Arguments<'_>) {
521521
//! write!(&mut io::stdout(), "{args}");
522522
//! }
523523
//! my_fmt_fn(format_args!(", or a {} too", "function"));

Diff for: library/alloc/src/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,7 @@ where
20392039
/// ```rust
20402040
/// # use std::rc::Rc;
20412041
/// # use std::borrow::Cow;
2042-
/// let cow: Cow<str> = Cow::Borrowed("eggplant");
2042+
/// let cow: Cow<'_, str> = Cow::Borrowed("eggplant");
20432043
/// let shared: Rc<str> = Rc::from(cow);
20442044
/// assert_eq!("eggplant", &shared[..]);
20452045
/// ```

Diff for: library/alloc/src/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2741,7 +2741,7 @@ impl<'a> From<Cow<'a, str>> for String {
27412741
/// ```
27422742
/// # use std::borrow::Cow;
27432743
/// // If the string is not owned...
2744-
/// let cow: Cow<str> = Cow::Borrowed("eggplant");
2744+
/// let cow: Cow<'_, str> = Cow::Borrowed("eggplant");
27452745
/// // It will allocate on the heap and copy the string.
27462746
/// let owned: String = String::from(cow);
27472747
/// assert_eq!(&owned[..], "eggplant");

Diff for: library/alloc/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,7 @@ where
27682768
/// ```rust
27692769
/// # use std::sync::Arc;
27702770
/// # use std::borrow::Cow;
2771-
/// let cow: Cow<str> = Cow::Borrowed("eggplant");
2771+
/// let cow: Cow<'_, str> = Cow::Borrowed("eggplant");
27722772
/// let shared: Arc<str> = Arc::from(cow);
27732773
/// assert_eq!("eggplant", &shared[..]);
27742774
/// ```

Diff for: library/alloc/src/vec/drain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::Vec;
1616
///
1717
/// ```
1818
/// let mut v = vec![0, 1, 2];
19-
/// let iter: std::vec::Drain<_> = v.drain(..);
19+
/// let iter: std::vec::Drain<'_, _> = v.drain(..);
2020
/// ```
2121
#[stable(feature = "drain", since = "1.6.0")]
2222
pub struct Drain<

Diff for: library/alloc/src/vec/drain_filter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::Vec;
1616
/// #![feature(drain_filter)]
1717
///
1818
/// let mut v = vec![0, 1, 2];
19-
/// let iter: std::vec::DrainFilter<_, _> = v.drain_filter(|x| *x % 2 == 0);
19+
/// let iter: std::vec::DrainFilter<'_, _, _> = v.drain_filter(|x| *x % 2 == 0);
2020
/// ```
2121
#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")]
2222
#[derive(Debug)]

Diff for: library/alloc/src/vec/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3142,8 +3142,8 @@ where
31423142
///
31433143
/// ```
31443144
/// # use std::borrow::Cow;
3145-
/// let o: Cow<[i32]> = Cow::Owned(vec![1, 2, 3]);
3146-
/// let b: Cow<[i32]> = Cow::Borrowed(&[1, 2, 3]);
3145+
/// let o: Cow<'_, [i32]> = Cow::Owned(vec![1, 2, 3]);
3146+
/// let b: Cow<'_, [i32]> = Cow::Borrowed(&[1, 2, 3]);
31473147
/// assert_eq!(Vec::from(o), Vec::from(b));
31483148
/// ```
31493149
fn from(s: Cow<'a, [T]>) -> Vec<T> {

0 commit comments

Comments
 (0)