diff --git a/Cargo.lock b/Cargo.lock index 6afbc7d22f098..cfed18eee113c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1665,7 +1665,6 @@ dependencies = [ "allocator-api2", "equivalent", "foldhash 0.1.5", - "serde", ] [[package]] @@ -1675,6 +1674,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ "foldhash 0.2.0", + "serde", + "serde_core", ] [[package]] @@ -1898,9 +1899,9 @@ dependencies = [ [[package]] name = "id-arena" -version = "2.2.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" [[package]] name = "ident_case" @@ -6152,9 +6153,9 @@ dependencies = [ [[package]] name = "wasm-component-ld" -version = "0.5.20" +version = "0.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "846d20ed66ae37b7a237e36dfcd2fdc979eae82a46cdb0586f9bba80782fd789" +checksum = "59dcd765f510df84d1677a502c49057761486597a95950b4c92153e5707af091" dependencies = [ "anyhow", "clap", @@ -6163,7 +6164,7 @@ dependencies = [ "libc", "tempfile", "wasi-preview1-component-adapter-provider", - "wasmparser 0.243.0", + "wasmparser 0.245.1", "wat", "windows-sys 0.61.2", "winsplit", @@ -6190,24 +6191,24 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.243.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55db9c896d70bd9fa535ce83cd4e1f2ec3726b0edd2142079f594fc3be1cb35" +checksum = "3f9dca005e69bf015e45577e415b9af8c67e8ee3c0e38b5b0add5aa92581ed5c" dependencies = [ "leb128fmt", - "wasmparser 0.243.0", + "wasmparser 0.245.1", ] [[package]] name = "wasm-metadata" -version = "0.243.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae05bf9579f45a62e8d0a4e3f52eaa8da518883ac5afa482ec8256c329ecd56" +checksum = "da55e60097e8b37b475a0fa35c3420dd71d9eb7bd66109978ab55faf56a57efb" dependencies = [ "anyhow", "indexmap", - "wasm-encoder 0.243.0", - "wasmparser 0.243.0", + "wasm-encoder 0.245.1", + "wasmparser 0.245.1", ] [[package]] @@ -6232,12 +6233,12 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.243.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d8db401b0528ec316dfbe579e6ab4152d61739cfe076706d2009127970159d" +checksum = "4f08c9adee0428b7bddf3890fc27e015ac4b761cc608c822667102b8bfd6995e" dependencies = [ "bitflags", - "hashbrown 0.15.5", + "hashbrown 0.16.1", "indexmap", "semver", "serde", @@ -6245,22 +6246,22 @@ dependencies = [ [[package]] name = "wast" -version = "243.0.0" +version = "245.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df21d01c2d91e46cb7a221d79e58a2d210ea02020d57c092e79255cc2999ca7f" +checksum = "28cf1149285569120b8ce39db8b465e8a2b55c34cbb586bd977e43e2bc7300bf" dependencies = [ "bumpalo", "leb128fmt", "memchr", "unicode-width 0.2.2", - "wasm-encoder 0.243.0", + "wasm-encoder 0.245.1", ] [[package]] name = "wat" -version = "1.243.0" +version = "1.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "226a9a91cd80a50449312fef0c75c23478fcecfcc4092bdebe1dc8e760ef521b" +checksum = "cd48d1679b6858988cb96b154dda0ec5bbb09275b71db46057be37332d5477be" dependencies = [ "wast", ] @@ -6707,9 +6708,9 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.243.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36f9fc53513e461ce51dcf17a3e331752cb829f1d187069e54af5608fc998fe4" +checksum = "4894f10d2d5cbc17c77e91f86a1e48e191a788da4425293b55c98b44ba3fcac9" dependencies = [ "anyhow", "bitflags", @@ -6718,19 +6719,20 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "wasm-encoder 0.243.0", + "wasm-encoder 0.245.1", "wasm-metadata", - "wasmparser 0.243.0", + "wasmparser 0.245.1", "wit-parser", ] [[package]] name = "wit-parser" -version = "0.243.0" +version = "0.245.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df983a8608e513d8997f435bb74207bf0933d0e49ca97aa9d8a6157164b9b7fc" +checksum = "330698718e82983499419494dd1e3d7811a457a9bf9f69734e8c5f07a2547929" dependencies = [ "anyhow", + "hashbrown 0.16.1", "id-arena", "indexmap", "log", @@ -6739,7 +6741,7 @@ dependencies = [ "serde_derive", "serde_json", "unicode-xid", - "wasmparser 0.243.0", + "wasmparser 0.245.1", ] [[package]] diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 88f8b7cc51704..2a783cd73d9de 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -1036,6 +1036,19 @@ impl Align { // LLVM has a maximal supported alignment of 2^29, we inherit that. pub const MAX: Align = Align { pow2: 29 }; + /// Either `1 << (pointer_bits - 1)` or [`Align::MAX`], whichever is smaller. + #[inline] + pub fn max_for_target(tdl: &TargetDataLayout) -> Align { + let pointer_bits = tdl.pointer_size().bits(); + if let Ok(pointer_bits) = u8::try_from(pointer_bits) + && pointer_bits <= Align::MAX.pow2 + { + Align { pow2: pointer_bits - 1 } + } else { + Align::MAX + } + } + #[inline] pub fn from_bits(bits: u64) -> Result { Align::from_bytes(Size::from_bits(bits).bytes()) diff --git a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs index f5ee9406f4bf1..fd0c7c656ac21 100644 --- a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs +++ b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs @@ -1,4 +1,4 @@ -use rustc_abi::WrappingRange; +use rustc_abi::{Align, WrappingRange}; use rustc_middle::mir::SourceInfo; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; @@ -179,9 +179,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let size_bound = bx.data_layout().ptr_sized_integer().signed_max() as u128; bx.range_metadata(value, WrappingRange { start: 0, end: size_bound }); } - // Alignment is always nonzero. + // Alignment is always a power of two, thus 1..=0x800…000, + // but also bounded by the maximum we support in type layout. sym::vtable_align => { - bx.range_metadata(value, WrappingRange { start: 1, end: !0 }) + let align_bound = Align::max_for_target(bx.data_layout()).bytes().into(); + bx.range_metadata(value, WrappingRange { start: 1, end: align_bound }) } _ => {} } diff --git a/compiler/rustc_codegen_ssa/src/size_of_val.rs b/compiler/rustc_codegen_ssa/src/size_of_val.rs index e1bd8014d7a2f..52ffc321cbb6f 100644 --- a/compiler/rustc_codegen_ssa/src/size_of_val.rs +++ b/compiler/rustc_codegen_ssa/src/size_of_val.rs @@ -1,6 +1,6 @@ //! Computing the size and alignment of a value. -use rustc_abi::WrappingRange; +use rustc_abi::{Align, WrappingRange}; use rustc_hir::LangItem; use rustc_middle::bug; use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths}; @@ -36,8 +36,10 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( // Size is always <= isize::MAX. let size_bound = bx.data_layout().ptr_sized_integer().signed_max() as u128; bx.range_metadata(size, WrappingRange { start: 0, end: size_bound }); - // Alignment is always nonzero. - bx.range_metadata(align, WrappingRange { start: 1, end: !0 }); + // Alignment is always a power of two, thus 1..=0x800…000, + // but also bounded by the maximum we support in type layout. + let align_bound = Align::max_for_target(bx.data_layout()).bytes().into(); + bx.range_metadata(align, WrappingRange { start: 1, end: align_bound }); (size, align) } diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 471aa4384984a..8df75148346a7 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -98,6 +98,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => { /* cannot have a non-rust abi */ } } + if self.is_scalable_vector_ctor(autoderef.final_ty()) { + let mut err = self.dcx().create_err(errors::ScalableVectorCtor { + span: callee_expr.span, + ty: autoderef.final_ty(), + }); + err.span_label(callee_expr.span, "you can create scalable vectors using intrinsics"); + Ty::new_error(self.tcx, err.emit()); + } + self.register_predicates(autoderef.into_obligations()); let output = match result { @@ -420,6 +429,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { None } + fn is_scalable_vector_ctor(&self, callee_ty: Ty<'_>) -> bool { + if let ty::FnDef(def_id, _) = callee_ty.kind() + && let def::DefKind::Ctor(def::CtorOf::Struct, _) = self.tcx.def_kind(def_id) + { + self.tcx + .opt_parent(*def_id) + .and_then(|id| self.tcx.adt_def(id).repr().scalable) + .is_some() + } else { + false + } + } + /// Give appropriate suggestion when encountering `||{/* not callable */}()`, where the /// likely intention is to call the closure, suggest `(||{})()`. (#55851) fn identify_bad_closure_def_and_call( diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs index 7e81abd1df293..5c44836adcd01 100644 --- a/compiler/rustc_hir_typeck/src/errors.rs +++ b/compiler/rustc_hir_typeck/src/errors.rs @@ -569,6 +569,14 @@ pub(crate) struct InvalidCallee<'tcx> { pub found: String, } +#[derive(Diagnostic)] +#[diag("scalable vector types cannot be initialised using their constructor")] +pub(crate) struct ScalableVectorCtor<'tcx> { + #[primary_span] + pub span: Span, + pub ty: Ty<'tcx>, +} + #[derive(Diagnostic)] #[diag("cannot cast `{$expr_ty}` to a pointer that {$known_wide -> [true] is diff --git a/library/alloctests/tests/lib.rs b/library/alloctests/tests/lib.rs index 699a5010282b0..f18d6e1bb3794 100644 --- a/library/alloctests/tests/lib.rs +++ b/library/alloctests/tests/lib.rs @@ -33,7 +33,6 @@ #![feature(thin_box)] #![feature(drain_keep_rest)] #![feature(local_waker)] -#![feature(str_as_str)] #![feature(strict_provenance_lints)] #![feature(string_replace_in_place)] #![feature(vec_deque_truncate_front)] diff --git a/library/core/src/bstr/mod.rs b/library/core/src/bstr/mod.rs index 34e1ea66c99ad..3e3b78b452e01 100644 --- a/library/core/src/bstr/mod.rs +++ b/library/core/src/bstr/mod.rs @@ -74,7 +74,6 @@ impl ByteStr { /// it helps dereferencing other "container" types, /// for example `Box` or `Arc`. #[inline] - // #[unstable(feature = "str_as_str", issue = "130366")] #[unstable(feature = "bstr", issue = "134915")] pub const fn as_byte_str(&self) -> &ByteStr { self @@ -86,7 +85,6 @@ impl ByteStr { /// it helps dereferencing other "container" types, /// for example `Box` or `MutexGuard`. #[inline] - // #[unstable(feature = "str_as_str", issue = "130366")] #[unstable(feature = "bstr", issue = "134915")] pub const fn as_mut_byte_str(&mut self) -> &mut ByteStr { self diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 621277179bb38..8097066a57339 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -655,7 +655,8 @@ impl CStr { /// it helps dereferencing other string-like types to string slices, /// for example references to `Box` or `Arc`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_c_str(&self) -> &CStr { self } diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 36dd4d6782ac1..ac3088142f7df 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -5337,7 +5337,8 @@ impl [T] { /// it helps dereferencing other "container" types to slices, /// for example `Box<[T]>` or `Arc<[T]>`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_slice(&self) -> &[T] { self } @@ -5348,7 +5349,8 @@ impl [T] { /// it helps dereferencing other "container" types to slices, /// for example `Box<[T]>` or `MutexGuard<[T]>`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_mut_slice(&mut self) -> &mut [T] { self } diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 98354643aa405..2d7fdb824d1f8 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -3137,7 +3137,8 @@ impl str { /// it helps dereferencing other string-like types to string slices, /// for example references to `Box` or `Arc`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_str(&self) -> &str { self } diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index ca910153e5260..6b4cf3cea831c 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1285,7 +1285,8 @@ impl OsStr { /// it helps dereferencing other string-like types to string slices, /// for example references to `Box` or `Arc`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_os_str(&self) -> &OsStr { self } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index bf27df7b04281..712031ff7ccb1 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -3235,7 +3235,8 @@ impl Path { /// it helps dereferencing other `PathBuf`-like types to `Path`s, /// for example references to `Box` or `Arc`. #[inline] - #[unstable(feature = "str_as_str", issue = "130366")] + #[stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "str_as_str", since = "CURRENT_RUSTC_VERSION")] pub const fn as_path(&self) -> &Path { self } diff --git a/library/std/tests/sync/oneshot.rs b/library/std/tests/sync/oneshot.rs index 8e63a26fa3ac8..6eaacfbc6497d 100644 --- a/library/std/tests/sync/oneshot.rs +++ b/library/std/tests/sync/oneshot.rs @@ -243,7 +243,9 @@ fn recv_deadline_passed() { } assert!(start.elapsed() >= timeout); - assert!(start.elapsed() < timeout * 3); + // FIXME(#152878): An upper-bound assertion on the elapsed time was removed, + // because CI runners can starve individual threads for a surprisingly long + // time, leading to flaky failures. } #[test] @@ -252,12 +254,16 @@ fn recv_time_passed() { let start = Instant::now(); let timeout = Duration::from_millis(100); + match receiver.recv_timeout(timeout) { Err(RecvTimeoutError::Timeout(_)) => {} _ => panic!("expected timeout error"), } + assert!(start.elapsed() >= timeout); - assert!(start.elapsed() < timeout * 3); + // FIXME(#152878): An upper-bound assertion on the elapsed time was removed, + // because CI runners can starve individual threads for a surprisingly long + // time, leading to flaky failures. } #[test] diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 9df9db5b4b69c..fce3269b149a0 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -504,12 +504,11 @@ impl<'test> TestCx<'test> { let normalized_revision = normalize_revision(revision); let cfg_arg = ["--cfg", &normalized_revision]; let arg = format!("--cfg={normalized_revision}"); - if self - .props - .compile_flags - .windows(2) - .any(|args| args == cfg_arg || args[0] == arg || args[1] == arg) - { + // Handle if compile_flags is length 1 + let contains_arg = + self.props.compile_flags.iter().any(|considered_arg| *considered_arg == arg); + let contains_cfg_arg = self.props.compile_flags.windows(2).any(|args| args == cfg_arg); + if contains_arg || contains_cfg_arg { error!( "redundant cfg argument `{normalized_revision}` is already created by the \ revision" diff --git a/src/tools/wasm-component-ld/Cargo.toml b/src/tools/wasm-component-ld/Cargo.toml index 2d44358c74334..3f20b9e3fa12e 100644 --- a/src/tools/wasm-component-ld/Cargo.toml +++ b/src/tools/wasm-component-ld/Cargo.toml @@ -10,4 +10,4 @@ name = "wasm-component-ld" path = "src/main.rs" [dependencies] -wasm-component-ld = "0.5.20" +wasm-component-ld = "0.5.21" diff --git a/tests/codegen-llvm/dst-vtable-align-nonzero.rs b/tests/codegen-llvm/dst-vtable-align-nonzero.rs index 1404bd64f500c..2eee91876683c 100644 --- a/tests/codegen-llvm/dst-vtable-align-nonzero.rs +++ b/tests/codegen-llvm/dst-vtable-align-nonzero.rs @@ -64,4 +64,4 @@ pub unsafe fn align_load_from_vtable_align_intrinsic(x: &dyn Trait) -> usize { core::intrinsics::vtable_align(vtable) } -// CHECK: [[RANGE_META]] = !{[[USIZE]] 1, [[USIZE]] 0} +// CHECK: [[RANGE_META]] = !{[[USIZE]] 1, [[USIZE]] [[#0x20000001]] diff --git a/tests/mir-opt/pre-codegen/copy_and_clone.rs b/tests/mir-opt/pre-codegen/copy_and_clone.rs index 05da25afa2a39..eb3c2eacc248b 100644 --- a/tests/mir-opt/pre-codegen/copy_and_clone.rs +++ b/tests/mir-opt/pre-codegen/copy_and_clone.rs @@ -1,4 +1,3 @@ -//@ [COPY] compile-flags: --cfg=copy //@ revisions: COPY CLONE // Test case from https://github.com/rust-lang/rust/issues/128081. diff --git a/tests/ui/scalable-vectors/illegal_init.rs b/tests/ui/scalable-vectors/illegal_init.rs new file mode 100644 index 0000000000000..e8c0447fea422 --- /dev/null +++ b/tests/ui/scalable-vectors/illegal_init.rs @@ -0,0 +1,10 @@ +#![allow(incomplete_features, internal_features)] +#![feature(rustc_attrs)] + +#[rustc_scalable_vector(4)] +#[allow(non_camel_case_types)] +struct svint32_t(i32); +fn main() { + let foo = svint32_t(1); + //~^ ERROR: scalable vector types cannot be initialised using their constructor +} diff --git a/tests/ui/scalable-vectors/illegal_init.stderr b/tests/ui/scalable-vectors/illegal_init.stderr new file mode 100644 index 0000000000000..db0fffcf3b772 --- /dev/null +++ b/tests/ui/scalable-vectors/illegal_init.stderr @@ -0,0 +1,8 @@ +error: scalable vector types cannot be initialised using their constructor + --> $DIR/illegal_init.rs:8:15 + | +LL | let foo = svint32_t(1); + | ^^^^^^^^^ you can create scalable vectors using intrinsics + +error: aborting due to 1 previous error +