Skip to content
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
32 changes: 24 additions & 8 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FieldIdx: Idx, VariantIdx: Idx> {
/// 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,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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})"),
Expand Down
12 changes: 6 additions & 6 deletions library/alloc/src/boxed/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ unsafe fn boxed_slice_as_array_unchecked<T, A: Allocator, const N: usize>(
}

#[stable(feature = "boxed_slice_try_from", since = "1.43.0")]
impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
type Error = Box<[T]>;
impl<T, const N: usize, A: Allocator> TryFrom<Box<[T], A>> for Box<[T; N], A> {
type Error = Box<[T], A>;

/// Attempts to convert a `Box<[T]>` into a `Box<[T; N]>`.
///
Expand All @@ -269,7 +269,7 @@ impl<T, const N: usize> TryFrom<Box<[T]>> 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<Self, Self::Error> {
fn try_from(boxed_slice: Box<[T], A>) -> Result<Self, Self::Error> {
if boxed_slice.len() == N {
// SAFETY: Checked length.
Ok(unsafe { boxed_slice_as_array_unchecked(boxed_slice) })
Expand All @@ -281,8 +281,8 @@ impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")]
impl<T, const N: usize> TryFrom<Vec<T>> for Box<[T; N]> {
type Error = Vec<T>;
impl<T, const N: usize, A: Allocator> TryFrom<Vec<T, A>> for Box<[T; N], A> {
type Error = Vec<T, A>;

/// Attempts to convert a `Vec<T>` into a `Box<[T; N]>`.
///
Expand All @@ -302,7 +302,7 @@ impl<T, const N: usize> TryFrom<Vec<T>> 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<T>) -> Result<Self, Self::Error> {
fn try_from(vec: Vec<T, A>) -> Result<Self, Self::Error> {
if vec.len() == N {
let boxed_slice = vec.into_boxed_slice();
// SAFETY: Checked length.
Expand Down
5 changes: 3 additions & 2 deletions library/alloc/src/bstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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<ByteStr> {
impl<A: Allocator + Clone> Clone for Box<ByteStr, A> {
#[inline]
fn clone(&self) -> Self {
Self::from(Box::<[u8]>::from(&self.0))
Box::clone_from_ref_in(&**self, Self::allocator(self).clone())
}
}

Expand Down
5 changes: 3 additions & 2 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -863,10 +864,10 @@ impl TryFrom<CString> for String {
}

#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
impl Clone for Box<CStr> {
impl<A: Allocator + Clone> Clone for Box<CStr, A> {
#[inline]
fn clone(&self) -> Self {
(**self).into()
Box::clone_from_ref_in(&**self, Self::allocator(self).clone())
}
}

Expand Down
5 changes: 3 additions & 2 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1395,10 +1396,10 @@ impl From<OsString> for Box<OsStr> {
}

#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
impl Clone for Box<OsStr> {
impl<A: Allocator + Clone> Clone for Box<OsStr, A> {
#[inline]
fn clone(&self) -> Self {
self.to_os_string().into_boxed_os_str()
Box::clone_from_ref_in(&**self, Self::allocator(self).clone())
}
}

Expand Down
5 changes: 3 additions & 2 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1972,10 +1973,10 @@ impl From<PathBuf> for Box<Path> {
}

#[stable(feature = "more_box_slice_clone", since = "1.29.0")]
impl Clone for Box<Path> {
impl<A: Allocator + Clone> Clone for Box<Path, A> {
#[inline]
fn clone(&self) -> Self {
self.to_path_buf().into_boxed_path()
Box::clone_from_ref_in(&**self, Self::allocator(self).clone())
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/ci/docker/scripts/build-make.sh
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 2 additions & 0 deletions tests/codegen-llvm/loongarch-abi/loongarch64-lp64d-abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
30 changes: 21 additions & 9 deletions tests/ui/self/suggest-self-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading