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>
This commit is contained in:
bors 2023-05-08 04:50:28 +00:00
commit ea0c22ea4f
37 changed files with 125 additions and 101 deletions

View File

@ -1477,6 +1477,8 @@ fn lower_ty_direct(&mut self, t: &Ty, itctx: &ImplTraitContext) -> hir::Ty<'hir>
/// Given a function definition like:
///
/// ```rust
/// use std::fmt::Debug;
///
/// fn test<'a, T: Debug>(x: &'a T) -> impl Debug + 'a {
/// x
/// }
@ -1484,13 +1486,13 @@ fn lower_ty_direct(&mut self, t: &Ty, itctx: &ImplTraitContext) -> hir::Ty<'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>
/// ```
///

View File

@ -1038,7 +1038,7 @@ fn create_method(
/// `&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 {

View File

@ -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("&sube;".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("&sube;".into())
//! }
//! }

View File

@ -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:
///
/// ```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;
/// 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:
///
/// ```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).
///
/// ```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:
///
/// ```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.
///
/// ```rust,ignore (pseudo-Rust)
/// trait_to_placeholder_substs = { T => &'i0 U0, Self => Foo, M => N0 }
/// ```
///
/// Applying this to the trait method type yields:
///
/// ```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 visit_ty(&mut self, ty: &'v hir::Ty<'v>) {
/// 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>;

View File

@ -1923,7 +1923,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, ()> { ... }
/// ```

View File

@ -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,

View File

@ -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);
/// }

View File

@ -14,7 +14,7 @@
/// 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); }
/// ```

View File

@ -13,9 +13,11 @@
/// Given a "verify-if-eq" type test like:
///
/// ```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:

View File

@ -277,7 +277,7 @@ fn declared_generic_bounds_from_env_for_erased_ty(
///
/// 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
/// {

View File

@ -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
/// ```
///

View File

@ -333,6 +333,7 @@
///
/// ```rust,compile_fail
/// #![deny(unused_extern_crates)]
/// #![deny(warnings)]
/// extern crate proc_macro;
/// ```
///
@ -1667,6 +1668,7 @@
///
/// ```rust,compile_fail
/// #![deny(elided_lifetimes_in_paths)]
/// #![deny(warnings)]
/// struct Foo<'a> {
/// x: &'a u32
/// }
@ -2158,6 +2160,7 @@
/// ```rust,compile_fail
/// # #![allow(unused)]
/// #![deny(explicit_outlives_requirements)]
/// #![deny(warnings)]
///
/// struct SharedRef<'a, T>
/// where

View File

@ -115,7 +115,7 @@ fn clone_into(&self, target: &mut T) {
/// ```
/// use std::borrow::Cow;
///
/// fn abs_all(input: &mut Cow<[i32]>) {
/// fn abs_all(input: &mut Cow<'_, [i32]>) {
/// for i in 0..input.len() {
/// let v = input[i];
/// if v < 0 {
@ -145,7 +145,7 @@ fn clone_into(&self, target: &mut T) {
/// ```
/// use std::borrow::Cow;
///
/// struct Items<'a, X: 'a> where [X]: ToOwned<Owned = Vec<X>> {
/// struct Items<'a, X> where [X]: ToOwned<Owned = Vec<X>> {
/// values: Cow<'a, [X]>,
/// }
///
@ -267,7 +267,7 @@ pub const fn is_owned(&self) -> bool {
///
/// assert_eq!(
/// cow,
/// Cow::Owned(String::from("FOO")) as Cow<str>
/// Cow::Owned(String::from("FOO")) as Cow<'_, str>
/// );
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
@ -311,7 +311,7 @@ pub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned {
/// use std::borrow::Cow;
///
/// let s = "Hello world!";
/// let cow: Cow<str> = Cow::Owned(String::from(s));
/// let cow: Cow<'_, str> = Cow::Owned(String::from(s));
///
/// assert_eq!(
/// cow.into_owned(),

View File

@ -363,7 +363,7 @@
//! # use std::fmt;
//! # struct Foo; // our custom type
//! # impl fmt::Display for Foo {
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
//! # write!(f, "testing, testing")
//! # } }
//! ```
@ -399,7 +399,7 @@
//! }
//!
//! impl fmt::Display for Vector2D {
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
//! // The `f` value implements the `Write` trait, which is what the
//! // write! macro is expecting. Note that this formatting ignores the
//! // various flags provided to format strings.
@ -410,7 +410,7 @@
//! // Different traits allow different forms of output of a type. The meaning
//! // of this format is to print the magnitude of a vector.
//! impl fmt::Binary for Vector2D {
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//! fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
//! let magnitude = (self.x * self.x + self.y * self.y) as f64;
//! let magnitude = magnitude.sqrt();
//!
@ -517,7 +517,7 @@
//! let mut some_writer = io::stdout();
//! write!(&mut some_writer, "{}", format_args!("print with a {}", "macro"));
//!
//! fn my_fmt_fn(args: fmt::Arguments) {
//! fn my_fmt_fn(args: fmt::Arguments<'_>) {
//! write!(&mut io::stdout(), "{args}");
//! }
//! my_fmt_fn(format_args!(", or a {} too", "function"));

View File

@ -2039,7 +2039,7 @@ impl<'a, B> From<Cow<'a, B>> for Rc<B>
/// ```rust
/// # use std::rc::Rc;
/// # use std::borrow::Cow;
/// let cow: Cow<str> = Cow::Borrowed("eggplant");
/// let cow: Cow<'_, str> = Cow::Borrowed("eggplant");
/// let shared: Rc<str> = Rc::from(cow);
/// assert_eq!("eggplant", &shared[..]);
/// ```

View File

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

View File

@ -2768,7 +2768,7 @@ impl<'a, B> From<Cow<'a, B>> for Arc<B>
/// ```rust
/// # use std::sync::Arc;
/// # use std::borrow::Cow;
/// let cow: Cow<str> = Cow::Borrowed("eggplant");
/// let cow: Cow<'_, str> = Cow::Borrowed("eggplant");
/// let shared: Arc<str> = Arc::from(cow);
/// assert_eq!("eggplant", &shared[..]);
/// ```

View File

@ -16,7 +16,7 @@
///
/// ```
/// let mut v = vec![0, 1, 2];
/// let iter: std::vec::Drain<_> = v.drain(..);
/// let iter: std::vec::Drain<'_, _> = v.drain(..);
/// ```
#[stable(feature = "drain", since = "1.6.0")]
pub struct Drain<

View File

@ -16,7 +16,7 @@
/// #![feature(drain_filter)]
///
/// let mut v = vec![0, 1, 2];
/// let iter: std::vec::DrainFilter<_, _> = v.drain_filter(|x| *x % 2 == 0);
/// let iter: std::vec::DrainFilter<'_, _, _> = v.drain_filter(|x| *x % 2 == 0);
/// ```
#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")]
#[derive(Debug)]

View File

@ -3142,8 +3142,8 @@ impl<'a, T> From<Cow<'a, [T]>> for Vec<T>
///
/// ```
/// # use std::borrow::Cow;
/// let o: Cow<[i32]> = Cow::Owned(vec![1, 2, 3]);
/// let b: Cow<[i32]> = Cow::Borrowed(&[1, 2, 3]);
/// let o: Cow<'_, [i32]> = Cow::Owned(vec![1, 2, 3]);
/// let b: Cow<'_, [i32]> = Cow::Borrowed(&[1, 2, 3]);
/// assert_eq!(Vec::from(o), Vec::from(b));
/// ```
fn from(s: Cow<'a, [T]>) -> Vec<T> {

View File

@ -14,7 +14,7 @@
/// ```
/// let mut v = vec![0, 1, 2];
/// let new = [7, 8];
/// let iter: std::vec::Splice<_> = v.splice(1.., new);
/// let iter: std::vec::Splice<'_, _> = v.splice(1.., new);
/// ```
#[derive(Debug)]
#[stable(feature = "vec_splice", since = "1.21.0")]

View File

@ -115,7 +115,7 @@
//! let shared_map: Rc<RefCell<_>> = Rc::new(RefCell::new(HashMap::new()));
//! // Create a new block to limit the scope of the dynamic borrow
//! {
//! let mut map: RefMut<_> = shared_map.borrow_mut();
//! let mut map: RefMut<'_, _> = shared_map.borrow_mut();
//! map.insert("africa", 92388);
//! map.insert("kyoto", 11837);
//! map.insert("piccadilly", 11826);
@ -1435,8 +1435,8 @@ pub fn clone(orig: &Ref<'b, T>) -> Ref<'b, T> {
/// use std::cell::{RefCell, Ref};
///
/// let c = RefCell::new((5, 'b'));
/// let b1: Ref<(u32, char)> = c.borrow();
/// let b2: Ref<u32> = Ref::map(b1, |t| &t.0);
/// let b1: Ref<'_, (u32, char)> = c.borrow();
/// let b2: Ref<'_, u32> = Ref::map(b1, |t| &t.0);
/// assert_eq!(*b2, 5)
/// ```
#[stable(feature = "cell_map", since = "1.8.0")]
@ -1464,8 +1464,8 @@ pub fn map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Ref<'b, U>
/// use std::cell::{RefCell, Ref};
///
/// let c = RefCell::new(vec![1, 2, 3]);
/// let b1: Ref<Vec<u32>> = c.borrow();
/// let b2: Result<Ref<u32>, _> = Ref::filter_map(b1, |v| v.get(1));
/// let b1: Ref<'_, Vec<u32>> = c.borrow();
/// let b2: Result<Ref<'_, u32>, _> = Ref::filter_map(b1, |v| v.get(1));
/// assert_eq!(*b2.unwrap(), 2);
/// ```
#[stable(feature = "cell_filter_map", since = "1.63.0")]
@ -1577,8 +1577,8 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
///
/// let c = RefCell::new((5, 'b'));
/// {
/// let b1: RefMut<(u32, char)> = c.borrow_mut();
/// let mut b2: RefMut<u32> = RefMut::map(b1, |t| &mut t.0);
/// let b1: RefMut<'_, (u32, char)> = c.borrow_mut();
/// let mut b2: RefMut<'_, u32> = RefMut::map(b1, |t| &mut t.0);
/// assert_eq!(*b2, 5);
/// *b2 = 42;
/// }
@ -1612,8 +1612,8 @@ pub fn map<U: ?Sized, F>(mut orig: RefMut<'b, T>, f: F) -> RefMut<'b, U>
/// let c = RefCell::new(vec![1, 2, 3]);
///
/// {
/// let b1: RefMut<Vec<u32>> = c.borrow_mut();
/// let mut b2: Result<RefMut<u32>, _> = RefMut::filter_map(b1, |v| v.get_mut(1));
/// let b1: RefMut<'_, Vec<u32>> = c.borrow_mut();
/// let mut b2: Result<RefMut<'_, u32>, _> = RefMut::filter_map(b1, |v| v.get_mut(1));
///
/// if let Ok(mut b2) = b2 {
/// *b2 += 2;

View File

@ -60,7 +60,7 @@ fn write_str(&mut self, s: &str) -> fmt::Result {
/// }
///
/// impl fmt::Debug for Foo {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_struct("Foo")
/// .field("bar", &self.bar)
/// .field("baz", &self.baz)
@ -249,7 +249,7 @@ fn is_pretty(&self) -> bool {
/// struct Foo(i32, String);
///
/// impl fmt::Debug for Foo {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_tuple("Foo")
/// .field(&self.0)
/// .field(&self.1)
@ -418,7 +418,7 @@ fn is_pretty(&self) -> bool {
/// struct Foo(Vec<i32>);
///
/// impl fmt::Debug for Foo {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_set().entries(self.0.iter()).finish()
/// }
/// }
@ -548,7 +548,7 @@ pub fn finish(&mut self) -> fmt::Result {
/// struct Foo(Vec<i32>);
///
/// impl fmt::Debug for Foo {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_list().entries(self.0.iter()).finish()
/// }
/// }
@ -678,7 +678,7 @@ pub fn finish(&mut self) -> fmt::Result {
/// struct Foo(Vec<(String, i32)>);
///
/// impl fmt::Debug for Foo {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_map().entries(self.0.iter().map(|&(ref k, ref v)| (k, v))).finish()
/// }
/// }

View File

@ -381,7 +381,7 @@ impl<'a> Arguments<'a> {
///
/// fn write_str(_: &str) { /* ... */ }
///
/// fn write_fmt(args: &Arguments) {
/// fn write_fmt(args: &Arguments<'_>) {
/// if let Some(s) = args.as_str() {
/// write_str(s)
/// } else {
@ -1228,7 +1228,7 @@ fn wrap_buf<'b, 'c, F>(&'b mut self, wrap: F) -> Formatter<'c>
/// }
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// // We need to remove "-" from the number output.
/// let tmp = self.nb.abs().to_string();
///
@ -1328,7 +1328,7 @@ fn write_prefix(f: &mut Formatter<'_>, sign: Option<char>, prefix: Option<&str>)
/// struct Foo;
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// formatter.pad("Foo")
/// }
/// }
@ -1510,7 +1510,7 @@ fn write_bytes(buf: &mut dyn Write, s: &[u8]) -> Result {
/// struct Foo;
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// formatter.write_str("Foo")
/// // This is equivalent to:
/// // write!(formatter, "Foo")
@ -1535,7 +1535,7 @@ pub fn write_str(&mut self, data: &str) -> Result {
/// struct Foo(i32);
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// formatter.write_fmt(format_args!("Foo {}", self.0))
/// }
/// }
@ -1570,7 +1570,7 @@ pub fn flags(&self) -> u32 {
/// struct Foo;
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// let c = formatter.fill();
/// if let Some(width) = formatter.width() {
/// for _ in 0..width {
@ -1598,14 +1598,12 @@ pub fn fill(&self) -> char {
/// # Examples
///
/// ```
/// extern crate core;
///
/// use std::fmt::{self, Alignment};
///
/// struct Foo;
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// let s = if let Some(s) = formatter.align() {
/// match s {
/// Alignment::Left => "left",
@ -1645,7 +1643,7 @@ pub fn align(&self) -> Option<Alignment> {
/// struct Foo(i32);
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// if let Some(width) = formatter.width() {
/// // If we received a width, we use it
/// write!(formatter, "{:width$}", format!("Foo({})", self.0), width = width)
@ -1676,7 +1674,7 @@ pub fn width(&self) -> Option<usize> {
/// struct Foo(f32);
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// if let Some(precision) = formatter.precision() {
/// // If we received a precision, we use it.
/// write!(formatter, "Foo({1:.*})", precision, self.0)
@ -1706,7 +1704,7 @@ pub fn precision(&self) -> Option<usize> {
/// struct Foo(i32);
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// if formatter.sign_plus() {
/// write!(formatter,
/// "Foo({}{})",
@ -1738,7 +1736,7 @@ pub fn sign_plus(&self) -> bool {
/// struct Foo(i32);
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// if formatter.sign_minus() {
/// // You want a minus sign? Have one!
/// write!(formatter, "-Foo({})", self.0)
@ -1767,7 +1765,7 @@ pub fn sign_minus(&self) -> bool {
/// struct Foo(i32);
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// if formatter.alternate() {
/// write!(formatter, "Foo({})", self.0)
/// } else {
@ -1795,7 +1793,7 @@ pub fn alternate(&self) -> bool {
/// struct Foo(i32);
///
/// impl fmt::Display for Foo {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
/// assert!(formatter.sign_aware_zero_pad());
/// assert_eq!(formatter.width(), Some(4));
/// // We ignore the formatter's options.
@ -1839,7 +1837,7 @@ fn debug_upper_hex(&self) -> bool {
/// }
///
/// impl fmt::Debug for Foo {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_struct("Foo")
/// .field("bar", &self.bar)
/// .field("baz", &self.baz)
@ -1997,7 +1995,7 @@ pub fn debug_struct_fields_finish<'b>(
/// struct Foo<T>(i32, String, PhantomData<T>);
///
/// impl<T> fmt::Debug for Foo<T> {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_tuple("Foo")
/// .field(&self.0)
/// .field(&self.1)
@ -2129,7 +2127,7 @@ pub fn debug_tuple_fields_finish<'b>(
/// struct Foo(Vec<i32>);
///
/// impl fmt::Debug for Foo {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_list().entries(self.0.iter()).finish()
/// }
/// }
@ -2152,7 +2150,7 @@ pub fn debug_list<'b>(&'b mut self) -> DebugList<'b, 'a> {
/// struct Foo(Vec<i32>);
///
/// impl fmt::Debug for Foo {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_set().entries(self.0.iter()).finish()
/// }
/// }
@ -2168,14 +2166,14 @@ pub fn debug_list<'b>(&'b mut self) -> DebugList<'b, 'a> {
/// ```rust
/// use std::fmt;
///
/// struct Arm<'a, L: 'a, R: 'a>(&'a (L, R));
/// struct Table<'a, K: 'a, V: 'a>(&'a [(K, V)], V);
/// struct Arm<'a, L, R>(&'a (L, R));
/// struct Table<'a, K, V>(&'a [(K, V)], V);
///
/// impl<'a, L, R> fmt::Debug for Arm<'a, L, R>
/// where
/// L: 'a + fmt::Debug, R: 'a + fmt::Debug
/// {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// L::fmt(&(self.0).0, fmt)?;
/// fmt.write_str(" => ")?;
/// R::fmt(&(self.0).1, fmt)
@ -2186,7 +2184,7 @@ pub fn debug_list<'b>(&'b mut self) -> DebugList<'b, 'a> {
/// where
/// K: 'a + fmt::Debug, V: 'a + fmt::Debug
/// {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_set()
/// .entries(self.0.iter().map(Arm))
/// .entry(&Arm(&(format_args!("_"), &self.1)))
@ -2210,7 +2208,7 @@ pub fn debug_set<'b>(&'b mut self) -> DebugSet<'b, 'a> {
/// struct Foo(Vec<(String, i32)>);
///
/// impl fmt::Debug for Foo {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
/// fmt.debug_map().entries(self.0.iter().map(|&(ref k, ref v)| (k, v))).finish()
/// }
/// }

View File

@ -15,7 +15,6 @@
//! ```rust
//! #![feature(core_intrinsics, custom_mir)]
//!
//! extern crate core;
//! use core::intrinsics::mir::*;
//!
//! #[custom_mir(dialect = "built")]
@ -65,7 +64,6 @@
//! ```rust
//! #![feature(core_intrinsics, custom_mir)]
//!
//! extern crate core;
//! use core::intrinsics::mir::*;
//!
//! #[custom_mir(dialect = "built")]
@ -317,7 +315,6 @@ fn Discriminant<T>(place: T) -> <T as ::core::marker::DiscriminantKind>::Discrim
/// ```rust
/// #![feature(custom_mir, core_intrinsics)]
///
/// extern crate core;
/// use core::intrinsics::mir::*;
///
/// #[custom_mir(dialect = "built")]

View File

@ -15,7 +15,7 @@
///
/// let a1 = [1, 2, 3];
/// let a2 = [4, 5, 6];
/// let iter: Chain<Iter<_>, Iter<_>> = a1.iter().chain(a2.iter());
/// let iter: Chain<Iter<'_, _>, Iter<'_, _>> = a1.iter().chain(a2.iter());
/// ```
#[derive(Clone, Debug)]
#[must_use = "iterators are lazy and do nothing unless consumed"]

View File

@ -498,7 +498,6 @@ macro_rules! r#try {
/// In a `no_std` setup you are responsible for the implementation details of the components.
///
/// ```no_run
/// # extern crate core;
/// use core::fmt::Write;
///
/// struct Example;

View File

@ -688,7 +688,7 @@ impl<T: ?Sized> !Sync for *mut T {}
/// use std::marker::PhantomData;
///
/// # #[allow(dead_code)]
/// struct Slice<'a, T: 'a> {
/// struct Slice<'a, T> {
/// start: *const T,
/// end: *const T,
/// phantom: PhantomData<&'a T>,
@ -704,7 +704,7 @@ impl<T: ?Sized> !Sync for *mut T {}
/// ```
/// # #![allow(dead_code)]
/// # use std::marker::PhantomData;
/// # struct Slice<'a, T: 'a> {
/// # struct Slice<'a, T> {
/// # start: *const T,
/// # end: *const T,
/// # phantom: PhantomData<&'a T>,

View File

@ -517,7 +517,7 @@ fn div(self, other: $t) -> $t { self / other }
/// use std::ops::Rem;
///
/// #[derive(PartialEq, Debug)]
/// struct SplitSlice<'a, T: 'a> {
/// struct SplitSlice<'a, T> {
/// slice: &'a [T],
/// }
///

View File

@ -550,6 +550,7 @@ impl Copy for () {
///
/// ```
/// # #![feature(rustc_private)]
/// #[allow(unused_extern_crates)]
/// extern crate libc;
///
/// use std::mem;

View File

@ -2287,7 +2287,7 @@ mod use_keyword {}
/// # #![allow(dead_code)]
/// pub enum Cow<'a, B>
/// where
/// B: 'a + ToOwned + ?Sized,
/// B: ToOwned + ?Sized,
/// {
/// Borrowed(&'a B),
/// Owned(<B as ToOwned>::Owned),

View File

@ -368,7 +368,7 @@ pub trait OpenOptionsExt {
///
/// ```no_run
/// # #![feature(rustc_private)]
/// extern crate libc;
/// use libc;
/// use std::fs::OpenOptions;
/// use std::os::unix::fs::OpenOptionsExt;
///

View File

@ -117,7 +117,7 @@
/// use std::path::Prefix::*;
/// use std::ffi::OsStr;
///
/// fn get_path_prefix(s: &str) -> Prefix {
/// fn get_path_prefix(s: &str) -> Prefix<'_> {
/// let path = Path::new(s);
/// match path.components().next().unwrap() {
/// Component::Prefix(prefix_component) => prefix_component.kind(),

View File

@ -550,6 +550,7 @@ impl Copy for () {
///
/// ```
/// # #![feature(rustc_private)]
/// #[allow(unused_extern_crates)]
/// extern crate libc;
///
/// use std::mem;

View File

@ -1842,7 +1842,7 @@ impl ExitCode {
/// # use std::fmt;
/// # enum UhOhError { GenericProblem, Specific, WithCode { exit_code: ExitCode, _x: () } }
/// # impl fmt::Display for UhOhError {
/// # fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { unimplemented!() }
/// # fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { unimplemented!() }
/// # }
/// // there's no way to gracefully recover from an UhOhError, so we just
/// // print a message and exit

View File

@ -2158,6 +2158,10 @@ pub(crate) fn open_in_browser(&self, path: impl AsRef<Path>) {
#[cfg(test)]
mod tests;
/// Represents flag values in `String` form with whitespace delimiter to pass it to the compiler later.
///
/// `-Z crate-attr` flags will be applied recursively on the target code using the `rustc_parse::parser::Parser`.
/// See `rustc_builtin_macros::cmdline_attrs::inject` for more information.
#[derive(Debug, Clone)]
struct Rustflags(String, TargetSelection);

View File

@ -412,6 +412,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
format!("-Zcrate-attr=doc(html_root_url=\"{}/\")", builder.doc_rust_lang_org_channel(),);
cargo.rustflag(&html_root);
cargo.rustdocflag(&html_root);
cargo.rustdocflag("-Zcrate-attr=warn(rust_2018_idioms)");
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@ -810,6 +812,9 @@ pub fn rustc_cargo(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelec
.arg(builder.rustc_features(builder.kind))
.arg("--manifest-path")
.arg(builder.src.join("compiler/rustc/Cargo.toml"));
cargo.rustdocflag("-Zcrate-attr=warn(rust_2018_idioms)");
rustc_cargo_env(builder, cargo, target, stage);
}