From 06a1c14d52a8482a33416c21b320970cab80cccc Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 17 Dec 2021 21:53:28 +0800 Subject: [PATCH] Switch all libraries to the 2021 edition --- library/alloc/Cargo.toml | 2 +- library/core/Cargo.toml | 2 +- library/core/src/array/mod.rs | 2 -- library/core/src/convert/mod.rs | 4 --- library/core/src/iter/traits/collect.rs | 6 ---- library/core/src/iter/traits/iterator.rs | 4 --- library/core/src/num/int_macros.rs | 6 ---- library/core/src/num/uint_macros.rs | 6 ---- library/panic_abort/Cargo.toml | 2 +- library/panic_unwind/Cargo.toml | 2 +- library/proc_macro/Cargo.toml | 2 +- library/profiler_builtins/Cargo.toml | 2 +- library/rustc-std-workspace-alloc/Cargo.toml | 2 +- library/rustc-std-workspace-core/Cargo.toml | 2 +- library/rustc-std-workspace-std/Cargo.toml | 2 +- library/test/Cargo.toml | 2 +- library/unwind/Cargo.toml | 2 +- src/tools/tidy/src/edition.rs | 33 +++++--------------- 18 files changed, 18 insertions(+), 65 deletions(-) diff --git a/library/alloc/Cargo.toml b/library/alloc/Cargo.toml index b3ff0fd0a31..265020209eb 100644 --- a/library/alloc/Cargo.toml +++ b/library/alloc/Cargo.toml @@ -6,7 +6,7 @@ repository = "https://github.com/rust-lang/rust.git" description = "The Rust core allocation and collections library" autotests = false autobenches = false -edition = "2018" +edition = "2021" [dependencies] core = { path = "../core" } diff --git a/library/core/Cargo.toml b/library/core/Cargo.toml index 6f10b9e4342..6bc4ba3cc0e 100644 --- a/library/core/Cargo.toml +++ b/library/core/Cargo.toml @@ -6,7 +6,7 @@ repository = "https://github.com/rust-lang/rust.git" description = "The Rust Core Library" autotests = false autobenches = false -edition = "2018" +edition = "2021" [lib] test = false diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 37292bf8e26..121aa634deb 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -66,8 +66,6 @@ /// /// ```rust /// #![feature(array_from_fn)] -/// # // Apparently these doc tests are still on edition2018 -/// # use std::convert::TryInto; /// /// let array: Result<[u8; 5], _> = std::array::try_from_fn(|i| i.try_into()); /// assert_eq!(array, Ok([0, 1, 2, 3, 4])); diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 1c2e673d604..d40f69f8b35 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -426,8 +426,6 @@ pub trait TryInto: Sized { /// `TryFrom` can be implemented as follows: /// /// ``` -/// use std::convert::TryFrom; -/// /// struct GreaterThanZero(i32); /// /// impl TryFrom for GreaterThanZero { @@ -448,8 +446,6 @@ pub trait TryInto: Sized { /// As described, [`i32`] implements `TryFrom<`[`i64`]`>`: /// /// ``` -/// use std::convert::TryFrom; -/// /// let big_number = 1_000_000_000_000i64; /// // Silently truncates `big_number`, requires detecting /// // and handling the truncation after the fact. diff --git a/library/core/src/iter/traits/collect.rs b/library/core/src/iter/traits/collect.rs index 56fad602cf9..26c97b8ed78 100644 --- a/library/core/src/iter/traits/collect.rs +++ b/library/core/src/iter/traits/collect.rs @@ -15,8 +15,6 @@ /// Basic usage: /// /// ``` -/// use std::iter::FromIterator; -/// /// let five_fives = std::iter::repeat(5).take(5); /// /// let v = Vec::from_iter(five_fives); @@ -37,8 +35,6 @@ /// Implementing `FromIterator` for your type: /// /// ``` -/// use std::iter::FromIterator; -/// /// // A sample collection, that's just a wrapper over Vec /// #[derive(Debug)] /// struct MyCollection(Vec); @@ -102,8 +98,6 @@ pub trait FromIterator: Sized { /// Basic usage: /// /// ``` - /// use std::iter::FromIterator; - /// /// let five_fives = std::iter::repeat(5).take(5); /// /// let v = Vec::from_iter(five_fives); diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 9a9a844f41b..2049adafa2f 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -1155,8 +1155,6 @@ fn take_while

(self, predicate: P) -> TakeWhile /// Stopping after an initial [`None`]: /// /// ``` - /// use std::convert::TryFrom; - /// /// let a = [0, 1, 2, -3, 4, 5, -6]; /// /// let iter = a.iter().map_while(|x| u32::try_from(*x).ok()); @@ -1172,8 +1170,6 @@ fn take_while

(self, predicate: P) -> TakeWhile /// removed: /// /// ``` - /// use std::convert::TryFrom; - /// /// let a = [1, 2, -3, 4]; /// let mut iter = a.iter(); /// diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index e6ae4afd7c1..6f7c5a6d119 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -2602,8 +2602,6 @@ pub const fn is_negative(self) -> bool { self < 0 } /// When starting from a slice rather than an array, fallible conversion APIs can be used: /// /// ``` - /// use std::convert::TryInto; - /// #[doc = concat!("fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {")] #[doc = concat!(" let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());")] /// *input = rest; @@ -2633,8 +2631,6 @@ pub const fn is_negative(self) -> bool { self < 0 } /// When starting from a slice rather than an array, fallible conversion APIs can be used: /// /// ``` - /// use std::convert::TryInto; - /// #[doc = concat!("fn read_le_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {")] #[doc = concat!(" let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());")] /// *input = rest; @@ -2675,8 +2671,6 @@ pub const fn is_negative(self) -> bool { self < 0 } /// When starting from a slice rather than an array, fallible conversion APIs can be used: /// /// ``` - /// use std::convert::TryInto; - /// #[doc = concat!("fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {")] #[doc = concat!(" let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());")] /// *input = rest; diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 3cc454baf35..1dd8b0a18ab 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -2323,8 +2323,6 @@ pub const fn wrapping_next_power_of_two(self) -> Self { /// When starting from a slice rather than an array, fallible conversion APIs can be used: /// /// ``` - /// use std::convert::TryInto; - /// #[doc = concat!("fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {")] #[doc = concat!(" let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());")] /// *input = rest; @@ -2354,8 +2352,6 @@ pub const fn wrapping_next_power_of_two(self) -> Self { /// When starting from a slice rather than an array, fallible conversion APIs can be used: /// /// ``` - /// use std::convert::TryInto; - /// #[doc = concat!("fn read_le_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {")] #[doc = concat!(" let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());")] /// *input = rest; @@ -2396,8 +2392,6 @@ pub const fn wrapping_next_power_of_two(self) -> Self { /// When starting from a slice rather than an array, fallible conversion APIs can be used: /// /// ``` - /// use std::convert::TryInto; - /// #[doc = concat!("fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {")] #[doc = concat!(" let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());")] /// *input = rest; diff --git a/library/panic_abort/Cargo.toml b/library/panic_abort/Cargo.toml index 6dec0e67497..46183d1ad00 100644 --- a/library/panic_abort/Cargo.toml +++ b/library/panic_abort/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.0" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/rust.git" description = "Implementation of Rust panics via process aborts" -edition = "2018" +edition = "2021" [lib] test = false diff --git a/library/panic_unwind/Cargo.toml b/library/panic_unwind/Cargo.toml index 67405463aa6..d720cc7bcbd 100644 --- a/library/panic_unwind/Cargo.toml +++ b/library/panic_unwind/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.0" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/rust.git" description = "Implementation of Rust panics via stack unwinding" -edition = "2018" +edition = "2021" [lib] test = false diff --git a/library/proc_macro/Cargo.toml b/library/proc_macro/Cargo.toml index faf460e32bd..db5e2e4e245 100644 --- a/library/proc_macro/Cargo.toml +++ b/library/proc_macro/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "proc_macro" version = "0.0.0" -edition = "2018" +edition = "2021" [dependencies] std = { path = "../std" } diff --git a/library/profiler_builtins/Cargo.toml b/library/profiler_builtins/Cargo.toml index 0f7f0067652..3371dfa1242 100644 --- a/library/profiler_builtins/Cargo.toml +++ b/library/profiler_builtins/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "profiler_builtins" version = "0.0.0" -edition = "2018" +edition = "2021" [lib] test = false diff --git a/library/rustc-std-workspace-alloc/Cargo.toml b/library/rustc-std-workspace-alloc/Cargo.toml index 1ea421834a7..049ca3e46b5 100644 --- a/library/rustc-std-workspace-alloc/Cargo.toml +++ b/library/rustc-std-workspace-alloc/Cargo.toml @@ -5,7 +5,7 @@ license = 'MIT OR Apache-2.0' description = """ Hack for the compiler's own build system """ -edition = "2018" +edition = "2021" [lib] path = "lib.rs" diff --git a/library/rustc-std-workspace-core/Cargo.toml b/library/rustc-std-workspace-core/Cargo.toml index 01e8b92e149..ff5cfcbd641 100644 --- a/library/rustc-std-workspace-core/Cargo.toml +++ b/library/rustc-std-workspace-core/Cargo.toml @@ -5,7 +5,7 @@ license = 'MIT OR Apache-2.0' description = """ Hack for the compiler's own build system """ -edition = "2018" +edition = "2021" [lib] path = "lib.rs" diff --git a/library/rustc-std-workspace-std/Cargo.toml b/library/rustc-std-workspace-std/Cargo.toml index 811bc78d210..3a1dc2a02b5 100644 --- a/library/rustc-std-workspace-std/Cargo.toml +++ b/library/rustc-std-workspace-std/Cargo.toml @@ -5,7 +5,7 @@ license = 'MIT OR Apache-2.0' description = """ Hack for the compiler's own build system """ -edition = "2018" +edition = "2021" [lib] path = "lib.rs" diff --git a/library/test/Cargo.toml b/library/test/Cargo.toml index 04dab6b804a..2da41484ca5 100644 --- a/library/test/Cargo.toml +++ b/library/test/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "test" version = "0.0.0" -edition = "2018" +edition = "2021" [lib] crate-type = ["dylib", "rlib"] diff --git a/library/unwind/Cargo.toml b/library/unwind/Cargo.toml index 1941f2b5a00..69fce8d7795 100644 --- a/library/unwind/Cargo.toml +++ b/library/unwind/Cargo.toml @@ -3,7 +3,7 @@ name = "unwind" version = "0.0.0" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/rust.git" -edition = "2018" +edition = "2021" include = [ '/libunwind/*', ] diff --git a/src/tools/tidy/src/edition.rs b/src/tools/tidy/src/edition.rs index f610dbd806a..b0abee45986 100644 --- a/src/tools/tidy/src/edition.rs +++ b/src/tools/tidy/src/edition.rs @@ -2,11 +2,6 @@ use std::path::Path; -fn is_edition_2018(mut line: &str) -> bool { - line = line.trim(); - line == "edition = \"2018\"" -} - fn is_edition_2021(mut line: &str) -> bool { line = line.trim(); line == "edition = \"2021\"" @@ -23,27 +18,13 @@ pub fn check(path: &Path, bad: &mut bool) { return; } - // Not all library crates are ready to migrate to 2021. - if file.components().any(|c| c.as_os_str() == "library") - && file.components().all(|c| c.as_os_str() != "std") - { - let has = contents.lines().any(is_edition_2018); - if !has { - tidy_error!( - bad, - "{} doesn't have `edition = \"2018\"` on a separate line", - file.display() - ); - } - } else { - let is_2021 = contents.lines().any(is_edition_2021); - if !is_2021 { - tidy_error!( - bad, - "{} doesn't have `edition = \"2021\"` on a separate line", - file.display() - ); - } + let is_2021 = contents.lines().any(is_edition_2021); + if !is_2021 { + tidy_error!( + bad, + "{} doesn't have `edition = \"2021\"` on a separate line", + file.display() + ); } }, );