Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch all libraries to the 2021 edition #92068

Merged
merged 3 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
3 changes: 0 additions & 3 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3009,22 +3009,19 @@ impl<T, A: Allocator, const N: usize> TryFrom<Vec<T, A>> for [T; N] {
/// # Examples
///
/// ```
/// use std::convert::TryInto;
/// assert_eq!(vec![1, 2, 3].try_into(), Ok([1, 2, 3]));
/// assert_eq!(<Vec<i32>>::new().try_into(), Ok([]));
/// ```
///
/// If the length doesn't match, the input comes back in `Err`:
/// ```
/// use std::convert::TryInto;
/// let r: Result<[i32; 4], _> = (0..10).collect::<Vec<_>>().try_into();
/// assert_eq!(r, Err(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));
/// ```
///
/// If you're fine with just getting a prefix of the `Vec<T>`,
/// you can call [`.truncate(N)`](Vec::truncate) first.
/// ```
/// use std::convert::TryInto;
/// let mut v = String::from("hello world").into_bytes();
/// v.sort();
/// v.truncate(2);
Expand Down
2 changes: 1 addition & 1 deletion library/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ where
///
/// ```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]));
Expand Down
4 changes: 0 additions & 4 deletions library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,6 @@ pub trait TryInto<T>: Sized {
/// `TryFrom<T>` can be implemented as follows:
///
/// ```
/// use std::convert::TryFrom;
///
/// struct GreaterThanZero(i32);
///
/// impl TryFrom<i32> for GreaterThanZero {
Expand All @@ -448,8 +446,6 @@ pub trait TryInto<T>: 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.
Expand Down
6 changes: 0 additions & 6 deletions library/core/src/iter/traits/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -37,8 +35,6 @@
/// Implementing `FromIterator` for your type:
///
/// ```
/// use std::iter::FromIterator;
///
/// // A sample collection, that's just a wrapper over Vec<T>
/// #[derive(Debug)]
/// struct MyCollection(Vec<i32>);
Expand Down Expand Up @@ -102,8 +98,6 @@ pub trait FromIterator<A>: Sized {
/// Basic usage:
///
/// ```
/// use std::iter::FromIterator;
///
/// let five_fives = std::iter::repeat(5).take(5);
///
/// let v = Vec::from_iter(five_fives);
Expand Down
4 changes: 0 additions & 4 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,8 +1155,6 @@ pub trait Iterator {
/// 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());
Expand All @@ -1172,8 +1170,6 @@ pub trait Iterator {
/// removed:
///
/// ```
/// use std::convert::TryFrom;
///
/// let a = [1, 2, -3, 4];
/// let mut iter = a.iter();
///
Expand Down
6 changes: 0 additions & 6 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2602,8 +2602,6 @@ macro_rules! int_impl {
/// 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;
Expand Down Expand Up @@ -2633,8 +2631,6 @@ macro_rules! int_impl {
/// 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;
Expand Down Expand Up @@ -2675,8 +2671,6 @@ macro_rules! int_impl {
/// 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;
Expand Down
6 changes: 0 additions & 6 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2323,8 +2323,6 @@ macro_rules! uint_impl {
/// 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;
Expand Down Expand Up @@ -2354,8 +2352,6 @@ macro_rules! uint_impl {
/// 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;
Expand Down Expand Up @@ -2396,8 +2392,6 @@ macro_rules! uint_impl {
/// 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;
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub const fn panic(expr: &'static str) -> ! {
#[inline]
#[track_caller]
#[lang = "panic_str"] // needed for `non-fmt-panics` lint
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
pub const fn panic_str(expr: &str) -> ! {
panic_display(&expr);
}
Expand All @@ -59,6 +60,7 @@ pub const fn panic_str(expr: &str) -> ! {
#[track_caller]
#[lang = "panic_display"] // needed for const-evaluated panics
#[rustc_do_not_const_check] // hooked by const-eval
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
pub const fn panic_display<T: fmt::Display>(x: &T) -> ! {
panic_fmt(format_args!("{}", *x));
}
Expand Down Expand Up @@ -89,6 +91,7 @@ fn panic_bounds_check(index: usize, len: usize) -> ! {
#[track_caller]
#[lang = "panic_fmt"] // needed for const-evaluated panics
#[rustc_do_not_const_check] // hooked by const-eval
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
if cfg!(feature = "panic_immediate_abort") {
super::intrinsics::abort()
Expand All @@ -109,6 +112,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {

/// This function is used instead of panic_fmt in const eval.
#[lang = "const_panic_fmt"]
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
pub const fn const_panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
if let Some(msg) = fmt.as_str() {
panic_str(msg);
Expand Down
2 changes: 1 addition & 1 deletion library/panic_abort/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/panic_unwind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/proc_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "proc_macro"
version = "0.0.0"
edition = "2018"
edition = "2021"

[dependencies]
std = { path = "../std" }
2 changes: 1 addition & 1 deletion library/profiler_builtins/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "profiler_builtins"
version = "0.0.0"
edition = "2018"
edition = "2021"

[lib]
test = false
Expand Down
2 changes: 1 addition & 1 deletion library/rustc-std-workspace-alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion library/rustc-std-workspace-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion library/rustc-std-workspace-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion library/test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "test"
version = "0.0.0"
edition = "2018"
edition = "2021"

[lib]
crate-type = ["dylib", "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion library/unwind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*',
]
Expand Down
33 changes: 7 additions & 26 deletions src/tools/tidy/src/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand All @@ -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()
);
}
},
);
Expand Down