From afbecc0f68c4dcfc4878ba5bcb1ac942544a1bdc Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 15 Mar 2022 16:56:28 +0100 Subject: [PATCH] remove now unnecessary lang items --- compiler/rustc_hir/src/lang_items.rs | 30 ---------------- compiler/rustc_span/src/symbol.rs | 10 ------ .../rustc_typeck/src/check/method/suggest.rs | 35 ++++++++++--------- library/alloc/src/slice.rs | 4 +-- library/alloc/src/str.rs | 2 +- library/core/src/array/mod.rs | 2 +- library/core/src/bool.rs | 2 +- library/core/src/char/methods.rs | 2 +- library/core/src/num/f32.rs | 2 +- library/core/src/num/f64.rs | 2 +- library/core/src/num/mod.rs | 32 ++++++++--------- library/core/src/ptr/const_ptr.rs | 4 +-- library/core/src/ptr/mut_ptr.rs | 4 +-- library/core/src/slice/ascii.rs | 2 +- library/core/src/slice/mod.rs | 2 +- library/core/src/str/mod.rs | 2 +- library/std/src/f32.rs | 2 +- library/std/src/f64.rs | 2 +- 18 files changed, 51 insertions(+), 90 deletions(-) diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 7c312e1b61d..b8df1632144 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -166,36 +166,6 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> { language_item_table! { // Variant name, Name, Method name, Target Generic requirements; - Bool, sym::bool, bool_impl, Target::Impl, GenericRequirement::None; - Char, sym::char, char_impl, Target::Impl, GenericRequirement::None; - Str, sym::str, str_impl, Target::Impl, GenericRequirement::None; - Array, sym::array, array_impl, Target::Impl, GenericRequirement::None; - Slice, sym::slice, slice_impl, Target::Impl, GenericRequirement::None; - SliceU8, sym::slice_u8, slice_u8_impl, Target::Impl, GenericRequirement::None; - StrAlloc, sym::str_alloc, str_alloc_impl, Target::Impl, GenericRequirement::None; - SliceAlloc, sym::slice_alloc, slice_alloc_impl, Target::Impl, GenericRequirement::None; - SliceU8Alloc, sym::slice_u8_alloc, slice_u8_alloc_impl, Target::Impl, GenericRequirement::None; - ConstPtr, sym::const_ptr, const_ptr_impl, Target::Impl, GenericRequirement::None; - MutPtr, sym::mut_ptr, mut_ptr_impl, Target::Impl, GenericRequirement::None; - ConstSlicePtr, sym::const_slice_ptr, const_slice_ptr_impl, Target::Impl, GenericRequirement::None; - MutSlicePtr, sym::mut_slice_ptr, mut_slice_ptr_impl, Target::Impl, GenericRequirement::None; - I8, sym::i8, i8_impl, Target::Impl, GenericRequirement::None; - I16, sym::i16, i16_impl, Target::Impl, GenericRequirement::None; - I32, sym::i32, i32_impl, Target::Impl, GenericRequirement::None; - I64, sym::i64, i64_impl, Target::Impl, GenericRequirement::None; - I128, sym::i128, i128_impl, Target::Impl, GenericRequirement::None; - Isize, sym::isize, isize_impl, Target::Impl, GenericRequirement::None; - U8, sym::u8, u8_impl, Target::Impl, GenericRequirement::None; - U16, sym::u16, u16_impl, Target::Impl, GenericRequirement::None; - U32, sym::u32, u32_impl, Target::Impl, GenericRequirement::None; - U64, sym::u64, u64_impl, Target::Impl, GenericRequirement::None; - U128, sym::u128, u128_impl, Target::Impl, GenericRequirement::None; - Usize, sym::usize, usize_impl, Target::Impl, GenericRequirement::None; - F32, sym::f32, f32_impl, Target::Impl, GenericRequirement::None; - F64, sym::f64, f64_impl, Target::Impl, GenericRequirement::None; - F32Runtime, sym::f32_runtime, f32_runtime_impl, Target::Impl, GenericRequirement::None; - F64Runtime, sym::f64_runtime, f64_runtime_impl, Target::Impl, GenericRequirement::None; - Sized, sym::sized, sized_trait, Target::Trait, GenericRequirement::Exact(0); Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1); /// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ"). diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 6dd9b8e44dd..84dbad846dd 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -494,11 +494,9 @@ symbols! { const_panic, const_panic_fmt, const_precise_live_drops, - const_ptr, const_raw_ptr_deref, const_raw_ptr_to_usize_cast, const_refs_to_cell, - const_slice_ptr, const_trait_bound_opt_out, const_trait_impl, const_transmute, @@ -655,9 +653,7 @@ symbols! { f, f16c_target_feature, f32, - f32_runtime, f64, - f64_runtime, fabsf32, fabsf64, fadd_fast, @@ -913,8 +909,6 @@ symbols! { mul_with_overflow, must_not_suspend, must_use, - mut_ptr, - mut_slice_ptr, naked, naked_functions, name, @@ -1314,11 +1308,8 @@ symbols! { sized, skip, slice, - slice_alloc, slice_len_fn, slice_patterns, - slice_u8, - slice_u8_alloc, slicing_syntax, soft, specialization, @@ -1348,7 +1339,6 @@ symbols! { stop_after_dataflow, store, str, - str_alloc, str_split_whitespace, str_trim, str_trim_end, diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 9c3f2da5644..cc4707b6b72 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -281,25 +281,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // There are methods that are defined on the primitive types and won't be // found when exploring `all_traits`, but we also need them to be acurate on // our suggestions (#47759). - let fund_assoc = |opt_def_id: Option| { - opt_def_id.and_then(|id| self.associated_value(id, item_name)).is_some() + let found_assoc = |ty: Ty<'tcx>| { + simplify_type(tcx, ty, TreatParams::AsPlaceholders).and_then(|simp| { + tcx.incoherent_impls(simp) + .iter() + .find_map(|&id| self.associated_value(id, item_name)) + }).is_some() }; - let lang_items = tcx.lang_items(); let found_candidate = candidates.next().is_some() - || fund_assoc(lang_items.i8_impl()) - || fund_assoc(lang_items.i16_impl()) - || fund_assoc(lang_items.i32_impl()) - || fund_assoc(lang_items.i64_impl()) - || fund_assoc(lang_items.i128_impl()) - || fund_assoc(lang_items.u8_impl()) - || fund_assoc(lang_items.u16_impl()) - || fund_assoc(lang_items.u32_impl()) - || fund_assoc(lang_items.u64_impl()) - || fund_assoc(lang_items.u128_impl()) - || fund_assoc(lang_items.f32_impl()) - || fund_assoc(lang_items.f32_runtime_impl()) - || fund_assoc(lang_items.f64_impl()) - || fund_assoc(lang_items.f64_runtime_impl()); + || found_assoc(tcx.types.i8) + || found_assoc(tcx.types.i16) + || found_assoc(tcx.types.i32) + || found_assoc(tcx.types.i64) + || found_assoc(tcx.types.i128) + || found_assoc(tcx.types.u8) + || found_assoc(tcx.types.u16) + || found_assoc(tcx.types.u32) + || found_assoc(tcx.types.u64) + || found_assoc(tcx.types.u128) + || found_assoc(tcx.types.f32) + || found_assoc(tcx.types.f32); if let (true, false, SelfSource::MethodCall(expr), true) = ( actual.is_numeric(), actual.has_concrete_skeleton(), diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 111c57e884b..c61e9d85dd1 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -237,7 +237,7 @@ mod hack { } } -#[lang = "slice_alloc"] +#[cfg_attr(bootstrap, lang = "slice_alloc")] #[cfg(not(test))] impl [T] { /// Sorts the slice. @@ -667,7 +667,7 @@ impl [T] { } } -#[lang = "slice_u8_alloc"] +#[cfg_attr(bootstrap, lang = "slice_u8_alloc")] #[cfg(not(test))] impl [u8] { /// Returns a vector containing a copy of this slice where each byte diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index bf70363258c..a3c17612c3a 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -235,7 +235,7 @@ impl ToOwned for str { } /// Methods for string slices. -#[lang = "str_alloc"] +#[cfg_attr(bootstrap, lang = "str_alloc")] #[cfg(not(test))] impl str { /// Converts a `Box` into a `Box<[u8]>` without copying or allocating. diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 20dfbc6347c..9e42ab5923a 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -395,7 +395,7 @@ macro_rules! array_impl_default { array_impl_default! {32, T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T} -#[lang = "array"] +#[cfg_attr(bootstrap, lang = "array")] impl [T; N] { /// Returns an array of the same size as `self`, with function `f` applied to each element /// in order. diff --git a/library/core/src/bool.rs b/library/core/src/bool.rs index a13593a539d..06aee3ccbaf 100644 --- a/library/core/src/bool.rs +++ b/library/core/src/bool.rs @@ -2,7 +2,7 @@ use crate::marker::Destruct; -#[lang = "bool"] +#[cfg_attr(bootstrap, lang = "bool")] impl bool { /// Returns `Some(t)` if the `bool` is [`true`](../std/keyword.true.html), /// or `None` otherwise. diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index f75cd74ee2d..7deb3358c95 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -7,7 +7,7 @@ use crate::unicode::{self, conversions}; use super::*; -#[lang = "char"] +#[cfg_attr(bootstrap, lang = "char")] impl char { /// The highest valid code point a `char` can have, `'\u{10FFFF}'`. /// diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index d8dcfdafa8d..17ca8547685 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -370,7 +370,7 @@ pub mod consts { pub const LN_10: f32 = 2.30258509299404568401799145468436421_f32; } -#[lang = "f32"] +#[cfg_attr(bootstrap, lang = "f32")] #[cfg(not(test))] impl f32 { /// The radix or base of the internal representation of `f32`. diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 7c2f51ff646..350d8529de5 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -370,7 +370,7 @@ pub mod consts { pub const LN_10: f64 = 2.30258509299404568401799145468436421_f64; } -#[lang = "f64"] +#[cfg_attr(bootstrap, lang = "f64")] #[cfg(not(test))] impl f64 { /// The radix or base of the internal representation of `f64`. diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index c09f642d969..f4f1d274d10 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -193,26 +193,26 @@ macro_rules! widening_impl { }; } -#[lang = "i8"] +#[cfg_attr(bootstrap, lang = "i8")] impl i8 { int_impl! { i8, i8, u8, 8, 7, -128, 127, 2, "-0x7e", "0xa", "0x12", "0x12", "0x48", "[0x12]", "[0x12]", "", "" } } -#[lang = "i16"] +#[cfg_attr(bootstrap, lang = "i16")] impl i16 { int_impl! { i16, i16, u16, 16, 15, -32768, 32767, 4, "-0x5ffd", "0x3a", "0x1234", "0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", "", "" } } -#[lang = "i32"] +#[cfg_attr(bootstrap, lang = "i32")] impl i32 { int_impl! { i32, i32, u32, 32, 31, -2147483648, 2147483647, 8, "0x10000b3", "0xb301", "0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]", "", "" } } -#[lang = "i64"] +#[cfg_attr(bootstrap, lang = "i64")] impl i64 { int_impl! { i64, i64, u64, 64, 63, -9223372036854775808, 9223372036854775807, 12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412", @@ -220,7 +220,7 @@ impl i64 { "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", "", "" } } -#[lang = "i128"] +#[cfg_attr(bootstrap, lang = "i128")] impl i128 { int_impl! { i128, i128, u128, 128, 127, -170141183460469231731687303715884105728, 170141183460469231731687303715884105727, 16, @@ -233,7 +233,7 @@ impl i128 { } #[cfg(target_pointer_width = "16")] -#[lang = "isize"] +#[cfg_attr(bootstrap, lang = "isize")] impl isize { int_impl! { isize, i16, usize, 16, 15, -32768, 32767, 4, "-0x5ffd", "0x3a", "0x1234", "0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", @@ -241,7 +241,7 @@ impl isize { } #[cfg(target_pointer_width = "32")] -#[lang = "isize"] +#[cfg_attr(bootstrap, lang = "isize")] impl isize { int_impl! { isize, i32, usize, 32, 31, -2147483648, 2147483647, 8, "0x10000b3", "0xb301", "0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", @@ -250,7 +250,7 @@ impl isize { } #[cfg(target_pointer_width = "64")] -#[lang = "isize"] +#[cfg_attr(bootstrap, lang = "isize")] impl isize { int_impl! { isize, i64, usize, 64, 63, -9223372036854775808, 9223372036854775807, 12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412", @@ -262,7 +262,7 @@ impl isize { /// If 6th bit set ascii is upper case. const ASCII_CASE_MASK: u8 = 0b0010_0000; -#[lang = "u8"] +#[cfg_attr(bootstrap, lang = "u8")] impl u8 { uint_impl! { u8, u8, i8, NonZeroU8, 8, 255, 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]", "[0x12]", "", "" } @@ -816,7 +816,7 @@ impl u8 { } } -#[lang = "u16"] +#[cfg_attr(bootstrap, lang = "u16")] impl u16 { uint_impl! { u16, u16, i16, NonZeroU16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", "", "" } @@ -848,14 +848,14 @@ impl u16 { } } -#[lang = "u32"] +#[cfg_attr(bootstrap, lang = "u32")] impl u32 { uint_impl! { u32, u32, i32, NonZeroU32, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]", "", "" } widening_impl! { u32, u64, 32, unsigned } } -#[lang = "u64"] +#[cfg_attr(bootstrap, lang = "u64")] impl u64 { uint_impl! { u64, u64, i64, NonZeroU64, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48", @@ -865,7 +865,7 @@ impl u64 { widening_impl! { u64, u128, 64, unsigned } } -#[lang = "u128"] +#[cfg_attr(bootstrap, lang = "u128")] impl u128 { uint_impl! { u128, u128, i128, NonZeroU128, 128, 340282366920938463463374607431768211455, 16, "0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012", @@ -878,7 +878,7 @@ impl u128 { } #[cfg(target_pointer_width = "16")] -#[lang = "usize"] +#[cfg_attr(bootstrap, lang = "usize")] impl usize { uint_impl! { usize, u16, isize, NonZeroUsize, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", @@ -886,7 +886,7 @@ impl usize { widening_impl! { usize, u32, 16, unsigned } } #[cfg(target_pointer_width = "32")] -#[lang = "usize"] +#[cfg_attr(bootstrap, lang = "usize")] impl usize { uint_impl! { usize, u32, isize, NonZeroUsize, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]", @@ -895,7 +895,7 @@ impl usize { } #[cfg(target_pointer_width = "64")] -#[lang = "usize"] +#[cfg_attr(bootstrap, lang = "usize")] impl usize { uint_impl! { usize, u64, isize, NonZeroUsize, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48", diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 74c64370ddc..ab2e6058d2f 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -4,7 +4,7 @@ use crate::intrinsics; use crate::mem; use crate::slice::{self, SliceIndex}; -#[lang = "const_ptr"] +#[cfg_attr(bootstrap, lang = "const_ptr")] impl *const T { /// Returns `true` if the pointer is null. /// @@ -969,7 +969,7 @@ impl *const T { } } -#[lang = "const_slice_ptr"] +#[cfg_attr(bootstrap, lang = "const_slice_ptr")] impl *const [T] { /// Returns the length of a raw slice. /// diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 7e48eac4fe0..6a71815c3cf 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -3,7 +3,7 @@ use crate::cmp::Ordering::{self, Equal, Greater, Less}; use crate::intrinsics; use crate::slice::{self, SliceIndex}; -#[lang = "mut_ptr"] +#[cfg_attr(bootstrap, lang = "mut_ptr")] impl *mut T { /// Returns `true` if the pointer is null. /// @@ -1240,7 +1240,7 @@ impl *mut T { } } -#[lang = "mut_slice_ptr"] +#[cfg_attr(bootstrap, lang = "mut_slice_ptr")] impl *mut [T] { /// Returns the length of a raw slice. /// diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index c02a6f2d78c..1825ccda479 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -6,7 +6,7 @@ use crate::iter; use crate::mem; use crate::ops; -#[lang = "slice_u8"] +#[cfg_attr(bootstrap, lang = "slice_u8")] #[cfg(not(test))] impl [u8] { /// Checks if all bytes in this slice are within the ASCII range. diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 26d4fa15d0a..77bf5f9dc34 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -109,7 +109,7 @@ enum Direction { Back, } -#[lang = "slice"] +#[cfg_attr(bootstrap, lang = "slice")] #[cfg(not(test))] impl [T] { /// Returns the number of elements in the slice. diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index c603420f0f8..6bfa6a5e015 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -130,7 +130,7 @@ fn slice_error_fail_rt(s: &str, begin: usize, end: usize) -> ! { ); } -#[lang = "str"] +#[cfg_attr(bootstrap, lang = "str")] #[cfg(not(test))] impl str { /// Returns the length of `self`. diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs index 1faf57e13db..70b5941c7c7 100644 --- a/library/std/src/f32.rs +++ b/library/std/src/f32.rs @@ -28,7 +28,7 @@ pub use core::f32::{ }; #[cfg(not(test))] -#[lang = "f32_runtime"] +#[cfg_attr(bootstrap, lang = "f32_runtime")] impl f32 { /// Returns the largest integer less than or equal to a number. /// diff --git a/library/std/src/f64.rs b/library/std/src/f64.rs index 22d58ab84cf..b90d068ec10 100644 --- a/library/std/src/f64.rs +++ b/library/std/src/f64.rs @@ -28,7 +28,7 @@ pub use core::f64::{ }; #[cfg(not(test))] -#[lang = "f64_runtime"] +#[cfg_attr(bootstrap, lang = "f64_runtime")] impl f64 { /// Returns the largest integer less than or equal to a number. ///