diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index b056fdc73d40b..774b597a73299 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -2005,24 +2005,40 @@ impl BackendRepr { } } +/// Describes the variants of a type. // NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage. #[derive(PartialEq, Eq, Hash, Clone, Debug)] #[cfg_attr(feature = "nightly", derive(StableHash))] pub enum Variants { - /// A type with no valid variants. Must be uninhabited. + /// The type has no valid variants. Must be uninhabited. + /// + /// This is the case for: + /// 1. enums with no inhabited variants + /// 2. the never type Empty, - /// Single enum variants, structs/tuples, unions, and all non-ADTs. + /// The type has a single valid variant. + /// + /// This is the case for: + /// 1. enums with a single inhabited variant + /// 2. structs, unions, and non-ADTs (except coroutines; see below), + /// as those can't have multiple variants Single { - /// Always `0` for types that cannot have multiple variants. + /// - for case 1, this is the index of the inhabited variant + /// - for case 2, this is always `0` (a dummy value) index: VariantIdx, }, - /// Enum-likes with more than one variant: each variant comes with - /// a *discriminant* (usually the same as the variant index but the user can - /// assign explicit discriminant values). That discriminant is encoded - /// as a *tag* on the machine. The layout of each variant is - /// a struct, and they all have space reserved for the tag. + /// The type has multiple valid variants. + /// + /// This is the case for: + /// 1. enums with multiple inhabited variants + /// 2. coroutines + /// + /// Each variant comes with a *discriminant* (usually the same as the + /// variant index but the user can assign explicit discriminant values). + /// That discriminant is encoded as a *tag* on the machine. The layout of + /// each variant is a struct, and they all have space reserved for the tag. /// For enums, the tag is the sole field of the layout. Multiple { tag: Scalar, diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index ac1bfcfb45afd..0ce3bfe07c413 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -559,12 +559,12 @@ pub(crate) unsafe fn create_module<'ll>( let name_metadata = cx.create_metadata(rustc_producer.as_bytes()); cx.module_add_named_metadata_node(llmod, c"llvm.ident", &[name_metadata]); - // Emit RISC-V specific target-abi metadata - // to workaround lld as the LTO plugin not - // correctly setting target-abi for the LTO object - // FIXME: https://github.com/llvm/llvm-project/issues/50591 + // Emit the target-abi module flag for LoongArch and RISC-V to pass the ABI to LTO. let llvm_abiname = &sess.target.options.llvm_abiname; - if matches!(sess.target.arch, Arch::RiscV32 | Arch::RiscV64) { + if matches!( + sess.target.arch, + Arch::LoongArch32 | Arch::LoongArch64 | Arch::RiscV32 | Arch::RiscV64 + ) { llvm::add_module_flag_str( llmod, llvm::ModuleFlagMergeBehavior::Error, diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 2f8fe09ce30aa..e66ba474cc0ed 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1220,7 +1220,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { err.note("constructor is not visible here due to private fields"); } } else { - err.span_suggestion( + err.span_suggestion_verbose( call_span, format!("try calling `{ident}` as a method"), format!("self.{path_str}({args_snippet})"), diff --git a/library/alloc/src/boxed/convert.rs b/library/alloc/src/boxed/convert.rs index f5c16dc7e7040..526e8b18a8031 100644 --- a/library/alloc/src/boxed/convert.rs +++ b/library/alloc/src/boxed/convert.rs @@ -257,8 +257,8 @@ unsafe fn boxed_slice_as_array_unchecked( } #[stable(feature = "boxed_slice_try_from", since = "1.43.0")] -impl TryFrom> for Box<[T; N]> { - type Error = Box<[T]>; +impl TryFrom> for Box<[T; N], A> { + type Error = Box<[T], A>; /// Attempts to convert a `Box<[T]>` into a `Box<[T; N]>`. /// @@ -269,7 +269,7 @@ impl TryFrom> for Box<[T; N]> { /// /// Returns the old `Box<[T]>` in the `Err` variant if /// `boxed_slice.len()` does not equal `N`. - fn try_from(boxed_slice: Box<[T]>) -> Result { + fn try_from(boxed_slice: Box<[T], A>) -> Result { if boxed_slice.len() == N { // SAFETY: Checked length. Ok(unsafe { boxed_slice_as_array_unchecked(boxed_slice) }) @@ -281,8 +281,8 @@ impl TryFrom> for Box<[T; N]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")] -impl TryFrom> for Box<[T; N]> { - type Error = Vec; +impl TryFrom> for Box<[T; N], A> { + type Error = Vec; /// Attempts to convert a `Vec` into a `Box<[T; N]>`. /// @@ -302,7 +302,7 @@ impl TryFrom> for Box<[T; N]> { /// let state: Box<[f32; 100]> = vec![1.0; 100].try_into().unwrap(); /// assert_eq!(state.len(), 100); /// ``` - fn try_from(vec: Vec) -> Result { + fn try_from(vec: Vec) -> Result { if vec.len() == N { let boxed_slice = vec.into_boxed_slice(); // SAFETY: Checked length. diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 8d993f6758a52..59909ed1db9b2 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -15,6 +15,7 @@ use core::ops::{ use core::str::{FromStr, Utf8Error}; use core::{fmt, hash}; +use crate::alloc::Allocator; use crate::borrow::{Cow, ToOwned}; use crate::boxed::Box; #[cfg(not(no_rc))] @@ -597,10 +598,10 @@ impl<'a> TryFrom<&'a ByteString> for &'a str { // Additional impls for `ByteStr` that require types from `alloc`: #[unstable(feature = "bstr", issue = "134915")] -impl Clone for Box { +impl Clone for Box { #[inline] fn clone(&self) -> Self { - Self::from(Box::<[u8]>::from(&self.0)) + Box::clone_from_ref_in(&**self, Self::allocator(self).clone()) } } diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index 78158cad394c6..d13808ee3d21c 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -7,6 +7,7 @@ use core::slice::memchr; use core::str::{self, FromStr, Utf8Error}; use core::{fmt, mem, ops, ptr, slice}; +use crate::alloc::Allocator; use crate::borrow::{Cow, ToOwned}; use crate::boxed::Box; use crate::rc::Rc; @@ -863,10 +864,10 @@ impl TryFrom for String { } #[stable(feature = "more_box_slice_clone", since = "1.29.0")] -impl Clone for Box { +impl Clone for Box { #[inline] fn clone(&self) -> Self { - (**self).into() + Box::clone_from_ref_in(&**self, Self::allocator(self).clone()) } } diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 6be8f775b441d..b9d344284734b 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -5,6 +5,7 @@ mod tests; use core::clone::CloneToUninit; +use crate::alloc::Allocator; use crate::borrow::{Borrow, Cow}; use crate::collections::TryReserveError; use crate::hash::{Hash, Hasher}; @@ -1395,10 +1396,10 @@ impl From for Box { } #[stable(feature = "more_box_slice_clone", since = "1.29.0")] -impl Clone for Box { +impl Clone for Box { #[inline] fn clone(&self) -> Self { - self.to_os_string().into_boxed_os_str() + Box::clone_from_ref_in(&**self, Self::allocator(self).clone()) } } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index fe72ad4692c02..1f45423bd8285 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -83,6 +83,7 @@ use core::clone::CloneToUninit; +use crate::alloc::Allocator; use crate::borrow::{Borrow, Cow}; use crate::collections::TryReserveError; use crate::error::Error; @@ -1972,10 +1973,10 @@ impl From for Box { } #[stable(feature = "more_box_slice_clone", since = "1.29.0")] -impl Clone for Box { +impl Clone for Box { #[inline] fn clone(&self) -> Self { - self.to_path_buf().into_boxed_path() + Box::clone_from_ref_in(&**self, Self::allocator(self).clone()) } } diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile index 6a5bdf05157bb..911bb168d2489 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile @@ -52,6 +52,10 @@ WORKDIR /tmp RUN mkdir /home/user COPY scripts/shared.sh /tmp/ +# GCC needs make >= 4 +COPY scripts/build-make.sh /tmp/ +RUN ./build-make.sh + # Need at least GCC 5.1 to compile LLVM nowadays COPY scripts/build-gcc.sh /tmp/ ENV GCC_VERSION=9.5.0 diff --git a/src/ci/docker/scripts/build-make.sh b/src/ci/docker/scripts/build-make.sh new file mode 100755 index 0000000000000..eb2bcfcf9a377 --- /dev/null +++ b/src/ci/docker/scripts/build-make.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -ex + +MAKE_VERSION="4.4.1" +curl -f "https://ci-mirrors.rust-lang.org/rustc/gcc/make-${MAKE_VERSION}.tar.gz" | tar xzf - +cd "make-${MAKE_VERSION}" +./configure --prefix=/rustroot +make +make install +cd .. +rm -rf "make-${MAKE_VERSION}" diff --git a/tests/codegen-llvm/loongarch-abi/loongarch64-lp64d-abi.rs b/tests/codegen-llvm/loongarch-abi/loongarch64-lp64d-abi.rs index 68f1267c2a444..5712aba612e5a 100644 --- a/tests/codegen-llvm/loongarch-abi/loongarch64-lp64d-abi.rs +++ b/tests/codegen-llvm/loongarch-abi/loongarch64-lp64d-abi.rs @@ -297,3 +297,5 @@ pub extern "C" fn f_double_u_arg(a: DoubleU) {} pub extern "C" fn f_ret_double_u() -> DoubleU { unsafe { DoubleU { a: 1. } } } + +// CHECK: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64d"} diff --git a/tests/ui/self/suggest-self-2.stderr b/tests/ui/self/suggest-self-2.stderr index 4bd025ea07630..90d2e5b7aa7f3 100644 --- a/tests/ui/self/suggest-self-2.stderr +++ b/tests/ui/self/suggest-self-2.stderr @@ -2,25 +2,37 @@ error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:5:9 | LL | bar(self); - | ^^^------ - | | - | help: try calling `bar` as a method: `self.bar()` + | ^^^ + | +help: try calling `bar` as a method + | +LL - bar(self); +LL + self.bar(); + | error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:9:9 | LL | bar(&&self, 102); - | ^^^------------- - | | - | help: try calling `bar` as a method: `self.bar(102)` + | ^^^ + | +help: try calling `bar` as a method + | +LL - bar(&&self, 102); +LL + self.bar(102); + | error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:13:9 | LL | bar(&mut self, 102, &"str"); - | ^^^------------------------ - | | - | help: try calling `bar` as a method: `self.bar(102, &"str")` + | ^^^ + | +help: try calling `bar` as a method + | +LL - bar(&mut self, 102, &"str"); +LL + self.bar(102, &"str"); + | error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:17:9