From 46dd39c31f787f51d3ddc894d21fef35a1a82573 Mon Sep 17 00:00:00 2001 From: malezjaa Date: Sat, 12 Sep 2026 23:55:17 +0200 Subject: [PATCH 01/16] regression test for unconstrained const args --- .../mgca/unconstrained-type-params.rs | 12 ++++++++++++ .../mgca/unconstrained-type-params.stderr | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/ui/const-generics/mgca/unconstrained-type-params.rs create mode 100644 tests/ui/const-generics/mgca/unconstrained-type-params.stderr diff --git a/tests/ui/const-generics/mgca/unconstrained-type-params.rs b/tests/ui/const-generics/mgca/unconstrained-type-params.rs new file mode 100644 index 0000000000000..7b9688f53818f --- /dev/null +++ b/tests/ui/const-generics/mgca/unconstrained-type-params.rs @@ -0,0 +1,12 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/146906 + +#![feature(min_generic_const_args)] + +trait Trait {} + +impl Trait for [(); N] {} +//~^ ERROR mismatched types + +fn N(f: impl FnOnce(f64) -> f64 + Trait) {} + +fn main() {} diff --git a/tests/ui/const-generics/mgca/unconstrained-type-params.stderr b/tests/ui/const-generics/mgca/unconstrained-type-params.stderr new file mode 100644 index 0000000000000..da3f64aedb15b --- /dev/null +++ b/tests/ui/const-generics/mgca/unconstrained-type-params.stderr @@ -0,0 +1,13 @@ +error[E0308]: mismatched types + --> $DIR/unconstrained-type-params.rs:7:21 + | +LL | impl Trait for [(); N] {} + | ^ expected `usize`, found fn item + | + = note: expected type `usize` + found fn item `fn(_) {N::<_>}` + = note: array length can only be `usize` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. From e7b3b140d9aad21a4c7a3de20648e6492a3e5447 Mon Sep 17 00:00:00 2001 From: Yukang Date: Tue, 22 Sep 2026 00:00:27 +0800 Subject: [PATCH 02/16] Add regression test for mutable closure argument suggestions --- tests/ui/suggestions/as-mut-closure.rs | 33 ++++++ tests/ui/suggestions/as-mut-closure.stderr | 111 +++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 tests/ui/suggestions/as-mut-closure.rs create mode 100644 tests/ui/suggestions/as-mut-closure.stderr diff --git a/tests/ui/suggestions/as-mut-closure.rs b/tests/ui/suggestions/as-mut-closure.rs new file mode 100644 index 0000000000000..ab1c8bff5bf77 --- /dev/null +++ b/tests/ui/suggestions/as-mut-closure.rs @@ -0,0 +1,33 @@ +// Borrowing a container for a closure argument must preserve the expected mutability. + +#![allow(unused_mut)] + +fn append(value: &mut String) { + value.push('!'); +} + +fn increment(value: &mut i32) { + *value += 1; +} + +fn main() { + let mut option = Some(String::new()); + let _ = option.map(|arg| append(arg)); + //~^ ERROR mismatched types + let _ = (&mut option).and_then(|arg| Some(append(arg))); + //~^ ERROR mismatched types + + let mut result: Result<_, ()> = Ok(String::new()); + let _ = result.map(|arg| append(arg)); + //~^ ERROR mismatched types + let _ = (&mut result).and_then(|arg| Ok(append(arg))); + //~^ ERROR mismatched types + + // A shared reference cannot supply `as_mut()`. Borrow the copied argument instead. + let shared = &Some(0); + let _ = shared.map(|mut arg| increment(arg)); + //~^ ERROR mismatched types + let nested = &mut &Some(0); + let _ = nested.map(|mut arg| increment(arg)); + //~^ ERROR mismatched types +} diff --git a/tests/ui/suggestions/as-mut-closure.stderr b/tests/ui/suggestions/as-mut-closure.stderr new file mode 100644 index 0000000000000..c133641b6a5a7 --- /dev/null +++ b/tests/ui/suggestions/as-mut-closure.stderr @@ -0,0 +1,111 @@ +error[E0308]: mismatched types + --> $DIR/as-mut-closure.rs:15:37 + | +LL | let _ = option.map(|arg| append(arg)); + | ------ ^^^ expected `&mut String`, found `String` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/as-mut-closure.rs:5:4 + | +LL | fn append(value: &mut String) { + | ^^^^^^ ------------------ +help: consider using `as_ref` instead + | +LL | let _ = option.as_ref().map(|arg| append(arg)); + | +++++++++ + +error[E0308]: mismatched types + --> $DIR/as-mut-closure.rs:17:54 + | +LL | let _ = (&mut option).and_then(|arg| Some(append(arg))); + | ------ ^^^ expected `&mut String`, found `String` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/as-mut-closure.rs:5:4 + | +LL | fn append(value: &mut String) { + | ^^^^^^ ------------------ +help: consider using `as_ref` instead + | +LL | let _ = (&mut option).as_ref().and_then(|arg| Some(append(arg))); + | +++++++++ + +error[E0308]: mismatched types + --> $DIR/as-mut-closure.rs:21:37 + | +LL | let _ = result.map(|arg| append(arg)); + | ------ ^^^ expected `&mut String`, found `String` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/as-mut-closure.rs:5:4 + | +LL | fn append(value: &mut String) { + | ^^^^^^ ------------------ +help: consider using `as_ref` instead + | +LL | let _ = result.as_ref().map(|arg| append(arg)); + | +++++++++ + +error[E0308]: mismatched types + --> $DIR/as-mut-closure.rs:23:52 + | +LL | let _ = (&mut result).and_then(|arg| Ok(append(arg))); + | ------ ^^^ expected `&mut String`, found `String` + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/as-mut-closure.rs:5:4 + | +LL | fn append(value: &mut String) { + | ^^^^^^ ------------------ +help: consider using `as_ref` instead + | +LL | let _ = (&mut result).as_ref().and_then(|arg| Ok(append(arg))); + | +++++++++ + +error[E0308]: mismatched types + --> $DIR/as-mut-closure.rs:28:44 + | +LL | let _ = shared.map(|mut arg| increment(arg)); + | --------- ^^^ expected `&mut i32`, found integer + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/as-mut-closure.rs:9:4 + | +LL | fn increment(value: &mut i32) { + | ^^^^^^^^^ --------------- +help: consider using `as_ref` instead + | +LL | let _ = shared.as_ref().map(|mut arg| increment(arg)); + | +++++++++ + +error[E0308]: mismatched types + --> $DIR/as-mut-closure.rs:31:44 + | +LL | let _ = nested.map(|mut arg| increment(arg)); + | --------- ^^^ expected `&mut i32`, found integer + | | + | arguments to this function are incorrect + | +note: function defined here + --> $DIR/as-mut-closure.rs:9:4 + | +LL | fn increment(value: &mut i32) { + | ^^^^^^^^^ --------------- +help: consider using `as_ref` instead + | +LL | let _ = nested.as_ref().map(|mut arg| increment(arg)); + | +++++++++ + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0308`. From a748eaedff6c55cab762add747a011271d93a0e8 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 22 Sep 2026 10:35:09 -0700 Subject: [PATCH 03/16] std: Update `wasip3` crate dependency Keeping it up-to-date and resolving minor issues with it. --- library/Cargo.lock | 12 ++++++------ library/std/Cargo.toml | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/Cargo.lock b/library/Cargo.lock index 3ddddbd5985b7..98fa2c5117411 100644 --- a/library/Cargo.lock +++ b/library/Cargo.lock @@ -426,9 +426,9 @@ dependencies = [ [[package]] name = "wasip2" -version = "2.0.0+wasi-0.2.12" +version = "2.0.1+wasi-0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96744b5e833bfd2d84c6faa7569693ce9e04a47c0a4d5519e6442f18af1a0fed" +checksum = "89aafd4b69fb41a64cfd5d7f214cde92ab422ec4d9bcd55fcc816d3f5f49bbf3" dependencies = [ "rustc-std-workspace-alloc", "rustc-std-workspace-core", @@ -437,9 +437,9 @@ dependencies = [ [[package]] name = "wasip3" -version = "0.8.0+wasi-0.3.0" +version = "0.9.0+wasi-0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a999271e77c083825863fc85404197523b3f3cebe9b402aece658ebea90065" +checksum = "f1d5749fdf69bb9400562eba50f8f25f5cd800ef4b74300038b6f99ae7409674" dependencies = [ "rustc-std-workspace-alloc", "rustc-std-workspace-core", @@ -456,9 +456,9 @@ version = "0.61.100" [[package]] name = "wit-bindgen" -version = "0.61.1" +version = "0.62.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e473fd0095479f9689ac7d2a52c427cc96bb2b973ace50238dfcc1ab1cd52d93" +checksum = "53cb4b5556c3a791e86838ea287782bdafa704d55b0e68b5b81a3a16b9ea5f4b" dependencies = [ "rustc-std-workspace-alloc", "rustc-std-workspace-core", diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index de5c1feadb298..1d35b42a53947 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -84,12 +84,12 @@ wasip1 = { version = "1.0.0", features = [ ], default-features = false } [target.'cfg(all(target_os = "wasi", target_env = "p2"))'.dependencies] -wasip2 = { version = '2.0.0', features = [ +wasip2 = { version = '2.0.1', features = [ 'rustc-dep-of-std', ], default-features = false } [target.'cfg(all(target_os = "wasi", target_env = "p3"))'.dependencies] -wasip3 = { version = '0.8.0', features = [ +wasip3 = { version = '0.9.0', features = [ 'rustc-dep-of-std', ], default-features = false } From 76c850e82b7ac6c81fefc4c1a82374f67ff02599 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Tue, 22 Sep 2026 20:42:24 +0200 Subject: [PATCH 04/16] document `#[rustc_dyn_incompatible_trait]` --- compiler/rustc_attr_ir/src/attribute_docs.rs | 60 +++++++++++++++++++ compiler/rustc_attr_ir/src/data_structures.rs | 2 +- .../rustc_dyn_incompatible_trait.rs | 8 +++ .../rustc_dyn_incompatible_trait.stderr | 18 ++++++ .../rustc_dyn_incompatible_trait2.rs | 52 ++++++++++++++++ 5 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait.rs create mode 100644 tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait.stderr create mode 100644 tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait2.rs diff --git a/compiler/rustc_attr_ir/src/attribute_docs.rs b/compiler/rustc_attr_ir/src/attribute_docs.rs index 4d40cd6d52f16..a2b00c90b3028 100644 --- a/compiler/rustc_attr_ir/src/attribute_docs.rs +++ b/compiler/rustc_attr_ir/src/attribute_docs.rs @@ -223,3 +223,63 @@ const _: () = (); /// /// [`vtable_entries`]: ../rustc_middle/ty/struct.TyCtxt.html#method.vtable_entries const _: () = (); + +#[doc(attribute = "rustc_dyn_incompatible_trait", alias = "rustc_do_not_implement_via_object")] +/// Opts a trait out of [dyn compatibility]. +/// +/// This is useful to reserve the ability to add dyn incompatible supertraits or methods to a trait +/// in the future and to ensure the soundness of various constructs - see below for more about that. +/// +/// For example [`Field`], [`FnPtr`], [`Tuple`], [`TransmuteFrom`], [`Sized`] and [`Unsize`] must +/// be dyn incompatible because these traits describe properties and layouts of types that would +/// be invalid for trait objects. +/// +/// While making a trait dyn incompatible can also be done by including a (hidden and/or unstable) +/// dyn incompatible method in the trait, using `#[rustc_dyn_incompatible_trait]` should be +/// preferred because it is self-documenting and generates better error messages. +/// +/// # Example +/// +#[doc = include_example!("rustc_dyn_incompatible_trait")] +/// +/// # Unsafe traits and dyn (in)compatibility +/// +/// [Recall] that a trait object (`dyn Trait`) implements the base trait, its auto traits, and any supertraits of +/// the base trait. This means that it's possible to run into subtle soundness problems when relying +/// on the safety contract of a dyn compatible unsafe trait. See the following example: +/// +// ignore-tidy-odd-backticks +/// ```should_panic +#[doc = include_str!("../../../tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait2.rs")] +// ignore-tidy-odd-backticks +/// ``` +/// +/// A solution for this is to make `UnsafeTrait` dyn incompatible, forcing `LocalTrait` to also be +/// dyn incompatible so that a `dyn LocalTrait` cannot be formed. This is what we ended up doing for +/// [#154619]. +/// +/// [`Allocator`] has had similar problems with [`Clone`] ([#156920]) +/// but as we really wanted `dyn Allocator` to be a thing we ended up not making it dyn +/// incompatible -- we ended up moving the safety contract to [`AllocatorClone`] instead. +/// +/// See also [#156917] and [#160045] for more examples of this problem. +/// +/// See [`AttributeKind::RustcDynIncompatibleTrait`] for the internal representation of this attribute. +/// +/// [`Allocator`]: core::alloc::Allocator +/// [`AllocatorClone`]: core::alloc::AllocatorClone +/// [`Clone`]: core::clone::Clone +/// [`Field`]: core::field::Field +// FIXME: use core::ops::FnPtr once trickled down to beta +/// [`FnPtr`]: https://doc.rust-lang.org/nightly/core/ops/trait.FnPtr.html +/// [`Tuple`]: core::marker::Tuple +/// [`TransmuteFrom`]: core::mem::TransmuteFrom +/// [`Sized`]: core::marker::Sized +/// [`Unsize`]: core::marker::Unsize +/// [dyn compatibility]: https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility +/// [recall]: https://doc.rust-lang.org/nightly/reference/types/trait-object.html#r-type.trait-object.impls +/// [#154619]: https://github.com/rust-lang/rust/issues/154619 "`deref_patterns` is unsound due to `dyn` of subtrait of `DerefPure`" +/// [#156917]: https://github.com/rust-lang/rust/issues/156917 "`dyn Allocator` together with `Allocator + PartialEq` safety requirements leads to unsoundness" +/// [#156920]:https://github.com/rust-lang/rust/issues/156920 "`dyn Allocator` together with `Allocator + Clone` requirements is unsound, leading to UB with `Arc`" +/// [#160045]:https://github.com/rust-lang/rust/issues/160045 "`iter::Rev`'s `TrustedLen` impl is unsound with trait objects" +const _: () = (); diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index d722d515582dc..712ed41ae7759 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -1267,7 +1267,7 @@ pub enum AttributeKind { /// Represents the [`rustc_dump_vtable`](./attribute.rustc_dump_vtable.html) attribute. RustcDumpVtable(Span), - /// Represents `#[rustc_dyn_incompatible_trait]`. + /// Represents the [`rustc_dyn_incompatible_trait`](./attribute.rustc_dyn_incompatible_trait.html) attribute. RustcDynIncompatibleTrait(Span), /// Represents `#[rustc_effective_visibility]`. diff --git a/tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait.rs b/tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait.rs new file mode 100644 index 0000000000000..912cdef5b60bb --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait.rs @@ -0,0 +1,8 @@ +//@ dont-require-annotations: ERROR +//@ compile-flags: --crate-type lib -Z ui-testing=no +#![feature(rustc_attrs)] + +#[rustc_dyn_incompatible_trait] +pub trait DynIncompatible {} + +pub fn f(_x: &dyn DynIncompatible) {} diff --git a/tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait.stderr b/tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait.stderr new file mode 100644 index 0000000000000..c871061a57507 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait.stderr @@ -0,0 +1,18 @@ +error[E0038]: the trait `DynIncompatible` is not dyn compatible + --> $DIR/rustc_dyn_incompatible_trait.rs:8:15 + | +8 | pub fn f(_x: &dyn DynIncompatible) {} + | ^^^^^^^^^^^^^^^^^^^ `DynIncompatible` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/rustc_dyn_incompatible_trait.rs:5:1 + | +5 | #[rustc_dyn_incompatible_trait] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because it opted out of dyn-compatibility +6 | pub trait DynIncompatible {} + | --------------- this trait is not dyn compatible... + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait2.rs b/tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait2.rs new file mode 100644 index 0000000000000..fd8b3ec4e2761 --- /dev/null +++ b/tests/ui/attributes/doc_examples/rustc_dyn_incompatible_trait2.rs @@ -0,0 +1,52 @@ +//@run-fail +mod foreign_crate { + /// # Safety requirements + /// + /// If this type also implements `SafeTrait`, + /// then that implementation must always return `true`. + pub unsafe trait UnsafeTrait {} + unsafe impl UnsafeTrait for &T {} + + pub trait SafeTrait { + fn returns_true(&self) -> bool; + } + impl SafeTrait for &T { + fn returns_true(&self) -> bool { + (*self).returns_true() + } + } + + impl SafeTrait for u8 { + fn returns_true(&self) -> bool { + true + } + } + /// Safety: impl returns `true`. + unsafe impl UnsafeTrait for u8 {} + + pub fn function(x: impl UnsafeTrait + SafeTrait) { + // Can't panic, after all, `x: UnsafeTrait` + // guarantees `returns_true` actually returns `true` + assert!(x.returns_true()); + } +} + +use foreign_crate::{SafeTrait, UnsafeTrait, function}; + +pub trait LocalTrait: UnsafeTrait {} +impl LocalTrait for T {} + +// We can do this because `dyn LocalTrait` is a local type. +// But `LocalTrait: UnsafeTrait`, so `dyn LocalTrait: UnsafeTrait` holds, +// and we don't have to `unsafe impl` it. +impl SafeTrait for dyn LocalTrait { + fn returns_true(&self) -> bool { + false + } +} + +fn main() { + let x = 42_u8; + let y: &dyn LocalTrait = &x; + function(y); // panics +} From 9b9cb70640a38e006a36b86e91975c6659802475 Mon Sep 17 00:00:00 2001 From: Manuel Drehwald Date: Tue, 22 Sep 2026 16:44:04 -0400 Subject: [PATCH 05/16] Stop embedding device code, now that the clang-linker-wrapper isn't consuming it anymore --- compiler/rustc_codegen_llvm/src/back/write.rs | 16 +--------------- compiler/rustc_codegen_llvm/src/diagnostics.rs | 4 ---- .../rustc_codegen_llvm/src/llvm/offload_ffi.rs | 16 ---------------- .../llvm-wrapper/offload/OffloadWrapper.cpp | 17 ----------------- 4 files changed, 1 insertion(+), 52 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 92989ba2dcf46..fa11a6abe6ed2 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -824,9 +824,7 @@ pub(crate) unsafe fn llvm_optimize( // This assumes that we previously compiled our kernels for a gpu target, which created a // `device.bin` artifact. The user is supposed to provide us with a path to this artifact, we - // don't need any other artifacts from the previous run. We will embed this artifact into our - // LLVM-IR host module, to create a `host.o` ObjectFile, which we will write to disk. - // The last, not yet automated steps uses the `clang-linker-wrapper` to process `host.o`. + // don't need any other artifacts from the previous run. if !cgcx.target_is_like_gpu && is_final_stage { if let Some(device_path) = config .offload @@ -850,18 +848,6 @@ pub(crate) unsafe fn llvm_optimize( let out_obj = host_dir.join("host.o"); let device_bin_c = path_to_c_string(device_pathbuf.as_path()); - // 2) Finalize host: lib.bc + device.bin -> host.o (host TM) - // We create a full clone of our LLVM host module, since we will embed the device IR - // into it, and this might break caching or incremental compilation otherwise. - let ok = unsafe { - llvm::RustOffloadWrapper::get_instance().llvm_rust_offload_embed_buffer_in_module( - module.module_llvm.llmod(), - device_bin_c.as_c_str(), - ) - }; - if !ok { - dcx.emit_err(crate::diagnostics::OffloadEmbedFailed); - } write_output_file( dcx, module.module_llvm.tm.raw(), diff --git a/compiler/rustc_codegen_llvm/src/diagnostics.rs b/compiler/rustc_codegen_llvm/src/diagnostics.rs index 78e502f13af75..d589c157cb9f0 100644 --- a/compiler/rustc_codegen_llvm/src/diagnostics.rs +++ b/compiler/rustc_codegen_llvm/src/diagnostics.rs @@ -101,10 +101,6 @@ pub(crate) struct OffloadNonexistingPath; #[diag("call to BundleImages failed, `device.bin` was not created")] pub(crate) struct OffloadBundleImagesFailed; -#[derive(Diagnostic)] -#[diag("call to EmbedBufferInModule failed, `host.o` was not created")] -pub(crate) struct OffloadEmbedFailed; - #[derive(Diagnostic)] #[diag("call to WrapImages failed, device image was not wrapped into the host module")] pub(crate) struct OffloadWrapImagesFailed; diff --git a/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs index fecb9e40eab88..da3da6bd7abd4 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs @@ -5,7 +5,6 @@ use std::sync::OnceLock; use super::ffi::{Module, TargetMachine, Value}; type LLVMRustBundleImagesFn = unsafe extern "C" fn(&Module, &TargetMachine, *const c_char) -> bool; -type LLVMRustOffloadEmbedBufferInModuleFn = unsafe extern "C" fn(&Module, *const c_char) -> bool; type LLVMRustOffloadMapperFn = unsafe extern "C" fn(&Value, &Value, *const &Value); type LLVMRustOffloadWrapImagesFn = unsafe extern "C" fn(&Module, *const c_char, *const c_char) -> bool; @@ -18,7 +17,6 @@ use crate::llvm; pub(crate) struct RustOffloadWrapper { LLVMRustBundleImages: LLVMRustBundleImagesFn, - LLVMRustOffloadEmbedBufferInModule: LLVMRustOffloadEmbedBufferInModuleFn, LLVMRustOffloadMapper: LLVMRustOffloadMapperFn, LLVMRustOffloadWrapImages: LLVMRustOffloadWrapImagesFn, lld_path: Option, @@ -65,14 +63,6 @@ impl RustOffloadWrapper { unsafe { (self.LLVMRustBundleImages)(m, tm, c.as_ptr()) } } - pub(crate) unsafe fn llvm_rust_offload_embed_buffer_in_module( - &self, - m: &Module, - i: &CStr, - ) -> bool { - unsafe { (self.LLVMRustOffloadEmbedBufferInModule)(m, i.as_ptr()) } - } - pub(crate) unsafe fn llvm_rust_offload_wrapper(&self, v1: &Value, v2: &Value, vs: &[&Value]) { unsafe { (self.LLVMRustOffloadMapper)(v1, v2, vs.as_ptr()) } } @@ -96,11 +86,6 @@ impl RustOffloadWrapper { let llvm_rust_bundle_images = *unsafe { lib.get::(b"LLVMRustBundleImages\0")? }; - let llvm_rust_offload_embed_buffer_in_module = *unsafe { - lib.get::( - b"LLVMRustOffloadEmbedBufferInModule\0", - )? - }; let llvm_rust_offload_wrapper = *unsafe { lib.get::(b"LLVMRustOffloadMapper\0")? }; let llvm_rust_offload_wrap_images = @@ -108,7 +93,6 @@ impl RustOffloadWrapper { Ok(Self { LLVMRustBundleImages: llvm_rust_bundle_images, - LLVMRustOffloadEmbedBufferInModule: llvm_rust_offload_embed_buffer_in_module, LLVMRustOffloadMapper: llvm_rust_offload_wrapper, LLVMRustOffloadWrapImages: llvm_rust_offload_wrap_images, lld_path, diff --git a/compiler/rustc_llvm/llvm-wrapper/offload/OffloadWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/offload/OffloadWrapper.cpp index bed54da0a7045..ca4d181179ffd 100644 --- a/compiler/rustc_llvm/llvm-wrapper/offload/OffloadWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/offload/OffloadWrapper.cpp @@ -28,7 +28,6 @@ #include "llvm/Target/TargetOptions.h" #include "llvm/TargetParser/Triple.h" #include "llvm/Transforms/Utils/Cloning.h" -#include "llvm/Transforms/Utils/ModuleUtils.h" #include "llvm/Transforms/Utils/ValueMapper.h" #include @@ -88,22 +87,6 @@ extern "C" bool LLVMRustBundleImages(LLVMModuleRef M, TargetMachine &TM, return true; } -extern "C" bool LLVMRustOffloadEmbedBufferInModule(LLVMModuleRef HostM, - const char *HostOutPath) { - auto MBOrErr = MemoryBuffer::getFile(HostOutPath); - if (!MBOrErr) { - auto E = MBOrErr.getError(); - auto _B = errorCodeToError(E); - return false; - } - MemoryBufferRef Buf = (*MBOrErr)->getMemBufferRef(); - Module *M = unwrap(HostM); - StringRef SectionName = ".llvm.offloading"; - Align Alignment = Align(8); - llvm::embedBufferInModule(*M, Buf, SectionName, Alignment); - return true; -} - // Clone OldFn into NewFn, remapping its arguments to RebuiltArgs. // Each arg of OldFn is replaced with the corresponding value in RebuiltArgs. // For scalars, RebuiltArgs contains the value cast and/or truncated to the From 4f20be313591a2bd1404bd85676ce38895330c77 Mon Sep 17 00:00:00 2001 From: Manuel Drehwald Date: Tue, 22 Sep 2026 16:50:51 -0400 Subject: [PATCH 06/16] also drop now unused host.o --- compiler/rustc_codegen_llvm/src/back/write.rs | 19 ------------------- .../offload/host-std-device-nostd/rmake.rs | 2 -- 2 files changed, 21 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index fa11a6abe6ed2..233e4a6b06612 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -843,26 +843,7 @@ pub(crate) unsafe fn llvm_optimize( } else if !device_pathbuf.exists() { dcx.emit_err(crate::diagnostics::OffloadNonexistingPath); } - let host_path = cgcx.output_filenames.path(OutputType::Object); - let host_dir = host_path.parent().unwrap(); - let out_obj = host_dir.join("host.o"); let device_bin_c = path_to_c_string(device_pathbuf.as_path()); - - write_output_file( - dcx, - module.module_llvm.tm.raw(), - config.no_builtins, - module.module_llvm.llmod(), - &out_obj, - None, - llvm::FileType::ObjectFile, - prof, - true, - ); - // We ignore cgcx.save_temps here and unconditionally always keep our `device.bin` artifact. - // Otherwise, recompiling the host code would fail since we deleted that device artifact - // in the previous host compilation, which would be confusing at best. - let ok = unsafe { llvm::RustOffloadWrapper::get_instance().llvm_rust_offload_wrap_images( module.module_llvm.llmod(), diff --git a/tests/run-make/offload/host-std-device-nostd/rmake.rs b/tests/run-make/offload/host-std-device-nostd/rmake.rs index 35f408e8b1cd0..6769993f9cf98 100644 --- a/tests/run-make/offload/host-std-device-nostd/rmake.rs +++ b/tests/run-make/offload/host-std-device-nostd/rmake.rs @@ -35,6 +35,4 @@ fn main() { .arg("-Clto=fat") .emit("obj") .run(); - - assert!(cwd().join("host.o").exists()); } From 87e95d69da85bc2c54432240cff00fb56c439eb2 Mon Sep 17 00:00:00 2001 From: Yukang Date: Tue, 22 Sep 2026 00:10:54 +0800 Subject: [PATCH 07/16] Enhance mutable closure suggestions with as_mut() support --- .../src/fn_ctxt/suggestions.rs | 33 ++++++++---- tests/ui/suggestions/as-mut-closure.fixed | 34 ++++++++++++ tests/ui/suggestions/as-mut-closure.rs | 1 + tests/ui/suggestions/as-mut-closure.stderr | 52 +++++++++---------- 4 files changed, 84 insertions(+), 36 deletions(-) create mode 100644 tests/ui/suggestions/as-mut-closure.fixed diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 8895faef0890f..49f7b2e551b78 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -2855,7 +2855,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { true } - /// Identify some cases where `as_ref()` would be appropriate and suggest it. + /// Identify some cases where `as_ref()` or `as_mut()` would be appropriate and suggest it. /// /// Given the following code: /// ```compile_fail,E0308 @@ -2871,7 +2871,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// ```ignore (illustrative) /// opt.map(|param| { takes_ref(param) }); /// ``` - fn can_use_as_ref(&self, expr: &hir::Expr<'_>) -> Option<(Vec<(Span, String)>, &'static str)> { + fn can_use_as_ref_or_mut( + &self, + expr: &hir::Expr<'_>, + mutability: hir::Mutability, + ) -> Option<(Vec<(Span, String)>, &'static str)> { let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind else { return None; }; @@ -2908,9 +2912,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return None; }; - let self_ty = self.typeck_results.borrow().expr_ty_opt(receiver)?; + let mut self_ty = self.typeck_results.borrow().expr_ty_opt(receiver)?; + while let ty::Ref(_, inner, ref_mutability) = self_ty.kind() { + // `as_mut()` cannot borrow through a shared reference, + // also we cannot suggest `as_ref()` either when the reference is shared + if mutability.is_mut() && ref_mutability.is_not() { + return None; + } + self_ty = *inner; + } let name = method_path.ident.name; - let is_as_ref_able = match self_ty.peel_refs().kind() { + let can_borrow = match self_ty.kind() { ty::Adt(def, _) => { (self.tcx.is_diagnostic_item(sym::Option, def.did()) || self.tcx.is_diagnostic_item(sym::Result, def.did())) @@ -2918,11 +2930,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ => false, }; - if is_as_ref_able { - Some(( - vec![(method_path.ident.span.shrink_to_lo(), "as_ref().".to_string())], - "consider using `as_ref` instead", - )) + if can_borrow { + let (suggestion, message) = match mutability { + hir::Mutability::Not => ("as_ref().", "consider using `as_ref` instead"), + hir::Mutability::Mut => ("as_mut().", "consider using `as_mut` instead"), + }; + Some((vec![(method_path.ident.span.shrink_to_lo(), suggestion.to_string())], message)) } else { None } @@ -3113,7 +3126,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return Some((suggs, help, app, mutref)); } - if let Some((sugg, msg)) = self.can_use_as_ref(expr) { + if let Some((sugg, msg)) = self.can_use_as_ref_or_mut(expr, mutability) { return Some(( sugg, msg.to_string(), diff --git a/tests/ui/suggestions/as-mut-closure.fixed b/tests/ui/suggestions/as-mut-closure.fixed new file mode 100644 index 0000000000000..76a9cc5ab7c88 --- /dev/null +++ b/tests/ui/suggestions/as-mut-closure.fixed @@ -0,0 +1,34 @@ +// Borrowing a container for a closure argument must preserve the expected mutability. +//@ run-rustfix + +#![allow(unused_mut)] + +fn append(value: &mut String) { + value.push('!'); +} + +fn increment(value: &mut i32) { + *value += 1; +} + +fn main() { + let mut option = Some(String::new()); + let _ = option.as_mut().map(|arg| append(arg)); + //~^ ERROR mismatched types + let _ = (&mut option).as_mut().and_then(|arg| Some(append(arg))); + //~^ ERROR mismatched types + + let mut result: Result<_, ()> = Ok(String::new()); + let _ = result.as_mut().map(|arg| append(arg)); + //~^ ERROR mismatched types + let _ = (&mut result).as_mut().and_then(|arg| Ok(append(arg))); + //~^ ERROR mismatched types + + // A shared reference cannot supply `as_mut()`. Borrow the copied argument instead. + let shared = &Some(0); + let _ = shared.map(|mut arg| increment(&mut arg)); + //~^ ERROR mismatched types + let nested = &mut &Some(0); + let _ = nested.map(|mut arg| increment(&mut arg)); + //~^ ERROR mismatched types +} diff --git a/tests/ui/suggestions/as-mut-closure.rs b/tests/ui/suggestions/as-mut-closure.rs index ab1c8bff5bf77..4b583cbc4f2dc 100644 --- a/tests/ui/suggestions/as-mut-closure.rs +++ b/tests/ui/suggestions/as-mut-closure.rs @@ -1,4 +1,5 @@ // Borrowing a container for a closure argument must preserve the expected mutability. +//@ run-rustfix #![allow(unused_mut)] diff --git a/tests/ui/suggestions/as-mut-closure.stderr b/tests/ui/suggestions/as-mut-closure.stderr index c133641b6a5a7..8a998be539458 100644 --- a/tests/ui/suggestions/as-mut-closure.stderr +++ b/tests/ui/suggestions/as-mut-closure.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/as-mut-closure.rs:15:37 + --> $DIR/as-mut-closure.rs:16:37 | LL | let _ = option.map(|arg| append(arg)); | ------ ^^^ expected `&mut String`, found `String` @@ -7,17 +7,17 @@ LL | let _ = option.map(|arg| append(arg)); | arguments to this function are incorrect | note: function defined here - --> $DIR/as-mut-closure.rs:5:4 + --> $DIR/as-mut-closure.rs:6:4 | LL | fn append(value: &mut String) { | ^^^^^^ ------------------ -help: consider using `as_ref` instead +help: consider using `as_mut` instead | -LL | let _ = option.as_ref().map(|arg| append(arg)); +LL | let _ = option.as_mut().map(|arg| append(arg)); | +++++++++ error[E0308]: mismatched types - --> $DIR/as-mut-closure.rs:17:54 + --> $DIR/as-mut-closure.rs:18:54 | LL | let _ = (&mut option).and_then(|arg| Some(append(arg))); | ------ ^^^ expected `&mut String`, found `String` @@ -25,17 +25,17 @@ LL | let _ = (&mut option).and_then(|arg| Some(append(arg))); | arguments to this function are incorrect | note: function defined here - --> $DIR/as-mut-closure.rs:5:4 + --> $DIR/as-mut-closure.rs:6:4 | LL | fn append(value: &mut String) { | ^^^^^^ ------------------ -help: consider using `as_ref` instead +help: consider using `as_mut` instead | -LL | let _ = (&mut option).as_ref().and_then(|arg| Some(append(arg))); +LL | let _ = (&mut option).as_mut().and_then(|arg| Some(append(arg))); | +++++++++ error[E0308]: mismatched types - --> $DIR/as-mut-closure.rs:21:37 + --> $DIR/as-mut-closure.rs:22:37 | LL | let _ = result.map(|arg| append(arg)); | ------ ^^^ expected `&mut String`, found `String` @@ -43,17 +43,17 @@ LL | let _ = result.map(|arg| append(arg)); | arguments to this function are incorrect | note: function defined here - --> $DIR/as-mut-closure.rs:5:4 + --> $DIR/as-mut-closure.rs:6:4 | LL | fn append(value: &mut String) { | ^^^^^^ ------------------ -help: consider using `as_ref` instead +help: consider using `as_mut` instead | -LL | let _ = result.as_ref().map(|arg| append(arg)); +LL | let _ = result.as_mut().map(|arg| append(arg)); | +++++++++ error[E0308]: mismatched types - --> $DIR/as-mut-closure.rs:23:52 + --> $DIR/as-mut-closure.rs:24:52 | LL | let _ = (&mut result).and_then(|arg| Ok(append(arg))); | ------ ^^^ expected `&mut String`, found `String` @@ -61,17 +61,17 @@ LL | let _ = (&mut result).and_then(|arg| Ok(append(arg))); | arguments to this function are incorrect | note: function defined here - --> $DIR/as-mut-closure.rs:5:4 + --> $DIR/as-mut-closure.rs:6:4 | LL | fn append(value: &mut String) { | ^^^^^^ ------------------ -help: consider using `as_ref` instead +help: consider using `as_mut` instead | -LL | let _ = (&mut result).as_ref().and_then(|arg| Ok(append(arg))); +LL | let _ = (&mut result).as_mut().and_then(|arg| Ok(append(arg))); | +++++++++ error[E0308]: mismatched types - --> $DIR/as-mut-closure.rs:28:44 + --> $DIR/as-mut-closure.rs:29:44 | LL | let _ = shared.map(|mut arg| increment(arg)); | --------- ^^^ expected `&mut i32`, found integer @@ -79,17 +79,17 @@ LL | let _ = shared.map(|mut arg| increment(arg)); | arguments to this function are incorrect | note: function defined here - --> $DIR/as-mut-closure.rs:9:4 + --> $DIR/as-mut-closure.rs:10:4 | LL | fn increment(value: &mut i32) { | ^^^^^^^^^ --------------- -help: consider using `as_ref` instead +help: consider mutably borrowing here | -LL | let _ = shared.as_ref().map(|mut arg| increment(arg)); - | +++++++++ +LL | let _ = shared.map(|mut arg| increment(&mut arg)); + | ++++ error[E0308]: mismatched types - --> $DIR/as-mut-closure.rs:31:44 + --> $DIR/as-mut-closure.rs:32:44 | LL | let _ = nested.map(|mut arg| increment(arg)); | --------- ^^^ expected `&mut i32`, found integer @@ -97,14 +97,14 @@ LL | let _ = nested.map(|mut arg| increment(arg)); | arguments to this function are incorrect | note: function defined here - --> $DIR/as-mut-closure.rs:9:4 + --> $DIR/as-mut-closure.rs:10:4 | LL | fn increment(value: &mut i32) { | ^^^^^^^^^ --------------- -help: consider using `as_ref` instead +help: consider mutably borrowing here | -LL | let _ = nested.as_ref().map(|mut arg| increment(arg)); - | +++++++++ +LL | let _ = nested.map(|mut arg| increment(&mut arg)); + | ++++ error: aborting due to 6 previous errors From e5e0b1057f9579198f4c536dcd2c2f7ad933cf75 Mon Sep 17 00:00:00 2001 From: Zac Harrold Date: Wed, 23 Sep 2026 13:44:47 +1000 Subject: [PATCH 08/16] Fix typo in std::sys::process::unix::unsupported::wait_status documentation --- library/std/src/sys/process/unix/unsupported/wait_status.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/process/unix/unsupported/wait_status.rs b/library/std/src/sys/process/unix/unsupported/wait_status.rs index ac54824875813..b77e7ae835656 100644 --- a/library/std/src/sys/process/unix/unsupported/wait_status.rs +++ b/library/std/src/sys/process/unix/unsupported/wait_status.rs @@ -1,4 +1,4 @@ -//! Emulated wait status for non-Unix #[cfg(unix) platforms +//! Emulated wait status for non-Unix `#[cfg(unix)]` platforms //! //! Separate module to facilitate testing against a real Unix implementation. From 16e81e97d9747e4da7d68e38234cb9a0e62197e5 Mon Sep 17 00:00:00 2001 From: Amar Shah Date: Tue, 22 Sep 2026 22:49:09 -0700 Subject: [PATCH 09/16] Fix bignum build on 16-bit targets --- library/core/src/num/imp/bignum.rs | 6 +++--- library/core/src/num/imp/flt2dec/strategy/dragon.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/library/core/src/num/imp/bignum.rs b/library/core/src/num/imp/bignum.rs index 95046e96fc8f2..5c2a19f39dfce 100644 --- a/library/core/src/num/imp/bignum.rs +++ b/library/core/src/num/imp/bignum.rs @@ -386,7 +386,7 @@ macro_rules! define_bignum { /// the digit type for `Big32x40` pub type Digit32 = u32; -#[cfg(target_pointer_width = "32")] +#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))] define_bignum!(Big32x40: type=Digit32, n=40); /// The digit type for `Big64x20`. @@ -395,12 +395,12 @@ pub type Digit64 = u64; #[cfg(target_pointer_width = "64")] define_bignum!(Big64x20: type=Digit64, n=20); -#[cfg(target_pointer_width = "32")] +#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))] pub type Big = Big32x40; #[cfg(target_pointer_width = "64")] pub type Big = Big64x20; -#[cfg(target_pointer_width = "32")] +#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))] pub type Digit = Digit32; #[cfg(target_pointer_width = "64")] pub type Digit = Digit64; diff --git a/library/core/src/num/imp/flt2dec/strategy/dragon.rs b/library/core/src/num/imp/flt2dec/strategy/dragon.rs index 4ae0d4b4ab0ba..b63b93034d57f 100644 --- a/library/core/src/num/imp/flt2dec/strategy/dragon.rs +++ b/library/core/src/num/imp/flt2dec/strategy/dragon.rs @@ -16,22 +16,22 @@ static POW10: [Digit; 10] = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]; // precalculated arrays of `Digit`s for 5^(2^n). // FIXME(#162879): these tables have u64 and u32 versions, future versions may be generated by macro. -#[cfg(target_pointer_width = "32")] +#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))] static POW5TO16: [Digit; 2] = [0x86f26fc1, 0x23]; #[cfg(target_pointer_width = "64")] static POW5TO16: [Digit; 1] = [0x2386f26fc1]; -#[cfg(target_pointer_width = "32")] +#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))] static POW5TO32: [Digit; 3] = [0x85acef81, 0x2d6d415b, 0x4ee]; #[cfg(target_pointer_width = "64")] static POW5TO32: [Digit; 2] = [0x2d6d415b85acef81, 0x4ee]; -#[cfg(target_pointer_width = "32")] +#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))] static POW5TO64: [Digit; 5] = [0xbf6a1f01, 0x6e38ed64, 0xdaa797ed, 0xe93ff9f4, 0x184f03]; #[cfg(target_pointer_width = "64")] static POW5TO64: [Digit; 3] = [0x6e38ed64bf6a1f01, 0xe93ff9f4daa797ed, 0x184f03]; -#[cfg(target_pointer_width = "32")] +#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))] static POW5TO128: [Digit; 10] = [ 0x2e953e01, 0x3df9909, 0xf1538fd, 0x2374e42f, 0xd3cff5ec, 0xc404dc08, 0xbccdb0da, 0xa6337f19, 0xe91f2603, 0x24e, @@ -40,7 +40,7 @@ static POW5TO128: [Digit; 10] = [ static POW5TO128: [Digit; 5] = [0x3df99092e953e01, 0x2374e42f0f1538fd, 0xc404dc08d3cff5ec, 0xa6337f19bccdb0da, 0x24ee91f2603]; -#[cfg(target_pointer_width = "32")] +#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))] static POW5TO256: [Digit; 19] = [ 0x982e7c01, 0xbed3875b, 0xd8d99f72, 0x12152f87, 0x6bde50c6, 0xcf4a6e70, 0xd595d80f, 0x26b2716e, 0xadc666b0, 0x1d153624, 0x3c42d35a, 0x63ff540e, 0xcc5573c0, 0x65f9ef17, 0x55bc28f2, 0x80dcc7f7, From 8084d720c54590965aac4779edd1d8dc96af51cf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 23 Sep 2026 15:44:49 +1000 Subject: [PATCH 10/16] Remove `DiagInner::sort_span` It's a field that can be used for sorting diagnostics. By default it is set to the primary span. It's only used for `BorrowckDiagnosticsBuffer`. This commit removes it and adds a `sort_span` to each diagnostic recorded in `BorrowckDiagnosticsBuffer`. This avoids various other pieces of code having to deal with it. --- .../rustc_borrowck/src/diagnostics/mod.rs | 20 ++++++++++++++----- .../src/diagnostics/outlives_suggestion.rs | 3 +-- compiler/rustc_codegen_ssa/src/back/write.rs | 2 -- compiler/rustc_errors/src/diagnostic.rs | 14 +------------ compiler/rustc_resolve/src/late.rs | 1 - 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index fadcf92b6ea7a..c8abc2689ff7f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -94,13 +94,19 @@ pub(crate) struct BorrowckDiagnosticsBuffer<'diag, 'tcx> { buffered_mut_errors: FxIndexMap, usize)>, - /// Buffer of diagnostics to be reported. - buffered_diags: Vec>, + /// Buffer of diagnostics to be reported. Each one is paired with a span for sorting purposes; + /// by default it's the primary span. + buffered_diags: Vec<(Span, Diag<'diag>)>, } impl<'diag, 'tcx> BorrowckDiagnosticsBuffer<'diag, 'tcx> { pub(crate) fn buffer_error(&mut self, diag: Diag<'diag>) { - self.buffered_diags.push(diag); + let sort_span = diag.span.primary_span().unwrap_or(DUMMY_SP); + self.buffered_diags.push((sort_span, diag)); + } + + pub(crate) fn buffer_error_with_sort_span(&mut self, diag: Diag<'diag>, sort_span: Span) { + self.buffered_diags.push((sort_span, diag)); } pub(crate) fn emit_errors(&mut self) { @@ -117,8 +123,8 @@ impl<'diag, 'tcx> BorrowckDiagnosticsBuffer<'diag, 'tcx> { } if !self.buffered_diags.is_empty() { - self.buffered_diags.sort_by_key(|diag| diag.sort_span); - for diag in self.buffered_diags.drain(..) { + self.buffered_diags.sort_by_key(|(sort_span, _)| *sort_span); + for (_, diag) in self.buffered_diags.drain(..) { diag.emit(); } } @@ -130,6 +136,10 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { self.diags_buffer.buffer_error(diag.with_dcx(self.dcx())); } + pub(crate) fn buffer_error_with_sort_span(&mut self, diag: Diag<'_>, sort_span: Span) { + self.diags_buffer.buffer_error_with_sort_span(diag.with_dcx(self.dcx()), sort_span); + } + pub(crate) fn buffer_move_error( &mut self, move_out_indices: Vec, diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index 75c666f49a2f7..d7ad34048e5bf 100644 --- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -220,9 +220,8 @@ impl OutlivesSuggestionBuilder { // We want this message to appear after other messages on the mir def. let mir_span = mbcx.body.span; - diag.sort_span = mir_span.shrink_to_hi(); // Buffer the diagnostic - mbcx.buffer_error(diag); + mbcx.buffer_error_with_sort_span(diag, mir_span.shrink_to_hi()); } } diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 06453ffd24ed9..f16eb78b36e35 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -1199,7 +1199,6 @@ pub struct CguMessage; // - `span`: it doesn't impl `Send`. // - `suggestions`: it doesn't impl `Send`, and isn't used for codegen // diagnostics. -// - `sort_span`: it doesn't impl `Send`. // - `is_lint`: lints aren't relevant during codegen. // - `emitted_at`: not used for codegen diagnostics. struct Diagnostic { @@ -1993,7 +1992,6 @@ impl Emitter for SharedEmitter { // the cut-down local `DiagInner`. assert!(!diag.span.has_span_labels()); assert_eq!(diag.suggestions, Suggestions::Enabled(vec![])); - assert_eq!(diag.sort_span, rustc_span::DUMMY_SP); assert_eq!(diag.is_lint, None); // No sensible check for `diag.emitted_at`. diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 729569fd5f5d1..9688f99abfebb 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -12,7 +12,7 @@ use rustc_error_messages::{DiagArgMap, DiagArgName, IntoDiagArg}; use rustc_hashes::Hash128; use rustc_lint_defs::{Applicability, LintExpectationId}; use rustc_macros::{Decodable, Encodable}; -use rustc_span::{DUMMY_SP, Span, Spanned, Symbol}; +use rustc_span::{Span, Spanned, Symbol}; use tracing::debug; use crate::{ @@ -195,14 +195,7 @@ pub struct DiagInner { pub children: Vec, pub suggestions: Suggestions, pub args: DiagArgMap, - - /// This is not used for highlighting or rendering any error message. Rather, it can be used - /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of - /// `span` if there is one. Otherwise, it is `DUMMY_SP`. - pub sort_span: Span, - pub is_lint: Option, - pub long_ty_path: Option, /// With `-Ztrack_diagnostics` enabled, /// we print where in rustc this error was emitted. @@ -226,7 +219,6 @@ impl DiagInner { children: vec![], suggestions: Suggestions::Enabled(vec![]), args: Default::default(), - sort_span: DUMMY_SP, is_lint: None, long_ty_path: None, emitted_at: DiagLocation::caller(), @@ -320,7 +312,6 @@ impl DiagInner { children, suggestions, args, - sort_span: _, // ignore is_lint, long_ty_path: _, // ignore emitted_at: _, // ignore @@ -1088,9 +1079,6 @@ impl<'a> Diag<'a> { /// Add a span. pub fn span(&mut self, sp: impl Into) -> &mut Self { self.span = sp.into(); - if let Some(span) = self.span.primary_span() { - self.sort_span = span; - } self } } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 7d90b93b62375..9c4d51aee9fe6 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -4751,7 +4751,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } else { err.children.append(&mut parent_err.children); } - err.sort_span = parent_err.sort_span; err.is_lint = parent_err.is_lint.clone(); // merge the parent_err's suggestions with the typo (err's) suggestions From 039b8bcadc7bcce087a278668f2bf7a56d7cc60c Mon Sep 17 00:00:00 2001 From: Flakebi Date: Tue, 1 Sep 2026 09:40:37 +0200 Subject: [PATCH 11/16] Add address_space and byref to abi PassMode::Indirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both will be used by the amdgpu target to implement the `gpu-kernel` ABI. `address_space` specifies the address space of an indirect argument. `AmdgpuKernelArg` translates to LLVM’s byref, which is similar to on_stack/byval, however, there is no extra copy made, the pointer may not point to the stack but can point to some other address space, and the passed argument should not be modified. byval and byref are mutually exclusive, so change on_stack to an enum with the new states, Pointer (none), OnStack and AmdgpuKernelArg. --- compiler/rustc_abi/src/layout/ty.rs | 4 +- .../src/abi/pass_mode.rs | 24 ++-- .../src/abi/returning.rs | 17 +-- compiler/rustc_codegen_gcc/src/abi.rs | 33 ++++- compiler/rustc_codegen_llvm/src/abi.rs | 111 +++++++++++++--- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 1 + compiler/rustc_codegen_llvm/src/llvm/mod.rs | 4 + compiler/rustc_codegen_ssa/src/mir/block.rs | 48 ++++--- compiler/rustc_codegen_ssa/src/mir/mod.rs | 16 ++- .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 5 + .../src/deduce_param_attrs.rs | 2 +- compiler/rustc_public/src/abi.rs | 18 ++- .../src/unstable/convert/stable/abi.rs | 35 +++-- compiler/rustc_target/src/callconv/mod.rs | 125 ++++++++++++++---- compiler/rustc_target/src/callconv/x86.rs | 5 +- compiler/rustc_target/src/callconv/xtensa.rs | 6 +- compiler/rustc_ty_utils/src/abi.rs | 14 +- tests/assembly-llvm/tail-call-indirect.rs | 6 +- tests/ui-fulldeps/rustc_public/check_abi.rs | 8 +- .../rustc_public/check_abi_cast.rs | 4 +- tests/ui/abi/c-zst.powerpc-linux.stderr | 3 +- tests/ui/abi/c-zst.s390x-linux.stderr | 3 +- tests/ui/abi/c-zst.sparc-linux.stderr | 3 +- tests/ui/abi/c-zst.sparc-none.stderr | 3 +- tests/ui/abi/c-zst.sparc64-linux.stderr | 3 +- .../ui/abi/c-zst.x86_64-pc-windows-gnu.stderr | 3 +- tests/ui/abi/debug.generic.stderr | 6 +- tests/ui/abi/debug.loongarch64.stderr | 6 +- tests/ui/abi/debug.riscv64.stderr | 6 +- tests/ui/abi/pass-indirectly-attr.rs | 2 +- tests/ui/abi/pass-indirectly-attr.stderr | 3 +- .../pass-by-value-abi.aarch64.stderr | 3 +- tests/ui/c-variadic/pass-by-value-abi.rs | 8 +- .../pass-by-value-abi.x86_64.stderr | 9 +- tests/ui/explicit-tail-calls/indirect.rs | 10 +- 35 files changed, 406 insertions(+), 151 deletions(-) diff --git a/compiler/rustc_abi/src/layout/ty.rs b/compiler/rustc_abi/src/layout/ty.rs index e51255dc5963f..b8928aecf0cc5 100644 --- a/compiler/rustc_abi/src/layout/ty.rs +++ b/compiler/rustc_abi/src/layout/ty.rs @@ -233,8 +233,8 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { } /// If this method returns `true`, then this type should always have a `PassMode` of - /// `Indirect { on_stack: false, .. }` when being used as the argument type of a function with a - /// non-Rustic ABI (this is true for structs annotated with the + /// `Indirect { mode: IndirectMode::Pointer, .. }` when being used as the argument type of a + /// function with a non-Rustic ABI (this is true for structs annotated with the /// `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute). /// /// This is used to replicate some of the behaviour of C array-to-pointer decay; however unlike diff --git a/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs b/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs index 1c552ca1a9c32..48ffc43c5cfa1 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs @@ -3,7 +3,7 @@ use cranelift_codegen::ir::ArgumentPurpose; use rustc_abi::{Reg, RegKind}; use rustc_target::callconv::{ - ArgAbi, ArgAttributes, ArgExtension as RustcArgExtension, CastTarget, PassMode, + ArgAbi, ArgAttributes, ArgExtension as RustcArgExtension, CastTarget, IndirectMode, PassMode, }; use smallvec::{SmallVec, smallvec}; @@ -126,8 +126,12 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { assert_eq!(pad_i32_count, 0, "padding support not yet implemented"); cast_target_to_abi_params(cast).into_iter().map(|(_, param)| param).collect() } - PassMode::Indirect { attrs, meta_attrs: None, on_stack } => { - if on_stack { + PassMode::Indirect { attrs, meta_attrs: None, address_space: _, mode } => { + assert!( + mode != IndirectMode::AmdgpuKernelArg, + "unsupported amdgpu kernel argument" + ); + if mode == IndirectMode::OnStack { // Abi requires aligning struct size to pointer size let size = self.layout.size.align_to(tcx.data_layout.pointer_align().abi); let size = u32::try_from(size.bytes()).unwrap(); @@ -139,8 +143,8 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { smallvec![apply_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), attrs)] } } - PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack } => { - assert!(!on_stack); + PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), address_space: _, mode } => { + assert!(mode == IndirectMode::Pointer); smallvec![ apply_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), attrs), apply_attrs_to_abi_param(AbiParam::new(pointer_ty(tcx)), meta_attrs), @@ -184,8 +188,8 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { None, cast_target_to_abi_params(cast).into_iter().map(|(_, param)| param).collect(), ), - PassMode::Indirect { attrs, meta_attrs: None, on_stack } => { - assert!(!on_stack); + PassMode::Indirect { attrs, meta_attrs: None, address_space: _, mode } => { + assert!(mode == IndirectMode::Pointer); ( Some(apply_attrs_to_abi_param( AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructReturn), @@ -194,7 +198,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { vec![], ) } - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { unreachable!("unsized return value") } } @@ -324,7 +328,7 @@ pub(super) fn cvalue_for_param<'tcx>( PassMode::Cast { ref cast, .. } => { from_casted_value(fx, &block_params, arg_abi.layout, cast) } - PassMode::Indirect { attrs, meta_attrs: None, on_stack: _ } => { + PassMode::Indirect { attrs, meta_attrs: None, address_space: _, mode: _ } => { assert_eq!(block_params.len(), 1, "{:?}", block_params); if let Some(pointee_align) = attrs.pointee_align && pointee_align < arg_abi.layout.align.abi @@ -342,7 +346,7 @@ pub(super) fn cvalue_for_param<'tcx>( CValue::by_ref(Pointer::new(block_params[0]), arg_abi.layout) } } - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { assert_eq!(block_params.len(), 2, "{:?}", block_params); CValue::by_ref_unsized(Pointer::new(block_params[0]), block_params[1], arg_abi.layout) } diff --git a/compiler/rustc_codegen_cranelift/src/abi/returning.rs b/compiler/rustc_codegen_cranelift/src/abi/returning.rs index 36087f96dd776..7f4ee9435b506 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/returning.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/returning.rs @@ -17,12 +17,12 @@ pub(super) fn codegen_return_param<'tcx>( let is_ssa = ssa_analyzed[RETURN_PLACE].is_ssa(fx, fx.fn_abi.ret.layout.ty); (super::make_local_place(fx, RETURN_PLACE, fx.fn_abi.ret.layout, is_ssa), smallvec![]) } - PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: None, address_space: _, mode: _ } => { let ret_param = block_params_iter.next().unwrap(); assert_eq!(fx.bcx.func.dfg.value_type(ret_param), fx.pointer_type); (CPlace::for_ptr(Pointer::new(ret_param), fx.fn_abi.ret.layout), smallvec![ret_param]) } - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { unreachable!("unsized return value") } }; @@ -50,7 +50,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx>( ) { let (ret_temp_place, return_ptr) = match ret_arg_abi.mode { PassMode::Ignore => (None, None), - PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: None, address_space: _, mode: _ } => { if let Some(ret_ptr) = ret_place.try_to_ptr() { // This is an optimization to prevent unnecessary copies of the return value when // the return place is already a memory place as opposed to a register. @@ -61,7 +61,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx>( (Some(place), Some(place.to_ptr().get_addr(fx))) } } - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { unreachable!("unsized return value") } PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast { .. } => (None, None), @@ -86,14 +86,14 @@ pub(super) fn codegen_with_call_return_arg<'tcx>( super::pass_mode::from_casted_value(fx, &results, ret_place.layout(), cast); ret_place.write_cvalue(fx, result); } - PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: None, address_space: _, mode: _ } => { if let Some(ret_temp_place) = ret_temp_place { // If ret_temp_place is None, it is not necessary to copy the return value. let ret_temp_value = ret_temp_place.to_cvalue(fx); ret_place.write_cvalue(fx, ret_temp_value); } } - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { unreachable!("unsized return value") } } @@ -102,10 +102,11 @@ pub(super) fn codegen_with_call_return_arg<'tcx>( /// Codegen a return instruction with the right return value(s) if any. pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) { match fx.fn_abi.ret.mode { - PassMode::Ignore | PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => { + PassMode::Ignore + | PassMode::Indirect { attrs: _, meta_attrs: None, address_space: _, mode: _ } => { fx.bcx.ins().return_(&[]); } - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { unreachable!("unsized return value") } PassMode::Direct(_) => { diff --git a/compiler/rustc_codegen_gcc/src/abi.rs b/compiler/rustc_codegen_gcc/src/abi.rs index 63eaf52ce9f01..5b88cebb4f174 100644 --- a/compiler/rustc_codegen_gcc/src/abi.rs +++ b/compiler/rustc_codegen_gcc/src/abi.rs @@ -11,7 +11,7 @@ use rustc_middle::ty::layout::LayoutOf; #[cfg(feature = "master")] use rustc_session::{Session, config}; use rustc_span::bug; -use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode}; +use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, IndirectMode, PassMode}; #[cfg(feature = "master")] use rustc_target::spec::Arch; @@ -189,7 +189,12 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { let ty = cast.gcc_type(cx); apply_attrs(ty, &cast.attrs, argument_tys.len()) } - PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: true } => { + PassMode::Indirect { + attrs: _, + meta_attrs: None, + address_space: _, + mode: IndirectMode::OnStack, + } => { let x86_interrupt_first_arg = { #[cfg(feature = "master")] { @@ -216,14 +221,32 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { arg.layout.gcc_type(cx) } } + PassMode::Indirect { + attrs: _, + meta_attrs: None, + address_space: _, + mode: IndirectMode::AmdgpuKernelArg, + } => { + unimplemented!("unsupported amdgpu kernel argument") + } PassMode::Direct(attrs) => { apply_attrs(arg.layout.immediate_gcc_type(cx), &attrs, argument_tys.len()) } - PassMode::Indirect { attrs, meta_attrs: None, on_stack: false } => { + PassMode::Indirect { + attrs, + meta_attrs: None, + address_space: _, + mode: IndirectMode::Pointer, + } => { apply_attrs(cx.type_ptr_to(arg.layout.gcc_type(cx)), &attrs, argument_tys.len()) } - PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack } => { - assert!(!on_stack); + PassMode::Indirect { + attrs, + meta_attrs: Some(meta_attrs), + address_space: _, + mode, + } => { + assert!(mode == IndirectMode::Pointer); // Construct the type of a (wide) pointer to `ty`, and pass its two fields. // Any two ABI-compatible unsized types have the same metadata type and // moreover the same metadata value leads to the same dynamic size and diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index dce8db6841b7f..e16f34483a0c5 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -15,7 +15,7 @@ use rustc_middle::ty::layout::LayoutOf; use rustc_session::{Session, config}; use rustc_span::bug; use rustc_target::callconv::{ - ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, CastTarget, FnAbi, PassMode, + ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, CastTarget, FnAbi, IndirectMode, PassMode, }; use rustc_target::spec::{Arch, SanitizerSet}; use smallvec::SmallVec; @@ -243,12 +243,12 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { match &self.mode { PassMode::Ignore => {} // Sized indirect arguments - PassMode::Indirect { attrs, meta_attrs: None, on_stack: _ } => { + PassMode::Indirect { attrs, meta_attrs: None, address_space: _, mode: _ } => { let align = attrs.pointee_align.unwrap_or(self.layout.align.abi); OperandValue::Ref(PlaceValue::new_sized(val, align)).store(bx, dst); } // Unsized indirect arguments cannot be stored - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { bug!("unsized `ArgAbi` cannot be stored"); } PassMode::Cast { cast, pad_i32_count: _ } => { @@ -304,11 +304,11 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { PassMode::Pair(..) => { OperandValue::Pair(next(), next()).store(bx, dst); } - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { bug!("unsized `ArgAbi` cannot be stored"); } PassMode::Direct(_) - | PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } + | PassMode::Indirect { attrs: _, meta_attrs: None, address_space: _, mode: _ } | PassMode::Cast { .. } => { let next_arg = next(); self.store(bx, next_arg, dst); @@ -369,8 +369,13 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { PassMode::Ignore => cx.type_void(), PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_llvm_type(cx), PassMode::Cast { cast, pad_i32_count: _ } => cast.llvm_type(cx), - PassMode::Indirect { .. } => { - llargument_tys.push(cx.type_ptr()); + PassMode::Indirect { address_space, .. } => { + let ty = if let Some(address_space) = address_space { + cx.type_ptr_ext(*address_space) + } else { + cx.type_ptr() + }; + llargument_tys.push(ty); cx.type_void() } }; @@ -395,7 +400,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { llargument_tys.push(arg.layout.scalar_pair_element_llvm_type(cx, 1, true)); continue; } - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { // Construct the type of a (wide) pointer to `ty`, and pass its two fields. // Any two ABI-compatible unsized types have the same metadata type and // moreover the same metadata value leads to the same dynamic size and @@ -406,7 +411,13 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 1, true)); continue; } - PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => cx.type_ptr(), + PassMode::Indirect { attrs: _, meta_attrs: None, address_space, mode: _ } => { + if let Some(address_space) = address_space { + cx.type_ptr_ext(*address_space) + } else { + cx.type_ptr() + } + } PassMode::Cast { cast, pad_i32_count } => { // Add padding. llargument_tys.extend(std::iter::repeat_n( @@ -496,8 +507,8 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { apply_range_attr(llvm::AttributePlace::ReturnValue, scalar); } } - PassMode::Indirect { attrs, meta_attrs: _, on_stack } => { - assert!(!on_stack); + PassMode::Indirect { attrs, meta_attrs: _, address_space: _, mode } => { + assert!(*mode == IndirectMode::Pointer); let i = apply(attrs); let sret = llvm::CreateStructRetAttr( cx.llcx, @@ -523,7 +534,12 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { for arg in self.args.iter() { match &arg.mode { PassMode::Ignore => {} - PassMode::Indirect { attrs, meta_attrs: None, on_stack: true } => { + PassMode::Indirect { + attrs, + meta_attrs: None, + address_space: _, + mode: IndirectMode::OnStack, + } => { let i = apply(attrs); let byval = llvm::CreateByValAttr( cx.llcx, @@ -531,13 +547,31 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { ); attributes::apply_to_llfn(llfn, llvm::AttributePlace::Argument(i), &[byval]); } + PassMode::Indirect { + attrs, + meta_attrs: None, + address_space: _, + mode: IndirectMode::AmdgpuKernelArg, + } => { + let i = apply(attrs); + let byref = llvm::CreateByRefAttr( + cx.llcx, + cx.type_array(cx.type_i8(), arg.layout.size.bytes()), + ); + attributes::apply_to_llfn(llfn, llvm::AttributePlace::Argument(i), &[byref]); + } PassMode::Direct(attrs) => { let i = apply(attrs); if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr { apply_range_attr(llvm::AttributePlace::Argument(i), scalar); } } - PassMode::Indirect { attrs, meta_attrs: None, on_stack: false } => { + PassMode::Indirect { + attrs, + meta_attrs: None, + address_space: _, + mode: IndirectMode::Pointer, + } => { let i = apply(attrs); if cx.sess().opts.optimize != config::OptLevel::No { attributes::apply_to_llfn( @@ -547,8 +581,13 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { ); } } - PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack } => { - assert!(!on_stack); + PassMode::Indirect { + attrs, + meta_attrs: Some(meta_attrs), + address_space: _, + mode, + } => { + assert!(*mode == IndirectMode::Pointer); apply(attrs); apply(meta_attrs); } @@ -626,8 +665,8 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { PassMode::Direct(attrs) => { attrs.apply_attrs_to_callsite(llvm::AttributePlace::ReturnValue, bx.cx, callsite); } - PassMode::Indirect { attrs, meta_attrs: _, on_stack } => { - assert!(!on_stack); + PassMode::Indirect { attrs, meta_attrs: _, address_space: _, mode } => { + assert!(*mode == IndirectMode::Pointer); let i = apply(bx.cx, attrs); let sret = llvm::CreateStructRetAttr( bx.cx.llcx, @@ -647,7 +686,12 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { for arg in self.args.iter() { match &arg.mode { PassMode::Ignore => {} - PassMode::Indirect { attrs, meta_attrs: None, on_stack: true } => { + PassMode::Indirect { + attrs, + meta_attrs: None, + address_space: _, + mode: IndirectMode::OnStack, + } => { let i = apply(bx.cx, attrs); let byval = llvm::CreateByValAttr( bx.cx.llcx, @@ -659,11 +703,38 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { &[byval], ); } + PassMode::Indirect { + attrs, + meta_attrs: None, + address_space: _, + mode: IndirectMode::AmdgpuKernelArg, + } => { + let i = apply(bx.cx, attrs); + let byref = llvm::CreateByRefAttr( + bx.cx.llcx, + bx.cx.type_array(bx.cx.type_i8(), arg.layout.size.bytes()), + ); + attributes::apply_to_callsite( + callsite, + llvm::AttributePlace::Argument(i), + &[byref], + ); + } PassMode::Direct(attrs) - | PassMode::Indirect { attrs, meta_attrs: None, on_stack: false } => { + | PassMode::Indirect { + attrs, + meta_attrs: None, + address_space: _, + mode: IndirectMode::Pointer, + } => { apply(bx.cx, attrs); } - PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack: _ } => { + PassMode::Indirect { + attrs, + meta_attrs: Some(meta_attrs), + address_space: _, + mode: _, + } => { apply(bx.cx, attrs); apply(bx.cx, meta_attrs); } diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 52218bfa336b8..07381745afe84 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -2016,6 +2016,7 @@ unsafe extern "C" { pub(crate) fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute; pub(crate) fn LLVMRustCreateDereferenceableOrNullAttr(C: &Context, bytes: u64) -> &Attribute; pub(crate) fn LLVMRustCreateByValAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute; + pub(crate) fn LLVMRustCreateByRefAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute; pub(crate) fn LLVMRustCreateStructRetAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute; pub(crate) fn LLVMRustCreateElementTypeAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute; pub(crate) fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute; diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs index 5452f4abc5c33..89e4d60656d34 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs @@ -122,6 +122,10 @@ pub(crate) fn CreateByValAttr<'ll>(llcx: &'ll Context, ty: &'ll Type) -> &'ll At unsafe { LLVMRustCreateByValAttr(llcx, ty) } } +pub(crate) fn CreateByRefAttr<'ll>(llcx: &'ll Context, ty: &'ll Type) -> &'ll Attribute { + unsafe { LLVMRustCreateByRefAttr(llcx, ty) } +} + pub(crate) fn CreateStructRetAttr<'ll>(llcx: &'ll Context, ty: &'ll Type) -> &'ll Attribute { unsafe { LLVMRustCreateStructRetAttr(llcx, ty) } } diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 6b0def4ffa182..f99009a0f4243 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -18,7 +18,7 @@ use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths}; use rustc_middle::ty::{self, Instance, Ty, TypeVisitableExt}; use rustc_session::config::OptLevel; use rustc_span::{Span, Spanned, bug, span_bug}; -use rustc_target::callconv::{ArgAbi, ArgAttributes, CastTarget, FnAbi, PassMode}; +use rustc_target::callconv::{ArgAbi, ArgAttributes, CastTarget, FnAbi, IndirectMode, PassMode}; use tracing::{debug, info}; use super::operand::OperandRef; @@ -1257,7 +1257,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { (args, None) }; - // Special logic for tail calls with `PassMode::Indirect { on_stack: false, .. }` arguments. + // Special logic for tail calls with `PassMode::Indirect { mode: IndirectMode::Pointer, .. }` arguments. // // Normally an indirect argument that is allocated in the caller's stack frame // would be passed as a pointer into the callee's stack frame. @@ -1282,10 +1282,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let mut tail_call_temporaries = vec![]; if kind == CallKind::Tail { tail_call_temporaries = vec![None; first_args.len()]; - // Copy the arguments that use `PassMode::Indirect { on_stack: false , ..}` + // Copy the arguments that use `PassMode::Indirect { mode: IndirectMode::Pointer , ..}` // to temporary stack allocations. See the comment above. for (i, arg) in first_args.iter().enumerate() { - if !matches!(fn_abi.args[i].mode, PassMode::Indirect { on_stack: false, .. }) { + if !matches!( + fn_abi.args[i].mode, + PassMode::Indirect { mode: IndirectMode::Pointer, .. } + ) { continue; } @@ -1353,10 +1356,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } - let by_move = if let PassMode::Indirect { on_stack: false, .. } = fn_abi.args[i].mode + let by_move = if let PassMode::Indirect { mode: IndirectMode::Pointer, .. } = + fn_abi.args[i].mode && kind == CallKind::Tail { - // Special logic for tail calls with `PassMode::Indirect { on_stack: false, .. }` arguments. + // Special logic for tail calls with `PassMode::Indirect { mode: IndirectMode::Pointer, .. }` arguments. // // Normally an indirect argument that is allocated in the caller's stack frame // would be passed as a pointer into the callee's stack frame. @@ -1977,14 +1981,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } _ => bug!("codegen_argument: {:?} invalid for pair argument", op), }, - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => match op.val { - Ref(PlaceValue { llval: a, llextra: Some(b), .. }) => { - llargs.push(a); - llargs.push(b); - return; + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { + match op.val { + Ref(PlaceValue { llval: a, llextra: Some(b), .. }) => { + llargs.push(a); + llargs.push(b); + return; + } + _ => bug!("codegen_argument: {:?} invalid for unsized indirect argument", op), } - _ => bug!("codegen_argument: {:?} invalid for unsized indirect argument", op), - }, + } _ => {} } @@ -2014,7 +2020,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { PassMode::Ignore | PassMode::Pair(..) => unreachable!("handled above"), }, Ref(op_place_val) => match arg.mode { - PassMode::Indirect { attrs, on_stack, .. } => { + PassMode::Indirect { attrs, mode, .. } => { + if mode == IndirectMode::AmdgpuKernelArg { + bug!("{op:?} passed as amdgpu kernel argument with abi {arg:?}"); + } // For `foo(packed.large_field)`, and types with <4 byte alignment on x86, // alignment requirements may be higher than the type's alignment, so copy // to a higher-aligned alloca. @@ -2023,7 +2032,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { None => arg.layout.align.abi, }; // Copy to an alloca when the argument is neither by-val nor by-move. - if op_place_val.align < required_align || (!on_stack && !by_move) { + if op_place_val.align < required_align + || (mode == IndirectMode::Pointer && !by_move) + { let scratch = PlaceValue::alloca(bx, arg.layout.size, required_align); bx.lifetime_start(scratch.llval, arg.layout.size); op.store_with_annotation(bx, scratch.with_type(arg.layout)); @@ -2036,8 +2047,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { _ => (op_place_val.llval, op_place_val.align, true), }, ZeroSized => match arg.mode { - PassMode::Indirect { on_stack, .. } => { - if on_stack { + PassMode::Indirect { mode, .. } => { + if mode == IndirectMode::AmdgpuKernelArg { + bug!("{op:?} passed as amdgpu kernel argument with abi {arg:?}"); + } + if mode == IndirectMode::OnStack { // It doesn't seem like any target can have `byval` ZSTs, so this assert // is here to replace a would-be untested codepath. bug!("ZST {op:?} passed on stack with abi {arg:?}"); diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index b5cecf4b5c434..aefa8356536dc 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -8,7 +8,7 @@ use rustc_middle::mir::{Body, Local, UnwindTerminateReason, traversal}; use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, TyAndLayout}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; use rustc_span::{ErrorGuaranteed, bug, span_bug}; -use rustc_target::callconv::{FnAbi, PassMode}; +use rustc_target::callconv::{FnAbi, IndirectMode, PassMode}; use tracing::{debug, instrument}; use crate::base; @@ -561,15 +561,21 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( match arg.mode { // Sized indirect arguments - PassMode::Indirect { attrs, meta_attrs: None, on_stack: _ } => { + PassMode::Indirect { attrs, meta_attrs: None, address_space: _, mode } => { // Don't copy an indirect argument to an alloca, the caller already put it // in a temporary alloca and gave it up. + // AmdgpuKernelArg/byref arguments must not be modified, so always create a + // local alloca for them. + // If the argument is underaligned, then we need to copy it to a higher-aligned + // alloca. // FIXME: lifetimes + let mut needs_alloca = mode == IndirectMode::AmdgpuKernelArg; if let Some(pointee_align) = attrs.pointee_align && pointee_align < arg.layout.align.abi { - // ...unless the argument is underaligned, then we need to copy it to - // a higher-aligned alloca. + needs_alloca = true; + } + if needs_alloca { let tmp = PlaceRef::alloca(bx, arg.layout); bx.store_fn_arg(arg, &mut llarg_idx, tmp); LocalRef::Place(tmp) @@ -580,7 +586,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( } } // Unsized indirect arguments - PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } => { // As the storage for the indirect argument lives during // the whole function call, we just copy the wide pointer. let llarg = bx.get_param(llarg_idx); diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 161b5bdb952d3..bc8fa60b66a52 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -480,6 +480,11 @@ extern "C" LLVMAttributeRef LLVMRustCreateByValAttr(LLVMContextRef C, return wrap(Attribute::getWithByValType(*unwrap(C), unwrap(Ty))); } +extern "C" LLVMAttributeRef LLVMRustCreateByRefAttr(LLVMContextRef C, + LLVMTypeRef Ty) { + return wrap(Attribute::getWithByRefType(*unwrap(C), unwrap(Ty))); +} + extern "C" LLVMAttributeRef LLVMRustCreateStructRetAttr(LLVMContextRef C, LLVMTypeRef Ty) { return wrap(Attribute::getWithStructRetType(*unwrap(C), unwrap(Ty))); diff --git a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs index 5bba125aefc58..8814670ca4300 100644 --- a/compiler/rustc_mir_transform/src/deduce_param_attrs.rs +++ b/compiler/rustc_mir_transform/src/deduce_param_attrs.rs @@ -135,7 +135,7 @@ impl<'tcx> Visitor<'tcx> for DeduceParamAttrs { } // Like a call, but more conservative because the backend may introduce writes to an - // argument if the argument is passed as `PassMode::Indirect { on_stack: false, ... }`. + // argument if the argument is passed as `PassMode::Indirect { mode: IndirectMode::Pointer, ... }`. TerminatorKind::TailCall { .. } => { for usage in self.usage.iter_mut() { *usage |= UsageSummary::MUTATE; diff --git a/compiler/rustc_public/src/abi.rs b/compiler/rustc_public/src/abi.rs index 67d609c780c42..72387fce19797 100644 --- a/compiler/rustc_public/src/abi.rs +++ b/compiler/rustc_public/src/abi.rs @@ -41,6 +41,19 @@ pub struct ArgAbi { pub mode: PassMode, } +/// Different modes in which indirect arguments can be passed. +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Serialize)] +pub enum IndirectMode { + /// Passed as a normal pointer, nothing special. + Pointer, + /// The value is placed at a fixed stack offset rather than passed as a regular pointer + /// argument. + OnStack, + /// Similar to `OnStack` except that the pointer does not necessarily point to the stack, no + /// extra copy is made, and the passed argument should not be modified. + AmdgpuKernelArg, +} + /// How a function argument should be passed in to the target function. /// /// The pass mode is determined by the platform's calling convention and the @@ -74,14 +87,13 @@ pub enum PassMode { /// Pass the argument indirectly via a pointer. /// /// The caller places the value in memory and passes a pointer to it. - /// When `on_stack` is true, the value is placed at a fixed stack offset - /// rather than passed as a regular pointer argument. Indirect { attrs: ArgAttributes, /// Attributes for the metadata pointer (vtable or length) of unsized arguments. /// Only present for unsized types (e.g., `dyn Trait`, `[T]`). meta_attrs: Option, - on_stack: bool, + address_space: Option, + mode: IndirectMode, }, } diff --git a/compiler/rustc_public/src/unstable/convert/stable/abi.rs b/compiler/rustc_public/src/unstable/convert/stable/abi.rs index 3c268a6dd23a4..1ac0b706ed091 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/abi.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/abi.rs @@ -11,9 +11,9 @@ use rustc_target::callconv; use crate::IndexedVal; use crate::abi::{ AddressSpace, ArgAbi, ArgAttributes, ArgExtension, CallConvention, CastTarget, FieldsShape, - FloatLength, FnAbi, IntegerLength, IntegerType, Layout, LayoutShape, NumScalableVectors, - PassMode, Primitive, Reg, RegKind, ReprFlags, ReprOptions, Scalar, TagEncoding, TyAndLayout, - Uniform, ValueRepr, VariantFields, VariantsShape, WrappingRange, + FloatLength, FnAbi, IndirectMode, IntegerLength, IntegerType, Layout, LayoutShape, + NumScalableVectors, PassMode, Primitive, Reg, RegKind, ReprFlags, ReprOptions, Scalar, + TagEncoding, TyAndLayout, Uniform, ValueRepr, VariantFields, VariantsShape, WrappingRange, }; use crate::compiler_interface::BridgeTys; use crate::target::MachineSize as Size; @@ -155,6 +155,22 @@ impl<'tcx> Stable<'tcx> for CanonAbi { } } +impl<'tcx> Stable<'tcx> for callconv::IndirectMode { + type T = IndirectMode; + + fn stable<'cx>( + &self, + _tables: &mut Tables<'cx, BridgeTys>, + _cx: &CompilerCtxt<'cx, BridgeTys>, + ) -> Self::T { + match self { + callconv::IndirectMode::Pointer => IndirectMode::Pointer, + callconv::IndirectMode::OnStack => IndirectMode::OnStack, + callconv::IndirectMode::AmdgpuKernelArg => IndirectMode::AmdgpuKernelArg, + } + } +} + impl<'tcx> Stable<'tcx> for callconv::PassMode { type T = PassMode; @@ -172,11 +188,14 @@ impl<'tcx> Stable<'tcx> for callconv::PassMode { callconv::PassMode::Cast { pad_i32_count, cast } => { PassMode::Cast { pad_i32_count: *pad_i32_count, cast: cast.stable(tables, cx) } } - callconv::PassMode::Indirect { attrs, meta_attrs, on_stack } => PassMode::Indirect { - attrs: attrs.stable(tables, cx), - meta_attrs: meta_attrs.map(|a| a.stable(tables, cx)), - on_stack: *on_stack, - }, + callconv::PassMode::Indirect { attrs, meta_attrs, address_space, mode } => { + PassMode::Indirect { + attrs: attrs.stable(tables, cx), + meta_attrs: meta_attrs.map(|a| a.stable(tables, cx)), + address_space: address_space.stable(tables, cx), + mode: mode.stable(tables, cx), + } + } } } } diff --git a/compiler/rustc_target/src/callconv/mod.rs b/compiler/rustc_target/src/callconv/mod.rs index 1ac6168035085..edc23b6c50b45 100644 --- a/compiler/rustc_target/src/callconv/mod.rs +++ b/compiler/rustc_target/src/callconv/mod.rs @@ -36,6 +36,25 @@ mod x86_win32; mod x86_win64; mod xtensa; +/// Different modes in which indirect arguments can be passed. +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, StableHash)] +pub enum IndirectMode { + /// Passed as a normal pointer, nothing special. + Pointer, + /// The value should be passed at a fixed stack offset in accordance to + /// the ABI rather than passed using a pointer. This corresponds to the `byval` LLVM argument + /// attribute. The `byval` argument will use a byte array with the same size as the Rust type + /// (which ensures that padding is preserved and that we do not rely on LLVM's struct layout), + /// and will use the alignment specified in `attrs.pointee_align` (if `Some`) or the type's + /// alignment (if `None`). This means that the alignment will not always + /// match the Rust type's alignment; see documentation of `pass_by_stack_offset` for more info. + OnStack, + /// `AmdgpuKernelArg` behaves similar to `OnStack` except that the pointer does not necessarily + /// point to the stack, no extra copy is made, and the passed argument should not be modified. + /// This corresponds to the `byref` LLVM argument attribute. + AmdgpuKernelArg, +} + #[derive(Clone, PartialEq, Eq, Hash, Debug, StableHash)] pub enum PassMode { /// Ignore the argument. @@ -63,16 +82,17 @@ pub enum PassMode { /// The `meta_attrs` value, if any, is for the metadata (vtable or length) of an unsized /// argument. (This is the only mode that supports unsized arguments.) /// - /// `on_stack` defines that the value should be passed at a fixed stack offset in accordance to - /// the ABI rather than passed using a pointer. This corresponds to the `byval` LLVM argument - /// attribute. The `byval` argument will use a byte array with the same size as the Rust type - /// (which ensures that padding is preserved and that we do not rely on LLVM's struct layout), - /// and will use the alignment specified in `attrs.pointee_align` (if `Some`) or the type's - /// alignment (if `None`). This means that the alignment will not always - /// match the Rust type's alignment; see documentation of `pass_by_stack_offset` for more info. + /// `address_space` specifies if the pointer is in a special address space or the default one. /// - /// `on_stack` cannot be true for unsized arguments, i.e., when `meta_attrs` is `Some`. - Indirect { attrs: ArgAttributes, meta_attrs: Option, on_stack: bool }, + /// `mode` can be a special way to pass an argument indirectly. + /// `OnStack` and `AmdgpuKernelArg` cannot be used for unsized arguments, i.e., when + /// `meta_attrs` is `Some`. + Indirect { + attrs: ArgAttributes, + meta_attrs: Option, + address_space: Option, + mode: IndirectMode, + }, } impl PassMode { @@ -89,13 +109,23 @@ impl PassMode { PassMode::Cast { cast: c2, pad_i32_count: pad2 }, ) => c1.eq_abi(c2) && pad1 == pad2, ( - PassMode::Indirect { attrs: a1, meta_attrs: None, on_stack: s1 }, - PassMode::Indirect { attrs: a2, meta_attrs: None, on_stack: s2 }, - ) => a1.eq_abi(a2) && s1 == s2, + PassMode::Indirect { attrs: a1, meta_attrs: None, address_space: as1, mode: m1 }, + PassMode::Indirect { attrs: a2, meta_attrs: None, address_space: as2, mode: m2 }, + ) => a1.eq_abi(a2) && as1 == as2 && m1 == m2, ( - PassMode::Indirect { attrs: a1, meta_attrs: Some(e1), on_stack: s1 }, - PassMode::Indirect { attrs: a2, meta_attrs: Some(e2), on_stack: s2 }, - ) => a1.eq_abi(a2) && e1.eq_abi(e2) && s1 == s2, + PassMode::Indirect { + attrs: a1, + meta_attrs: Some(e1), + address_space: as1, + mode: m1, + }, + PassMode::Indirect { + attrs: a2, + meta_attrs: Some(e2), + address_space: as2, + mode: m2, + }, + ) => a1.eq_abi(a2) && as1 == as2 && e1.eq_abi(e2) && m1 == m2, _ => false, } } @@ -424,7 +454,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> { let meta_attrs = layout.is_unsized().then_some(ArgAttributes::new()); - PassMode::Indirect { attrs, meta_attrs, on_stack: false } + PassMode::Indirect { attrs, meta_attrs, address_space: None, mode: IndirectMode::Pointer } } /// Pass this argument indirectly, by passing a (thin or wide) pointer to the argument instead. @@ -435,13 +465,31 @@ impl<'a, Ty> ArgAbi<'a, Ty> { PassMode::Direct(_) | PassMode::Pair(_, _) => { self.mode = Self::indirect_pass_mode(&self.layout); } - PassMode::Indirect { attrs: _, meta_attrs: _, on_stack: false } => { + PassMode::Indirect { + attrs: _, + meta_attrs: _, + address_space: _, + mode: IndirectMode::Pointer, + } => { // already indirect } _ => panic!("Tried to make {:?} indirect", self.mode), } } + /// Pass this argument indirectly, by passing a (thin or wide) pointer to the argument instead. + /// This is valid for both sized and unsized arguments. + #[track_caller] + pub fn make_indirect_addrspace(&mut self, addrspace: AddressSpace) { + self.make_indirect(); + match self.mode { + PassMode::Indirect { ref mut address_space, .. } => { + *address_space = Some(addrspace); + } + _ => unreachable!(), + } + } + /// Same as `make_indirect`, but for arguments that are ignored. Only needed for ABIs that pass /// ZSTs indirectly. #[track_caller] @@ -450,7 +498,12 @@ impl<'a, Ty> ArgAbi<'a, Ty> { PassMode::Ignore => { self.mode = Self::indirect_pass_mode(&self.layout); } - PassMode::Indirect { attrs: _, meta_attrs: _, on_stack: false } => { + PassMode::Indirect { + attrs: _, + meta_attrs: _, + address_space: _, + mode: IndirectMode::Pointer, + } => { // already indirect } _ => panic!("Tried to make {:?} indirect (expected `PassMode::Ignore`)", self.mode), @@ -477,8 +530,8 @@ impl<'a, Ty> ArgAbi<'a, Ty> { assert!(!self.layout.is_unsized(), "used byval ABI for unsized layout"); self.make_indirect(); match self.mode { - PassMode::Indirect { ref mut attrs, meta_attrs: _, ref mut on_stack } => { - *on_stack = true; + PassMode::Indirect { ref mut attrs, meta_attrs: _, address_space: _, ref mut mode } => { + *mode = IndirectMode::OnStack; // Some platforms, like 32-bit x86, change the alignment of the type when passing // `byval`. Account for that. @@ -492,6 +545,22 @@ impl<'a, Ty> ArgAbi<'a, Ty> { } } + /// Pass this argument indirectly. + /// This corresponds to the `byref` LLVM argument attribute. + /// + /// `address_space` specifies the address space of the passed pointer. + pub fn pass_amdgpu_kernel_arg(&mut self, addrspace: Option) { + assert!(!self.layout.is_unsized(), "used amdgpu kernel arg ABI for unsized layout"); + self.make_indirect(); + match self.mode { + PassMode::Indirect { attrs: _, meta_attrs: _, ref mut address_space, ref mut mode } => { + *mode = IndirectMode::AmdgpuKernelArg; + *address_space = addrspace; + } + _ => unreachable!(), + } + } + pub fn extend_integer_width_to(&mut self, bits: u64) { // Only integers have signedness if let BackendRepr::Scalar(scalar) = self.layout.backend_repr @@ -545,11 +614,17 @@ impl<'a, Ty> ArgAbi<'a, Ty> { } pub fn is_sized_indirect(&self) -> bool { - matches!(self.mode, PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ }) + matches!( + self.mode, + PassMode::Indirect { attrs: _, meta_attrs: None, address_space: _, mode: _ } + ) } pub fn is_unsized_indirect(&self) -> bool { - matches!(self.mode, PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ }) + matches!( + self.mode, + PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } + ) } pub fn is_ignore(&self) -> bool { @@ -851,7 +926,7 @@ impl<'a, Ty> FnAbi<'a, Ty> { // Compute `Aggregate` ABI. let is_indirect_not_on_stack = - matches!(arg.mode, PassMode::Indirect { on_stack: false, .. }); + matches!(arg.mode, PassMode::Indirect { mode: IndirectMode::Pointer, .. }); assert!(is_indirect_not_on_stack); let size = arg.layout.size; @@ -962,7 +1037,7 @@ mod size_asserts { use super::*; // tidy-alphabetical-start - static_assert_size!(ArgAbi<'_, usize>, 56); - static_assert_size!(FnAbi<'_, usize>, 80); + static_assert_size!(ArgAbi<'_, usize>, 64); + static_assert_size!(FnAbi<'_, usize>, 88); // tidy-alphabetical-end } diff --git a/compiler/rustc_target/src/callconv/x86.rs b/compiler/rustc_target/src/callconv/x86.rs index a1c59d885b7fc..3476f41e3bc75 100644 --- a/compiler/rustc_target/src/callconv/x86.rs +++ b/compiler/rustc_target/src/callconv/x86.rs @@ -200,12 +200,13 @@ pub(crate) fn fill_inregs<'a, Ty, C>( for arg in fn_abi.args.iter_mut() { let attrs = match arg.mode { - PassMode::Ignore | PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => { + PassMode::Ignore + | PassMode::Indirect { attrs: _, meta_attrs: None, address_space: _, mode: _ } => { continue; } PassMode::Direct(ref mut attrs) => attrs, PassMode::Pair(..) - | PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } + | PassMode::Indirect { attrs: _, meta_attrs: Some(_), address_space: _, mode: _ } | PassMode::Cast { .. } => { unreachable!("x86 shouldn't be passing arguments by {:?}", arg.mode) } diff --git a/compiler/rustc_target/src/callconv/xtensa.rs b/compiler/rustc_target/src/callconv/xtensa.rs index 4dc9fad650636..49005adeb33c0 100644 --- a/compiler/rustc_target/src/callconv/xtensa.rs +++ b/compiler/rustc_target/src/callconv/xtensa.rs @@ -7,7 +7,7 @@ use rustc_abi::{BackendRepr, HasDataLayout, Size, TyAbiInterface}; -use crate::callconv::{ArgAbi, FnAbi, Reg, Uniform}; +use crate::callconv::{ArgAbi, FnAbi, IndirectMode, Reg, Uniform}; use crate::spec::HasTargetSpec; const NUM_ARG_GPRS: u64 = 6; @@ -29,8 +29,8 @@ where classify_arg_ty(cx, arg, &mut arg_gprs_left, true); // Ret args cannot be passed via stack, we lower to indirect and let the backend handle the invisible reference match arg.mode { - super::PassMode::Indirect { attrs: _, meta_attrs: _, ref mut on_stack } => { - *on_stack = false; + super::PassMode::Indirect { attrs: _, meta_attrs: _, address_space: _, ref mut mode } => { + *mode = IndirectMode::Pointer; } _ => {} } diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index bcba5839926db..a9d8aa23b1ea5 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -12,7 +12,9 @@ use rustc_middle::ty::layout::{ use rustc_middle::ty::{self, InstanceKind, ShimKind, Ty, TyCtxt, Unnormalized}; use rustc_span::def_id::DefId; use rustc_span::{DUMMY_SP, bug}; -use rustc_target::callconv::{AbiMap, ArgAbi, ArgAttribute, ArgAttributes, FnAbi, PassMode}; +use rustc_target::callconv::{ + AbiMap, ArgAbi, ArgAttribute, ArgAttributes, FnAbi, IndirectMode, PassMode, +}; use tracing::debug; pub(crate) fn provide(providers: &mut Providers) { @@ -444,15 +446,15 @@ fn fn_abi_sanity_check<'tcx>( // omitted entirely in the calling convention. assert!(arg.is_ignore()); } - if let PassMode::Indirect { on_stack, .. } = arg.mode + if let PassMode::Indirect { mode, .. } = arg.mode && spec_abi != ExternAbi::RustTail { - assert!(!on_stack, "rustic abi {spec_abi:?} shouldn't use on_stack"); + assert!(mode == IndirectMode::Pointer, "rust abi must use plain pointer mode"); } } else if arg.layout.pass_indirectly_in_non_rustic_abis(cx) { assert_matches!( arg.mode, - PassMode::Indirect { on_stack: false, .. }, + PassMode::Indirect { mode: IndirectMode::Pointer, .. }, "the {spec_abi} ABI does not implement `#[rustc_pass_indirectly_in_non_rustic_abis]`" ); } @@ -506,9 +508,9 @@ fn fn_abi_sanity_check<'tcx>( // Indirect returns are arguments from an ABI perspective. fn_arg_attrs_sanity_check(attrs, false); } - PassMode::Indirect { meta_attrs: Some(meta_attrs), attrs, on_stack } => { + PassMode::Indirect { meta_attrs: Some(meta_attrs), attrs, address_space: _, mode } => { // With metadata. Must be unsized and not on the stack. - assert!(arg.layout.is_unsized() && !on_stack); + assert!(arg.layout.is_unsized() && *mode == IndirectMode::Pointer); // Also, must not be `extern` type. let tail = tcx.struct_tail_for_codegen(arg.layout.ty, cx.typing_env); if matches!(tail.kind(), ty::Foreign(..)) { diff --git a/tests/assembly-llvm/tail-call-indirect.rs b/tests/assembly-llvm/tail-call-indirect.rs index 2bc1743a9bafd..918283966b405 100644 --- a/tests/assembly-llvm/tail-call-indirect.rs +++ b/tests/assembly-llvm/tail-call-indirect.rs @@ -10,10 +10,10 @@ #![no_core] #![crate_type = "lib"] -// Test tail calls with `PassMode::Indirect { on_stack: false, .. }` arguments. +// Test tail calls with `PassMode::Indirect { mode: IndirectMode::Pointer, .. }` arguments. // -// Normally an indirect argument with `on_stack: false` would be passed as a pointer to the -// caller's stack frame. For tail calls, that would be unsound, because the caller's stack +// Normally an indirect argument with `mode: IndirectMode::Pointer` would be passed as a pointer to +// the caller's stack frame. For tail calls, that would be unsound, because the caller's stack // frame is overwritten by the callee's stack frame. // // The solution is to write the argument into the caller's argument place (stored somewhere further diff --git a/tests/ui-fulldeps/rustc_public/check_abi.rs b/tests/ui-fulldeps/rustc_public/check_abi.rs index ed616cc4d9bb0..92d6f28f8fd8c 100644 --- a/tests/ui-fulldeps/rustc_public/check_abi.rs +++ b/tests/ui-fulldeps/rustc_public/check_abi.rs @@ -15,8 +15,8 @@ extern crate rustc_middle; extern crate rustc_public; use rustc_public::abi::{ - ArgAbi, ArgExtension, CallConvention, FieldsShape, IntegerLength, PassMode, Primitive, Scalar, - ValueRepr, VariantsShape, + ArgAbi, ArgExtension, CallConvention, FieldsShape, IndirectMode, IntegerLength, PassMode, + Primitive, Scalar, ValueRepr, VariantsShape, }; use rustc_public::mir::MirVisitor; use rustc_public::mir::mono::Instance; @@ -127,14 +127,14 @@ fn check_primitive(abi: &ArgAbi) { /// Check the return value: `Result`. fn check_result(abi: &ArgAbi) { assert!(abi.ty.kind().is_enum()); - let PassMode::Indirect { ref attrs, ref meta_attrs, on_stack } = abi.mode else { + let PassMode::Indirect { ref attrs, ref meta_attrs, address_space: _, mode } = abi.mode else { panic!("Expected PassMode::Indirect for Result, got: {:?}", abi.mode); }; // Indirect arguments have a pointee alignment (the pointer must be aligned). assert!(attrs.pointee_align().is_some()); // Result is a sized type, so no metadata pointer. assert!(meta_attrs.is_none()); - assert!(!on_stack); + assert!(mode == IndirectMode::Pointer); let layout = abi.layout.shape(); assert!(layout.is_sized()); assert_matches!(layout.fields, FieldsShape::Arbitrary { .. }); diff --git a/tests/ui-fulldeps/rustc_public/check_abi_cast.rs b/tests/ui-fulldeps/rustc_public/check_abi_cast.rs index 0bd4ac684066e..a54abdd5deeaf 100644 --- a/tests/ui-fulldeps/rustc_public/check_abi_cast.rs +++ b/tests/ui-fulldeps/rustc_public/check_abi_cast.rs @@ -23,7 +23,7 @@ use std::convert::TryFrom; use std::io::Write; use std::ops::ControlFlow; -use rustc_public::abi::{CallConvention, PassMode, RegKind}; +use rustc_public::abi::{CallConvention, IndirectMode, PassMode, RegKind}; use rustc_public::mir::mono::Instance; use rustc_public::{CrateDef, ItemKind}; @@ -147,7 +147,7 @@ fn test_abi_cast() -> ControlFlow<()> { } // Fourth TwoWords has no registers left → Indirect (on stack) assert!( - matches!(&abi.args[3].mode, PassMode::Indirect { on_stack: true, .. }), + matches!(&abi.args[3].mode, PassMode::Indirect { mode: IndirectMode::OnStack, .. }), "Expected arg 3 to be Indirect on stack, got: {:?}", abi.args[3].mode ); diff --git a/tests/ui/abi/c-zst.powerpc-linux.stderr b/tests/ui/abi/c-zst.powerpc-linux.stderr index 302ffe1efc8b8..e5cad2199491b 100644 --- a/tests/ui/abi/c-zst.powerpc-linux.stderr +++ b/tests/ui/abi/c-zst.powerpc-linux.stderr @@ -35,7 +35,8 @@ error: fn_abi_of(pass_zst) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/abi/c-zst.s390x-linux.stderr b/tests/ui/abi/c-zst.s390x-linux.stderr index 302ffe1efc8b8..e5cad2199491b 100644 --- a/tests/ui/abi/c-zst.s390x-linux.stderr +++ b/tests/ui/abi/c-zst.s390x-linux.stderr @@ -35,7 +35,8 @@ error: fn_abi_of(pass_zst) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/abi/c-zst.sparc-linux.stderr b/tests/ui/abi/c-zst.sparc-linux.stderr index 302ffe1efc8b8..e5cad2199491b 100644 --- a/tests/ui/abi/c-zst.sparc-linux.stderr +++ b/tests/ui/abi/c-zst.sparc-linux.stderr @@ -35,7 +35,8 @@ error: fn_abi_of(pass_zst) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/abi/c-zst.sparc-none.stderr b/tests/ui/abi/c-zst.sparc-none.stderr index 302ffe1efc8b8..e5cad2199491b 100644 --- a/tests/ui/abi/c-zst.sparc-none.stderr +++ b/tests/ui/abi/c-zst.sparc-none.stderr @@ -35,7 +35,8 @@ error: fn_abi_of(pass_zst) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/abi/c-zst.sparc64-linux.stderr b/tests/ui/abi/c-zst.sparc64-linux.stderr index 302ffe1efc8b8..e5cad2199491b 100644 --- a/tests/ui/abi/c-zst.sparc64-linux.stderr +++ b/tests/ui/abi/c-zst.sparc64-linux.stderr @@ -35,7 +35,8 @@ error: fn_abi_of(pass_zst) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/abi/c-zst.x86_64-pc-windows-gnu.stderr b/tests/ui/abi/c-zst.x86_64-pc-windows-gnu.stderr index 302ffe1efc8b8..e5cad2199491b 100644 --- a/tests/ui/abi/c-zst.x86_64-pc-windows-gnu.stderr +++ b/tests/ui/abi/c-zst.x86_64-pc-windows-gnu.stderr @@ -35,7 +35,8 @@ error: fn_abi_of(pass_zst) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/abi/debug.generic.stderr b/tests/ui/abi/debug.generic.stderr index 6242d93b09534..1793674fa462a 100644 --- a/tests/ui/abi/debug.generic.stderr +++ b/tests/ui/abi/debug.generic.stderr @@ -446,7 +446,8 @@ error: ABIs are not compatible ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], @@ -519,7 +520,8 @@ error: ABIs are not compatible ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/abi/debug.loongarch64.stderr b/tests/ui/abi/debug.loongarch64.stderr index 176c68ecd4c7b..29ec7846101f1 100644 --- a/tests/ui/abi/debug.loongarch64.stderr +++ b/tests/ui/abi/debug.loongarch64.stderr @@ -446,7 +446,8 @@ error: ABIs are not compatible ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], @@ -519,7 +520,8 @@ error: ABIs are not compatible ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/abi/debug.riscv64.stderr b/tests/ui/abi/debug.riscv64.stderr index 176c68ecd4c7b..29ec7846101f1 100644 --- a/tests/ui/abi/debug.riscv64.stderr +++ b/tests/ui/abi/debug.riscv64.stderr @@ -446,7 +446,8 @@ error: ABIs are not compatible ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], @@ -519,7 +520,8 @@ error: ABIs are not compatible ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/abi/pass-indirectly-attr.rs b/tests/ui/abi/pass-indirectly-attr.rs index 54aafc716587c..bb90b8354ea91 100644 --- a/tests/ui/abi/pass-indirectly-attr.rs +++ b/tests/ui/abi/pass-indirectly-attr.rs @@ -20,7 +20,7 @@ pub struct Type(u8); pub extern "C" fn extern_c(_: Type) {} //~^ ERROR fn_abi_of(extern_c) = FnAbi { //~| ERROR mode: Indirect -//~| ERROR on_stack: false, +//~| ERROR mode: Pointer, //~| ERROR conv: C, #[rustc_abi(debug)] diff --git a/tests/ui/abi/pass-indirectly-attr.stderr b/tests/ui/abi/pass-indirectly-attr.stderr index efeec0d86982b..5821e6279bb85 100644 --- a/tests/ui/abi/pass-indirectly-attr.stderr +++ b/tests/ui/abi/pass-indirectly-attr.stderr @@ -48,7 +48,8 @@ error: fn_abi_of(extern_c) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/c-variadic/pass-by-value-abi.aarch64.stderr b/tests/ui/c-variadic/pass-by-value-abi.aarch64.stderr index 45edd7bc0e0ee..c9e77ac941901 100644 --- a/tests/ui/c-variadic/pass-by-value-abi.aarch64.stderr +++ b/tests/ui/c-variadic/pass-by-value-abi.aarch64.stderr @@ -35,7 +35,8 @@ error: fn_abi_of(take_va_list) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/c-variadic/pass-by-value-abi.rs b/tests/ui/c-variadic/pass-by-value-abi.rs index bcca09e90438a..317840601c050 100644 --- a/tests/ui/c-variadic/pass-by-value-abi.rs +++ b/tests/ui/c-variadic/pass-by-value-abi.rs @@ -27,9 +27,9 @@ use std::ffi::VaList; pub extern "C" fn take_va_list(_: VaList<'_>) {} //~^ ERROR fn_abi_of(take_va_list) = FnAbi { //[x86_64]~^^ ERROR mode: Indirect { -//[x86_64]~^^^ ERROR on_stack: false, +//[x86_64]~^^^ ERROR mode: Pointer, //[aarch64]~^^^^ ERROR mode: Indirect { -//[aarch64]~^^^^^ ERROR on_stack: false, +//[aarch64]~^^^^^ ERROR mode: Pointer, //[win]~^^^^^^ ERROR mode: Direct( #[cfg(all(target_arch = "x86_64", not(windows)))] @@ -37,11 +37,11 @@ pub extern "C" fn take_va_list(_: VaList<'_>) {} pub extern "sysv64" fn take_va_list_sysv64(_: VaList<'_>) {} //[x86_64]~^ ERROR fn_abi_of(take_va_list_sysv64) = FnAbi { //[x86_64]~^^ ERROR mode: Indirect { -//[x86_64]~^^^ ERROR on_stack: false, +//[x86_64]~^^^ ERROR mode: Pointer, #[cfg(all(target_arch = "x86_64", not(windows)))] #[rustc_abi(debug)] pub extern "win64" fn take_va_list_win64(_: VaList<'_>) {} //[x86_64]~^ ERROR: fn_abi_of(take_va_list_win64) = FnAbi { //[x86_64]~^^ ERROR mode: Indirect { -//[x86_64]~^^^ ERROR on_stack: false, +//[x86_64]~^^^ ERROR mode: Pointer, diff --git a/tests/ui/c-variadic/pass-by-value-abi.x86_64.stderr b/tests/ui/c-variadic/pass-by-value-abi.x86_64.stderr index 1e203b93e66b3..04320a5312361 100644 --- a/tests/ui/c-variadic/pass-by-value-abi.x86_64.stderr +++ b/tests/ui/c-variadic/pass-by-value-abi.x86_64.stderr @@ -35,7 +35,8 @@ error: fn_abi_of(take_va_list) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], @@ -113,7 +114,8 @@ error: fn_abi_of(take_va_list_sysv64) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], @@ -193,7 +195,8 @@ error: fn_abi_of(take_va_list_win64) = FnAbi { ), }, meta_attrs: None, - on_stack: false, + address_space: None, + mode: Pointer, }, }, ], diff --git a/tests/ui/explicit-tail-calls/indirect.rs b/tests/ui/explicit-tail-calls/indirect.rs index b3e2613efad25..71107ef420c35 100644 --- a/tests/ui/explicit-tail-calls/indirect.rs +++ b/tests/ui/explicit-tail-calls/indirect.rs @@ -25,17 +25,17 @@ #![feature(explicit_tail_calls)] #![expect(incomplete_features)] -// Test tail calls with `PassMode::Indirect { on_stack: false, .. }` arguments. +// Test tail calls with `PassMode::Indirect { mode: IndirectMode::Pointer, .. }` arguments. // -// Normally an indirect argument with `on_stack: false` would be passed as a pointer to the -// caller's stack frame. For tail calls, that would be unsound, because the caller's stack +// Normally an indirect argument with `mode: IndirectMode::Pointer` would be passed as a pointer to +// the caller's stack frame. For tail calls, that would be unsound, because the caller's stack // frame is overwritten by the callee's stack frame. // // The solution is to write the argument into the caller's argument place (stored somewhere further // up the stack), and forward that place. // A struct big enough that it is not passed via registers, so that the rust calling convention uses -// `Indirect { on_stack: false, .. }`. +// `Indirect { mode: IndirectMode::Pointer, .. }`. #[repr(C)] #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] pub struct Big([u64; 4]); @@ -79,7 +79,7 @@ fn main() { assert_eq!(update_in_caller(Big::default()), 0 + 2 + 3 + 4); assert_eq!(swapper(u8::MIN, u8::MAX), (u8::MAX, u8::MIN)); - // i128 uses `PassMode::Indirect { on_stack: false, .. }` on x86_64 MSVC. + // i128 uses `PassMode::Indirect { mode: IndirectMode::Pointer, .. }` on x86_64 MSVC. assert_eq!(swapper(i128::MIN, i128::MAX), (i128::MAX, i128::MIN)); assert_eq!(swapper(Big([1; 4]), Big([2; 4])), (Big([2; 4]), Big([1; 4]))); From b8c747f548ba53a20b57484fc06b567a82aa227b Mon Sep 17 00:00:00 2001 From: Flakebi Date: Thu, 3 Sep 2026 09:21:39 +0200 Subject: [PATCH 12/16] Pre-commit amdgpu gpu-kernel ABI test --- tests/codegen-llvm/amdgpu-abi/struct-abi.rs | 133 ++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 tests/codegen-llvm/amdgpu-abi/struct-abi.rs diff --git a/tests/codegen-llvm/amdgpu-abi/struct-abi.rs b/tests/codegen-llvm/amdgpu-abi/struct-abi.rs new file mode 100644 index 0000000000000..bf51cbfa7f7a0 --- /dev/null +++ b/tests/codegen-llvm/amdgpu-abi/struct-abi.rs @@ -0,0 +1,133 @@ +//@ add-minicore +//@ compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 -Copt-level=3 +//@ needs-llvm-components: amdgpu +#![feature(no_core, abi_gpu_kernel)] +#![no_core] +#![allow(improper_gpu_kernel_arg)] + +extern crate minicore; +use minicore::num::Complex; + +// Tests from llvm-project/clang/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl + +#[repr(C)] +pub struct SingleElementStructArg { + i: i32, +} + +#[repr(C)] +pub struct NestedSingleElementStructArg { + i: SingleElementStructArg, +} + +#[repr(C)] +pub struct StructArg { + i1: i32, + f: f32, + i2: i32, +} + +#[repr(C)] +pub struct StructPaddingArg { + i1: i8, + f: i64, +} + +#[repr(C)] +pub struct StructOfArraysArg { + i1: [i32; 2], + f1: f32, + i2: [i32; 4], + f2: [f32; 3], + i3: i32, +} + +#[repr(C)] +pub struct StructOfStructsArg { + i1: i32, + f1: f32, + s1: StructArg, + i2: i32, +} + +#[repr(C)] +pub union U { + b1: i32, + b2: f32, +} + +#[repr(C)] +pub struct SingleArrayElementStructArg { + i: [i32; 4], +} + +#[repr(C)] +pub struct SingleStructElementStructArgInner { + i: i32, + b: i64, +} + +#[repr(C)] +pub struct SingleStructElementStructArg { + s: SingleStructElementStructArgInner, +} + +#[repr(C)] +pub struct DifferentSizeTypePair { + l: i64, + i: i32, +} + +// CHECK: define amdgpu_kernel void @kernel_single_element_struct_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(4) {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_single_element_struct_arg(_: SingleElementStructArg) {} + +// CHECK: define amdgpu_kernel void @kernel_nested_single_element_struct_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(4) {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_nested_single_element_struct_arg( + _: NestedSingleElementStructArg, +) { +} + +// CHECK: define amdgpu_kernel void @kernel_struct_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(12) {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_struct_arg(_: StructArg) {} + +// CHECK: define amdgpu_kernel void @kernel_struct_padding_arg(i8 noundef {{%.+}}, i64 noundef {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_struct_padding_arg(_: StructPaddingArg) {} + +// CHECK: define amdgpu_kernel void @kernel_struct_of_arrays_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(44) {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_struct_of_arrays_arg(_: StructOfArraysArg) {} + +// CHECK: define amdgpu_kernel void @kernel_struct_of_structs_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(24) {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_struct_of_structs_arg(_: StructOfStructsArg) {} + +// CHECK: define amdgpu_kernel void @test_kernel_union_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(4) {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn test_kernel_union_arg(_: U) {} + +// CHECK: define amdgpu_kernel void @kernel_single_array_element_struct_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(16) {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_single_array_element_struct_arg(_: SingleArrayElementStructArg) {} + +// CHECK: define amdgpu_kernel void @kernel_single_struct_element_struct_arg(i32 noundef {{%.+}}, i64 noundef {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_single_struct_element_struct_arg( + _: SingleStructElementStructArg, +) { +} + +// CHECK: define amdgpu_kernel void @kernel_different_size_type_pair_arg(i64 noundef {{%.+}}, i32 noundef {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_different_size_type_pair_arg(_: DifferentSizeTypePair) {} + +// CHECK: define amdgpu_kernel void @kernel_complex(float noundef {{%.+}}, float noundef {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_complex(_: Complex) {} + +// CHECK: define amdgpu_kernel void @kernel_slice(ptr noalias nofree noundef nonnull readonly align 4 captures(none) {{%.+}}, i64 noundef range(i64 0, 2305843009213693952) {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_slice(_: &[u32]) {} From be988e9f8563e138c777cd4530594972a81af9b9 Mon Sep 17 00:00:00 2001 From: Flakebi Date: Tue, 15 Sep 2026 10:33:14 +0200 Subject: [PATCH 13/16] Properly implement the gpu-kernel ABI for amdgpu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support to pass structs, arrays and vectors to amdgpu kernels. Scalars and vectors are taken by value, aggregates are passed by byref pointers. Structs containing a single scalar/vector are handled like a scalar. Judging from clang tests, nvptx seems to do somewhat the same, just using byval instead of byref: https://github.com/llvm/llvm-project/blob/3a8affeef4da19d39191aac316e189eca3214a8c/clang/test/CodeGenCUDA/kernel-args.cu I tested a couple of the lit test signatures on real hardware and it seems to work fine. Given the relatively simple implementation, I hope this amount of testing is enough (the C calling convention seems like a worse fit for Rust’s current ABI code, it’s still giving me headaches). --- compiler/rustc_abi/src/lib.rs | 4 + compiler/rustc_target/src/callconv/amdgpu.rs | 82 ++++++++++++++---- tests/codegen-llvm/amdgpu-abi/struct-abi.rs | 88 ++++++++++++++++---- 3 files changed, 139 insertions(+), 35 deletions(-) diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 9c11405e9bb58..56cfbf138af00 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -1778,6 +1778,10 @@ pub struct AddressSpace(pub u32); impl AddressSpace { /// LLVM's `0` address space. pub const ZERO: Self = AddressSpace(0); + /// The address space for constant memory on nvptx and amdgpu. + /// This address space is used e.g. for kernel arguments that are constant throughout the + /// execution. + pub const GPU_CONSTANT: Self = AddressSpace(4); /// The address space for workgroup memory on nvptx and amdgpu. /// See e.g. the `gpu_launch_sized_workgroup_mem` intrinsic for details. pub const GPU_WORKGROUP: Self = AddressSpace(3); diff --git a/compiler/rustc_target/src/callconv/amdgpu.rs b/compiler/rustc_target/src/callconv/amdgpu.rs index 98ab3ce8eb746..7a9eeaba19c96 100644 --- a/compiler/rustc_target/src/callconv/amdgpu.rs +++ b/compiler/rustc_target/src/callconv/amdgpu.rs @@ -1,25 +1,60 @@ -use rustc_abi::{HasDataLayout, TyAbiInterface}; +use rustc_abi::{ + AddressSpace, BackendRepr, CanonAbi, HasDataLayout, Reg, RegKind, TyAbiInterface, TyAndLayout, +}; -use crate::callconv::{ArgAbi, FnAbi}; +use crate::callconv::{FnAbi, Uniform}; -fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>) -where - Ty: TyAbiInterface<'a, C> + Copy, - C: HasDataLayout, -{ - ret.extend_integer_width_to(32); -} +// For reference, see llvm-project/clang/lib/CodeGen/Targets/AMDGPU.cpp -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) +/// If the given type is a (potentially nested) struct containing a single scalar, return +/// a `Uniform` for the contained, single element. +fn single_element_struct_to_reg<'a, Ty, C>(cx: &C, ty: TyAndLayout<'a, Ty>) -> Option where Ty: TyAbiInterface<'a, C> + Copy, C: HasDataLayout, { - if arg.layout.pass_indirectly_in_non_rustic_abis(cx) { - arg.make_indirect(); - return; + assert!(ty.is_aggregate(), "Only handles aggregate types"); + if ty.layout.fields.count() != 1 { + return None; + } + let field = ty.field(cx, 0); + match field.backend_repr { + BackendRepr::SimdScalableVector { .. } => panic!("scalable vectors are unsupported"), + BackendRepr::Scalar(_) => { + // Check that the size is the same as the size for ty, so no extra padding + let size = field.layout.size.bytes(); + if ty.layout.size.bytes() != size { + return None; + } + + // clang passes the inner type directly, we emulate it with fitting integer types + match size { + 1 => Some(Uniform::new(Reg::i8(), field.layout.size)), + 2 => Some(Uniform::new(Reg::i16(), field.layout.size)), + 4 => Some(Uniform::new(Reg::i32(), field.layout.size)), + 8 => Some(Uniform::new(Reg::i64(), field.layout.size)), + 16 => Some(Uniform::new(Reg::i128(), field.layout.size)), + s => panic!("Unhandled scalar of size {s} in amdgpu gpu-kernel ABI"), + } + } + BackendRepr::SimdVector { element, .. } => { + // Check that the size is the same as the size for ty, so no extra padding + let size = field.layout.size.bytes(); + if ty.layout.size.bytes() != size { + return None; + } + + // clang passes the inner type directly, we emulate it with a vector of the same type. + // The size is rounded up to the size of the complete type (including alignment). + let reg = Reg { + kind: RegKind::Vector { hint_vector_elem: element.primitive() }, + size: field.layout.size, + }; + Some(Uniform::new(reg, field.layout.size)) + } + BackendRepr::Memory { .. } => single_element_struct_to_reg(cx, field), + BackendRepr::ScalarPair { .. } => None, } - arg.extend_integer_width_to(32); } pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) @@ -27,14 +62,25 @@ where Ty: TyAbiInterface<'a, C> + Copy, C: HasDataLayout, { - if !fn_abi.ret.is_ignore() { - classify_ret(cx, &mut fn_abi.ret); - } + // Kernels cannot return values, so do not handle return types + // Try to fill first registers with values and pass by_ref pointers for later indirect arguments for arg in fn_abi.args.iter_mut() { if arg.is_ignore() { continue; } - classify_arg(cx, arg); + if fn_abi.conv == CanonAbi::GpuKernel { + if arg.layout.is_aggregate() { + if let Some(uniform) = single_element_struct_to_reg(cx, arg.layout) { + // Single element structs are passed directly as the inner type + arg.cast_to(uniform); + } else { + // All other aggregates are passed as by_ref pointer in the constant address space + arg.pass_amdgpu_kernel_arg(Some(AddressSpace::GPU_CONSTANT)); + } + } + } else { + // FIXME: C ABI is not yet implemented + } } } diff --git a/tests/codegen-llvm/amdgpu-abi/struct-abi.rs b/tests/codegen-llvm/amdgpu-abi/struct-abi.rs index bf51cbfa7f7a0..bc83f6510a6fe 100644 --- a/tests/codegen-llvm/amdgpu-abi/struct-abi.rs +++ b/tests/codegen-llvm/amdgpu-abi/struct-abi.rs @@ -1,7 +1,7 @@ //@ add-minicore //@ compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ctarget-cpu=gfx900 -Copt-level=3 //@ needs-llvm-components: amdgpu -#![feature(no_core, abi_gpu_kernel)] +#![feature(no_core, abi_gpu_kernel, repr_simd)] #![no_core] #![allow(improper_gpu_kernel_arg)] @@ -10,14 +10,32 @@ use minicore::num::Complex; // Tests from llvm-project/clang/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl +#[repr(simd)] +pub struct I8X2([i8; 2]); + +#[repr(simd)] +pub struct I16X2([i16; 2]); + +#[repr(simd)] +pub struct I16X3([i16; 3]); + +#[repr(simd)] +pub struct I16X4([i16; 4]); + +#[repr(simd)] +pub struct I32X3([i32; 3]); + +#[repr(simd)] +pub struct I32X4([i32; 4]); + #[repr(C)] -pub struct SingleElementStructArg { - i: i32, +pub struct SingleElementStructArg { + i: T, } #[repr(C)] pub struct NestedSingleElementStructArg { - i: SingleElementStructArg, + i: SingleElementStructArg, } #[repr(C)] @@ -78,56 +96,92 @@ pub struct DifferentSizeTypePair { i: i32, } -// CHECK: define amdgpu_kernel void @kernel_single_element_struct_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(4) {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_single_element_struct_arg(i32 %0) #[no_mangle] -pub extern "gpu-kernel" fn kernel_single_element_struct_arg(_: SingleElementStructArg) {} +pub extern "gpu-kernel" fn kernel_single_element_struct_arg(_: SingleElementStructArg) {} -// CHECK: define amdgpu_kernel void @kernel_nested_single_element_struct_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(4) {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_nested_single_element_struct_arg(i32 %0) #[no_mangle] pub extern "gpu-kernel" fn kernel_nested_single_element_struct_arg( _: NestedSingleElementStructArg, ) { } -// CHECK: define amdgpu_kernel void @kernel_struct_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(12) {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_struct_arg(ptr addrspace(4) noalias nofree noundef readnone byref([12 x i8]) align 4 captures(none) dereferenceable(12) {{%.+}}) #[no_mangle] pub extern "gpu-kernel" fn kernel_struct_arg(_: StructArg) {} -// CHECK: define amdgpu_kernel void @kernel_struct_padding_arg(i8 noundef {{%.+}}, i64 noundef {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_struct_padding_arg(ptr addrspace(4) noalias nofree noundef readnone byref([16 x i8]) align 8 captures(none) dereferenceable(16) {{%.+}}) #[no_mangle] pub extern "gpu-kernel" fn kernel_struct_padding_arg(_: StructPaddingArg) {} -// CHECK: define amdgpu_kernel void @kernel_struct_of_arrays_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(44) {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_struct_of_arrays_arg(ptr addrspace(4) noalias nofree noundef readnone byref([44 x i8]) align 4 captures(none) dereferenceable(44) {{%.+}}) #[no_mangle] pub extern "gpu-kernel" fn kernel_struct_of_arrays_arg(_: StructOfArraysArg) {} -// CHECK: define amdgpu_kernel void @kernel_struct_of_structs_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(24) {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_struct_of_structs_arg(ptr addrspace(4) noalias nofree noundef readnone byref([24 x i8]) align 4 captures(none) dereferenceable(24) {{%.+}}) #[no_mangle] pub extern "gpu-kernel" fn kernel_struct_of_structs_arg(_: StructOfStructsArg) {} -// CHECK: define amdgpu_kernel void @test_kernel_union_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(4) {{%.+}}) +// CHECK: define amdgpu_kernel void @test_kernel_union_arg(ptr addrspace(4) noalias nofree noundef readnone byref([4 x i8]) align 4 captures(none) dereferenceable(4) {{%.+}}) #[no_mangle] pub extern "gpu-kernel" fn test_kernel_union_arg(_: U) {} -// CHECK: define amdgpu_kernel void @kernel_single_array_element_struct_arg(ptr noalias nofree noundef readnone align 4 captures(none) dead_on_return dereferenceable(16) {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_single_array_element_struct_arg(ptr addrspace(4) noalias nofree noundef readnone byref([16 x i8]) align 4 captures(none) dereferenceable(16) {{%.+}}) #[no_mangle] pub extern "gpu-kernel" fn kernel_single_array_element_struct_arg(_: SingleArrayElementStructArg) {} -// CHECK: define amdgpu_kernel void @kernel_single_struct_element_struct_arg(i32 noundef {{%.+}}, i64 noundef {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_single_struct_element_struct_arg(ptr addrspace(4) noalias nofree noundef readnone byref([16 x i8]) align 8 captures(none) dereferenceable(16) {{%.+}}) #[no_mangle] pub extern "gpu-kernel" fn kernel_single_struct_element_struct_arg( _: SingleStructElementStructArg, ) { } -// CHECK: define amdgpu_kernel void @kernel_different_size_type_pair_arg(i64 noundef {{%.+}}, i32 noundef {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_different_size_type_pair_arg(ptr addrspace(4) noalias nofree noundef readnone byref([16 x i8]) align 8 captures(none) dereferenceable(16) {{%.+}}) #[no_mangle] pub extern "gpu-kernel" fn kernel_different_size_type_pair_arg(_: DifferentSizeTypePair) {} -// CHECK: define amdgpu_kernel void @kernel_complex(float noundef {{%.+}}, float noundef {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_complex(ptr addrspace(4) noalias nofree noundef readnone byref([8 x i8]) align 4 captures(none) dereferenceable(8) {{%.+}}) #[no_mangle] pub extern "gpu-kernel" fn kernel_complex(_: Complex) {} -// CHECK: define amdgpu_kernel void @kernel_slice(ptr noalias nofree noundef nonnull readonly align 4 captures(none) {{%.+}}, i64 noundef range(i64 0, 2305843009213693952) {{%.+}}) +// CHECK: define amdgpu_kernel void @kernel_slice(ptr addrspace(4) noalias nofree noundef readnone byref([16 x i8]) align 8 captures(none) dereferenceable(16) {{%.+}}) #[no_mangle] pub extern "gpu-kernel" fn kernel_slice(_: &[u32]) {} + +// CHECK: define amdgpu_kernel void @kernel_i64(i64 noundef {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_i64(_: i64) {} + +// CHECK: define amdgpu_kernel void @kernel_i64_struct(i64 {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_i64_struct(_: SingleElementStructArg) {} + +// CHECK: define amdgpu_kernel void @kernel_i128_struct(i128 {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_i128_struct(_: SingleElementStructArg) {} + +// CHECK: define amdgpu_kernel void @kernel_i8x2_struct(<2 x i8> {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_i8x2_struct(_: SingleElementStructArg) {} + +// CHECK: define amdgpu_kernel void @kernel_i16x2_struct(<2 x i16> {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_i16x2_struct(_: SingleElementStructArg) {} + +// CHECK: define amdgpu_kernel void @kernel_i16x3_struct(<4 x i16> {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_i16x3_struct(_: SingleElementStructArg) {} + +// CHECK: define amdgpu_kernel void @kernel_i16x4_struct(<4 x i16> {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_i16x4_struct(_: SingleElementStructArg) {} + +// CHECK: define amdgpu_kernel void @kernel_i32x3_struct(<4 x i32> {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_i32x3_struct(_: SingleElementStructArg) {} + +// CHECK: define amdgpu_kernel void @kernel_i32x4_struct(<4 x i32> {{%.+}}) +#[no_mangle] +pub extern "gpu-kernel" fn kernel_i32x4_struct(_: SingleElementStructArg) {} From b267be921e3f95b96c7eafd6e47028822afe96e2 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Wed, 23 Sep 2026 12:03:41 +0200 Subject: [PATCH 14/16] Remove `suggestion_for_allocator_api` --- compiler/rustc_middle/src/middle/stability.rs | 62 +++---------------- compiler/rustc_resolve/src/macros.rs | 1 - compiler/rustc_span/src/symbol.rs | 1 - 3 files changed, 7 insertions(+), 57 deletions(-) diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 8213646b4625d..0235d5bb17224 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -7,7 +7,7 @@ use rustc_ast::NodeId; use rustc_attr_ir::{ ConstStability, DefaultBodyStability, DeprecatedSince, Deprecation, Stability, StabilityLevel, }; -use rustc_errors::{Applicability, Diag, Diagnostic, LintBuffer, msg}; +use rustc_errors::{Diag, Diagnostic, LintBuffer, msg}; use rustc_feature::GateIssue; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, HirId}; @@ -62,7 +62,6 @@ pub fn report_unstable( feature: Symbol, reason: Option, issue: Option>, - suggestion: Option<(Span, String, String, Applicability)>, span: Span, kind: UnstableKind, ) { @@ -77,9 +76,6 @@ pub fn report_unstable( }; let mut err = feature_err_issue(sess, feature, span, GateIssue::Library(issue), msg); - if let Some((inner_types, msg, sugg, applicability)) = suggestion { - err.span_suggestion(inner_types, msg, sugg, applicability); - } if let UnstableKind::Const(kw) = kind { err.span_label(kw, "trait is not stable as const yet"); } @@ -260,42 +256,11 @@ pub enum EvalResult { Allow, /// We cannot use the item because it is unstable and we did not provide the /// corresponding feature gate. - Deny { - feature: Symbol, - reason: Option, - issue: Option>, - suggestion: Option<(Span, String, String, Applicability)>, - }, + Deny { feature: Symbol, reason: Option, issue: Option> }, /// The item does not have the `#[stable]` or `#[unstable]` marker assigned. Unmarked, } -// See issue #83250. -fn suggestion_for_allocator_api( - tcx: TyCtxt<'_>, - def_id: DefId, - span: Span, - feature: Symbol, -) -> Option<(Span, String, String, Applicability)> { - if feature == sym::allocator_api { - if let Some(trait_) = tcx.opt_parent(def_id) { - if tcx.is_diagnostic_item(sym::Vec, trait_) { - let sm = tcx.sess.psess.source_map(); - let inner_types = sm.span_extend_to_prev_char(span, '<', true); - if let Ok(snippet) = sm.span_to_snippet(inner_types) { - return Some(( - inner_types, - "consider wrapping the inner types in tuple".to_string(), - format!("({snippet})"), - Applicability::MaybeIncorrect, - )); - } - } - } - } - None -} - /// An override option for eval_stability. pub enum AllowUnstable { /// Don't emit an unstable error for the item @@ -425,8 +390,7 @@ impl<'tcx> TyCtxt<'tcx> { return EvalResult::Allow; } - let suggestion = suggestion_for_allocator_api(self, def_id, span, feature); - EvalResult::Deny { feature, reason: reason.to_opt_reason(), issue, suggestion } + EvalResult::Deny { feature, reason: reason.to_opt_reason(), issue } } Some(_) => { // Stable APIs are always ok to call and deprecated APIs are @@ -472,12 +436,7 @@ impl<'tcx> TyCtxt<'tcx> { return EvalResult::Allow; } - EvalResult::Deny { - feature, - reason: reason.to_opt_reason(), - issue, - suggestion: None, - } + EvalResult::Deny { feature, reason: reason.to_opt_reason(), issue } } Some(_) => { // Stable APIs are always ok to call @@ -559,15 +518,9 @@ impl<'tcx> TyCtxt<'tcx> { let is_allowed = matches!(eval_result, EvalResult::Allow); match eval_result { EvalResult::Allow => {} - EvalResult::Deny { feature, reason, issue, suggestion } => report_unstable( - self.sess, - feature, - reason, - issue, - suggestion, - span, - UnstableKind::Regular, - ), + EvalResult::Deny { feature, reason, issue } => { + report_unstable(self.sess, feature, reason, issue, span, UnstableKind::Regular) + } EvalResult::Unmarked => unmarked(span, def_id), } @@ -628,7 +581,6 @@ impl<'tcx> TyCtxt<'tcx> { feature, reason.to_opt_reason(), issue, - None, span, UnstableKind::Const(const_kw_span), ); diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 24a52d4143493..823a66dcd5d93 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -1098,7 +1098,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { feature, reason.to_opt_reason(), issue, - None, span, stability::UnstableKind::Regular, ); diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index bd70e5acab4d7..f2ab04b41d938 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -413,7 +413,6 @@ symbols! { alloc_layout, alloc_zeroed, allocator, - allocator_api, allocator_internals, allow, allow_fail, From 71d4ef88c61ab0f4673589bb4d19e96c76f89560 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 23 Sep 2026 09:30:29 +1000 Subject: [PATCH 15/16] Remove unused `StashKey::UnderscoreForArrayLengths` It's no longer ever used for stashing, so the code looking for it is dead. It became dead in PR 141610 when `generic_arg_infer` was stabilized and `[T; _]` became valid. --- compiler/rustc_errors/src/lib.rs | 1 - compiler/rustc_hir_typeck/src/expr.rs | 29 --------------------------- 2 files changed, 30 deletions(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 68e10802e21c5..25a82b22707cc 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -375,7 +375,6 @@ struct DiagCtxtInner { #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum StashKey { ItemNoType, - UnderscoreForArrayLengths, EarlySyntaxWarning, CallIntoMethod, /// When an invalid lifetime e.g. `'2` should be reinterpreted diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 04e55dd0fdd95..8944d6a47488a 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1702,34 +1702,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.next_ty_var(expr.span) }; let array_len = args.len() as u64; - self.suggest_array_len(expr, array_len); Ty::new_array(self.tcx, element_ty, array_len) } - fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) { - let parent_node = self.tcx.hir_parent_iter(expr.hir_id).find(|(_, node)| { - !matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::AddrOf(..), .. })) - }); - let Some((_, hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), .. }))) = parent_node else { - return; - }; - if let hir::TyKind::Array(_, ct) = ty.peel_refs().kind { - let span = ct.span; - self.dcx().try_steal_modify_and_emit_err( - span, - StashKey::UnderscoreForArrayLengths, - |err| { - err.span_suggestion_verbose( - span, - "consider specifying the array length", - array_len, - Applicability::MaybeIncorrect, - ); - }, - ); - } - } - pub(super) fn check_expr_const_block( &self, block: &'tcx hir::ConstBlock, @@ -1764,10 +1739,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ), ); - if let Some(count) = count.try_to_target_usize(tcx) { - self.suggest_array_len(expr, count); - } - let uty = match expected { ExpectHasType(uty) => uty.builtin_index(), _ => None, From 4dcd02e3aa1b8101d24aa4ef8d887627407539a1 Mon Sep 17 00:00:00 2001 From: khyperia <953151+khyperia@users.noreply.github.com> Date: Wed, 23 Sep 2026 10:50:17 +0000 Subject: [PATCH 16/16] rename direct_const_arg! to gca! Co-authored-by: Boxy --- compiler/rustc_ast/src/ast.rs | 10 +- compiler/rustc_ast/src/util/classify.rs | 6 +- compiler/rustc_ast/src/visit.rs | 2 +- compiler/rustc_ast_lowering/src/expr.rs | 4 +- compiler/rustc_ast_lowering/src/lib.rs | 31 +++--- compiler/rustc_ast_pretty/src/pprust/state.rs | 4 +- .../rustc_ast_pretty/src/pprust/state/expr.rs | 4 +- .../src/assert/context.rs | 2 +- .../src/{direct_const_arg.rs => gca.rs} | 7 +- compiler/rustc_builtin_macros/src/lib.rs | 4 +- compiler/rustc_feature/src/unstable.rs | 4 +- compiler/rustc_hir/src/hir.rs | 2 +- .../src/check/compare_impl_item.rs | 4 +- .../src/hir_ty_lowering/mod.rs | 8 +- compiler/rustc_lint/src/unused.rs | 4 +- compiler/rustc_middle/src/queries.rs | 4 +- compiler/rustc_parse/src/parser/expr.rs | 2 +- compiler/rustc_passes/src/input_stats.rs | 4 +- compiler/rustc_resolve/src/late.rs | 2 +- compiler/rustc_span/src/symbol.rs | 2 +- library/core/src/marker.rs | 8 +- library/std/src/lib.rs | 2 + ...macroless-const-item-generic-const-args.md | 6 +- .../macroless-generic-const-args.md | 16 ++-- .../min-generic-const-args.md | 28 +++--- .../clippy_utils/src/check_proc_macro.rs | 2 +- src/tools/clippy/clippy_utils/src/sugg.rs | 2 +- .../clippy/tests/ui/crashes/mgca-16691.rs | 4 +- src/tools/rustfmt/src/expr.rs | 2 +- src/tools/rustfmt/src/types.rs | 2 +- src/tools/rustfmt/src/utils.rs | 2 +- .../rustfmt/tests/source/direct_const_arg.rs | 15 --- src/tools/rustfmt/tests/source/gca.rs | 17 ++++ .../rustfmt/tests/target/direct_const_arg.rs | 15 --- src/tools/rustfmt/tests/target/gca.rs | 17 ++++ tests/crashes/138009.rs | 5 +- tests/crashes/149809.rs | 8 +- tests/crashes/150049.rs | 5 +- tests/crashes/150749.rs | 6 +- tests/debuginfo/associated-const-bindings.rs | 5 +- tests/pretty/direct-const-arg.rs | 10 -- .../{direct-const-arg.pp => gca-macro.pp} | 9 +- tests/pretty/gca-macro.rs | 12 +++ .../rustdoc-html/type-const-free-in-array.rs | 4 +- .../type-const-inherent-with-body.rs | 4 +- .../type-const-in-array-len-wrong-type.rs | 4 +- .../type-const-in-array-len-wrong-type.stderr | 2 +- .../type-const-in-array-len.rs | 8 +- .../duplicate-bound-err.rs | 6 +- .../associated-type-bounds/duplicate-bound.rs | 4 +- .../type-const-inherent-impl-normalize.rs | 4 +- .../type-const-inherent-impl-normalize.stderr | 10 +- .../resolved-region-var-max-universe.rs | 4 +- .../resolved-region-var-max-universe.stderr | 2 +- .../associated-const-bindings/ambiguity.rs | 4 +- .../ambiguity.stderr | 8 +- .../associated-const-bindings/assoc-const.rs | 4 +- .../coexisting-with-type-binding.rs | 4 +- .../associated-const-bindings/coherence.rs | 4 +- .../coherence.stderr | 2 +- .../const_evaluatable_unchecked.rs | 4 +- .../dyn-compat-basic.rs | 4 +- .../dyn-compat-const-mismatch.rs | 4 +- .../dyn-compat-const-mismatch.stderr | 2 +- ...ompat-const-param-default-mentions-self.rs | 4 +- ...t-const-param-default-mentions-self.stderr | 2 +- ...und-on-assoc-const-allowed-and-enforced.rs | 4 +- ...on-assoc-const-allowed-and-enforced.stderr | 6 +- ...elf-const-projections-in-assoc-const-ty.rs | 4 +- ...const-projections-in-assoc-const-ty.stderr | 4 +- ...ompat-self-const-projections-in-methods.rs | 6 +- .../equality-unused-issue-126729.rs | 12 ++- .../equality_bound_with_infer.rs | 4 +- .../mismatched-types-with-generic-in-ace.rs | 4 +- ...ismatched-types-with-generic-in-ace.stderr | 8 +- .../wf-mismatch-3.rs | 4 +- .../wf-mismatch-3.stderr | 6 +- ...-on-failed-eval-with-vars-fail.next.stderr | 16 ++-- ...ambiguous-on-failed-eval-with-vars-fail.rs | 6 +- tests/ui/const-generics/gca/assoc-const.rs | 7 +- .../gca/basic-different-definitions.rs | 4 +- tests/ui/const-generics/gca/basic.rs | 6 +- tests/ui/const-generics/gca/coherence-ok.rs | 6 +- .../gca/gca-anon-const-rejected.rs | 4 +- .../gca/gca-anon-const-rejected.stderr | 6 +- ...st-arg-fn-call.rs => gca-macro-fn-call.rs} | 0 ...n-call.stderr => gca-macro-fn-call.stderr} | 10 +- .../gca/non-type-equality-fail.rs | 9 +- .../gca/non-type-equality-fail.stderr | 20 ++-- .../ui/const-generics/gca/rhs-but-not-root.rs | 6 +- .../gca/rhs-but-not-root.stderr | 6 +- .../suggest-const-item-for-generic-expr.rs | 2 +- .../ui/const-generics/gca/wf-inherentimpl.rs | 3 +- .../auxiliary/non_local_type_const.rs | 4 +- .../inherent-type-const.rs | 6 +- .../mgca/adt_expr_arg_simple.rs | 4 +- .../mgca/adt_expr_arg_simple.stderr | 8 +- .../mgca/adt_expr_infers_from_value.rs | 3 +- .../mgca/array-const-arg-len-mismatch.rs | 3 +- .../mgca/array-const-arg-len-mismatch.stderr | 20 ++-- .../mgca/array-expr-complex.r1.stderr | 6 +- .../mgca/array-expr-complex.r2.stderr | 6 +- .../mgca/array-expr-complex.r3.stderr | 6 +- .../const-generics/mgca/array-expr-complex.rs | 8 +- .../mgca/array_expr_arg_complex.rs | 6 +- .../mgca/array_expr_arg_complex.stderr | 12 +-- .../mgca/assoc-const-projection-in-bound.rs | 4 +- .../mgca/bad-const-arg-fn-154539.rs | 4 +- .../mgca/bad-const-arg-fn-154539.stderr | 6 +- .../mgca/bad-direct-const-arg.rs | 15 --- .../mgca/bad-direct-const-arg.stderr | 20 ---- tests/ui/const-generics/mgca/bad-gca-macro.rs | 17 ++++ .../const-generics/mgca/bad-gca-macro.stderr | 20 ++++ .../mgca/bad-type_const-syntax.rs | 13 ++- .../mgca/bad-type_const-syntax.stderr | 60 +++++++++--- .../mgca/braced-const-infer-in-body.rs | 8 +- .../mgca/braced-const-infer-in-body.stderr | 8 +- .../concrete-expr-with-generics-in-env.rs | 9 +- ...const-arg-coherence-conflicting-methods.rs | 4 +- ...t-arg-coherence-conflicting-methods.stderr | 6 +- .../const-arg-mismatched-literal-suffix.rs | 4 +- ...const-arg-mismatched-literal-suffix.stderr | 4 +- .../mgca/cyclic-type-const-151251.rs | 4 +- .../mgca/cyclic-type-const-151251.stderr | 4 +- .../mgca/direct-const-arg-correct-rib.stderr | 8 -- .../mgca/direct-const-arg-multiple-exprs.rs | 5 - .../direct-const-arg-multiple-exprs.stderr | 8 -- .../mgca/direct_const_arg-infer-as-type.rs | 13 --- .../direct_const_arg-infer-as-type.stderr | 15 --- .../mgca/explicit_anon_consts.rs | 22 +++-- .../mgca/explicit_anon_consts.stderr | 54 +++++------ .../mgca/free-const-recursive.gca.stderr | 8 +- .../mgca/free-const-recursive.min_gca.stderr | 4 +- .../mgca/free-const-recursive.rs | 4 +- ...orrect-rib.rs => gca-macro-correct-rib.rs} | 6 +- .../mgca/gca-macro-correct-rib.stderr | 8 ++ ...ture-gate.rs => gca-macro-feature-gate.rs} | 4 +- ...e.stderr => gca-macro-feature-gate.stderr} | 20 ++-- .../mgca/gca-macro-infer-as-type.rs | 14 +++ .../mgca/gca-macro-infer-as-type.stderr | 15 +++ .../mgca/gca-macro-multiple-exprs.rs | 6 ++ .../mgca/gca-macro-multiple-exprs.stderr | 8 ++ ...eric-args-on-enum-variant-segments-fail.rs | 7 +- ...-args-on-enum-variant-segments-fail.stderr | 38 ++++---- .../generic-args-on-enum-variant-segments.rs | 6 +- ...eneric_const_items-mismatched-array-len.rs | 4 +- ...ic_const_items-mismatched-array-len.stderr | 4 +- ...onst_parameter_types-inferred-array-len.rs | 5 +- .../mgca/generic_const_type_mismatch.rs | 4 +- .../mgca/generic_const_type_mismatch.stderr | 6 +- .../mgca/inherent-alias-default.rs | 6 +- ...t-const-arg-owner-issue-159172.expr.stderr | 13 --- ...d-gca-macro-owner-issue-159172.expr.stderr | 13 +++ ...> invalid-gca-macro-owner-issue-159172.rs} | 10 +- ...id-gca-macro-owner-issue-159172.ty.stderr} | 6 +- .../mgca/macro-const-arg-infer.rs | 5 +- .../mgca/macro-const-arg-infer.stderr | 14 +-- ...ixed-direct-anon-expression-diagnostics.rs | 4 +- ...-direct-anon-expression-diagnostics.stderr | 8 +- ...onst_args.rs => multi_braced_gca_macro.rs} | 0 .../non-local-const-without-type_const.stderr | 2 +- .../mgca/none-as-usize-const-arg.rs | 4 +- .../mgca/none-as-usize-const-arg.stderr | 16 ++-- .../opaque-ty-assoc-const-equality-117923.rs | 4 +- tests/ui/const-generics/mgca/paren.rs | 52 +++++----- .../mgca/projection-const-recursive.rs | 4 +- .../mgca/projection-const-recursive.stderr | 8 +- .../const-generics/mgca/static-const-arg.rs | 6 +- .../mgca/static-const-arg.stderr | 12 +-- .../mgca/suggest-direct-const.fixed | 33 ++++--- .../mgca/suggest-direct-const.rs | 21 +++-- .../mgca/suggest-direct-const.stderr | 94 +++++++++---------- .../mgca/syntactic-type-mismatch.rs | 6 +- .../mgca/syntactic-type-mismatch.stderr | 10 +- .../mgca/tuple_ctor_complex_args.rs | 3 +- .../mgca/tuple_ctor_complex_args.stderr | 8 +- .../mgca/tuple_ctor_erroneous.rs | 3 +- .../mgca/tuple_ctor_erroneous.stderr | 22 ++--- .../mgca/tuple_expr_arg_complex.rs | 10 +- .../mgca/tuple_expr_arg_complex.stderr | 24 ++--- .../mgca/tuple_expr_arg_simple.rs | 10 +- .../type-const-assoc-const-without-body.rs | 4 +- ...type-const-assoc-const-without-body.stderr | 8 +- .../mgca/type-const-associated-default.rs | 3 +- .../mgca/type-const-associated-default.stderr | 6 +- .../mgca/type-const-ctor-148953.rs | 5 +- .../type-const-free-anon-const-mismatch.rs | 6 +- ...type-const-free-anon-const-mismatch.stderr | 8 +- ...st-free-value-type-mismatch.current.stderr | 6 +- ...const-free-value-type-mismatch.next.stderr | 8 +- .../type-const-free-value-type-mismatch.rs | 4 +- .../type-const-free-value-used-in-body.rs | 6 +- .../type-const-free-value-used-in-body.stderr | 8 +- ...nherent-value-type-mismatch.current.stderr | 6 +- ...t-inherent-value-type-mismatch.next.stderr | 8 +- ...type-const-inherent-value-type-mismatch.rs | 4 +- .../mgca/type-const-used-in-trait.rs | 4 +- ...e-const-value-type-mismatch.current.stderr | 10 +- ...type-const-value-type-mismatch.next.stderr | 10 +- .../mgca/type-const-value-type-mismatch.rs | 4 +- .../mgca/type_const-adt-expr-missing-field.rs | 6 +- .../type_const-adt-expr-missing-field.stderr | 16 ++-- .../mgca/type_const-array-return.rs | 4 +- ..._const-generic-param-in-type.nogate.stderr | 18 ++-- .../mgca/type_const-generic-param-in-type.rs | 19 ++-- .../mgca/type_const-incemental-compile.rs | 4 +- .../type_const-inherent-const-omitted-type.rs | 4 +- ...e_const-inherent-const-omitted-type.stderr | 12 +-- .../type_const-mismatched-type-incremental.rs | 11 ++- ...e_const-mismatched-type-incremental.stderr | 16 ++-- .../mgca/type_const-mismatched-types.rs | 8 +- .../mgca/type_const-mismatched-types.stderr | 16 ++-- .../mgca/type_const-not-constparamty.rs | 6 +- .../mgca/type_const-not-constparamty.stderr | 10 +- .../mgca/type_const-on-generic-expr.rs | 6 +- .../mgca/type_const-on-generic-expr.stderr | 12 +-- .../mgca/type_const-on-generic_expr-2.rs | 8 +- .../mgca/type_const-on-generic_expr-2.stderr | 18 ++-- .../type_const-only-in-impl-omitted-type.rs | 6 +- ...ype_const-only-in-impl-omitted-type.stderr | 20 ++-- .../mgca/type_const-only-in-impl.rs | 6 +- .../mgca/type_const-only-in-impl.stderr | 10 +- .../mgca/type_const-only-in-trait.rs | 4 +- .../mgca/type_const-only-in-trait.stderr | 6 +- .../ui/const-generics/mgca/type_const-pub.rs | 4 +- .../mgca/type_const-recursive.rs | 4 +- .../mgca/type_const-recursive.stderr | 4 +- .../ui/const-generics/mgca/type_const-use.rs | 4 +- .../mgca/type_const_in_pattern.rs | 8 +- .../unbraced_const_block_const_arg_gated.rs | 6 +- ...nbraced_const_block_const_arg_gated.stderr | 24 ++--- .../mgca/unmarked-free-const.rs | 4 +- .../mgca/unmarked-free-const.stderr | 12 +-- .../type-const-ice-issue-151631.rs | 4 +- .../type-const-ice-issue-151631.stderr | 10 +- .../type-relative-path-144547.rs | 2 +- ...ems-before-lowering-ices.ice_155125.stderr | 8 +- ...ems-before-lowering-ices.ice_155127.stderr | 2 +- ...ems-before-lowering-ices.ice_155128.stderr | 6 +- ...ems-before-lowering-ices.ice_155164.stderr | 6 +- ...ems-before-lowering-ices.ice_155202.stderr | 4 +- .../hir-crate-items-before-lowering-ices.rs | 6 +- .../inside-const-body-ice-155300.rs | 4 +- .../inside-const-body-ice-155300.stderr | 8 +- .../ui/delegation/wrong-fn-kind-ice-159127.rs | 6 +- .../wrong-fn-kind-ice-159127.stderr | 8 +- .../feature-gate-generic-const-args.rs | 4 +- .../feature-gate-generic-const-args.stderr | 6 +- .../feature-gate-mgca-type-const-syntax.rs | 10 +- ...feature-gate-mgca-type-const-syntax.stderr | 24 ++--- .../feature-gate-min-generic-const-args.rs | 4 +- ...feature-gate-min-generic-const-args.stderr | 16 ++-- .../assoc-const-bindings.rs | 7 +- .../assoc-const-no-infer-ice-115806.rs | 6 +- .../assoc-const-no-infer-ice-115806.stderr | 6 +- .../type-const-nested-assoc-const.rs | 6 +- .../object-lifetime-default-inherent-gac.rs | 8 +- ...bject-lifetime-default-inherent-gac.stderr | 4 +- .../assoc-const-projection-issue-151878.rs | 4 +- .../overlap-due-to-unsatisfied-const-bound.rs | 4 +- ...rlap-due-to-unsatisfied-const-bound.stderr | 2 +- tests/ui/supertrait-shadowing/assoc-const.rs | 4 +- .../supertrait-shadowing/common-ancestor-2.rs | 3 +- .../common-ancestor-2.stderr | 18 ++-- .../supertrait-shadowing/common-ancestor-3.rs | 5 +- .../common-ancestor-3.stderr | 30 +++--- .../supertrait-shadowing/common-ancestor.rs | 3 +- .../common-ancestor.stderr | 18 ++-- .../no-common-ancestor-2.rs | 5 +- .../no-common-ancestor-2.stderr | 22 ++--- tests/ui/supertrait-shadowing/out-of-scope.rs | 3 +- .../ui/supertrait-shadowing/type-dependent.rs | 3 +- .../next-solver/normalize-const-item-type.rs | 8 +- .../normalize-const-item-type.stderr | 18 ++-- 274 files changed, 1325 insertions(+), 1042 deletions(-) rename compiler/rustc_builtin_macros/src/{direct_const_arg.rs => gca.rs} (81%) delete mode 100644 src/tools/rustfmt/tests/source/direct_const_arg.rs create mode 100644 src/tools/rustfmt/tests/source/gca.rs delete mode 100644 src/tools/rustfmt/tests/target/direct_const_arg.rs create mode 100644 src/tools/rustfmt/tests/target/gca.rs delete mode 100644 tests/pretty/direct-const-arg.rs rename tests/pretty/{direct-const-arg.pp => gca-macro.pp} (60%) create mode 100644 tests/pretty/gca-macro.rs rename tests/ui/const-generics/gca/{direct-const-arg-fn-call.rs => gca-macro-fn-call.rs} (100%) rename tests/ui/const-generics/gca/{direct-const-arg-fn-call.stderr => gca-macro-fn-call.stderr} (81%) delete mode 100644 tests/ui/const-generics/mgca/bad-direct-const-arg.rs delete mode 100644 tests/ui/const-generics/mgca/bad-direct-const-arg.stderr create mode 100644 tests/ui/const-generics/mgca/bad-gca-macro.rs create mode 100644 tests/ui/const-generics/mgca/bad-gca-macro.stderr delete mode 100644 tests/ui/const-generics/mgca/direct-const-arg-correct-rib.stderr delete mode 100644 tests/ui/const-generics/mgca/direct-const-arg-multiple-exprs.rs delete mode 100644 tests/ui/const-generics/mgca/direct-const-arg-multiple-exprs.stderr delete mode 100644 tests/ui/const-generics/mgca/direct_const_arg-infer-as-type.rs delete mode 100644 tests/ui/const-generics/mgca/direct_const_arg-infer-as-type.stderr rename tests/ui/const-generics/mgca/{direct-const-arg-correct-rib.rs => gca-macro-correct-rib.rs} (57%) create mode 100644 tests/ui/const-generics/mgca/gca-macro-correct-rib.stderr rename tests/ui/const-generics/mgca/{direct-const-arg-feature-gate.rs => gca-macro-feature-gate.rs} (52%) rename tests/ui/const-generics/mgca/{direct-const-arg-feature-gate.stderr => gca-macro-feature-gate.stderr} (56%) create mode 100644 tests/ui/const-generics/mgca/gca-macro-infer-as-type.rs create mode 100644 tests/ui/const-generics/mgca/gca-macro-infer-as-type.stderr create mode 100644 tests/ui/const-generics/mgca/gca-macro-multiple-exprs.rs create mode 100644 tests/ui/const-generics/mgca/gca-macro-multiple-exprs.stderr delete mode 100644 tests/ui/const-generics/mgca/invalid-direct-const-arg-owner-issue-159172.expr.stderr create mode 100644 tests/ui/const-generics/mgca/invalid-gca-macro-owner-issue-159172.expr.stderr rename tests/ui/const-generics/mgca/{invalid-direct-const-arg-owner-issue-159172.rs => invalid-gca-macro-owner-issue-159172.rs} (57%) rename tests/ui/const-generics/mgca/{invalid-direct-const-arg-owner-issue-159172.ty.stderr => invalid-gca-macro-owner-issue-159172.ty.stderr} (58%) rename tests/ui/const-generics/mgca/{multi_braced_direct_const_args.rs => multi_braced_gca_macro.rs} (100%) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 5b9f3231fc744..2f1a547e05a48 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1623,7 +1623,7 @@ impl Expr { | ExprKind::UnsafeBinderCast(..) | ExprKind::While(..) | ExprKind::Yield(YieldKind::Postfix(..)) - | ExprKind::DirectConstArg(..) + | ExprKind::GcaMacro(..) | ExprKind::Err(_) | ExprKind::Dummy => prefix_attrs_precedence(&self.attrs), } @@ -1920,8 +1920,8 @@ pub enum ExprKind { UnsafeBinderCast(UnsafeBinderCastKind, Box, Option>), - /// An mGCA `direct_const_arg!()` expression. - DirectConstArg(Box), + /// An mGCA `gca!()` expression. + GcaMacro(Box), /// Placeholder for an expression that wasn't syntactically well formed in some way. Err(ErrorGuaranteed), @@ -2579,8 +2579,8 @@ pub enum TyKind { FieldOf(Box, Option, Ident), /// A view of a type. `T.{ field_1, field_2 }`. View(Box, #[visitable(ignore)] ThinVec), - /// An mGCA `direct_const_arg!()` expression. - DirectConstArg(Box), + /// An mGCA `gca!()` expression. + GcaMacro(Box), /// Sometimes we need a dummy value when no error has occurred. Dummy, /// Placeholder for a kind that has failed to be defined. diff --git a/compiler/rustc_ast/src/util/classify.rs b/compiler/rustc_ast/src/util/classify.rs index e799f73ff544f..c4c181743543e 100644 --- a/compiler/rustc_ast/src/util/classify.rs +++ b/compiler/rustc_ast/src/util/classify.rs @@ -158,7 +158,7 @@ pub fn leading_labeled_expr(mut expr: &ast::Expr) -> bool { | Yeet(..) | Yield(..) | UnsafeBinderCast(..) - | DirectConstArg(..) + | GcaMacro(..) | Err(..) | Dummy => return false, } @@ -244,7 +244,7 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option> { | Try(_) | Yeet(None) | UnsafeBinderCast(..) - | DirectConstArg(..) + | GcaMacro(..) | Err(_) | Dummy => { break None; @@ -307,7 +307,7 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> { | ast::TyKind::Pat(..) | ast::TyKind::FieldOf(..) | ast::TyKind::View(..) - | ast::TyKind::DirectConstArg(..) + | ast::TyKind::GcaMacro(..) | ast::TyKind::Dummy | ast::TyKind::Err(..) => break None, } diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 4270ac0656deb..ec77de62607ce 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -1112,7 +1112,7 @@ macro_rules! common_visitor_and_walkers { visit_visitable!(vis, bytes), ExprKind::UnsafeBinderCast(kind, expr, ty) => visit_visitable!(vis, kind, expr, ty), - ExprKind::DirectConstArg(expr) => + ExprKind::GcaMacro(expr) => visit_visitable!(vis, expr), ExprKind::Err(_guar) => {} ExprKind::Dummy => {} diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index c3bc86a352644..f4bfec24e3b1b 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -544,8 +544,8 @@ impl<'hir> LoweringContext<'_, 'hir> { ExprKind::MacCall(_) => panic!("{:?} shouldn't exist here", e.span), - ExprKind::DirectConstArg(expr) => { - let e = self.emit_bad_direct_const_arg(e.span, expr, "expression"); + ExprKind::GcaMacro(expr) => { + let e = self.emit_bad_gca_macro(e.span, expr, "expression"); hir::ExprKind::Err(e) } }; diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 7ff6a2538c1e7..ba5a9b52f7dd1 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1489,9 +1489,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let ct = self.arena.alloc(ct); return GenericArg::Const(ct.try_as_ambig_ct().unwrap()); } - TyKind::DirectConstArg(expr) - if self.tcx.features().min_generic_const_args() => - { + TyKind::GcaMacro(expr) if self.tcx.features().min_generic_const_args() => { let ct = match self.can_lower_expr_to_const_arg_direct( expr, DirectConstArgContext::MacrolessMinGenericConstArgs, @@ -1797,8 +1795,8 @@ impl<'hir> LoweringContext<'_, 'hir> { let fields = self.arena.alloc_slice(fields); hir::TyKind::View(ty, fields) } - TyKind::DirectConstArg(expr) => { - let e = self.emit_bad_direct_const_arg(t.span, expr, "type"); + TyKind::GcaMacro(expr) => { + let e = self.emit_bad_gca_macro(t.span, expr, "type"); hir::TyKind::Err(e) } TyKind::Dummy => panic!("`TyKind::Dummy` should never be lowered"), @@ -1807,16 +1805,16 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) } } - pub(crate) fn emit_bad_direct_const_arg( + pub(crate) fn emit_bad_gca_macro( &mut self, span: Span, expr: &Expr, expected: &'static str, ) -> ErrorGuaranteed { - let msg = format!("expected {expected}, found `direct_const_arg!()` constant"); + let msg = format!("expected {expected}, found `gca!()` constant"); if expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break() { // FIXME(mgca): make this non-fatal once we have a better way to handle - // nested items in invalid `direct_const_arg!()` arguments. + // nested items in invalid `gca!()` arguments. self.dcx().span_fatal(span, msg) } else { self.dcx().span_err(span, msg) @@ -2711,9 +2709,9 @@ impl<'hir> LoweringContext<'_, 'hir> { .is_ok() } else { // do not check can_lower_expr_to_const_arg_direct, but rather just - // ExprKind::DirectConstArg, because we don't want e.g. + // ExprKind::GcaMacro, because we don't want e.g. // `impl { const C: u8 = N; }` to be a direct-rhs const - matches!(body, Expr { kind: ExprKind::DirectConstArg(_), .. }) + matches!(body, Expr { kind: ExprKind::GcaMacro(_), .. }) } }; if self.tcx.features().min_generic_const_args() @@ -2816,7 +2814,7 @@ impl<'hir> LoweringContext<'_, 'hir> { Ok(()) } (ExprKind::ConstBlock(_), MacrolessMinGenericConstArgs) => Ok(()), - (ExprKind::DirectConstArg(_), MacrolessMinGenericConstArgs | MinGenericConstArgs) => { + (ExprKind::GcaMacro(_), MacrolessMinGenericConstArgs | MinGenericConstArgs) => { // Always report this as able to be represented directly. If it turns out not to be, // `lower_expr_to_const_arg_direct` will report an error. Ok(()) @@ -2998,11 +2996,10 @@ impl<'hir> LoweringContext<'_, 'hir> { span, } } - ExprKind::DirectConstArg(expr) => { + ExprKind::GcaMacro(expr) => { // `can_lower_expr_to_const_arg_direct` always returns success upon encountering a - // ExprKind::DirectConstArg, which effectively forces the expression to be lowered - // as a direct arg. If it actually turns out to not be possible, emit an error - // instead. + // ExprKind::GcaMacro, which effectively forces the expression to be lowered as a + // direct arg. If it actually turns out to not be possible, emit an error instead. // Always use MacrolessMinGenericConstArgs, even if we're under regular GCA, because // that's what the macro means: to enter a context that is like macroless GCA. match self.can_lower_expr_to_const_arg_direct( @@ -3354,12 +3351,12 @@ enum DirectConstArgContext { /// The only allowed direct const arg representation is simple paths that nameres to generic /// const parameters. Stable, - /// The allowed representations are what is allowed on stable, plus the `direct_const_arg!` macro. + /// The allowed representations are what is allowed on stable, plus the `gca!` macro. MinGenericConstArgs, /// Expressions attempt to be lowered directly, and if that fails, the expression falls back to /// being represented as an anon const. /// - /// This context is also used under MinGenericConstArgs inside a `direct_const_arg!` macro, for + /// This context is also used under MinGenericConstArgs inside a `gca!` macro, for /// simplicity, as they allow the same code. MacrolessMinGenericConstArgs, } diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index d97bf7a2a6db3..6637ed356f557 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1460,8 +1460,8 @@ impl<'a> State<'a> { self.print_type(ty); self.print_view(fields); } - ast::TyKind::DirectConstArg(expr) => { - self.word_nbsp("core::direct_const_arg!"); + ast::TyKind::GcaMacro(expr) => { + self.word_nbsp("core::gca!"); self.popen(); self.print_expr(expr, FixupContext::default()); self.pclose(); diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index b6c22e7da9cb1..d6e8f69dbfa03 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -883,8 +883,8 @@ impl<'a> State<'a> { self.word("/*DUMMY*/"); self.pclose(); } - ast::ExprKind::DirectConstArg(expr) => { - self.word_nbsp("core::direct_const_arg!"); + ast::ExprKind::GcaMacro(expr) => { + self.word_nbsp("core::gca!"); self.popen(); self.print_expr(expr, FixupContext::default()); self.pclose() diff --git a/compiler/rustc_builtin_macros/src/assert/context.rs b/compiler/rustc_builtin_macros/src/assert/context.rs index aa339ce7f4252..cb3ea2475721e 100644 --- a/compiler/rustc_builtin_macros/src/assert/context.rs +++ b/compiler/rustc_builtin_macros/src/assert/context.rs @@ -321,7 +321,7 @@ impl<'cx, 'a> Context<'cx, 'a> { | ExprKind::Yeet(_) | ExprKind::Become(_) | ExprKind::Yield(_) - | ExprKind::DirectConstArg(_) + | ExprKind::GcaMacro(_) | ExprKind::UnsafeBinderCast(..) => {} } } diff --git a/compiler/rustc_builtin_macros/src/direct_const_arg.rs b/compiler/rustc_builtin_macros/src/gca.rs similarity index 81% rename from compiler/rustc_builtin_macros/src/direct_const_arg.rs rename to compiler/rustc_builtin_macros/src/gca.rs index 6af503e9a4681..ba26b16d06be5 100644 --- a/compiler/rustc_builtin_macros/src/direct_const_arg.rs +++ b/compiler/rustc_builtin_macros/src/gca.rs @@ -10,8 +10,7 @@ pub(crate) fn expand<'cx>( span: Span, tts: TokenStream, ) -> MacroExpanderResult<'cx> { - let ExpandResult::Ready(expr) = get_single_expr_from_tts(cx, span, tts, "direct_const_arg!") - else { + let ExpandResult::Ready(expr) = get_single_expr_from_tts(cx, span, tts, "gca!") else { return ExpandResult::Retry(()); }; let expr = match expr { @@ -23,12 +22,12 @@ pub(crate) fn expand<'cx>( ExpandResult::Ready(Box::new(base::MacEager { expr: Some(Box::new(ast::Expr { id, - kind: ast::ExprKind::DirectConstArg(expr.clone()), + kind: ast::ExprKind::GcaMacro(expr.clone()), span, attrs: Default::default(), tokens: None, })), - ty: Some(Box::new(ast::Ty { id, kind: ast::TyKind::DirectConstArg(expr), span })), + ty: Some(Box::new(ast::Ty { id, kind: ast::TyKind::GcaMacro(expr), span })), ..Default::default() })) } diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 57759bb113401..c564e14776c91 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -34,12 +34,12 @@ mod define_opaque; mod derive; mod deriving; mod diagnostics; -mod direct_const_arg; mod edition_panic; mod eii; mod env; mod format; mod format_foreign; +mod gca; mod global_allocator; mod iter; mod log_syntax; @@ -83,11 +83,11 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { concat_bytes: concat_bytes::expand_concat_bytes, const_format_args: format::expand_format_args, core_panic: edition_panic::expand_panic, - direct_const_arg: direct_const_arg::expand, env: env::expand_env, file: source_util::expand_file, format_args: format::expand_format_args, format_args_nl: format::expand_format_args_nl, + gca: gca::expand, global_asm: asm::expand_global_asm, include: source_util::expand_include, include_bytes: source_util::expand_include_bytes, diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 94e3b77c6b575..a020ff315e470 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -610,9 +610,9 @@ declare_features! ( /// Provides a way to concatenate identifiers using metavariable expressions. (unstable, macro_metavar_expr_concat, "1.81.0", Some(124225)), /// Allows directly represented generic_const_args as the rhs of const items without the - /// `direct_const_arg!` macro. + /// `gca!` macro. (incomplete, macroless_const_item_generic_const_args, "CURRENT_RUSTC_VERSION", Some(162540)), - /// Allows directly represented generic_const_args without the `direct_const_arg!` macro. + /// Allows directly represented generic_const_args without the `gca!` macro. (incomplete, macroless_generic_const_args, "1.99.0", Some(159006)), /// Allows `#[marker]` on certain traits allowing overlapping implementations. (unstable, marker_trait_attr, "1.30.0", Some(29864)), diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index ee79680d7d1e9..203f2bb935133 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -554,7 +554,7 @@ pub enum InferArgKind { /// determined during HIR ty lowering. TypeOrConst, /// An infer argument with unambiguous const syntax, e.g. S<{ _ }> or - /// S. It can only be inferred to a const. + /// S. It can only be inferred to a const. Const, } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 01f4f5cc527d6..af380929c446e 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -2171,7 +2171,7 @@ pub(super) fn compare_const_directness<'tcx>( tcx.dcx() .struct_span_err( tcx.def_span(impl_const_item.def_id), - "implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS", + "implementation of a `#[rustc_always_gca]` must have a `gca!` RHS", ) .with_span_note( tcx.def_span(trait_const_item.def_id), @@ -2182,7 +2182,7 @@ pub(super) fn compare_const_directness<'tcx>( tcx.dcx() .struct_span_err( tcx.def_span(impl_const_item.def_id), - "implementation of a regular const cannot have a `direct_const_arg!` RHS", + "implementation of a regular const cannot have a `gca!` RHS", ) .with_span_note( tcx.def_span(trait_const_item.def_id), diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index e7ecde09ce27b..99694554b00af 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -3147,9 +3147,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { let body_span = tcx.hir_body(body_id).value.span; err.multipart_suggestion( - "add direct_const_arg!() to the right-hand side of the constant", + "add gca!() to the right-hand side of the constant", vec![ - (body_span.shrink_to_lo(), String::from("core::direct_const_arg!(")), + (body_span.shrink_to_lo(), String::from("core::gca!(")), (body_span.shrink_to_hi(), String::from(")")), ], Applicability::MaybeIncorrect, @@ -3165,9 +3165,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ); } } else { - err.note( - "only consts with a `direct_const_arg!` right-hand side may be used in types", - ); + err.note("only consts with a `gca!` right-hand side may be used in types"); } Err(err.emit_err()) } diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 17c078615c411..2651ce55281fe 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -198,8 +198,8 @@ trait UnusedDelimLint { | Paren(_) | Become(_) => true, Call(..) | MethodCall(_) | Let(..) | Field(..) | MacCall(_) | FormatArgs(_) => false, - // `direct_const_arg!()` is invalid in function/method argument position. - DirectConstArg(_) => false, + // `gca!()` is invalid in function/method argument position. + GcaMacro(_) => false, // don't lint for placeholder/error-recovery Underscore | Err(_) | Dummy => false, } diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index 9e1bafa4fd2a2..8612adb8aa975 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -287,8 +287,8 @@ rustc_queries! { } /// Returns the const of the RHS of a (free or assoc) const item, if it is a `type const`, or if - /// it is a directly represented `const` (i.e. a const with a `direct_const_arg!` RHS, or a - /// const that `feature(macroless_generic_const_args)` has decided is direct). + /// it is a directly represented `const` (i.e. a const with a `gca!` RHS, or a const that + /// `feature(macroless_generic_const_args)` has decided is direct). /// /// When a const item is used in a type-level expression, like in equality for an assoc const /// projection, this allows us to retrieve the typesystem-appropriate representation of the diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 5bc30ae7ba325..a5c31672a2bc7 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -4358,7 +4358,7 @@ impl MutVisitor for CondChecker<'_> { | ExprKind::IncludedBytes(_) | ExprKind::FormatArgs(_) | ExprKind::Err(_) - | ExprKind::DirectConstArg(_) + | ExprKind::GcaMacro(_) | ExprKind::Dummy => { // These would forbid any let expressions they contain already. } diff --git a/compiler/rustc_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs index 961e6e63a81da..c7bcbfe82f3f2 100644 --- a/compiler/rustc_passes/src/input_stats.rs +++ b/compiler/rustc_passes/src/input_stats.rs @@ -661,7 +661,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { If, While, ForLoop, Loop, Match, Closure, Block, Await, Move, Use, TryBlock, Assign, AssignOp, Field, Index, Range, Underscore, Path, AddrOf, Break, Continue, Ret, InlineAsm, FormatArgs, OffsetOf, MacCall, Struct, Repeat, Paren, Try, Yield, Yeet, - Become, IncludedBytes, Gen, UnsafeBinderCast, Err, Dummy, DirectConstArg + Become, IncludedBytes, Gen, UnsafeBinderCast, GcaMacro, Err, Dummy ] ); ast_visit::walk_expr(self, e) @@ -691,7 +691,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { CVarArgs, FieldOf, View, - DirectConstArg, + GcaMacro, Dummy, Err ] diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 7d90b93b62375..aab01d43acba9 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1034,7 +1034,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc self.visit_ty(element_ty); self.resolve_anon_const(length, AnonConstKind::ArrayLength); } - TyKind::DirectConstArg(expr) => self.resolve_anon_const_manual( + TyKind::GcaMacro(expr) => self.resolve_anon_const_manual( true, AnonConstKind::ConstArg(IsRepeatExpr::No), |this| this.resolve_expr(expr, None), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index bd70e5acab4d7..748c2c23fd10d 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -848,7 +848,6 @@ symbols! { diagnostic_opaque, dialect, direct, - direct_const_arg, discriminant_kind, discriminant_type, discriminant_value, @@ -1068,6 +1067,7 @@ symbols! { future_output, future_trait, fxsr, + gca, gdb_script_file, ge, gen_blocks, diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 217f29d6a86e1..e67c7114d6d6a 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1076,13 +1076,13 @@ pub trait Tuple {} /// Creates a new style directly represented const argument. /// ```ignore (cannot test this from within core yet) -/// const BAR: usize = direct_const_arg!(N); -/// const FOO: usize = direct_const_arg!(BAR::); +/// const BAR: usize = gca!(N); +/// const FOO: usize = gca!(BAR::); /// ``` -#[rustc_builtin_macro(direct_const_arg)] +#[rustc_builtin_macro(gca)] #[unstable(feature = "min_generic_const_args", issue = "132980")] #[macro_export] -macro_rules! direct_const_arg { +macro_rules! gca { ($($arg:tt)*) => { /* compiler built-in */ }; diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index acc8cdfc8281d..93b129c5c6641 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -758,6 +758,8 @@ pub use core::concat_bytes; )] #[unstable(feature = "derive_macro_global_path", issue = "154645")] pub use core::derive; +#[unstable(feature = "min_generic_const_args", issue = "132980")] +pub use core::gca; #[stable(feature = "matches_macro", since = "1.42.0")] pub use core::matches; #[stable(feature = "core_primitive", since = "1.43.0")] diff --git a/src/doc/unstable-book/src/language-features/macroless-const-item-generic-const-args.md b/src/doc/unstable-book/src/language-features/macroless-const-item-generic-const-args.md index df9172e04b9ac..feb03a633d1bd 100644 --- a/src/doc/unstable-book/src/language-features/macroless-const-item-generic-const-args.md +++ b/src/doc/unstable-book/src/language-features/macroless-const-item-generic-const-args.md @@ -1,6 +1,6 @@ # macroless_generic_const_args -Enables implementing const items under `#![feature(min_generic_const_args)]` and `#![feature(generic_const_args)]` without the `direct_const_arg!` macro. +Enables implementing const items under `#![feature(min_generic_const_args)]` and `#![feature(generic_const_args)]` without the `gca!` macro. The tracking issue for this feature is: [#162540] @@ -11,7 +11,7 @@ The tracking issue for this feature is: [#162540] Warning: This feature is incomplete; its design and syntax may change. Related features: -- [min_generic_const_args]. See that doc for what the `direct_const_arg!` is. This feature enables +- [min_generic_const_args]. See that doc for what the `gca!` is. This feature enables support for directly represented const arguments as the rhs of const items without the macro. - [macroless_generic_const_args]. For a version of this feature that works for const arguments in other positions @@ -39,7 +39,7 @@ trait Trait { } impl Trait for () { - const ASSOC: usize = core::direct_const_arg!(N); + const ASSOC: usize = core::gca!(N); } fn foo() { diff --git a/src/doc/unstable-book/src/language-features/macroless-generic-const-args.md b/src/doc/unstable-book/src/language-features/macroless-generic-const-args.md index 410834a79712e..fadc2260bfbdc 100644 --- a/src/doc/unstable-book/src/language-features/macroless-generic-const-args.md +++ b/src/doc/unstable-book/src/language-features/macroless-generic-const-args.md @@ -1,6 +1,6 @@ # macroless_generic_const_args -Enables using `#![feature(min_generic_const_args)]` without the `direct_const_arg!` macro. +Enables using `#![feature(min_generic_const_args)]` without the `gca!` macro. The tracking issue for this feature is: [#159006] @@ -11,7 +11,7 @@ The tracking issue for this feature is: [#159006] Warning: This feature is incomplete; its design and syntax may change. Related features: -- [min_generic_const_args]. See that doc for what the `direct_const_arg!` is. This feature enables +- [min_generic_const_args]. See that doc for what the `gca!` is. This feature enables support for directly represented const arguments without the macro. - [macroless_const_item_generic_const_args]. For a version of this feature that works for const arguments as the right hand side of a const item. @@ -39,13 +39,13 @@ trait Bar { struct Baz; impl Bar for Baz { - const VAL: usize = core::direct_const_arg!(2); - const VAL2: usize = core::direct_const_arg!(const { Self::VAL * 2 }); + const VAL: usize = core::gca!(2); + const VAL2: usize = core::gca!(const { Self::VAL * 2 }); } struct Foo { - arr1: [usize; core::direct_const_arg!(B::VAL)], - arr2: [usize; core::direct_const_arg!(B::VAL2)], + arr1: [usize; core::gca!(B::VAL)], + arr2: [usize; core::gca!(B::VAL2)], } ``` @@ -66,8 +66,8 @@ struct Baz; impl Bar for Baz { // note these still need a macro, macroless for these is `macroless_const_item_generic_const_args` - const VAL: usize = core::direct_const_arg!(2); - const VAL2: usize = core::direct_const_arg!(const { Self::VAL * 2 }); + const VAL: usize = core::gca!(2); + const VAL2: usize = core::gca!(const { Self::VAL * 2 }); } struct Foo { diff --git a/src/doc/unstable-book/src/language-features/min-generic-const-args.md b/src/doc/unstable-book/src/language-features/min-generic-const-args.md index 0d33af9092cf6..920bc0e36c1ba 100644 --- a/src/doc/unstable-book/src/language-features/min-generic-const-args.md +++ b/src/doc/unstable-book/src/language-features/min-generic-const-args.md @@ -23,36 +23,36 @@ Related features: [macroless_generic_const_args], [generic_const_args], [generic [generic_const_args]: generic-const-args.md [generic_const_items]: generic-const-items.md -## `direct_const_arg!` macro +## `gca!` macro -This feature introduces a new macro: `direct_const_arg!`. +This feature introduces a new macro: `gca!`. When an expression is used as a generic argument, it is typically lowered as an "anon const", which is an expression -that is opaque to the type system and cannot contain generics. Using `direct_const_arg!` instead represents the +that is opaque to the type system and cannot contain generics. Using `gca!` instead represents the expression "directly", i.e. without an anon const, in a way that is visible to the type system. -(Note that plain paths to generic parameters are always represented directly, without `direct_const_arg!`, as this +(Note that plain paths to generic parameters are always represented directly, without `gca!`, as this already works on stable) -See [macroless_generic_const_args] as a feature to disable the requirement of writing `direct_const_arg!`. +See [macroless_generic_const_args] as a feature to disable the requirement of writing `gca!`. [macroless_generic_const_args]: macroless-generic-const-args.md ## direct const items -This feature introduces a new item kind: consts with a `direct_const_arg!` right-hand side. +This feature introduces a new item kind: consts with a `gca!` right-hand side. Constants with a direct right-hand side are allowed to be used in type contexts, e.g.: ```compile_fail #![allow(incomplete_features)] #![feature(min_generic_const_args)] -const X: usize = core::direct_const_arg!(1); +const X: usize = core::gca!(1); const Y: usize = 1; struct Foo { - good_arr: [(); core::direct_const_arg!(X)], // Allowed - bad_arr: [(); core::direct_const_arg!(Y)], // Will not compile + good_arr: [(); core::gca!(X)], // Allowed + bad_arr: [(); core::gca!(Y)], // Will not compile } ``` @@ -72,13 +72,13 @@ trait Bar { struct Baz; impl Bar for Baz { - const VAL: usize = core::direct_const_arg!(2); - const VAL2: usize = core::direct_const_arg!(const { Self::VAL * 2 }); + const VAL: usize = core::gca!(2); + const VAL2: usize = core::gca!(const { Self::VAL * 2 }); } struct Foo { - arr1: [usize; core::direct_const_arg!(B::VAL)], - arr2: [usize; core::direct_const_arg!(B::VAL2)], + arr1: [usize; core::gca!(B::VAL)], + arr2: [usize; core::gca!(B::VAL2)], } ``` @@ -122,7 +122,7 @@ const fn inc(val: usize) -> usize { val + 1 } -const INC: usize = core::direct_const_arg!(const { inc(VAL) }); +const INC: usize = core::gca!(const { inc(VAL) }); const ARR: [usize; INC] = [0; INC]; ``` diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index c8ee7c5a1034f..baff6a99fc9e0 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -539,7 +539,7 @@ fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) { | TyKind::Pat(..) | TyKind::FieldOf(..) | TyKind::View(..) - | TyKind::DirectConstArg(..) + | TyKind::GcaMacro(..) // unused | TyKind::CVarArgs diff --git a/src/tools/clippy/clippy_utils/src/sugg.rs b/src/tools/clippy/clippy_utils/src/sugg.rs index 3d4645f72fce3..d2045c1346ee5 100644 --- a/src/tools/clippy/clippy_utils/src/sugg.rs +++ b/src/tools/clippy/clippy_utils/src/sugg.rs @@ -248,7 +248,7 @@ impl<'a> Sugg<'a> { | ast::ExprKind::Array(..) | ast::ExprKind::While(..) | ast::ExprKind::Await(..) - | ast::ExprKind::DirectConstArg(..) + | ast::ExprKind::GcaMacro(..) | ast::ExprKind::Err(_) | ast::ExprKind::Dummy | ast::ExprKind::UnsafeBinderCast(..) => Sugg::NonParen(snippet(expr.span)), diff --git a/src/tools/clippy/tests/ui/crashes/mgca-16691.rs b/src/tools/clippy/tests/ui/crashes/mgca-16691.rs index 7e45f96fa9a9a..554528905fc85 100644 --- a/src/tools/clippy/tests/ui/crashes/mgca-16691.rs +++ b/src/tools/clippy/tests/ui/crashes/mgca-16691.rs @@ -2,6 +2,8 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] +use std::gca; + trait Trait { #[rustc_always_gca] const N: usize; @@ -9,7 +11,7 @@ trait Trait { } impl Trait for () { - const N: usize = core::direct_const_arg!(3); + const N: usize = gca!(3); fn process() { const N: usize = <()>::N; _ = 0..Self::N; diff --git a/src/tools/rustfmt/src/expr.rs b/src/tools/rustfmt/src/expr.rs index f0e56ffb8ea1a..48f17fb0fd1a8 100644 --- a/src/tools/rustfmt/src/expr.rs +++ b/src/tools/rustfmt/src/expr.rs @@ -430,7 +430,7 @@ pub(crate) fn format_expr( | ast::ExprKind::IncludedBytes(..) | ast::ExprKind::OffsetOf(..) | ast::ExprKind::UnsafeBinderCast(..) - | ast::ExprKind::DirectConstArg(..) => { + | ast::ExprKind::GcaMacro(..) => { // These don't normally occur in the AST because macros aren't expanded. However, // rustfmt tries to parse macro arguments when formatting macros, so it's not totally // impossible for rustfmt to come across one of these nodes when formatting a file. diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs index e2c92e58062ae..d119cd50c846a 100644 --- a/src/tools/rustfmt/src/types.rs +++ b/src/tools/rustfmt/src/types.rs @@ -1043,7 +1043,7 @@ impl Rewrite for ast::Ty { result.push_str(&rewrite); Ok(result) } - ast::TyKind::Pat(..) | ast::TyKind::View(..) | ast::TyKind::DirectConstArg(..) => { + ast::TyKind::Pat(..) | ast::TyKind::View(..) | ast::TyKind::GcaMacro(..) => { // These don't normally occur in the AST because macros aren't expanded. However, // rustfmt tries to parse macro arguments when formatting macros, so it's not // totally impossible for rustfmt to come across these nodes when formatting a file. diff --git a/src/tools/rustfmt/src/utils.rs b/src/tools/rustfmt/src/utils.rs index 6f9fa7ff7024f..f7933ac52f75c 100644 --- a/src/tools/rustfmt/src/utils.rs +++ b/src/tools/rustfmt/src/utils.rs @@ -562,7 +562,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr | ast::ExprKind::Unary(_, ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Yield(YieldKind::Prefix(Some(ref expr))) - | ast::ExprKind::DirectConstArg(ref expr) => is_block_expr(context, expr, repr), + | ast::ExprKind::GcaMacro(ref expr) => is_block_expr(context, expr, repr), ast::ExprKind::Closure(ref closure) => is_block_expr(context, &closure.body, repr), // This can only be a string lit ast::ExprKind::Lit(_) => { diff --git a/src/tools/rustfmt/tests/source/direct_const_arg.rs b/src/tools/rustfmt/tests/source/direct_const_arg.rs deleted file mode 100644 index 6486d782cc1f5..0000000000000 --- a/src/tools/rustfmt/tests/source/direct_const_arg.rs +++ /dev/null @@ -1,15 +0,0 @@ -// direct_const_arg! is a built-in macro relevant to min_generic_const_args; its contents should be -// formatted as if its contents were passed through unchanged (the macro changes the semantics of -// the contained expression, the syntax is unchanged) - -#![feature(min_generic_const_args)] - -trait Trait { - #[rustc_always_gca] - const TYPE_CONST: usize; -} - -struct S; - -fn parsed_as_expr_kind(_: S<{ core::direct_const_arg!( T :: TYPE_CONST ) }>) {} -fn parsed_as_ty_kind(_: S< core::direct_const_arg!( T :: TYPE_CONST ) >) {} diff --git a/src/tools/rustfmt/tests/source/gca.rs b/src/tools/rustfmt/tests/source/gca.rs new file mode 100644 index 0000000000000..ab394c21b8b32 --- /dev/null +++ b/src/tools/rustfmt/tests/source/gca.rs @@ -0,0 +1,17 @@ +// gca! is a built-in macro relevant to min_generic_const_args; its contents should be formatted as +// if its contents were passed through unchanged (the macro changes the semantics of the contained +// expression, the syntax is unchanged) + +#![feature(min_generic_const_args)] + +use std::gca; + +trait Trait { + #[rustc_always_gca] + const TYPE_CONST: usize; +} + +struct S; + +fn parsed_as_expr_kind(_: S<{ gca!( T :: TYPE_CONST ) }>) {} +fn parsed_as_ty_kind(_: S< gca!( T :: TYPE_CONST ) >) {} diff --git a/src/tools/rustfmt/tests/target/direct_const_arg.rs b/src/tools/rustfmt/tests/target/direct_const_arg.rs deleted file mode 100644 index 94a6c864b78ef..0000000000000 --- a/src/tools/rustfmt/tests/target/direct_const_arg.rs +++ /dev/null @@ -1,15 +0,0 @@ -// direct_const_arg! is a built-in macro relevant to min_generic_const_args; its contents should be -// formatted as if its contents were passed through unchanged (the macro changes the semantics of -// the contained expression, the syntax is unchanged) - -#![feature(min_generic_const_args)] - -trait Trait { - #[rustc_always_gca] - const TYPE_CONST: usize; -} - -struct S; - -fn parsed_as_expr_kind(_: S<{ core::direct_const_arg!(T::TYPE_CONST) }>) {} -fn parsed_as_ty_kind(_: S) {} diff --git a/src/tools/rustfmt/tests/target/gca.rs b/src/tools/rustfmt/tests/target/gca.rs new file mode 100644 index 0000000000000..8110bb0d2c827 --- /dev/null +++ b/src/tools/rustfmt/tests/target/gca.rs @@ -0,0 +1,17 @@ +// gca! is a built-in macro relevant to min_generic_const_args; its contents should be formatted as +// if its contents were passed through unchanged (the macro changes the semantics of the contained +// expression, the syntax is unchanged) + +#![feature(min_generic_const_args)] + +use std::gca; + +trait Trait { + #[rustc_always_gca] + const TYPE_CONST: usize; +} + +struct S; + +fn parsed_as_expr_kind(_: S<{ gca!(T::TYPE_CONST) }>) {} +fn parsed_as_ty_kind(_: S) {} diff --git a/tests/crashes/138009.rs b/tests/crashes/138009.rs index 15c34a848e05f..494e3fb827ddb 100644 --- a/tests/crashes/138009.rs +++ b/tests/crashes/138009.rs @@ -1,6 +1,9 @@ //@ known-bug: #138009 #![feature(min_generic_const_args)] + +use std::gca; + #[repr(simd)] -struct T([isize; core::direct_const_arg!(N)]); +struct T([isize; gca!(N)]); static X: T = T(); diff --git a/tests/crashes/149809.rs b/tests/crashes/149809.rs index c2392a9c41eb2..b1172b72b17cd 100644 --- a/tests/crashes/149809.rs +++ b/tests/crashes/149809.rs @@ -1,12 +1,16 @@ //@ known-bug: #149809 #![feature(min_generic_const_args)] #![feature(inherent_associated_types)] + +use std::gca; + struct Qux<'a> { x: &'a (), } + impl<'a> Qux<'a> { - const LEN: usize = core::direct_const_arg!(4); - fn foo(_: [u8; core::direct_const_arg!(Qux::LEN)]) {} + const LEN: usize = gca!(4); + fn foo(_: [u8; gca!(Qux::LEN)]) {} } fn main() {} diff --git a/tests/crashes/150049.rs b/tests/crashes/150049.rs index 45289679e04ba..994e257a28d59 100644 --- a/tests/crashes/150049.rs +++ b/tests/crashes/150049.rs @@ -1,12 +1,15 @@ //@ known-bug: #150049 #![feature(min_generic_const_args)] #![feature(inherent_associated_types)] + +use std::gca; + struct Foo<'a> { x: &'a (), } impl<'a> Foo<'a> { - fn foo(_: [u8; core::direct_const_arg!(Foo::X)]) { + fn foo(_: [u8; gca!(Foo::X)]) { std::mem::transmute([4]) } } diff --git a/tests/crashes/150749.rs b/tests/crashes/150749.rs index 59d07f9860b9a..8e4e413236c82 100644 --- a/tests/crashes/150749.rs +++ b/tests/crashes/150749.rs @@ -1,12 +1,16 @@ //@ known-bug: #150749 #![feature(min_generic_const_args)] +use std::gca; + trait CollectArray { fn inner_array(); } + impl CollectArray for () { fn inner_array() { - let temp_ptr: [(); core::direct_const_arg!(Self)]; + let temp_ptr: [(); gca!(Self)]; } } + fn main() {} diff --git a/tests/debuginfo/associated-const-bindings.rs b/tests/debuginfo/associated-const-bindings.rs index 1a7ca6a5b0a95..171d457925522 100644 --- a/tests/debuginfo/associated-const-bindings.rs +++ b/tests/debuginfo/associated-const-bindings.rs @@ -13,12 +13,15 @@ #![feature(min_generic_const_args)] #![expect(unused_variables, incomplete_features)] +use std::gca; + trait Trait { #[rustc_always_gca] const N: usize; } + impl Trait for () { - const N: usize = core::direct_const_arg!(101); + const N: usize = gca!(101); } fn main() { diff --git a/tests/pretty/direct-const-arg.rs b/tests/pretty/direct-const-arg.rs deleted file mode 100644 index 330c1cac024de..0000000000000 --- a/tests/pretty/direct-const-arg.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ pretty-mode:expanded -//@ pp-exact:direct-const-arg.pp -#![feature(min_generic_const_args)] - -fn f() {} - -fn main() { - f::(); - f::<{ core::direct_const_arg!(2) }>(); -} diff --git a/tests/pretty/direct-const-arg.pp b/tests/pretty/gca-macro.pp similarity index 60% rename from tests/pretty/direct-const-arg.pp rename to tests/pretty/gca-macro.pp index a76ed9a480e71..8912d790b337a 100644 --- a/tests/pretty/direct-const-arg.pp +++ b/tests/pretty/gca-macro.pp @@ -1,15 +1,14 @@ #![feature(prelude_import)] #![no_std] //@ pretty-mode:expanded -//@ pp-exact:direct-const-arg.pp +//@ pp-exact:gca-macro.pp #![feature(min_generic_const_args)] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; +use std::gca; + fn f() {} -fn main() { - f::(); - f::<{ core::direct_const_arg! (2) }>(); -} +fn main() { f::(); f::<{ core::gca! (2) }>(); } diff --git a/tests/pretty/gca-macro.rs b/tests/pretty/gca-macro.rs new file mode 100644 index 0000000000000..248fd4424e1da --- /dev/null +++ b/tests/pretty/gca-macro.rs @@ -0,0 +1,12 @@ +//@ pretty-mode:expanded +//@ pp-exact:gca-macro.pp +#![feature(min_generic_const_args)] + +use std::gca; + +fn f() {} + +fn main() { + f::(); + f::<{ gca!(2) }>(); +} diff --git a/tests/rustdoc-html/type-const-free-in-array.rs b/tests/rustdoc-html/type-const-free-in-array.rs index 4583e20fb8998..3fd6b21e34eea 100644 --- a/tests/rustdoc-html/type-const-free-in-array.rs +++ b/tests/rustdoc-html/type-const-free-in-array.rs @@ -2,7 +2,9 @@ #![feature(min_generic_const_args, macroless_generic_const_args)] #![expect(incomplete_features)] -const N: usize = core::direct_const_arg!(2); +use std::gca; + +const N: usize = gca!(2); //@ has 'foo/trait.CollectArray.html' //@ has - '//pre[@class="rust item-decl"]/code' '[A; N]' diff --git a/tests/rustdoc-html/type-const-inherent-with-body.rs b/tests/rustdoc-html/type-const-inherent-with-body.rs index a209ac47dcb0d..030ca8608a02d 100644 --- a/tests/rustdoc-html/type-const-inherent-with-body.rs +++ b/tests/rustdoc-html/type-const-inherent-with-body.rs @@ -2,10 +2,12 @@ #![feature(min_generic_const_args, macroless_generic_const_args, inherent_associated_types)] #![expect(incomplete_features)] +use std::gca; + pub struct Foo; impl Foo { - const LEN: usize = core::direct_const_arg!(4); + const LEN: usize = gca!(4); } //@ has 'foo/fn.mk_array.html' diff --git a/tests/ui/associated-consts/type-const-in-array-len-wrong-type.rs b/tests/ui/associated-consts/type-const-in-array-len-wrong-type.rs index 919aba47aea28..bb5e7ad4be181 100644 --- a/tests/ui/associated-consts/type-const-in-array-len-wrong-type.rs +++ b/tests/ui/associated-consts/type-const-in-array-len-wrong-type.rs @@ -5,10 +5,12 @@ inherent_associated_types )] +use std::gca; + struct OnDiskDirEntry<'a>(&'a ()); impl<'a> OnDiskDirEntry<'a> { - const LFN_FRAGMENT_LEN: i64 = core::direct_const_arg!(2); + const LFN_FRAGMENT_LEN: i64 = gca!(2); fn lfn_contents() -> [char; Self::LFN_FRAGMENT_LEN] { //~^ ERROR the constant `2` is not of type `usize` diff --git a/tests/ui/associated-consts/type-const-in-array-len-wrong-type.stderr b/tests/ui/associated-consts/type-const-in-array-len-wrong-type.stderr index dcb88f77f82cd..80c477ed43f29 100644 --- a/tests/ui/associated-consts/type-const-in-array-len-wrong-type.stderr +++ b/tests/ui/associated-consts/type-const-in-array-len-wrong-type.stderr @@ -1,5 +1,5 @@ error: the constant `2` is not of type `usize` - --> $DIR/type-const-in-array-len-wrong-type.rs:13:26 + --> $DIR/type-const-in-array-len-wrong-type.rs:15:26 | LL | fn lfn_contents() -> [char; Self::LFN_FRAGMENT_LEN] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `i64` diff --git a/tests/ui/associated-consts/type-const-in-array-len.rs b/tests/ui/associated-consts/type-const-in-array-len.rs index 0f53aa9dd56fe..b4cf05a618255 100644 --- a/tests/ui/associated-consts/type-const-in-array-len.rs +++ b/tests/ui/associated-consts/type-const-in-array-len.rs @@ -2,10 +2,12 @@ #![feature(min_generic_const_args, macroless_generic_const_args, inherent_associated_types)] +use std::gca; + // Test case from #138226: generic impl with multiple type parameters struct Foo(A, B); impl Foo { - const LEN: usize = core::direct_const_arg!(4); + const LEN: usize = gca!(4); fn foo() { let _ = [5; Self::LEN]; @@ -15,7 +17,7 @@ impl Foo { // Test case from #138226: generic impl with const parameter struct Bar; impl Bar { - const LEN: usize = core::direct_const_arg!(4); + const LEN: usize = gca!(4); fn bar() { let _ = [0; Self::LEN]; @@ -25,7 +27,7 @@ impl Bar { // Test case from #150960: non-generic impl with const block struct Baz; impl Baz { - const LEN: usize = core::direct_const_arg!(4); + const LEN: usize = gca!(4); fn baz() { let _ = [0; { Self::LEN }]; diff --git a/tests/ui/associated-type-bounds/duplicate-bound-err.rs b/tests/ui/associated-type-bounds/duplicate-bound-err.rs index 0d1ab691c5c7f..5dc2ad6a3a56c 100644 --- a/tests/ui/associated-type-bounds/duplicate-bound-err.rs +++ b/tests/ui/associated-type-bounds/duplicate-bound-err.rs @@ -4,7 +4,7 @@ #![expect(incomplete_features)] #![allow(refining_impl_trait_internal)] -use std::iter; +use std::{gca, iter}; fn rpit1() -> impl Iterator { iter::empty() @@ -55,7 +55,7 @@ trait Trait { impl Trait for () { type Gat = (); - const ASSOC: i32 = core::direct_const_arg!(3); + const ASSOC: i32 = gca!(3); fn foo() {} } @@ -63,7 +63,7 @@ impl Trait for () { impl Trait for u32 { type Gat = (); - const ASSOC: i32 = core::direct_const_arg!(4); + const ASSOC: i32 = gca!(4); fn foo() -> u32 { 42 diff --git a/tests/ui/associated-type-bounds/duplicate-bound.rs b/tests/ui/associated-type-bounds/duplicate-bound.rs index 233b1ffb6ce76..68f9c373cd49c 100644 --- a/tests/ui/associated-type-bounds/duplicate-bound.rs +++ b/tests/ui/associated-type-bounds/duplicate-bound.rs @@ -5,8 +5,8 @@ #![expect(incomplete_features)] #![allow(dead_code, refining_impl_trait_internal, type_alias_bounds)] -use std::iter; use std::mem::ManuallyDrop; +use std::{gca, iter}; struct Si1> { f: T, @@ -198,7 +198,7 @@ trait Trait { impl Trait for () { type Gat = (); - const ASSOC: i32 = core::direct_const_arg!(3); + const ASSOC: i32 = gca!(3); fn foo() {} } diff --git a/tests/ui/associated-types/type-const-inherent-impl-normalize.rs b/tests/ui/associated-types/type-const-inherent-impl-normalize.rs index 63fa8eff1473b..8a0d14554d201 100644 --- a/tests/ui/associated-types/type-const-inherent-impl-normalize.rs +++ b/tests/ui/associated-types/type-const-inherent-impl-normalize.rs @@ -1,8 +1,8 @@ struct S; impl S { - const LEN: usize = core::direct_const_arg!(1); + const LEN: usize = std::gca!(1); //~^ ERROR: use of unstable library feature `min_generic_const_args` [E0658] - //~| ERROR: expected expression, found `direct_const_arg!()` + //~| ERROR: expected expression, found `gca!()` fn arr() { [8; Self::LEN] } diff --git a/tests/ui/associated-types/type-const-inherent-impl-normalize.stderr b/tests/ui/associated-types/type-const-inherent-impl-normalize.stderr index 421c2a83a19b9..9ee66984529de 100644 --- a/tests/ui/associated-types/type-const-inherent-impl-normalize.stderr +++ b/tests/ui/associated-types/type-const-inherent-impl-normalize.stderr @@ -1,18 +1,18 @@ error[E0658]: use of unstable library feature `min_generic_const_args` --> $DIR/type-const-inherent-impl-normalize.rs:3:24 | -LL | const LEN: usize = core::direct_const_arg!(1); - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | const LEN: usize = std::gca!(1); + | ^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: expected expression, found `direct_const_arg!()` constant +error: expected expression, found `gca!()` constant --> $DIR/type-const-inherent-impl-normalize.rs:3:24 | -LL | const LEN: usize = core::direct_const_arg!(1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const LEN: usize = std::gca!(1); + | ^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.rs b/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.rs index ffc605c0d51e0..378af46decb96 100644 --- a/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.rs +++ b/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.rs @@ -10,12 +10,14 @@ #![feature(min_generic_const_args, inherent_associated_types, generic_const_items)] +use std::gca; + struct Parent<'a> { a: &'a str, } impl<'a> Parent<'a> { - const CT: usize = core::direct_const_arg!(0); + const CT: usize = gca!(0); } fn check() diff --git a/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.stderr b/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.stderr index e77a0994fc2db..3cdd01182f84c 100644 --- a/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.stderr +++ b/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find type `T` in this scope - --> $DIR/resolved-region-var-max-universe.rs:23:23 + --> $DIR/resolved-region-var-max-universe.rs:25:23 | LL | [(); Parent::CT::]:, | ^ not found in this scope diff --git a/tests/ui/const-generics/associated-const-bindings/ambiguity.rs b/tests/ui/const-generics/associated-const-bindings/ambiguity.rs index 88c1212fe2c93..a8d66c950a064 100644 --- a/tests/ui/const-generics/associated-const-bindings/ambiguity.rs +++ b/tests/ui/const-generics/associated-const-bindings/ambiguity.rs @@ -4,6 +4,8 @@ #![feature(adt_const_params, min_generic_const_args, unsized_const_params)] #![allow(incomplete_features)] +use std::gca; + trait Trait0: Parent0 + Parent0 {} trait Parent0 { #[rustc_always_gca] @@ -23,7 +25,7 @@ trait Parent2 { const C: &'static str; } -fn take1(_: impl Trait1) {} +fn take1(_: impl Trait1) {} //~^ ERROR ambiguous associated constant `C` in bounds of `Trait1` fn main() {} diff --git a/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr b/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr index 5ed843de96074..88f356d1297bc 100644 --- a/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr +++ b/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr @@ -1,5 +1,5 @@ error[E0222]: ambiguous associated constant `K` in bounds of `Trait0` - --> $DIR/ambiguity.rs:13:25 + --> $DIR/ambiguity.rs:15:25 | LL | const K: (); | ----------- @@ -17,7 +17,7 @@ LL | fn take0(_: impl Trait0) {} T: Parent0::K = const {} error[E0222]: ambiguous associated constant `C` in bounds of `Trait1` - --> $DIR/ambiguity.rs:26:25 + --> $DIR/ambiguity.rs:28:25 | LL | const C: i32; | ------------ ambiguous `C` from `Parent1` @@ -25,8 +25,8 @@ LL | const C: i32; LL | const C: &'static str; | --------------------- ambiguous `C` from `Parent2` ... -LL | fn take1(_: impl Trait1) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ambiguous associated constant `C` +LL | fn take1(_: impl Trait1) {} + | ^^^^^^^^^^^^^^^^^ ambiguous associated constant `C` | = help: consider introducing a new type parameter `T` and adding `where` constraints: where diff --git a/tests/ui/const-generics/associated-const-bindings/assoc-const.rs b/tests/ui/const-generics/associated-const-bindings/assoc-const.rs index 598924316590c..d7e5ce3229dfd 100644 --- a/tests/ui/const-generics/associated-const-bindings/assoc-const.rs +++ b/tests/ui/const-generics/associated-const-bindings/assoc-const.rs @@ -2,6 +2,8 @@ #![feature(min_generic_const_args)] #![allow(unused, incomplete_features)] +use std::gca; + pub trait Foo { #[rustc_always_gca] const N: usize; @@ -10,7 +12,7 @@ pub trait Foo { pub struct Bar; impl Foo for Bar { - const N: usize = core::direct_const_arg!(3); + const N: usize = gca!(3); } fn foo>() {} diff --git a/tests/ui/const-generics/associated-const-bindings/coexisting-with-type-binding.rs b/tests/ui/const-generics/associated-const-bindings/coexisting-with-type-binding.rs index a6c86ce4b867d..f6fa6ece02ad9 100644 --- a/tests/ui/const-generics/associated-const-bindings/coexisting-with-type-binding.rs +++ b/tests/ui/const-generics/associated-const-bindings/coexisting-with-type-binding.rs @@ -8,6 +8,8 @@ #![feature(adt_const_params, min_generic_const_args, unsized_const_params)] #![allow(incomplete_features)] +use std::gca; + trait Trait: SuperTrait { type N; type Q; @@ -23,6 +25,6 @@ trait SuperTrait { fn take0(_: impl Trait) {} -fn take1(_: impl Trait) {} +fn take1(_: impl Trait) {} fn main() {} diff --git a/tests/ui/const-generics/associated-const-bindings/coherence.rs b/tests/ui/const-generics/associated-const-bindings/coherence.rs index aa26c6f4cd18f..d5764bfc93b61 100644 --- a/tests/ui/const-generics/associated-const-bindings/coherence.rs +++ b/tests/ui/const-generics/associated-const-bindings/coherence.rs @@ -1,12 +1,14 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] +use std::gca; + pub trait IsVoid { #[rustc_always_gca] const IS_VOID: bool; } impl IsVoid for () { - const IS_VOID: bool = core::direct_const_arg!(true); + const IS_VOID: bool = gca!(true); } pub trait Maybe {} diff --git a/tests/ui/const-generics/associated-const-bindings/coherence.stderr b/tests/ui/const-generics/associated-const-bindings/coherence.stderr index ca1c968801243..519c95719a732 100644 --- a/tests/ui/const-generics/associated-const-bindings/coherence.stderr +++ b/tests/ui/const-generics/associated-const-bindings/coherence.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Maybe` for type `()` - --> $DIR/coherence.rs:14:1 + --> $DIR/coherence.rs:16:1 | LL | impl Maybe for () {} | ----------------- first implementation here diff --git a/tests/ui/const-generics/associated-const-bindings/const_evaluatable_unchecked.rs b/tests/ui/const-generics/associated-const-bindings/const_evaluatable_unchecked.rs index a472118e51a82..7f7aec0ebcdd5 100644 --- a/tests/ui/const-generics/associated-const-bindings/const_evaluatable_unchecked.rs +++ b/tests/ui/const-generics/associated-const-bindings/const_evaluatable_unchecked.rs @@ -7,9 +7,11 @@ #![feature(min_generic_const_args, associated_type_defaults)] #![allow(incomplete_features)] +use std::gca; + pub trait TraitA { #[rustc_always_gca] - const K: u8 = core::direct_const_arg!(0); + const K: u8 = gca!(0); } pub trait TraitB {} diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-basic.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-basic.rs index 3a896b6b2e1fa..cddb6eb88e937 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-basic.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-basic.rs @@ -6,6 +6,8 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] +use std::gca; + trait Trait: SuperTrait { #[rustc_always_gca] const K: usize; @@ -24,7 +26,7 @@ trait Bound { } impl Bound for () { - const N: usize = core::direct_const_arg!(10); + const N: usize = gca!(10); } fn main() { diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.rs index a28805f87b0f8..c38431c8e1d78 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.rs @@ -3,13 +3,15 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] +use std::gca; + trait Trait { #[rustc_always_gca] const N: usize; } impl Trait for () { - const N: usize = core::direct_const_arg!(1); + const N: usize = gca!(1); } fn main() { diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.stderr index ea781f784a9b0..82b4f7ca9ba6e 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.stderr @@ -1,5 +1,5 @@ error[E0271]: type mismatch resolving `<() as Trait>::N == 0` - --> $DIR/dyn-compat-const-mismatch.rs:16:32 + --> $DIR/dyn-compat-const-mismatch.rs:18:32 | LL | let _: &dyn Trait = &(); | ^^^ expected `0`, found `1` diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.rs index f957a60a78b0b..b6d67f8fd8b19 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.rs @@ -4,6 +4,8 @@ #![feature(min_generic_const_args, macroless_generic_const_args)] #![expect(incomplete_features)] +use std::gca; + trait X::N }> {} trait Y { @@ -12,7 +14,7 @@ trait Y { } impl Y for T { - const N: usize = core::direct_const_arg!(1); + const N: usize = gca!(1); } fn main() { diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.stderr index 365bae2188b00..bfe1e213e330b 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.stderr @@ -1,5 +1,5 @@ error[E0393]: the const parameter `N` must be explicitly specified - --> $DIR/dyn-compat-const-param-default-mentions-self.rs:19:16 + --> $DIR/dyn-compat-const-param-default-mentions-self.rs:21:16 | LL | trait X::N }> {} | -------------------------------------------- const parameter `N` must be specified for this diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs index 16fb2af1c4b54..2d282ace5436a 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs @@ -5,13 +5,15 @@ #![feature(min_generic_const_args, generic_const_items)] #![expect(incomplete_features)] +use std::gca; + trait Trait { #[rustc_always_gca] const N: i32 where Self: Bound; } impl Trait for () { - const N: i32 = core::direct_const_arg!(0); + const N: i32 = gca!(0); } trait Bound {} diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.stderr index 770e7b561fadd..38a5ec4e1a9f8 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.stderr @@ -1,16 +1,16 @@ error[E0277]: the trait bound `(): Bound` is not satisfied - --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:22:32 + --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:24:32 | LL | let _: &dyn Trait = &(); | ^^^ the trait `Bound` is not implemented for `()` | help: this trait has no implementations, consider adding one - --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:17:1 + --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:19:1 | LL | trait Bound {} | ^^^^^^^^^^^ note: required by a bound in `Trait::N` - --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:10:30 + --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:12:30 | LL | trait Trait { LL | #[rustc_always_gca] diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.rs index b2f0b25041056..53746231f46d7 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.rs @@ -13,6 +13,8 @@ )] #![expect(incomplete_features)] +use std::gca; + trait A { type Ty: std::marker::ConstParamTy_; #[rustc_always_gca] @@ -21,7 +23,7 @@ trait A { impl A for () { type Ty = i32; - const CT: i32 = core::direct_const_arg!(0); + const CT: i32 = gca!(0); } fn main() { diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.stderr index e3873eae6f04f..50faeaf4eed9e 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.stderr @@ -1,11 +1,11 @@ error: type annotations needed for the literal - --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:34:33 + --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:36:33 | LL | let _: dyn A; | ^ error: type annotations needed for the literal - --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:36:34 + --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:38:34 | LL | let _: &dyn A = &(); | ^ diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-methods.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-methods.rs index 148f5b8654af0..7cd8d6ef36302 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-methods.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-methods.rs @@ -14,6 +14,8 @@ #![feature(min_generic_const_args, macroless_generic_const_args)] #![expect(incomplete_features)] +use std::gca; + trait Trait { #[rustc_always_gca] const N: usize; @@ -22,7 +24,7 @@ trait Trait { } impl Trait for u8 { - const N: usize = core::direct_const_arg!(2); + const N: usize = gca!(2); fn process(&self, [x, y]: [u8; Self::N]) -> [u8; Self::N] { [self * x, self + y] @@ -30,7 +32,7 @@ impl Trait for u8 { } impl Trait for [u8; N] { - const N: usize = core::direct_const_arg!(N); + const N: usize = gca!(N); fn process(&self, other: [u8; Self::N]) -> [u8; Self::N] { let mut result = [0; _]; diff --git a/tests/ui/const-generics/associated-const-bindings/equality-unused-issue-126729.rs b/tests/ui/const-generics/associated-const-bindings/equality-unused-issue-126729.rs index 7b05da5623b10..0b4e871ceb5c6 100644 --- a/tests/ui/const-generics/associated-const-bindings/equality-unused-issue-126729.rs +++ b/tests/ui/const-generics/associated-const-bindings/equality-unused-issue-126729.rs @@ -4,13 +4,15 @@ #![allow(incomplete_features)] #![deny(dead_code)] +use std::gca; + trait Tr { #[rustc_always_gca] const I: i32; } impl Tr for () { - const I: i32 = core::direct_const_arg!(1); + const I: i32 = gca!(1); } fn foo() -> impl Tr {} @@ -23,20 +25,22 @@ trait Tr2 { } impl Tr2 for () { - const J: i32 = core::direct_const_arg!(1); - const K: i32 = core::direct_const_arg!(1); + const J: i32 = gca!(1); + const K: i32 = gca!(1); } fn foo2() -> impl Tr2 {} mod t { + use std::gca; + pub trait Tr3 { #[rustc_always_gca] const L: i32; } impl Tr3 for () { - const L: i32 = core::direct_const_arg!(1); + const L: i32 = gca!(1); } } diff --git a/tests/ui/const-generics/associated-const-bindings/equality_bound_with_infer.rs b/tests/ui/const-generics/associated-const-bindings/equality_bound_with_infer.rs index 01589ac645b05..3027357d0fb7e 100644 --- a/tests/ui/const-generics/associated-const-bindings/equality_bound_with_infer.rs +++ b/tests/ui/const-generics/associated-const-bindings/equality_bound_with_infer.rs @@ -3,6 +3,8 @@ #![feature(min_generic_const_args, generic_const_items)] #![expect(incomplete_features)] +use std::gca; + // Regression test for #133066 where we would try to evaluate `<() as Foo>::ASSOC<_>` even // though it contained inference variables, which would cause ICEs. @@ -12,7 +14,7 @@ trait Foo { } impl Foo for () { - const ASSOC: u32 = core::direct_const_arg!(N); + const ASSOC: u32 = gca!(N); } fn bar = 10>>() {} diff --git a/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.rs b/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.rs index 818609486d20c..9ef5c902062e3 100644 --- a/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.rs +++ b/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.rs @@ -1,13 +1,15 @@ #![feature(generic_const_items, min_generic_const_args)] #![expect(incomplete_features)] +use std::gca; + trait Foo { #[rustc_always_gca] const ASSOC: u32; } impl Foo for () { - const ASSOC: u32 = core::direct_const_arg!(N); + const ASSOC: u32 = gca!(N); } fn bar = { N }>>() {} diff --git a/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.stderr b/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.stderr index e879cafdc86ea..1eaa635e13532 100644 --- a/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.stderr +++ b/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.stderr @@ -1,11 +1,11 @@ error: the constant `N` is not of type `u32` - --> $DIR/mismatched-types-with-generic-in-ace.rs:13:29 + --> $DIR/mismatched-types-with-generic-in-ace.rs:15:29 | LL | fn bar = { N }>>() {} | ^^^^^^^^^^^^^^^^ expected `u32`, found `u64` | note: required by a const generic parameter in `Foo::ASSOC` - --> $DIR/mismatched-types-with-generic-in-ace.rs:6:17 + --> $DIR/mismatched-types-with-generic-in-ace.rs:8:17 | LL | trait Foo { LL | #[rustc_always_gca] @@ -13,13 +13,13 @@ LL | const ASSOC: u32; | ^^^^^^^^^^^^ required by this const generic parameter in `Foo::ASSOC` error: the constant `10` is not of type `u32` - --> $DIR/mismatched-types-with-generic-in-ace.rs:17:5 + --> $DIR/mismatched-types-with-generic-in-ace.rs:19:5 | LL | bar::<10_u64, ()>(); | ^^^^^^^^^^^^^^^^^^^ expected `u32`, found `u64` | note: required by a const generic parameter in `Foo::ASSOC` - --> $DIR/mismatched-types-with-generic-in-ace.rs:6:17 + --> $DIR/mismatched-types-with-generic-in-ace.rs:8:17 | LL | trait Foo { LL | #[rustc_always_gca] diff --git a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.rs b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.rs index d5682e7de1294..0180aa4694f67 100644 --- a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.rs +++ b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.rs @@ -4,6 +4,8 @@ #![feature(min_generic_const_args, macroless_generic_const_args)] #![expect(incomplete_features)] +use std::gca; + trait Trait { #[rustc_always_gca] const CT: bool; @@ -14,7 +16,7 @@ trait Bound { const N: u32; } impl Bound for () { - const N: u32 = core::direct_const_arg!(0); + const N: u32 = gca!(0); } fn f() { diff --git a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.stderr b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.stderr index f921e5893b51e..ddcf1d00dfbd8 100644 --- a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.stderr +++ b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.stderr @@ -1,17 +1,17 @@ error: the constant `0` is not of type `bool` - --> $DIR/wf-mismatch-3.rs:24:20 + --> $DIR/wf-mismatch-3.rs:26:20 | LL | fn g(_: impl Trait::N }>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `u32` | note: required by a const generic parameter in `g` - --> $DIR/wf-mismatch-3.rs:24:20 + --> $DIR/wf-mismatch-3.rs:26:20 | LL | fn g(_: impl Trait::N }>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `g` error: the constant `0` is not of type `bool` - --> $DIR/wf-mismatch-3.rs:21:12 + --> $DIR/wf-mismatch-3.rs:23:12 | LL | let _: dyn Trait::N }>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `u32` diff --git a/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.next.stderr b/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.next.stderr index 3b53adb07a2b9..0bbfe0626470d 100644 --- a/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.next.stderr +++ b/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.next.stderr @@ -1,13 +1,13 @@ error[E0284]: type annotations needed for `([(); _], [(); 10])` - --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:31:9 + --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:33:9 | LL | let (mut arr, mut arr_with_weird_len) = free(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------ type must be known at this point | note: required by a const generic parameter in `free` - --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:26:9 + --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:28:9 | -LL | fn free() -> ([(); N], [(); core::direct_const_arg!(FREE::)]) { +LL | fn free() -> ([(); N], [(); gca!(FREE::)]) { | ^^^^^^^^^^^^^^ required by this const generic parameter in `free` help: consider giving this pattern a type, where the value of const parameter `N` is specified | @@ -15,7 +15,7 @@ LL | let (mut arr, mut arr_with_weird_len): ([_; N], _) = free(); | +++++++++++++ error[E0271]: type mismatch resolving `FREE<10> == 2` - --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:37:45 + --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:39:45 | LL | let (mut arr, mut arr_with_weird_len) = free(); | ^^^^^^ expected `2`, found `10` @@ -24,16 +24,16 @@ LL | let (mut arr, mut arr_with_weird_len) = free(); found constant `10` error[E0284]: type annotations needed for `([(); _], [(); 10])` - --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:48:9 + --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:50:9 | LL | let (mut arr, mut arr_with_weird_len) = proj(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------ type must be known at this point | = note: cannot satisfy `::PROJ<_> == 10` note: required by a const generic parameter in `proj` - --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:43:9 + --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:45:9 | -LL | fn proj() -> ([(); N], [(); core::direct_const_arg!(::PROJ::)]) { +LL | fn proj() -> ([(); N], [(); gca!(::PROJ::)]) { | ^^^^^^^^^^^^^^ required by this const generic parameter in `proj` help: consider giving this pattern a type, where the value of const parameter `N` is specified | @@ -41,7 +41,7 @@ LL | let (mut arr, mut arr_with_weird_len): ([_; N], _) = proj(); | +++++++++++++ error[E0271]: type mismatch resolving `::PROJ<10> == 2` - --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:54:45 + --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:56:45 | LL | let (mut arr, mut arr_with_weird_len) = proj(); | ^^^^^^ expected `2`, found `10` diff --git a/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.rs b/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.rs index 8ee278af6ef56..a178a0f0d0b95 100644 --- a/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.rs +++ b/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.rs @@ -12,6 +12,8 @@ )] #![expect(incomplete_features)] +use std::gca; + const FREE: usize = 10; trait Trait { @@ -23,7 +25,7 @@ impl Trait for S { const PROJ: usize = 10; } -fn free() -> ([(); N], [(); core::direct_const_arg!(FREE::)]) { +fn free() -> ([(); N], [(); gca!(FREE::)]) { loop {} } @@ -40,7 +42,7 @@ fn test_free_mismatch() { arr = [(); 10]; } -fn proj() -> ([(); N], [(); core::direct_const_arg!(::PROJ::)]) { +fn proj() -> ([(); N], [(); gca!(::PROJ::)]) { loop {} } diff --git a/tests/ui/const-generics/gca/assoc-const.rs b/tests/ui/const-generics/gca/assoc-const.rs index 8a8d1b52e7e5a..316084e5b8cf9 100644 --- a/tests/ui/const-generics/gca/assoc-const.rs +++ b/tests/ui/const-generics/gca/assoc-const.rs @@ -2,12 +2,14 @@ //@ compile-flags: -Znext-solver #![feature(min_generic_const_args, generic_const_args)] +use std::gca; + trait Trait { const ASSOC: usize; } impl Trait for T { - const ASSOC: usize = core::direct_const_arg!(T::RIGID); + const ASSOC: usize = gca!(T::RIGID); } trait Other { @@ -15,8 +17,7 @@ trait Other { } fn foo() { - let a: [(); core::direct_const_arg!(::ASSOC)] = - [(); core::direct_const_arg!(T::RIGID)]; + let a: [(); gca!(::ASSOC)] = [(); gca!(T::RIGID)]; } fn main() {} diff --git a/tests/ui/const-generics/gca/basic-different-definitions.rs b/tests/ui/const-generics/gca/basic-different-definitions.rs index a80e50a6cb9e9..215b28c985113 100644 --- a/tests/ui/const-generics/gca/basic-different-definitions.rs +++ b/tests/ui/const-generics/gca/basic-different-definitions.rs @@ -6,10 +6,12 @@ #![feature(generic_const_args)] #![expect(incomplete_features)] +use std::gca; + const ADD1: usize = N + 1; const INC: usize = N + 1; -const ARR: [(); core::direct_const_arg!(ADD1::<0>)] = [(); core::direct_const_arg!(INC::<0>)]; +const ARR: [(); gca!(ADD1::<0>)] = [(); gca!(INC::<0>)]; fn main() {} diff --git a/tests/ui/const-generics/gca/basic.rs b/tests/ui/const-generics/gca/basic.rs index 55712a80f2195..c6158023a1be5 100644 --- a/tests/ui/const-generics/gca/basic.rs +++ b/tests/ui/const-generics/gca/basic.rs @@ -6,10 +6,12 @@ #![feature(generic_const_args)] #![expect(incomplete_features)] +use std::gca; + const ADD1: usize = N + 1; -const INC: usize = core::direct_const_arg!(ADD1::); +const INC: usize = gca!(ADD1::); -const ARR: [(); core::direct_const_arg!(ADD1::<0>)] = [(); core::direct_const_arg!(INC::<0>)]; +const ARR: [(); gca!(ADD1::<0>)] = [(); gca!(INC::<0>)]; fn main() {} diff --git a/tests/ui/const-generics/gca/coherence-ok.rs b/tests/ui/const-generics/gca/coherence-ok.rs index 5feebd2b2a6fb..4ea66eb8e290d 100644 --- a/tests/ui/const-generics/gca/coherence-ok.rs +++ b/tests/ui/const-generics/gca/coherence-ok.rs @@ -3,13 +3,15 @@ #![feature(generic_const_items, min_generic_const_args, generic_const_args)] #![expect(incomplete_features)] +use std::gca; + // computing different values with the same const item should be fine const ADD1: usize = N + 1; trait Trait {} -impl Trait for [(); core::direct_const_arg!(ADD1::<1>)] {} -impl Trait for [(); core::direct_const_arg!(ADD1::<2>)] {} +impl Trait for [(); gca!(ADD1::<1>)] {} +impl Trait for [(); gca!(ADD1::<2>)] {} fn main() {} diff --git a/tests/ui/const-generics/gca/gca-anon-const-rejected.rs b/tests/ui/const-generics/gca/gca-anon-const-rejected.rs index 72babbcfe0401..9cb0891127dd8 100644 --- a/tests/ui/const-generics/gca/gca-anon-const-rejected.rs +++ b/tests/ui/const-generics/gca/gca-anon-const-rejected.rs @@ -4,6 +4,8 @@ // `const FOO: usize = N + 1;` #![feature(generic_const_args, min_generic_const_args, generic_const_items)] -const FOO: usize = core::direct_const_arg!(const { N + 1 }); //~ ERROR generic parameters in const blocks are not allowed; use a named `const` item instead +use std::gca; + +const FOO: usize = gca!(const { N + 1 }); //~ ERROR generic parameters in const blocks are not allowed; use a named `const` item instead fn main() {} diff --git a/tests/ui/const-generics/gca/gca-anon-const-rejected.stderr b/tests/ui/const-generics/gca/gca-anon-const-rejected.stderr index 1b98cd734afd2..93d4c1ce76e39 100644 --- a/tests/ui/const-generics/gca/gca-anon-const-rejected.stderr +++ b/tests/ui/const-generics/gca/gca-anon-const-rejected.stderr @@ -1,8 +1,8 @@ error: generic parameters in const blocks are not allowed; use a named `const` item instead - --> $DIR/gca-anon-const-rejected.rs:7:68 + --> $DIR/gca-anon-const-rejected.rs:9:49 | -LL | const FOO: usize = core::direct_const_arg!(const { N + 1 }); - | ^ +LL | const FOO: usize = gca!(const { N + 1 }); + | ^ | = help: consider factoring the expression into a `type const` item and use it as the const argument instead diff --git a/tests/ui/const-generics/gca/direct-const-arg-fn-call.rs b/tests/ui/const-generics/gca/gca-macro-fn-call.rs similarity index 100% rename from tests/ui/const-generics/gca/direct-const-arg-fn-call.rs rename to tests/ui/const-generics/gca/gca-macro-fn-call.rs diff --git a/tests/ui/const-generics/gca/direct-const-arg-fn-call.stderr b/tests/ui/const-generics/gca/gca-macro-fn-call.stderr similarity index 81% rename from tests/ui/const-generics/gca/direct-const-arg-fn-call.stderr rename to tests/ui/const-generics/gca/gca-macro-fn-call.stderr index b73cc02dae915..1399bcb1dee92 100644 --- a/tests/ui/const-generics/gca/direct-const-arg-fn-call.stderr +++ b/tests/ui/const-generics/gca/gca-macro-fn-call.stderr @@ -1,29 +1,29 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/direct-const-arg-fn-call.rs:35:23 + --> $DIR/gca-macro-fn-call.rs:35:23 | LL | fn bad(_: FieldName<{ FieldName::len() }>) {} | ^^^^^^^^^^^^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/direct-const-arg-fn-call.rs:44:31 + --> $DIR/gca-macro-fn-call.rs:44:31 | LL | fn bad_tracing(_: FieldName<{ FieldName::len_of("id") }>) {} | ^^^^^^^^^^^^^^^^^^^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/direct-const-arg-fn-call.rs:61:23 + --> $DIR/gca-macro-fn-call.rs:61:23 | LL | fn bad_union(_: Tag<{ Tag::width() }>) {} | ^^^^^^^^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/direct-const-arg-fn-call.rs:70:28 + --> $DIR/gca-macro-fn-call.rs:70:28 | LL | fn bad_prim(_: FieldName<{ u32::from_str_radix("10", 10) }>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/direct-const-arg-fn-call.rs:81:31 + --> $DIR/gca-macro-fn-call.rs:81:31 | LL | fn bad_foreign(_: FieldName<{ Opaque::foo() }>) {} | ^^^^^^^^^^^^^ diff --git a/tests/ui/const-generics/gca/non-type-equality-fail.rs b/tests/ui/const-generics/gca/non-type-equality-fail.rs index e058648e3da54..1ea34829c6c6a 100644 --- a/tests/ui/const-generics/gca/non-type-equality-fail.rs +++ b/tests/ui/const-generics/gca/non-type-equality-fail.rs @@ -3,6 +3,8 @@ #![feature(min_generic_const_args, generic_const_args)] #![expect(incomplete_features)] +use std::gca; + trait Trait { const PROJECTED_A: usize; const PROJECTED_B: usize; @@ -27,14 +29,13 @@ const FREE_B: usize = 1; struct Struct; fn f() { - let _: Struct<{ core::direct_const_arg!( as Trait>::PROJECTED_A) }> = - Struct::<{ core::direct_const_arg!( as Trait>::PROJECTED_B) }>; + let _: Struct<{ gca!( as Trait>::PROJECTED_A) }> = + Struct::<{ gca!( as Trait>::PROJECTED_B) }>; //~^ ERROR mismatched types } fn g() { - let _: Struct<{ core::direct_const_arg!(T::PROJECTED_A) }> = - Struct::<{ core::direct_const_arg!(T::PROJECTED_B) }>; + let _: Struct<{ gca!(T::PROJECTED_A) }> = Struct::<{ gca!(T::PROJECTED_B) }>; //~^ ERROR mismatched types } diff --git a/tests/ui/const-generics/gca/non-type-equality-fail.stderr b/tests/ui/const-generics/gca/non-type-equality-fail.stderr index 28557d76d84e5..413ccf59a3290 100644 --- a/tests/ui/const-generics/gca/non-type-equality-fail.stderr +++ b/tests/ui/const-generics/gca/non-type-equality-fail.stderr @@ -1,21 +1,21 @@ error[E0308]: mismatched types - --> $DIR/non-type-equality-fail.rs:31:9 + --> $DIR/non-type-equality-fail.rs:33:9 | -LL | let _: Struct<{ core::direct_const_arg!( as Trait>::PROJECTED_A) }> = - | --------------------------------------------------------------------------------- expected due to this -LL | Struct::<{ core::direct_const_arg!( as Trait>::PROJECTED_B) }>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected ` as Trait>::PROJECTED_A`, found ` as Trait>::PROJECTED_B` +LL | let _: Struct<{ gca!( as Trait>::PROJECTED_A) }> = + | -------------------------------------------------------------- expected due to this +LL | Struct::<{ gca!( as Trait>::PROJECTED_B) }>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected ` as Trait>::PROJECTED_A`, found ` as Trait>::PROJECTED_B` | = note: expected struct `Struct< as Trait>::PROJECTED_A>` found struct `Struct< as Trait>::PROJECTED_B>` error[E0308]: mismatched types - --> $DIR/non-type-equality-fail.rs:37:9 + --> $DIR/non-type-equality-fail.rs:38:47 | -LL | let _: Struct<{ core::direct_const_arg!(T::PROJECTED_A) }> = - | --------------------------------------------------- expected due to this -LL | Struct::<{ core::direct_const_arg!(T::PROJECTED_B) }>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `::PROJECTED_A`, found `::PROJECTED_B` +LL | let _: Struct<{ gca!(T::PROJECTED_A) }> = Struct::<{ gca!(T::PROJECTED_B) }>; + | -------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `::PROJECTED_A`, found `::PROJECTED_B` + | | + | expected due to this | = note: expected struct `Struct<::PROJECTED_A>` found struct `Struct<::PROJECTED_B>` diff --git a/tests/ui/const-generics/gca/rhs-but-not-root.rs b/tests/ui/const-generics/gca/rhs-but-not-root.rs index 2c5f1e050a3fe..4f355c84e4875 100644 --- a/tests/ui/const-generics/gca/rhs-but-not-root.rs +++ b/tests/ui/const-generics/gca/rhs-but-not-root.rs @@ -4,9 +4,11 @@ #![feature(generic_const_args)] #![expect(incomplete_features)] +use std::gca; + // Anon consts must be the root of the RHS to be GCA. -const FOO: usize = core::direct_const_arg!(ID::); +const FOO: usize = gca!(ID::); //~^ ERROR generic parameters in const blocks are not allowed; use a named `const` item instead -const ID: usize = core::direct_const_arg!(N); +const ID: usize = gca!(N); fn main() {} diff --git a/tests/ui/const-generics/gca/rhs-but-not-root.stderr b/tests/ui/const-generics/gca/rhs-but-not-root.stderr index 6b2e5d61112d9..d34d7f6b51a74 100644 --- a/tests/ui/const-generics/gca/rhs-but-not-root.stderr +++ b/tests/ui/const-generics/gca/rhs-but-not-root.stderr @@ -1,8 +1,8 @@ error: generic parameters in const blocks are not allowed; use a named `const` item instead - --> $DIR/rhs-but-not-root.rs:8:73 + --> $DIR/rhs-but-not-root.rs:10:54 | -LL | const FOO: usize = core::direct_const_arg!(ID::); - | ^ +LL | const FOO: usize = gca!(ID::); + | ^ | = help: consider factoring the expression into a `type const` item and use it as the const argument instead diff --git a/tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.rs b/tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.rs index f6415412e0df4..85be63fd83b59 100644 --- a/tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.rs +++ b/tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.rs @@ -1,7 +1,7 @@ // Regression test for https://github.com/rust-lang/rust/issues/156729 // // When a generic parameter is used in a const operation, the diagnostic should -// suggest creating a `direct_const_arg!` item as an alternative to `generic_const_exprs`. +// suggest creating a `gca!` item as an alternative to `generic_const_exprs`. use std::mem::size_of; diff --git a/tests/ui/const-generics/gca/wf-inherentimpl.rs b/tests/ui/const-generics/gca/wf-inherentimpl.rs index c0a7e7f930877..8248c7b01832a 100644 --- a/tests/ui/const-generics/gca/wf-inherentimpl.rs +++ b/tests/ui/const-generics/gca/wf-inherentimpl.rs @@ -5,10 +5,11 @@ #![feature(inherent_associated_types)] #![feature(generic_const_args, min_generic_const_args)] //[old]~^ ERROR `generic_const_args` requires -Znext-solver=globally to be enabled +use std::gca; struct Foo; impl Foo { const SIZE: usize = { todo!() }; - fn to_bytes() -> [u8; core::direct_const_arg!(Self::SIZE)] { + fn to_bytes() -> [u8; gca!(Self::SIZE)] { todo!() } } diff --git a/tests/ui/const-generics/generic_const_exprs/auxiliary/non_local_type_const.rs b/tests/ui/const-generics/generic_const_exprs/auxiliary/non_local_type_const.rs index 689a981e5469b..b4401b182be4e 100644 --- a/tests/ui/const-generics/generic_const_exprs/auxiliary/non_local_type_const.rs +++ b/tests/ui/const-generics/generic_const_exprs/auxiliary/non_local_type_const.rs @@ -1,4 +1,6 @@ #![feature(min_generic_const_args)] #![allow(incomplete_features)] -pub const NON_LOCAL_CONST: char = core::direct_const_arg!('a'); +use std::gca; + +pub const NON_LOCAL_CONST: char = gca!('a'); diff --git a/tests/ui/const-generics/generic_const_parameter_types/inherent-type-const.rs b/tests/ui/const-generics/generic_const_parameter_types/inherent-type-const.rs index be91b0a5933bd..97edbef7df10d 100644 --- a/tests/ui/const-generics/generic_const_parameter_types/inherent-type-const.rs +++ b/tests/ui/const-generics/generic_const_parameter_types/inherent-type-const.rs @@ -10,15 +10,17 @@ const_param_ty_trait )] +use std::gca; + struct ThreeTypes(T1, T2, T3); impl ThreeTypes { - const INHERENT: [T3; 0] = core::direct_const_arg!([]); + const INHERENT: [T3; 0] = gca!([]); } struct Struct; -fn f() -> Struct<{ core::direct_const_arg!(ThreeTypes::::INHERENT) }> { +fn f() -> Struct<{ gca!(ThreeTypes::::INHERENT) }> { Struct } diff --git a/tests/ui/const-generics/mgca/adt_expr_arg_simple.rs b/tests/ui/const-generics/mgca/adt_expr_arg_simple.rs index 34fca58ff4e00..32714ca551fbc 100644 --- a/tests/ui/const-generics/mgca/adt_expr_arg_simple.rs +++ b/tests/ui/const-generics/mgca/adt_expr_arg_simple.rs @@ -1,6 +1,8 @@ #![feature(min_generic_const_args, macroless_generic_const_args, adt_const_params)] #![expect(incomplete_features)] +use std::gca; + #[derive(Eq, PartialEq, std::marker::ConstParamTy)] enum Option { Some(T), @@ -26,7 +28,7 @@ fn bar() { // this on the other hand is not allowed as `N + 1` is not a legal // const argument - foo::<{ core::direct_const_arg!(Some:: { 0: N + 1 }) }>(); + foo::<{ gca!(Some:: { 0: N + 1 }) }>(); //~^ ERROR: complex const arguments must be placed inside of a `const` block // this also is not allowed as generic parameters cannot be used diff --git a/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr b/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr index 7b1249773f0cb..0213c447b59ca 100644 --- a/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr +++ b/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr @@ -1,11 +1,11 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/adt_expr_arg_simple.rs:29:54 + --> $DIR/adt_expr_arg_simple.rs:31:35 | -LL | foo::<{ core::direct_const_arg!(Some:: { 0: N + 1 }) }>(); - | ^^^^^ +LL | foo::<{ gca!(Some:: { 0: N + 1 }) }>(); + | ^^^^^ error: generic parameters may not be used in const operations - --> $DIR/adt_expr_arg_simple.rs:34:38 + --> $DIR/adt_expr_arg_simple.rs:36:38 | LL | foo::<{ Some:: { 0: const { N + 1 } } }>(); | ^ diff --git a/tests/ui/const-generics/mgca/adt_expr_infers_from_value.rs b/tests/ui/const-generics/mgca/adt_expr_infers_from_value.rs index bcd6660dc3533..3db15a2aef49c 100644 --- a/tests/ui/const-generics/mgca/adt_expr_infers_from_value.rs +++ b/tests/ui/const-generics/mgca/adt_expr_infers_from_value.rs @@ -10,6 +10,7 @@ )] #![expect(incomplete_features)] +use std::gca; use std::marker::{ConstParamTy, ConstParamTy_, PhantomData}; #[derive(PartialEq, Eq, ConstParamTy)] @@ -17,7 +18,7 @@ struct Foo { field: T, } -const WRAP: Foo = core::direct_const_arg!(Foo:: { field: N }); +const WRAP: Foo = gca!(Foo:: { field: N }); fn main() { // What we're trying to accomplish here is winding up with an equality relation diff --git a/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.rs b/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.rs index f2c8a242dbcc0..78e9c0821fa88 100644 --- a/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.rs +++ b/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.rs @@ -6,6 +6,7 @@ #![feature(adt_const_params, min_generic_const_args, macroless_generic_const_args)] #![feature(unsized_const_params, generic_const_parameter_types)] +use std::gca; use std::marker::ConstParamTy_; fn foo() -> [T; N] { @@ -21,7 +22,7 @@ trait Trait { struct S; impl Trait for S { - const LEN: usize = core::direct_const_arg!(3); + const LEN: usize = gca!(3); } fn baz::LEN]>() {} diff --git a/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.stderr b/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.stderr index 82a9cfc86b5d7..72c2a367c7246 100644 --- a/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.stderr +++ b/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.stderr @@ -1,59 +1,59 @@ error: the constant `*b""` is not of type `[u8; 2]` - --> $DIR/array-const-arg-len-mismatch.rs:30:11 + --> $DIR/array-const-arg-len-mismatch.rs:31:11 | LL | foo::(); | ^^ expected `[u8; 2]`, found `[u8; 0]` | note: required by a const generic parameter in `foo` - --> $DIR/array-const-arg-len-mismatch.rs:11:42 + --> $DIR/array-const-arg-len-mismatch.rs:12:42 | LL | fn foo() -> [T; N] { | ^^^^^^^^^^^^^^^ required by this const generic parameter in `foo` error: the constant `*b"\x00\x00\x00"` is not of type `[u8; 2]` - --> $DIR/array-const-arg-len-mismatch.rs:32:11 + --> $DIR/array-const-arg-len-mismatch.rs:33:11 | LL | foo::(); | ^^ expected `[u8; 2]`, found `[u8; 3]` | note: required by a const generic parameter in `foo` - --> $DIR/array-const-arg-len-mismatch.rs:11:42 + --> $DIR/array-const-arg-len-mismatch.rs:12:42 | LL | fn foo() -> [T; N] { | ^^^^^^^^^^^^^^^ required by this const generic parameter in `foo` error: the constant `*b""` is not of type `[u8; 2]` - --> $DIR/array-const-arg-len-mismatch.rs:34:13 + --> $DIR/array-const-arg-len-mismatch.rs:35:13 | LL | bar::<{ [] }>(); | ^^ expected `[u8; 2]`, found `[u8; 0]` | note: required by a const generic parameter in `bar` - --> $DIR/array-const-arg-len-mismatch.rs:15:8 + --> $DIR/array-const-arg-len-mismatch.rs:16:8 | LL | fn bar() {} | ^^^^^^^^^^^^^^^^ required by this const generic parameter in `bar` error: the constant `*b"\x01\x02\x03"` is not of type `[u8; 2]` - --> $DIR/array-const-arg-len-mismatch.rs:36:13 + --> $DIR/array-const-arg-len-mismatch.rs:37:13 | LL | bar::<{ [1, 2, 3] }>(); | ^^^^^^^^^ expected `[u8; 2]`, found `[u8; 3]` | note: required by a const generic parameter in `bar` - --> $DIR/array-const-arg-len-mismatch.rs:15:8 + --> $DIR/array-const-arg-len-mismatch.rs:16:8 | LL | fn bar() {} | ^^^^^^^^^^^^^^^^ required by this const generic parameter in `bar` error: the constant `*b"*"` is not of type `[u8; 3]` - --> $DIR/array-const-arg-len-mismatch.rs:38:13 + --> $DIR/array-const-arg-len-mismatch.rs:39:13 | LL | baz::<{ [42] }>(); | ^^^^ expected `[u8; 3]`, found `[u8; 1]` | note: required by a const generic parameter in `baz` - --> $DIR/array-const-arg-len-mismatch.rs:27:8 + --> $DIR/array-const-arg-len-mismatch.rs:28:8 | LL | fn baz::LEN]>() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `baz` diff --git a/tests/ui/const-generics/mgca/array-expr-complex.r1.stderr b/tests/ui/const-generics/mgca/array-expr-complex.r1.stderr index a226d7ff0c225..2e3b2172b7325 100644 --- a/tests/ui/const-generics/mgca/array-expr-complex.r1.stderr +++ b/tests/ui/const-generics/mgca/array-expr-complex.r1.stderr @@ -1,8 +1,8 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/array-expr-complex.rs:11:52 + --> $DIR/array-expr-complex.rs:13:33 | -LL | takes_array::<{ core::direct_const_arg!([1, 2, 1 + 2]) }>(); - | ^^^^^ +LL | takes_array::<{ gca!([1, 2, 1 + 2]) }>(); + | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/array-expr-complex.r2.stderr b/tests/ui/const-generics/mgca/array-expr-complex.r2.stderr index cc1e70c1d9a7a..2b25efb6ab090 100644 --- a/tests/ui/const-generics/mgca/array-expr-complex.r2.stderr +++ b/tests/ui/const-generics/mgca/array-expr-complex.r2.stderr @@ -1,8 +1,8 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/array-expr-complex.rs:14:45 + --> $DIR/array-expr-complex.rs:16:26 | -LL | takes_array::<{ core::direct_const_arg!([X; 3]) }>(); - | ^^^^^^ +LL | takes_array::<{ gca!([X; 3]) }>(); + | ^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/array-expr-complex.r3.stderr b/tests/ui/const-generics/mgca/array-expr-complex.r3.stderr index cc52abe0e8fb8..09515bafa7025 100644 --- a/tests/ui/const-generics/mgca/array-expr-complex.r3.stderr +++ b/tests/ui/const-generics/mgca/array-expr-complex.r3.stderr @@ -1,8 +1,8 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/array-expr-complex.rs:17:45 + --> $DIR/array-expr-complex.rs:19:26 | -LL | takes_array::<{ core::direct_const_arg!([0; Y]) }>(); - | ^^^^^^ +LL | takes_array::<{ gca!([0; Y]) }>(); + | ^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/array-expr-complex.rs b/tests/ui/const-generics/mgca/array-expr-complex.rs index 7f5a77fdff3df..be3b85e2bd240 100644 --- a/tests/ui/const-generics/mgca/array-expr-complex.rs +++ b/tests/ui/const-generics/mgca/array-expr-complex.rs @@ -3,18 +3,20 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args, adt_const_params)] +use std::gca; + fn takes_array() {} fn generic_caller() { // not supported yet #[cfg(r1)] - takes_array::<{ core::direct_const_arg!([1, 2, 1 + 2]) }>(); + takes_array::<{ gca!([1, 2, 1 + 2]) }>(); //[r1]~^ ERROR: complex const arguments must be placed inside of a `const` block #[cfg(r2)] - takes_array::<{ core::direct_const_arg!([X; 3]) }>(); + takes_array::<{ gca!([X; 3]) }>(); //[r2]~^ ERROR: complex const arguments must be placed inside of a `const` block #[cfg(r3)] - takes_array::<{ core::direct_const_arg!([0; Y]) }>(); + takes_array::<{ gca!([0; Y]) }>(); //[r3]~^ ERROR: complex const arguments must be placed inside of a `const` block } diff --git a/tests/ui/const-generics/mgca/array_expr_arg_complex.rs b/tests/ui/const-generics/mgca/array_expr_arg_complex.rs index 3d62adae09ada..76534f12d80c8 100644 --- a/tests/ui/const-generics/mgca/array_expr_arg_complex.rs +++ b/tests/ui/const-generics/mgca/array_expr_arg_complex.rs @@ -1,6 +1,8 @@ #![feature(min_generic_const_args, adt_const_params, unsized_const_params)] #![expect(incomplete_features)] +use std::gca; + trait Trait { #[rustc_always_gca] const ASSOC: usize; @@ -10,8 +12,8 @@ fn takes_array() {} fn takes_tuple_with_array() {} fn generic_caller() { - takes_array::<{ core::direct_const_arg!([N, N + 1]) }>(); //~ ERROR complex const arguments must be placed inside of a `const` block - takes_tuple_with_array::<{ core::direct_const_arg!(([N, N + 1], N)) }>(); //~ ERROR complex const arguments must be placed inside of a `const` block + takes_array::<{ gca!([N, N + 1]) }>(); //~ ERROR complex const arguments must be placed inside of a `const` block + takes_tuple_with_array::<{ gca!(([N, N + 1], N)) }>(); //~ ERROR complex const arguments must be placed inside of a `const` block } fn main() {} diff --git a/tests/ui/const-generics/mgca/array_expr_arg_complex.stderr b/tests/ui/const-generics/mgca/array_expr_arg_complex.stderr index c7db1e4753f8c..b044775b80c94 100644 --- a/tests/ui/const-generics/mgca/array_expr_arg_complex.stderr +++ b/tests/ui/const-generics/mgca/array_expr_arg_complex.stderr @@ -1,14 +1,14 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/array_expr_arg_complex.rs:13:49 + --> $DIR/array_expr_arg_complex.rs:15:30 | -LL | takes_array::<{ core::direct_const_arg!([N, N + 1]) }>(); - | ^^^^^ +LL | takes_array::<{ gca!([N, N + 1]) }>(); + | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/array_expr_arg_complex.rs:14:61 + --> $DIR/array_expr_arg_complex.rs:16:42 | -LL | takes_tuple_with_array::<{ core::direct_const_arg!(([N, N + 1], N)) }>(); - | ^^^^^ +LL | takes_tuple_with_array::<{ gca!(([N, N + 1], N)) }>(); + | ^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/assoc-const-projection-in-bound.rs b/tests/ui/const-generics/mgca/assoc-const-projection-in-bound.rs index 1b4c5b60edb72..9601cbc997f45 100644 --- a/tests/ui/const-generics/mgca/assoc-const-projection-in-bound.rs +++ b/tests/ui/const-generics/mgca/assoc-const-projection-in-bound.rs @@ -4,6 +4,8 @@ #![feature(min_generic_const_args, macroless_generic_const_args)] #![allow(dead_code)] +use std::gca; + trait Abc {} trait A { @@ -12,7 +14,7 @@ trait A { } impl A for T { - const VALUE: usize = core::direct_const_arg!(0); + const VALUE: usize = gca!(0); } trait S {} diff --git a/tests/ui/const-generics/mgca/bad-const-arg-fn-154539.rs b/tests/ui/const-generics/mgca/bad-const-arg-fn-154539.rs index e3d1f577d4f60..a4ad2cccaa544 100644 --- a/tests/ui/const-generics/mgca/bad-const-arg-fn-154539.rs +++ b/tests/ui/const-generics/mgca/bad-const-arg-fn-154539.rs @@ -1,8 +1,10 @@ #![feature(min_generic_const_args)] +use std::gca; + trait Iter< const FN: fn() = { - core::direct_const_arg!(|| { + gca!(|| { //~^ ERROR complex const arguments must be placed inside of a `const` block use std::io::*; write!(_, "") diff --git a/tests/ui/const-generics/mgca/bad-const-arg-fn-154539.stderr b/tests/ui/const-generics/mgca/bad-const-arg-fn-154539.stderr index 96fcea9e906cf..49796692d9dcc 100644 --- a/tests/ui/const-generics/mgca/bad-const-arg-fn-154539.stderr +++ b/tests/ui/const-generics/mgca/bad-const-arg-fn-154539.stderr @@ -1,8 +1,8 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/bad-const-arg-fn-154539.rs:5:33 + --> $DIR/bad-const-arg-fn-154539.rs:7:14 | -LL | core::direct_const_arg!(|| { - | _________________________________^ +LL | gca!(|| { + | ______________^ LL | | LL | | use std::io::*; LL | | write!(_, "") diff --git a/tests/ui/const-generics/mgca/bad-direct-const-arg.rs b/tests/ui/const-generics/mgca/bad-direct-const-arg.rs deleted file mode 100644 index 59fdccf29b7b5..0000000000000 --- a/tests/ui/const-generics/mgca/bad-direct-const-arg.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ edition: 2024 - -//! Reject direct const arguments in value/type positions without unrelated brace suggestions. -#![feature(min_generic_const_args)] -#![deny(unused_braces)] - -fn main(x: core::direct_const_arg!(2)) { - //~^ ERROR expected type, found `direct_const_arg!()` constant - let _ = core::direct_const_arg!(2); - //~^ ERROR expected expression, found `direct_const_arg!()` constant - consume({ core::direct_const_arg!(2) }); - //~^ ERROR expected expression, found `direct_const_arg!()` constant -} - -fn consume(_: usize) {} diff --git a/tests/ui/const-generics/mgca/bad-direct-const-arg.stderr b/tests/ui/const-generics/mgca/bad-direct-const-arg.stderr deleted file mode 100644 index d54a2c4400ea7..0000000000000 --- a/tests/ui/const-generics/mgca/bad-direct-const-arg.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: expected expression, found `direct_const_arg!()` constant - --> $DIR/bad-direct-const-arg.rs:9:13 - | -LL | let _ = core::direct_const_arg!(2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: expected expression, found `direct_const_arg!()` constant - --> $DIR/bad-direct-const-arg.rs:11:15 - | -LL | consume({ core::direct_const_arg!(2) }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: expected type, found `direct_const_arg!()` constant - --> $DIR/bad-direct-const-arg.rs:7:12 - | -LL | fn main(x: core::direct_const_arg!(2)) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/tests/ui/const-generics/mgca/bad-gca-macro.rs b/tests/ui/const-generics/mgca/bad-gca-macro.rs new file mode 100644 index 0000000000000..50f2ebe65e818 --- /dev/null +++ b/tests/ui/const-generics/mgca/bad-gca-macro.rs @@ -0,0 +1,17 @@ +//@ edition: 2024 + +//! Reject direct const arguments in value/type positions without unrelated brace suggestions. +#![feature(min_generic_const_args)] +#![deny(unused_braces)] + +use std::gca; + +fn main(x: gca!(2)) { + //~^ ERROR expected type, found `gca!()` constant + let _ = gca!(2); + //~^ ERROR expected expression, found `gca!()` constant + consume({ gca!(2) }); + //~^ ERROR expected expression, found `gca!()` constant +} + +fn consume(_: usize) {} diff --git a/tests/ui/const-generics/mgca/bad-gca-macro.stderr b/tests/ui/const-generics/mgca/bad-gca-macro.stderr new file mode 100644 index 0000000000000..e22bfc76d43c7 --- /dev/null +++ b/tests/ui/const-generics/mgca/bad-gca-macro.stderr @@ -0,0 +1,20 @@ +error: expected expression, found `gca!()` constant + --> $DIR/bad-gca-macro.rs:11:13 + | +LL | let _ = gca!(2); + | ^^^^^^^ + +error: expected expression, found `gca!()` constant + --> $DIR/bad-gca-macro.rs:13:15 + | +LL | consume({ gca!(2) }); + | ^^^^^^^ + +error: expected type, found `gca!()` constant + --> $DIR/bad-gca-macro.rs:9:12 + | +LL | fn main(x: gca!(2)) { + | ^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/tests/ui/const-generics/mgca/bad-type_const-syntax.rs b/tests/ui/const-generics/mgca/bad-type_const-syntax.rs index 9ffc2b70eecaf..c0391d54e423d 100644 --- a/tests/ui/const-generics/mgca/bad-type_const-syntax.rs +++ b/tests/ui/const-generics/mgca/bad-type_const-syntax.rs @@ -2,15 +2,22 @@ trait Tr { #[rustc_always_gca] //~^ ERROR: the `rustc_always_gca` attribute is an experimental feature [E0658] const N: usize; + #[rustc_always_gca] + //~^ ERROR: the `rustc_always_gca` attribute is an experimental feature [E0658] + const M: usize; } struct S; impl Tr for S { - const N: usize = core::direct_const_arg!(0); + const N: usize = core::gca!(0); + //~^ ERROR: use of unstable library feature `min_generic_const_args` [E0658] + //~| ERROR: implementation of a `#[rustc_always_gca]` must have a `gca!` RHS + //~| ERROR: expected expression, found `gca!()` constant + const M: usize = std::gca!(0); //~^ ERROR: use of unstable library feature `min_generic_const_args` [E0658] - //~| ERROR: implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS - //~| ERROR: expected expression, found `direct_const_arg!()` constant + //~| ERROR: implementation of a `#[rustc_always_gca]` must have a `gca!` RHS + //~| ERROR: expected expression, found `gca!()` constant } fn main() {} diff --git a/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr b/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr index 31be797b12590..0e8c2f4971a41 100644 --- a/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr +++ b/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr @@ -1,8 +1,18 @@ error[E0658]: use of unstable library feature `min_generic_const_args` - --> $DIR/bad-type_const-syntax.rs:10:22 + --> $DIR/bad-type_const-syntax.rs:13:22 | -LL | const N: usize = core::direct_const_arg!(0); - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | const N: usize = core::gca!(0); + | ^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: use of unstable library feature `min_generic_const_args` + --> $DIR/bad-type_const-syntax.rs:17:22 + | +LL | const M: usize = std::gca!(0); + | ^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable @@ -18,16 +28,32 @@ LL | #[rustc_always_gca] = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: expected expression, found `direct_const_arg!()` constant - --> $DIR/bad-type_const-syntax.rs:10:22 +error[E0658]: the `rustc_always_gca` attribute is an experimental feature + --> $DIR/bad-type_const-syntax.rs:5:7 + | +LL | #[rustc_always_gca] + | ^^^^^^^^^^^^^^^^ | -LL | const N: usize = core::direct_const_arg!(0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: expected expression, found `gca!()` constant + --> $DIR/bad-type_const-syntax.rs:13:22 + | +LL | const N: usize = core::gca!(0); + | ^^^^^^^^^^^^^ -error: implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS - --> $DIR/bad-type_const-syntax.rs:10:5 +error: expected expression, found `gca!()` constant + --> $DIR/bad-type_const-syntax.rs:17:22 | -LL | const N: usize = core::direct_const_arg!(0); +LL | const M: usize = std::gca!(0); + | ^^^^^^^^^^^^ + +error: implementation of a `#[rustc_always_gca]` must have a `gca!` RHS + --> $DIR/bad-type_const-syntax.rs:13:5 + | +LL | const N: usize = core::gca!(0); | ^^^^^^^^^^^^^^ | note: trait declaration of const is marked as `#[rustc_always_gca]` @@ -36,6 +62,18 @@ note: trait declaration of const is marked as `#[rustc_always_gca]` LL | const N: usize; | ^^^^^^^^^^^^^^ -error: aborting due to 4 previous errors +error: implementation of a `#[rustc_always_gca]` must have a `gca!` RHS + --> $DIR/bad-type_const-syntax.rs:17:5 + | +LL | const M: usize = std::gca!(0); + | ^^^^^^^^^^^^^^ + | +note: trait declaration of const is marked as `#[rustc_always_gca]` + --> $DIR/bad-type_const-syntax.rs:7:5 + | +LL | const M: usize; + | ^^^^^^^^^^^^^^ + +error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/const-generics/mgca/braced-const-infer-in-body.rs b/tests/ui/const-generics/mgca/braced-const-infer-in-body.rs index a696ff5964e7f..38851a6e5130f 100644 --- a/tests/ui/const-generics/mgca/braced-const-infer-in-body.rs +++ b/tests/ui/const-generics/mgca/braced-const-infer-in-body.rs @@ -3,6 +3,8 @@ #![feature(min_generic_const_args)] #![feature(macroless_generic_const_args)] +use std::gca; + trait Trait {} impl Trait for i32 {} @@ -13,11 +15,11 @@ fn main() { // Const-only infer args used for a type parameter are rejected. let _z: &[&dyn Trait<{ _ }>] = &[&0i32]; //~^ ERROR: constant provided when a type was expected - let _y: &dyn Trait = &0i32; + let _y: &dyn Trait = &0i32; //~^ ERROR: constant provided when a type was expected let _a: S<{ _ }> = S::<3>; - let _b: S = S::<3>; - let _c: S<{ core::direct_const_arg!(_) }> = S::<3>; + let _b: S = S::<3>; + let _c: S<{ gca!(_) }> = S::<3>; let _d: S<_> = S::<3>; } diff --git a/tests/ui/const-generics/mgca/braced-const-infer-in-body.stderr b/tests/ui/const-generics/mgca/braced-const-infer-in-body.stderr index dec966c111253..2a7960c57b1e9 100644 --- a/tests/ui/const-generics/mgca/braced-const-infer-in-body.stderr +++ b/tests/ui/const-generics/mgca/braced-const-infer-in-body.stderr @@ -1,14 +1,14 @@ error[E0747]: constant provided when a type was expected - --> $DIR/braced-const-infer-in-body.rs:14:28 + --> $DIR/braced-const-infer-in-body.rs:16:28 | LL | let _z: &[&dyn Trait<{ _ }>] = &[&0i32]; | ^ error[E0747]: constant provided when a type was expected - --> $DIR/braced-const-infer-in-body.rs:16:48 + --> $DIR/braced-const-infer-in-body.rs:18:29 | -LL | let _y: &dyn Trait = &0i32; - | ^ +LL | let _y: &dyn Trait = &0i32; + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/concrete-expr-with-generics-in-env.rs b/tests/ui/const-generics/mgca/concrete-expr-with-generics-in-env.rs index b365de395e80d..9f6a62aa60e17 100644 --- a/tests/ui/const-generics/mgca/concrete-expr-with-generics-in-env.rs +++ b/tests/ui/const-generics/mgca/concrete-expr-with-generics-in-env.rs @@ -3,8 +3,7 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args, generic_const_items)] -extern crate core; -use core::direct_const_arg; +use std::gca; pub trait Tr { #[rustc_always_gca] @@ -18,9 +17,9 @@ pub trait Tr { pub struct S; impl Tr for S { - const N1: usize = core::direct_const_arg!(0); - const N2: usize = core::direct_const_arg!(1); - const N3: usize = core::direct_const_arg!(2); + const N1: usize = gca!(0); + const N2: usize = gca!(1); + const N3: usize = gca!(2); } fn main() {} diff --git a/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.rs b/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.rs index c89c6a14a367a..e19b71153b1e5 100644 --- a/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.rs +++ b/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.rs @@ -3,7 +3,9 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -const C: usize = core::direct_const_arg!(0); +use std::gca; + +const C: usize = gca!(0); pub struct A {} impl A { fn fun1() {} diff --git a/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.stderr b/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.stderr index 3d74d1db206e1..c82f8a96167ba 100644 --- a/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.stderr +++ b/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.stderr @@ -1,11 +1,11 @@ error[E0107]: missing generics for struct `A` - --> $DIR/const-arg-coherence-conflicting-methods.rs:12:6 + --> $DIR/const-arg-coherence-conflicting-methods.rs:14:6 | LL | impl A { | ^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `M` - --> $DIR/const-arg-coherence-conflicting-methods.rs:7:12 + --> $DIR/const-arg-coherence-conflicting-methods.rs:9:12 | LL | pub struct A {} | ^ -------------- @@ -15,7 +15,7 @@ LL | impl A { | +++ error[E0592]: duplicate definitions with name `fun1` - --> $DIR/const-arg-coherence-conflicting-methods.rs:9:5 + --> $DIR/const-arg-coherence-conflicting-methods.rs:11:5 | LL | fn fun1() {} | ^^^^^^^^^ duplicate definitions for `fun1` diff --git a/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.rs b/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.rs index df2dd048e6a43..c4e941edbb4de 100644 --- a/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.rs +++ b/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.rs @@ -1,7 +1,9 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] -const CONST: usize = core::direct_const_arg!(1_i32); +use std::gca; + +const CONST: usize = gca!(1_i32); //~^ ERROR the constant `1` is not of type `usize` //~| NOTE expected `usize`, found `i32` diff --git a/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.stderr b/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.stderr index 49f9f76d6cb1b..3f009d17be58a 100644 --- a/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.stderr +++ b/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.stderr @@ -1,7 +1,7 @@ error: the constant `1` is not of type `usize` - --> $DIR/const-arg-mismatched-literal-suffix.rs:4:1 + --> $DIR/const-arg-mismatched-literal-suffix.rs:6:1 | -LL | const CONST: usize = core::direct_const_arg!(1_i32); +LL | const CONST: usize = gca!(1_i32); | ^^^^^^^^^^^^^^^^^^ expected `usize`, found `i32` error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs b/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs index 89320472a3913..7c0a6c9f7771b 100644 --- a/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs +++ b/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs @@ -4,7 +4,9 @@ #![feature(generic_const_exprs)] #![expect(incomplete_features)] -const A: u8 = core::direct_const_arg!(A); +use std::gca; + +const A: u8 = gca!(A); //~^ ERROR cycle detected when computing the type-level value for `A` fn main() {} diff --git a/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr b/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr index ac37da026f95f..934057da24139 100644 --- a/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr +++ b/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr @@ -1,7 +1,7 @@ error[E0391]: cycle detected when computing the type-level value for `A` - --> $DIR/cyclic-type-const-151251.rs:7:1 + --> $DIR/cyclic-type-const-151251.rs:9:1 | -LL | const A: u8 = core::direct_const_arg!(A); +LL | const A: u8 = gca!(A); | ^^^^^^^^^^^ | = note: ...which immediately requires computing the type-level value for `A` again diff --git a/tests/ui/const-generics/mgca/direct-const-arg-correct-rib.stderr b/tests/ui/const-generics/mgca/direct-const-arg-correct-rib.stderr deleted file mode 100644 index 76f189e38e4d5..0000000000000 --- a/tests/ui/const-generics/mgca/direct-const-arg-correct-rib.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: attempt to use a non-constant value in a constant - --> $DIR/direct-const-arg-correct-rib.rs:8:42 - | -LL | let _: V; - | ^^^^ help: try using `Self` - -error: aborting due to 1 previous error - diff --git a/tests/ui/const-generics/mgca/direct-const-arg-multiple-exprs.rs b/tests/ui/const-generics/mgca/direct-const-arg-multiple-exprs.rs deleted file mode 100644 index 8c802e563db7c..0000000000000 --- a/tests/ui/const-generics/mgca/direct-const-arg-multiple-exprs.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![feature(min_generic_const_args)] -struct S; -fn foo(_: S) {} -//~^ ERROR direct_const_arg! takes 1 argument -fn main() {} diff --git a/tests/ui/const-generics/mgca/direct-const-arg-multiple-exprs.stderr b/tests/ui/const-generics/mgca/direct-const-arg-multiple-exprs.stderr deleted file mode 100644 index 6f54a563ffbfc..0000000000000 --- a/tests/ui/const-generics/mgca/direct-const-arg-multiple-exprs.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: direct_const_arg! takes 1 argument - --> $DIR/direct-const-arg-multiple-exprs.rs:3:45 - | -LL | fn foo(_: S) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/const-generics/mgca/direct_const_arg-infer-as-type.rs b/tests/ui/const-generics/mgca/direct_const_arg-infer-as-type.rs deleted file mode 100644 index 9e2c744c617c5..0000000000000 --- a/tests/ui/const-generics/mgca/direct_const_arg-infer-as-type.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! `direct_const_arg!(_)` used to be allowed to infer to a type as a compiler -//! implementation quirk. Since it uses explicit const argument syntax, -//! it is now rejected when passed as a type argument -#![feature(min_generic_const_args)] - -struct S(T); - -fn main() { - let _: S = S(2u32); - //~^ ERROR: constant provided when a type was expected - let _: S<{ core::direct_const_arg!(_) }> = S(2u32); - //~^ ERROR: constant provided when a type was expected -} diff --git a/tests/ui/const-generics/mgca/direct_const_arg-infer-as-type.stderr b/tests/ui/const-generics/mgca/direct_const_arg-infer-as-type.stderr deleted file mode 100644 index 07e0faf0ba792..0000000000000 --- a/tests/ui/const-generics/mgca/direct_const_arg-infer-as-type.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0747]: constant provided when a type was expected - --> $DIR/direct_const_arg-infer-as-type.rs:9:38 - | -LL | let _: S = S(2u32); - | ^ - -error[E0747]: constant provided when a type was expected - --> $DIR/direct_const_arg-infer-as-type.rs:11:40 - | -LL | let _: S<{ core::direct_const_arg!(_) }> = S(2u32); - | ^ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0747`. diff --git a/tests/ui/const-generics/mgca/explicit_anon_consts.rs b/tests/ui/const-generics/mgca/explicit_anon_consts.rs index 2fc1a0ea4b8ed..3c7c1da90ed39 100644 --- a/tests/ui/const-generics/mgca/explicit_anon_consts.rs +++ b/tests/ui/const-generics/mgca/explicit_anon_consts.rs @@ -4,13 +4,15 @@ // DefIds which were created for const args. #![crate_type = "lib"] +use std::gca; + struct Foo; type Adt1 = Foo; type Adt2 = Foo<{ N }>; type Adt3 = Foo; //~^ ERROR: generic parameters may not be used in const operations -type Adt4 = Foo; +type Adt4 = Foo; //~^ ERROR: complex const arguments must be placed inside of a `const` block type Adt5 = Foo; @@ -18,7 +20,7 @@ type Arr = [(); N]; type Arr2 = [(); { N }]; type Arr3 = [(); const { N }]; //~^ ERROR: generic parameters may not be used in const operations -type Arr4 = [(); core::direct_const_arg!(1 + 1)]; +type Arr4 = [(); gca!(1 + 1)]; //~^ ERROR: complex const arguments must be placed inside of a `const` block type Arr5 = [(); const { 1 + 1 }]; @@ -27,24 +29,24 @@ fn repeats() -> [(); N] { let _2 = [(); { N }]; let _3 = [(); const { N }]; //~^ ERROR: generic parameters may not be used in const operations - let _4 = [(); core::direct_const_arg!(1 + 1)]; + let _4 = [(); gca!(1 + 1)]; //~^ ERROR: complex const arguments must be placed inside of a `const` block let _5 = [(); const { 1 + 1 }]; let _6: [(); const { N }] = todo!(); //~^ ERROR: generic parameters may not be used in const operations } -const ITEM1: usize = core::direct_const_arg!(N); +const ITEM1: usize = gca!(N); -const ITEM2: usize = core::direct_const_arg!({ N }); +const ITEM2: usize = gca!({ N }); -const ITEM3: usize = core::direct_const_arg!(const { N }); +const ITEM3: usize = gca!(const { N }); //~^ ERROR: generic parameters may not be used in const operations -const ITEM4: usize = core::direct_const_arg!(1 + 1); +const ITEM4: usize = gca!(1 + 1); //~^ ERROR: complex const arguments must be placed inside of a `const` block -const ITEM5: usize = core::direct_const_arg!(const { 1 + 1 }); +const ITEM5: usize = gca!(const { 1 + 1 }); trait Trait { #[rustc_always_gca] @@ -58,7 +60,7 @@ fn ace_bounds< T2: Trait, T3: Trait, //~^ ERROR: generic parameters may not be used in const operations - T4: Trait, + T4: Trait, //~^ ERROR: complex const arguments must be placed inside of a `const` block T5: Trait, >() { @@ -68,6 +70,6 @@ struct Default1; struct Default2; struct Default3; //~^ ERROR: generic parameters may not be used in const operations -struct Default4; +struct Default4; //~^ ERROR: complex const arguments must be placed inside of a `const` block struct Default5; diff --git a/tests/ui/const-generics/mgca/explicit_anon_consts.stderr b/tests/ui/const-generics/mgca/explicit_anon_consts.stderr index aa479bce84a7e..ad533df5138f5 100644 --- a/tests/ui/const-generics/mgca/explicit_anon_consts.stderr +++ b/tests/ui/const-generics/mgca/explicit_anon_consts.stderr @@ -1,49 +1,49 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/explicit_anon_consts.rs:13:57 + --> $DIR/explicit_anon_consts.rs:15:38 | -LL | type Adt4 = Foo; - | ^^^^^ +LL | type Adt4 = Foo; + | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/explicit_anon_consts.rs:21:58 + --> $DIR/explicit_anon_consts.rs:23:39 | -LL | type Arr4 = [(); core::direct_const_arg!(1 + 1)]; - | ^^^^^ +LL | type Arr4 = [(); gca!(1 + 1)]; + | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/explicit_anon_consts.rs:30:43 + --> $DIR/explicit_anon_consts.rs:32:24 | -LL | let _4 = [(); core::direct_const_arg!(1 + 1)]; - | ^^^^^ +LL | let _4 = [(); gca!(1 + 1)]; + | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/explicit_anon_consts.rs:44:62 + --> $DIR/explicit_anon_consts.rs:46:43 | -LL | const ITEM4: usize = core::direct_const_arg!(1 + 1); - | ^^^^^ +LL | const ITEM4: usize = gca!(1 + 1); + | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/explicit_anon_consts.rs:61:49 + --> $DIR/explicit_anon_consts.rs:63:30 | -LL | T4: Trait, - | ^^^^^ +LL | T4: Trait, + | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/explicit_anon_consts.rs:71:76 + --> $DIR/explicit_anon_consts.rs:73:57 | -LL | struct Default4; - | ^^^^^ +LL | struct Default4; + | ^^^^^ error: generic parameters may not be used in const operations - --> $DIR/explicit_anon_consts.rs:41:70 + --> $DIR/explicit_anon_consts.rs:43:51 | -LL | const ITEM3: usize = core::direct_const_arg!(const { N }); - | ^ +LL | const ITEM3: usize = gca!(const { N }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/explicit_anon_consts.rs:59:31 + --> $DIR/explicit_anon_consts.rs:61:31 | LL | T3: Trait, | ^ @@ -51,7 +51,7 @@ LL | T3: Trait, = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/explicit_anon_consts.rs:69:58 + --> $DIR/explicit_anon_consts.rs:71:58 | LL | struct Default3; | ^ @@ -59,7 +59,7 @@ LL | struct Default3; = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/explicit_anon_consts.rs:28:27 + --> $DIR/explicit_anon_consts.rs:30:27 | LL | let _3 = [(); const { N }]; | ^ @@ -67,7 +67,7 @@ LL | let _3 = [(); const { N }]; = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/explicit_anon_consts.rs:33:26 + --> $DIR/explicit_anon_consts.rs:35:26 | LL | let _6: [(); const { N }] = todo!(); | ^ @@ -75,7 +75,7 @@ LL | let _6: [(); const { N }] = todo!(); = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/explicit_anon_consts.rs:11:41 + --> $DIR/explicit_anon_consts.rs:13:41 | LL | type Adt3 = Foo; | ^ @@ -83,7 +83,7 @@ LL | type Adt3 = Foo; = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/explicit_anon_consts.rs:19:42 + --> $DIR/explicit_anon_consts.rs:21:42 | LL | type Arr3 = [(); const { N }]; | ^ diff --git a/tests/ui/const-generics/mgca/free-const-recursive.gca.stderr b/tests/ui/const-generics/mgca/free-const-recursive.gca.stderr index fdbfeae464f8d..7bdab2d09acda 100644 --- a/tests/ui/const-generics/mgca/free-const-recursive.gca.stderr +++ b/tests/ui/const-generics/mgca/free-const-recursive.gca.stderr @@ -1,13 +1,13 @@ error[E0275]: overflow evaluating the requirement `A == _` - --> $DIR/free-const-recursive.rs:11:1 + --> $DIR/free-const-recursive.rs:13:1 | -LL | const A: () = core::direct_const_arg!(A); +LL | const A: () = gca!(A); | ^^^^^^^^^^^ error[E0275]: overflow evaluating the requirement `the constant `A` has type `()`` - --> $DIR/free-const-recursive.rs:11:1 + --> $DIR/free-const-recursive.rs:13:1 | -LL | const A: () = core::direct_const_arg!(A); +LL | const A: () = gca!(A); | ^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/free-const-recursive.min_gca.stderr b/tests/ui/const-generics/mgca/free-const-recursive.min_gca.stderr index 5f588a00055b6..3dcce0ad7eea6 100644 --- a/tests/ui/const-generics/mgca/free-const-recursive.min_gca.stderr +++ b/tests/ui/const-generics/mgca/free-const-recursive.min_gca.stderr @@ -1,7 +1,7 @@ error[E0391]: cycle detected when computing the type-level value for `A` - --> $DIR/free-const-recursive.rs:11:1 + --> $DIR/free-const-recursive.rs:13:1 | -LL | const A: () = core::direct_const_arg!(A); +LL | const A: () = gca!(A); | ^^^^^^^^^^^ | = note: ...which immediately requires computing the type-level value for `A` again diff --git a/tests/ui/const-generics/mgca/free-const-recursive.rs b/tests/ui/const-generics/mgca/free-const-recursive.rs index 6d4d78b46dccc..3fdeb37aa5d5d 100644 --- a/tests/ui/const-generics/mgca/free-const-recursive.rs +++ b/tests/ui/const-generics/mgca/free-const-recursive.rs @@ -8,7 +8,9 @@ #![expect(incomplete_features)] #![cfg_attr(gca, feature(generic_const_args))] -const A: () = core::direct_const_arg!(A); +use std::gca; + +const A: () = gca!(A); //[gca]~^ ERROR: overflow evaluating the requirement `A == _` //[gca]~| ERROR: overflow evaluating the requirement `the constant `A` has type `()`` //[min_gca]~^^^ ERROR: cycle detected when computing the type-level value for `A` diff --git a/tests/ui/const-generics/mgca/direct-const-arg-correct-rib.rs b/tests/ui/const-generics/mgca/gca-macro-correct-rib.rs similarity index 57% rename from tests/ui/const-generics/mgca/direct-const-arg-correct-rib.rs rename to tests/ui/const-generics/mgca/gca-macro-correct-rib.rs index 9f088a05b98f9..b03bbb7faacc3 100644 --- a/tests/ui/const-generics/mgca/direct-const-arg-correct-rib.rs +++ b/tests/ui/const-generics/mgca/gca-macro-correct-rib.rs @@ -1,11 +1,13 @@ -//! make sure TyKind::DirectConstArg resolves properly with the correct ribs and doesn't ICE +//! make sure TyKind::GcaMacro resolves properly with the correct ribs and doesn't ICE #![feature(min_generic_const_args)] +use std::gca; + struct S; struct V; impl S { fn f(self) { - let _: V; + let _: V; //~^ ERROR attempt to use a non-constant value in a constant } } diff --git a/tests/ui/const-generics/mgca/gca-macro-correct-rib.stderr b/tests/ui/const-generics/mgca/gca-macro-correct-rib.stderr new file mode 100644 index 0000000000000..baf864f60f8f0 --- /dev/null +++ b/tests/ui/const-generics/mgca/gca-macro-correct-rib.stderr @@ -0,0 +1,8 @@ +error: attempt to use a non-constant value in a constant + --> $DIR/gca-macro-correct-rib.rs:10:23 + | +LL | let _: V; + | ^^^^ help: try using `Self` + +error: aborting due to 1 previous error + diff --git a/tests/ui/const-generics/mgca/direct-const-arg-feature-gate.rs b/tests/ui/const-generics/mgca/gca-macro-feature-gate.rs similarity index 52% rename from tests/ui/const-generics/mgca/direct-const-arg-feature-gate.rs rename to tests/ui/const-generics/mgca/gca-macro-feature-gate.rs index 16ba349a29be6..1f4d302110490 100644 --- a/tests/ui/const-generics/mgca/direct-const-arg-feature-gate.rs +++ b/tests/ui/const-generics/mgca/gca-macro-feature-gate.rs @@ -1,5 +1,5 @@ -fn foo(_: [(); core::direct_const_arg!(N)]) {} +fn foo(_: [(); std::gca!(N)]) {} //~^ ERROR use of unstable library feature `min_generic_const_args` -//~| ERROR expected expression, found `direct_const_arg!()` constant +//~| ERROR expected expression, found `gca!()` constant //~| ERROR generic parameters may not be used in const operations fn main() {} diff --git a/tests/ui/const-generics/mgca/direct-const-arg-feature-gate.stderr b/tests/ui/const-generics/mgca/gca-macro-feature-gate.stderr similarity index 56% rename from tests/ui/const-generics/mgca/direct-const-arg-feature-gate.stderr rename to tests/ui/const-generics/mgca/gca-macro-feature-gate.stderr index a2927d0625b55..70586b9b288b4 100644 --- a/tests/ui/const-generics/mgca/direct-const-arg-feature-gate.stderr +++ b/tests/ui/const-generics/mgca/gca-macro-feature-gate.stderr @@ -1,28 +1,28 @@ error[E0658]: use of unstable library feature `min_generic_const_args` - --> $DIR/direct-const-arg-feature-gate.rs:1:32 + --> $DIR/gca-macro-feature-gate.rs:1:32 | -LL | fn foo(_: [(); core::direct_const_arg!(N)]) {} - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | fn foo(_: [(); std::gca!(N)]) {} + | ^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: generic parameters may not be used in const operations - --> $DIR/direct-const-arg-feature-gate.rs:1:56 + --> $DIR/gca-macro-feature-gate.rs:1:42 | -LL | fn foo(_: [(); core::direct_const_arg!(N)]) {} - | ^ cannot perform const operation using `N` +LL | fn foo(_: [(); std::gca!(N)]) {} + | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments here, i.e. `N` = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item -error: expected expression, found `direct_const_arg!()` constant - --> $DIR/direct-const-arg-feature-gate.rs:1:32 +error: expected expression, found `gca!()` constant + --> $DIR/gca-macro-feature-gate.rs:1:32 | -LL | fn foo(_: [(); core::direct_const_arg!(N)]) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn foo(_: [(); std::gca!(N)]) {} + | ^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/mgca/gca-macro-infer-as-type.rs b/tests/ui/const-generics/mgca/gca-macro-infer-as-type.rs new file mode 100644 index 0000000000000..155626ad9d47f --- /dev/null +++ b/tests/ui/const-generics/mgca/gca-macro-infer-as-type.rs @@ -0,0 +1,14 @@ +//! `gca!(_)` used to be allowed to infer to a type as a compiler implementation quirk. Since it +//! uses explicit const argument syntax, it is now rejected when passed as a type argument +#![feature(min_generic_const_args)] + +use std::gca; + +struct S(T); + +fn main() { + let _: S = S(2u32); + //~^ ERROR: constant provided when a type was expected + let _: S<{ gca!(_) }> = S(2u32); + //~^ ERROR: constant provided when a type was expected +} diff --git a/tests/ui/const-generics/mgca/gca-macro-infer-as-type.stderr b/tests/ui/const-generics/mgca/gca-macro-infer-as-type.stderr new file mode 100644 index 0000000000000..22c20958b6626 --- /dev/null +++ b/tests/ui/const-generics/mgca/gca-macro-infer-as-type.stderr @@ -0,0 +1,15 @@ +error[E0747]: constant provided when a type was expected + --> $DIR/gca-macro-infer-as-type.rs:10:19 + | +LL | let _: S = S(2u32); + | ^ + +error[E0747]: constant provided when a type was expected + --> $DIR/gca-macro-infer-as-type.rs:12:21 + | +LL | let _: S<{ gca!(_) }> = S(2u32); + | ^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0747`. diff --git a/tests/ui/const-generics/mgca/gca-macro-multiple-exprs.rs b/tests/ui/const-generics/mgca/gca-macro-multiple-exprs.rs new file mode 100644 index 0000000000000..518fc63d68bb9 --- /dev/null +++ b/tests/ui/const-generics/mgca/gca-macro-multiple-exprs.rs @@ -0,0 +1,6 @@ +#![feature(min_generic_const_args)] +use std::gca; +struct S; +fn foo(_: S) {} +//~^ ERROR gca! takes 1 argument +fn main() {} diff --git a/tests/ui/const-generics/mgca/gca-macro-multiple-exprs.stderr b/tests/ui/const-generics/mgca/gca-macro-multiple-exprs.stderr new file mode 100644 index 0000000000000..992d981624924 --- /dev/null +++ b/tests/ui/const-generics/mgca/gca-macro-multiple-exprs.stderr @@ -0,0 +1,8 @@ +error: gca! takes 1 argument + --> $DIR/gca-macro-multiple-exprs.rs:4:45 + | +LL | fn foo(_: S) {} + | ^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.rs b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.rs index b435dcde6dc93..4f71ad857cf5a 100644 --- a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.rs +++ b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.rs @@ -1,5 +1,6 @@ #![feature(min_generic_const_args)] #![feature(adt_const_params, unsized_const_params)] +use std::gca; #[derive(PartialEq, Eq, std::marker::ConstParamTy)] pub enum Enum { Unit, @@ -10,10 +11,10 @@ pub mod module { pub use super::Enum::Store; } fn main() { - const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Unit::<()>); + const _: Enum<()> = gca!(Enum::<()>::Unit::<()>); //~^ ERROR: type arguments are not allowed on unit variant `Unit` [E0109] - const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Tuple::<()>()); + const _: Enum<()> = gca!(Enum::<()>::Tuple::<()>()); //~^ ERROR: type arguments are not allowed on tuple variant `Tuple` [E0109] - const _: Enum<()> = core::direct_const_arg!(self::::Enum::<()>::Store); + const _: Enum<()> = gca!(self::::Enum::<()>::Store); //~^ ERROR: type arguments are not allowed on module `generic_args_on_enum_variant_segments_fail` [E0109] } diff --git a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.stderr b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.stderr index 3a6c7a17544c8..02903379932ae 100644 --- a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.stderr +++ b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.stderr @@ -1,40 +1,40 @@ error[E0109]: type arguments are not allowed on unit variant `Unit` - --> $DIR/generic-args-on-enum-variant-segments-fail.rs:13:68 + --> $DIR/generic-args-on-enum-variant-segments-fail.rs:14:49 | -LL | const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Unit::<()>); - | ---- ^^ type argument not allowed - | | - | not allowed on unit variant `Unit` +LL | const _: Enum<()> = gca!(Enum::<()>::Unit::<()>); + | ---- ^^ type argument not allowed + | | + | not allowed on unit variant `Unit` | = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other help: remove the generics arguments from one of the path segments | -LL - const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Unit::<()>); -LL + const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Unit); +LL - const _: Enum<()> = gca!(Enum::<()>::Unit::<()>); +LL + const _: Enum<()> = gca!(Enum::<()>::Unit); | error[E0109]: type arguments are not allowed on tuple variant `Tuple` - --> $DIR/generic-args-on-enum-variant-segments-fail.rs:15:69 + --> $DIR/generic-args-on-enum-variant-segments-fail.rs:16:50 | -LL | const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Tuple::<()>()); - | ----- ^^ type argument not allowed - | | - | not allowed on tuple variant `Tuple` +LL | const _: Enum<()> = gca!(Enum::<()>::Tuple::<()>()); + | ----- ^^ type argument not allowed + | | + | not allowed on tuple variant `Tuple` | = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other help: remove the generics arguments from one of the path segments | -LL - const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Tuple::<()>()); -LL + const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Tuple()); +LL - const _: Enum<()> = gca!(Enum::<()>::Tuple::<()>()); +LL + const _: Enum<()> = gca!(Enum::<()>::Tuple()); | error[E0109]: type arguments are not allowed on module `generic_args_on_enum_variant_segments_fail` - --> $DIR/generic-args-on-enum-variant-segments-fail.rs:17:56 + --> $DIR/generic-args-on-enum-variant-segments-fail.rs:18:37 | -LL | const _: Enum<()> = core::direct_const_arg!(self::::Enum::<()>::Store); - | ---- ^^^ type argument not allowed - | | - | not allowed on module `generic_args_on_enum_variant_segments_fail` +LL | const _: Enum<()> = gca!(self::::Enum::<()>::Store); + | ---- ^^^ type argument not allowed + | | + | not allowed on module `generic_args_on_enum_variant_segments_fail` error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments.rs b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments.rs index 234bca78d6cb3..94782da82f150 100644 --- a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments.rs +++ b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments.rs @@ -3,6 +3,8 @@ #![feature(min_generic_const_args)] #![feature(adt_const_params, unsized_const_params)] +use std::gca; + #[derive(PartialEq, Eq, std::marker::ConstParamTy)] enum Enum { Unit, @@ -10,7 +12,7 @@ enum Enum { Store(T), } -const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Unit); -const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Tuple()); +const _: Enum<()> = gca!(Enum::<()>::Unit); +const _: Enum<()> = gca!(Enum::<()>::Tuple()); fn main() {} diff --git a/tests/ui/const-generics/mgca/generic_const_items-mismatched-array-len.rs b/tests/ui/const-generics/mgca/generic_const_items-mismatched-array-len.rs index 2c680a37ea1f9..fad1703e3bfee 100644 --- a/tests/ui/const-generics/mgca/generic_const_items-mismatched-array-len.rs +++ b/tests/ui/const-generics/mgca/generic_const_items-mismatched-array-len.rs @@ -3,6 +3,8 @@ #![feature(adt_const_params, min_generic_const_args, macroless_generic_const_args)] #![feature(generic_const_parameter_types)] +use std::gca; + trait Trait { #[rustc_always_gca] const LEN: usize; @@ -10,7 +12,7 @@ trait Trait { struct S; impl Trait for S { - const LEN: usize = core::direct_const_arg!(2); + const LEN: usize = gca!(2); } fn foo::LEN]>() -> [u8; ::LEN] { diff --git a/tests/ui/const-generics/mgca/generic_const_items-mismatched-array-len.stderr b/tests/ui/const-generics/mgca/generic_const_items-mismatched-array-len.stderr index c9ee69146f326..4906b05939900 100644 --- a/tests/ui/const-generics/mgca/generic_const_items-mismatched-array-len.stderr +++ b/tests/ui/const-generics/mgca/generic_const_items-mismatched-array-len.stderr @@ -1,11 +1,11 @@ error: the constant `*b"\x01\x02\x03"` is not of type `[u8; ::LEN]` - --> $DIR/generic_const_items-mismatched-array-len.rs:21:11 + --> $DIR/generic_const_items-mismatched-array-len.rs:23:11 | LL | foo::() | ^ expected `[u8; ::LEN]`, found `[u8; 3]` | note: required by a const generic parameter in `foo` - --> $DIR/generic_const_items-mismatched-array-len.rs:16:18 + --> $DIR/generic_const_items-mismatched-array-len.rs:18:18 | LL | fn foo::LEN]>() -> [u8; ::LEN] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `foo` diff --git a/tests/ui/const-generics/mgca/generic_const_parameter_types-inferred-array-len.rs b/tests/ui/const-generics/mgca/generic_const_parameter_types-inferred-array-len.rs index 5891e66aa77b0..eb32077dcfaca 100644 --- a/tests/ui/const-generics/mgca/generic_const_parameter_types-inferred-array-len.rs +++ b/tests/ui/const-generics/mgca/generic_const_parameter_types-inferred-array-len.rs @@ -1,8 +1,11 @@ //@ check-pass #![feature(min_adt_const_params, min_generic_const_args, generic_const_parameter_types)] + +use std::gca; + fn foo() {} fn main() { - foo::<_, core::direct_const_arg!([0, 1, 2, 3])>(); + foo::<_, gca!([0, 1, 2, 3])>(); } diff --git a/tests/ui/const-generics/mgca/generic_const_type_mismatch.rs b/tests/ui/const-generics/mgca/generic_const_type_mismatch.rs index 928205d4bc4df..55443874a36d1 100644 --- a/tests/ui/const-generics/mgca/generic_const_type_mismatch.rs +++ b/tests/ui/const-generics/mgca/generic_const_type_mismatch.rs @@ -7,13 +7,15 @@ min_generic_const_args, const_param_ty_trait )] + +use std::gca; use std::marker::ConstParamTy_; struct Foo { field: T, } -const WRAP: T = core::direct_const_arg!(Foo:: { field: 1 }); +const WRAP: T = gca!(Foo:: { field: 1 }); //~^ ERROR: type annotations needed for the literal fn main() {} diff --git a/tests/ui/const-generics/mgca/generic_const_type_mismatch.stderr b/tests/ui/const-generics/mgca/generic_const_type_mismatch.stderr index d7f89bede8d4d..241e396c11569 100644 --- a/tests/ui/const-generics/mgca/generic_const_type_mismatch.stderr +++ b/tests/ui/const-generics/mgca/generic_const_type_mismatch.stderr @@ -1,8 +1,8 @@ error: type annotations needed for the literal - --> $DIR/generic_const_type_mismatch.rs:16:77 + --> $DIR/generic_const_type_mismatch.rs:18:58 | -LL | const WRAP: T = core::direct_const_arg!(Foo:: { field: 1 }); - | ^ +LL | const WRAP: T = gca!(Foo:: { field: 1 }); + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/inherent-alias-default.rs b/tests/ui/const-generics/mgca/inherent-alias-default.rs index 9ba6d1d15e856..2ef400454a195 100644 --- a/tests/ui/const-generics/mgca/inherent-alias-default.rs +++ b/tests/ui/const-generics/mgca/inherent-alias-default.rs @@ -5,11 +5,13 @@ //! ensure_ok(). This test just makes sure that codepath is hit in tests. #![feature(min_generic_const_args, inherent_associated_types)] +use std::gca; + struct Struct(T1, T2, T3); impl Struct { - const INHERENT: usize = core::direct_const_arg!(2); + const INHERENT: usize = gca!(2); } -struct WithDefault::INHERENT) }>; +struct WithDefault::INHERENT) }>; fn main() {} diff --git a/tests/ui/const-generics/mgca/invalid-direct-const-arg-owner-issue-159172.expr.stderr b/tests/ui/const-generics/mgca/invalid-direct-const-arg-owner-issue-159172.expr.stderr deleted file mode 100644 index 016c7afc4b8b5..0000000000000 --- a/tests/ui/const-generics/mgca/invalid-direct-const-arg-owner-issue-159172.expr.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: expected expression, found `direct_const_arg!()` constant - --> $DIR/invalid-direct-const-arg-owner-issue-159172.rs:21:13 - | -LL | let _ = core::direct_const_arg!(|| { - | _____________^ -LL | | -LL | | use std::io::*; -LL | | write!(_, "") -LL | | }); - | |______^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/const-generics/mgca/invalid-gca-macro-owner-issue-159172.expr.stderr b/tests/ui/const-generics/mgca/invalid-gca-macro-owner-issue-159172.expr.stderr new file mode 100644 index 0000000000000..d579038f3cd7b --- /dev/null +++ b/tests/ui/const-generics/mgca/invalid-gca-macro-owner-issue-159172.expr.stderr @@ -0,0 +1,13 @@ +error: expected expression, found `gca!()` constant + --> $DIR/invalid-gca-macro-owner-issue-159172.rs:23:13 + | +LL | let _ = gca!(|| { + | _____________^ +LL | | +LL | | use std::io::*; +LL | | write!(_, "") +LL | | }); + | |______^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/const-generics/mgca/invalid-direct-const-arg-owner-issue-159172.rs b/tests/ui/const-generics/mgca/invalid-gca-macro-owner-issue-159172.rs similarity index 57% rename from tests/ui/const-generics/mgca/invalid-direct-const-arg-owner-issue-159172.rs rename to tests/ui/const-generics/mgca/invalid-gca-macro-owner-issue-159172.rs index 80673ec127adf..0b0f30fd5b9fe 100644 --- a/tests/ui/const-generics/mgca/invalid-direct-const-arg-owner-issue-159172.rs +++ b/tests/ui/const-generics/mgca/invalid-gca-macro-owner-issue-159172.rs @@ -1,10 +1,12 @@ //@ revisions: ty expr #![feature(min_generic_const_args)] +use std::gca; + #[cfg(ty)] trait Iter< - const C: core::direct_const_arg!(|| { - //[ty]~^ ERROR expected type, found `direct_const_arg!()` constant + const C: gca!(|| { + //[ty]~^ ERROR expected type, found `gca!()` constant use std::io::*; let mut buffer = std::fs::File::create("foo.txt")?; write!(buffer, "oh no")?; @@ -18,8 +20,8 @@ fn main() {} #[cfg(expr)] fn main() { - let _ = core::direct_const_arg!(|| { - //[expr]~^ ERROR expected expression, found `direct_const_arg!()` constant + let _ = gca!(|| { + //[expr]~^ ERROR expected expression, found `gca!()` constant use std::io::*; write!(_, "") }); diff --git a/tests/ui/const-generics/mgca/invalid-direct-const-arg-owner-issue-159172.ty.stderr b/tests/ui/const-generics/mgca/invalid-gca-macro-owner-issue-159172.ty.stderr similarity index 58% rename from tests/ui/const-generics/mgca/invalid-direct-const-arg-owner-issue-159172.ty.stderr rename to tests/ui/const-generics/mgca/invalid-gca-macro-owner-issue-159172.ty.stderr index 936153ce52b75..b3882df585ac0 100644 --- a/tests/ui/const-generics/mgca/invalid-direct-const-arg-owner-issue-159172.ty.stderr +++ b/tests/ui/const-generics/mgca/invalid-gca-macro-owner-issue-159172.ty.stderr @@ -1,7 +1,7 @@ -error: expected type, found `direct_const_arg!()` constant - --> $DIR/invalid-direct-const-arg-owner-issue-159172.rs:6:14 +error: expected type, found `gca!()` constant + --> $DIR/invalid-gca-macro-owner-issue-159172.rs:8:14 | -LL | const C: core::direct_const_arg!(|| { +LL | const C: gca!(|| { | ______________^ LL | | LL | | use std::io::*; diff --git a/tests/ui/const-generics/mgca/macro-const-arg-infer.rs b/tests/ui/const-generics/mgca/macro-const-arg-infer.rs index a768228d94d28..010b1c240e2a6 100644 --- a/tests/ui/const-generics/mgca/macro-const-arg-infer.rs +++ b/tests/ui/const-generics/mgca/macro-const-arg-infer.rs @@ -1,6 +1,9 @@ //! Regression test for https://github.com/rust-lang/rust/issues/153198 #![feature(min_generic_const_args)] #![allow(incomplete_features)] + +use std::gca; + macro_rules! y { ( $($matcher:tt)*) => { _ //~ ERROR: constant provided when a type was expected @@ -11,7 +14,7 @@ macro_rules! y { struct A; //~ ERROR: type parameter `T` is never used const y: A< - core::direct_const_arg!(y! { + gca!(y! { x }), > = 1; diff --git a/tests/ui/const-generics/mgca/macro-const-arg-infer.stderr b/tests/ui/const-generics/mgca/macro-const-arg-infer.stderr index b46114bf4bd5f..a791b9d17fcce 100644 --- a/tests/ui/const-generics/mgca/macro-const-arg-infer.stderr +++ b/tests/ui/const-generics/mgca/macro-const-arg-infer.stderr @@ -1,5 +1,5 @@ error[E0392]: type parameter `T` is never used - --> $DIR/macro-const-arg-infer.rs:11:10 + --> $DIR/macro-const-arg-infer.rs:14:10 | LL | struct A; | ^ unused type parameter @@ -8,29 +8,29 @@ LL | struct A; = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead error[E0747]: constant provided when a type was expected - --> $DIR/macro-const-arg-infer.rs:6:9 + --> $DIR/macro-const-arg-infer.rs:9:9 | LL | macro_rules! y { LL | ( $($matcher:tt)*) => { LL | _ | ^ ... -LL | core::direct_const_arg!(y! { - | _____________________________- +LL | gca!(y! { + | __________- LL | | x LL | | }), | |_____- in this macro invocation error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/macro-const-arg-infer.rs:6:9 + --> $DIR/macro-const-arg-infer.rs:9:9 | LL | macro_rules! y { LL | ( $($matcher:tt)*) => { LL | _ | ^ not allowed in type signatures ... -LL | core::direct_const_arg!(y! { - | _____________________________- +LL | gca!(y! { + | __________- LL | | x LL | | }), | |_____- in this macro invocation diff --git a/tests/ui/const-generics/mgca/mixed-direct-anon-expression-diagnostics.rs b/tests/ui/const-generics/mgca/mixed-direct-anon-expression-diagnostics.rs index 1653fd63ed3f8..b4214f5f74e89 100644 --- a/tests/ui/const-generics/mgca/mixed-direct-anon-expression-diagnostics.rs +++ b/tests/ui/const-generics/mgca/mixed-direct-anon-expression-diagnostics.rs @@ -5,12 +5,14 @@ #![feature(min_generic_const_args, min_adt_const_params)] #![allow(incomplete_features)] +use std::gca; + fn f() {} fn g() { f::<{ (N, 1 + 1) }>(); //~^ ERROR: generic parameters may not be used in const operations - f::<{ core::direct_const_arg!((N, 1 + 1)) }>(); + f::<{ gca!((N, 1 + 1)) }>(); //~^ ERROR: complex const arguments must be placed inside of a `const` block } diff --git a/tests/ui/const-generics/mgca/mixed-direct-anon-expression-diagnostics.stderr b/tests/ui/const-generics/mgca/mixed-direct-anon-expression-diagnostics.stderr index 50f849b6389ee..920143d33626f 100644 --- a/tests/ui/const-generics/mgca/mixed-direct-anon-expression-diagnostics.stderr +++ b/tests/ui/const-generics/mgca/mixed-direct-anon-expression-diagnostics.stderr @@ -1,11 +1,11 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/mixed-direct-anon-expression-diagnostics.rs:13:39 + --> $DIR/mixed-direct-anon-expression-diagnostics.rs:15:20 | -LL | f::<{ core::direct_const_arg!((N, 1 + 1)) }>(); - | ^^^^^ +LL | f::<{ gca!((N, 1 + 1)) }>(); + | ^^^^^ error: generic parameters may not be used in const operations - --> $DIR/mixed-direct-anon-expression-diagnostics.rs:11:12 + --> $DIR/mixed-direct-anon-expression-diagnostics.rs:13:12 | LL | f::<{ (N, 1 + 1) }>(); | ^ diff --git a/tests/ui/const-generics/mgca/multi_braced_direct_const_args.rs b/tests/ui/const-generics/mgca/multi_braced_gca_macro.rs similarity index 100% rename from tests/ui/const-generics/mgca/multi_braced_direct_const_args.rs rename to tests/ui/const-generics/mgca/multi_braced_gca_macro.rs diff --git a/tests/ui/const-generics/mgca/non-local-const-without-type_const.stderr b/tests/ui/const-generics/mgca/non-local-const-without-type_const.stderr index 593eac88122c0..a9a6c168b8d14 100644 --- a/tests/ui/const-generics/mgca/non-local-const-without-type_const.stderr +++ b/tests/ui/const-generics/mgca/non-local-const-without-type_const.stderr @@ -4,7 +4,7 @@ error: use of `const` in the type system not marked as direct LL | let x = [(); non_local_const::N]; | ^^^^^^^^^^^^^^^^^^ | - = note: only consts with a `direct_const_arg!` right-hand side may be used in types + = note: only consts with a `gca!` right-hand side may be used in types error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/none-as-usize-const-arg.rs b/tests/ui/const-generics/mgca/none-as-usize-const-arg.rs index c21f1d0014ad5..d691aaaa6cf88 100644 --- a/tests/ui/const-generics/mgca/none-as-usize-const-arg.rs +++ b/tests/ui/const-generics/mgca/none-as-usize-const-arg.rs @@ -3,11 +3,13 @@ #![feature(generic_const_exprs)] #![feature(min_generic_const_args)] +use std::gca; + fn pass_enum { //~^ ERROR: missing parameters for function definition //~| ERROR: defaults for generic parameters are not allowed here //~| ERROR: overly complex generic constant - pass_enum::<{ core::direct_const_arg!(None) }> + pass_enum::<{ gca!(None) }> //~^ ERROR: missing generics for enum `Option` [E0107] } diff --git a/tests/ui/const-generics/mgca/none-as-usize-const-arg.stderr b/tests/ui/const-generics/mgca/none-as-usize-const-arg.stderr index dbd1ac607e88c..2cba595e2048b 100644 --- a/tests/ui/const-generics/mgca/none-as-usize-const-arg.stderr +++ b/tests/ui/const-generics/mgca/none-as-usize-const-arg.stderr @@ -1,5 +1,5 @@ error: missing parameters for function definition - --> $DIR/none-as-usize-const-arg.rs:6:59 + --> $DIR/none-as-usize-const-arg.rs:8:59 | LL | fn pass_enum { | ^ @@ -10,24 +10,24 @@ LL | fn pass_enum() { | ++ error: defaults for generic parameters are not allowed here - --> $DIR/none-as-usize-const-arg.rs:6:30 + --> $DIR/none-as-usize-const-arg.rs:8:30 | LL | fn pass_enum { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0107]: missing generics for enum `Option` - --> $DIR/none-as-usize-const-arg.rs:10:43 + --> $DIR/none-as-usize-const-arg.rs:12:24 | -LL | pass_enum::<{ core::direct_const_arg!(None) }> - | ^^^^ expected 1 generic argument +LL | pass_enum::<{ gca!(None) }> + | ^^^^ expected 1 generic argument | help: add missing generic argument | -LL | pass_enum::<{ core::direct_const_arg!(None) }> - | +++ +LL | pass_enum::<{ gca!(None) }> + | +++ error: overly complex generic constant - --> $DIR/none-as-usize-const-arg.rs:6:47 + --> $DIR/none-as-usize-const-arg.rs:8:47 | LL | fn pass_enum { | ^^^^^^^^^^^ const blocks are not supported in generic constants diff --git a/tests/ui/const-generics/mgca/opaque-ty-assoc-const-equality-117923.rs b/tests/ui/const-generics/mgca/opaque-ty-assoc-const-equality-117923.rs index ee336ea3f61e7..71112d632b5d8 100644 --- a/tests/ui/const-generics/mgca/opaque-ty-assoc-const-equality-117923.rs +++ b/tests/ui/const-generics/mgca/opaque-ty-assoc-const-equality-117923.rs @@ -3,6 +3,8 @@ #![feature(min_generic_const_args, macroless_generic_const_args)] #![allow(incomplete_features, dead_code)] +use std::gca; + trait Trait { #[rustc_always_gca] const CT: usize; @@ -13,7 +15,7 @@ struct Type { } impl Trait for Type { - const CT: usize = core::direct_const_arg!(N); + const CT: usize = gca!(N); } fn func() -> impl Trait as Trait>::CT }> { diff --git a/tests/ui/const-generics/mgca/paren.rs b/tests/ui/const-generics/mgca/paren.rs index de9e726a756f0..df60c06531755 100644 --- a/tests/ui/const-generics/mgca/paren.rs +++ b/tests/ui/const-generics/mgca/paren.rs @@ -2,35 +2,37 @@ //! See also: tests/ui/const-generics/paren.rs #![feature(min_generic_const_args, generic_const_items)] +use std::gca; + struct Thing; -const A: usize = core::direct_const_arg!(N); +const A: usize = gca!(N); fn f() { - let _: [u32; core::direct_const_arg!(_)] = [5; 5]; - let _: [u32; core::direct_const_arg!((_))] = [5; 5]; - let _: [u32; core::direct_const_arg!({ _ })] = [5; 5]; - let _: [u32; core::direct_const_arg!({ (_) })] = [5; 5]; - let _: [u32; core::direct_const_arg!(N)] = [5; _]; - let _: [u32; core::direct_const_arg!((N))] = [5; _]; - let _: [u32; core::direct_const_arg!({ N })] = [5; _]; - let _: [u32; core::direct_const_arg!({ (N) })] = [5; _]; - let _: [u32; core::direct_const_arg!(A::)] = [5; _]; - let _: [u32; core::direct_const_arg!((A::))] = [5; _]; - let _: [u32; core::direct_const_arg!({ A:: })] = [5; _]; - let _: [u32; core::direct_const_arg!({ (A::) })] = [5; _]; - let _: Thing = Thing::<5>; - let _: Thing = Thing::<5>; - let _: Thing = Thing::<5>; - let _: Thing = Thing::<5>; - let _: Thing = Thing; - let _: Thing = Thing; - let _: Thing = Thing; - let _: Thing = Thing; - let _: Thing)> = Thing; - let _: Thing))> = Thing; - let _: Thing })> = Thing; - let _: Thing) })> = Thing; + let _: [u32; gca!(_)] = [5; 5]; + let _: [u32; gca!((_))] = [5; 5]; + let _: [u32; gca!({ _ })] = [5; 5]; + let _: [u32; gca!({ (_) })] = [5; 5]; + let _: [u32; gca!(N)] = [5; _]; + let _: [u32; gca!((N))] = [5; _]; + let _: [u32; gca!({ N })] = [5; _]; + let _: [u32; gca!({ (N) })] = [5; _]; + let _: [u32; gca!(A::)] = [5; _]; + let _: [u32; gca!((A::))] = [5; _]; + let _: [u32; gca!({ A:: })] = [5; _]; + let _: [u32; gca!({ (A::) })] = [5; _]; + let _: Thing = Thing::<5>; + let _: Thing = Thing::<5>; + let _: Thing = Thing::<5>; + let _: Thing = Thing::<5>; + let _: Thing = Thing; + let _: Thing = Thing; + let _: Thing = Thing; + let _: Thing = Thing; + let _: Thing)> = Thing; + let _: Thing))> = Thing; + let _: Thing })> = Thing; + let _: Thing) })> = Thing; } fn main() {} diff --git a/tests/ui/const-generics/mgca/projection-const-recursive.rs b/tests/ui/const-generics/mgca/projection-const-recursive.rs index 0f1e30e0e610b..4a4b0c918e80a 100644 --- a/tests/ui/const-generics/mgca/projection-const-recursive.rs +++ b/tests/ui/const-generics/mgca/projection-const-recursive.rs @@ -6,13 +6,15 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] +use std::gca; + trait Trait { #[rustc_always_gca] const A: (); } impl Trait for () { - const A: () = core::direct_const_arg!(<() as Trait>::A); + const A: () = gca!(<() as Trait>::A); //~^ ERROR: overflow evaluating the requirement `<() as Trait>::A == _` //~| ERROR: overflow evaluating the requirement `the constant `<() as Trait>::A` has type `()`` } diff --git a/tests/ui/const-generics/mgca/projection-const-recursive.stderr b/tests/ui/const-generics/mgca/projection-const-recursive.stderr index 54f94ea2e8e2e..1ffb6a88cc0f3 100644 --- a/tests/ui/const-generics/mgca/projection-const-recursive.stderr +++ b/tests/ui/const-generics/mgca/projection-const-recursive.stderr @@ -1,13 +1,13 @@ error[E0275]: overflow evaluating the requirement `<() as Trait>::A == _` - --> $DIR/projection-const-recursive.rs:15:5 + --> $DIR/projection-const-recursive.rs:17:5 | -LL | const A: () = core::direct_const_arg!(<() as Trait>::A); +LL | const A: () = gca!(<() as Trait>::A); | ^^^^^^^^^^^ error[E0275]: overflow evaluating the requirement `the constant `<() as Trait>::A` has type `()`` - --> $DIR/projection-const-recursive.rs:15:5 + --> $DIR/projection-const-recursive.rs:17:5 | -LL | const A: () = core::direct_const_arg!(<() as Trait>::A); +LL | const A: () = gca!(<() as Trait>::A); | ^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/static-const-arg.rs b/tests/ui/const-generics/mgca/static-const-arg.rs index 8afc57c1c2785..cc97267b4726e 100644 --- a/tests/ui/const-generics/mgca/static-const-arg.rs +++ b/tests/ui/const-generics/mgca/static-const-arg.rs @@ -5,14 +5,16 @@ #![feature(min_generic_const_args)] #![allow(incomplete_features)] +use std::gca; + static A: u32 = 0; struct Foo; -const _: Foo<{ core::direct_const_arg!(A) }> = Foo; +const _: Foo<{ gca!(A) }> = Foo; //~^ ERROR static items cannot be used as const arguments -const _: Foo = Foo; +const _: Foo = Foo; //~^ ERROR static items cannot be used as const arguments fn main() {} diff --git a/tests/ui/const-generics/mgca/static-const-arg.stderr b/tests/ui/const-generics/mgca/static-const-arg.stderr index d2f878545971b..1ba21dc552961 100644 --- a/tests/ui/const-generics/mgca/static-const-arg.stderr +++ b/tests/ui/const-generics/mgca/static-const-arg.stderr @@ -1,14 +1,14 @@ error: static items cannot be used as const arguments - --> $DIR/static-const-arg.rs:12:40 + --> $DIR/static-const-arg.rs:14:21 | -LL | const _: Foo<{ core::direct_const_arg!(A) }> = Foo; - | ^ +LL | const _: Foo<{ gca!(A) }> = Foo; + | ^ error: static items cannot be used as const arguments - --> $DIR/static-const-arg.rs:15:38 + --> $DIR/static-const-arg.rs:17:19 | -LL | const _: Foo = Foo; - | ^ +LL | const _: Foo = Foo; + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/suggest-direct-const.fixed b/tests/ui/const-generics/mgca/suggest-direct-const.fixed index 6a6af81570255..044d875f1b4bb 100644 --- a/tests/ui/const-generics/mgca/suggest-direct-const.fixed +++ b/tests/ui/const-generics/mgca/suggest-direct-const.fixed @@ -4,35 +4,38 @@ #![allow(dead_code)] mod impl_item { + use std::gca; pub struct Bar; impl Bar { - pub const PUBLIC: usize = core::direct_const_arg!(1); - pub(crate) const RESTRICTED: usize = core::direct_const_arg!(1); - const PRIVATE: usize = core::direct_const_arg!(1); + pub const PUBLIC: usize = core::gca!(1); + pub(crate) const RESTRICTED: usize = core::gca!(1); + const PRIVATE: usize = core::gca!(1); } - pub struct Foo1([u8; core::direct_const_arg!(Bar::PUBLIC)]); + pub struct Foo1([u8; gca!(Bar::PUBLIC)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Foo2([u8; core::direct_const_arg!(Bar::RESTRICTED)]); + pub struct Foo2([u8; gca!(Bar::RESTRICTED)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Foo3([u8; core::direct_const_arg!(Bar::PRIVATE)]); + pub struct Foo3([u8; gca!(Bar::PRIVATE)]); //~^ ERROR: use of `const` in the type system not marked as direct } mod top_level_item { - pub const PUBLIC: usize = core::direct_const_arg!(1); - pub(crate) const RESTRICTED: usize = core::direct_const_arg!(1); - const PRIVATE: usize = core::direct_const_arg!(1); + use std::gca; + pub const PUBLIC: usize = core::gca!(1); + pub(crate) const RESTRICTED: usize = core::gca!(1); + const PRIVATE: usize = core::gca!(1); - pub struct Foo1([u8; core::direct_const_arg!(PUBLIC)]); + pub struct Foo1([u8; gca!(PUBLIC)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Foo2([u8; core::direct_const_arg!(RESTRICTED)]); + pub struct Foo2([u8; gca!(RESTRICTED)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Foo3([u8; core::direct_const_arg!(PRIVATE)]); + pub struct Foo3([u8; gca!(PRIVATE)]); //~^ ERROR: use of `const` in the type system not marked as direct } mod trait_item { + use std::gca; pub trait Foo { #[rustc_always_gca] const PUBLIC: usize; //~^ ERROR: [E0449] @@ -41,11 +44,11 @@ mod trait_item { #[rustc_always_gca] const PRIVATE: usize; } - pub struct Bar([u8; core::direct_const_arg!(T::PUBLIC)]); + pub struct Bar([u8; gca!(T::PUBLIC)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Bar2([u8; core::direct_const_arg!(T::RESTRICTED)]); + pub struct Bar2([u8; gca!(T::RESTRICTED)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Bar3([u8; core::direct_const_arg!(T::PRIVATE)]); + pub struct Bar3([u8; gca!(T::PRIVATE)]); //~^ ERROR: use of `const` in the type system not marked as direct } diff --git a/tests/ui/const-generics/mgca/suggest-direct-const.rs b/tests/ui/const-generics/mgca/suggest-direct-const.rs index 05b538a6cd1d9..e4f394e9c18bd 100644 --- a/tests/ui/const-generics/mgca/suggest-direct-const.rs +++ b/tests/ui/const-generics/mgca/suggest-direct-const.rs @@ -4,6 +4,7 @@ #![allow(dead_code)] mod impl_item { + use std::gca; pub struct Bar; impl Bar { pub const PUBLIC: usize = 1; @@ -11,28 +12,30 @@ mod impl_item { const PRIVATE: usize = 1; } - pub struct Foo1([u8; core::direct_const_arg!(Bar::PUBLIC)]); + pub struct Foo1([u8; gca!(Bar::PUBLIC)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Foo2([u8; core::direct_const_arg!(Bar::RESTRICTED)]); + pub struct Foo2([u8; gca!(Bar::RESTRICTED)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Foo3([u8; core::direct_const_arg!(Bar::PRIVATE)]); + pub struct Foo3([u8; gca!(Bar::PRIVATE)]); //~^ ERROR: use of `const` in the type system not marked as direct } mod top_level_item { + use std::gca; pub const PUBLIC: usize = 1; pub(crate) const RESTRICTED: usize = 1; const PRIVATE: usize = 1; - pub struct Foo1([u8; core::direct_const_arg!(PUBLIC)]); + pub struct Foo1([u8; gca!(PUBLIC)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Foo2([u8; core::direct_const_arg!(RESTRICTED)]); + pub struct Foo2([u8; gca!(RESTRICTED)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Foo3([u8; core::direct_const_arg!(PRIVATE)]); + pub struct Foo3([u8; gca!(PRIVATE)]); //~^ ERROR: use of `const` in the type system not marked as direct } mod trait_item { + use std::gca; pub trait Foo { pub const PUBLIC: usize; //~^ ERROR: [E0449] @@ -41,11 +44,11 @@ mod trait_item { const PRIVATE: usize; } - pub struct Bar([u8; core::direct_const_arg!(T::PUBLIC)]); + pub struct Bar([u8; gca!(T::PUBLIC)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Bar2([u8; core::direct_const_arg!(T::RESTRICTED)]); + pub struct Bar2([u8; gca!(T::RESTRICTED)]); //~^ ERROR: use of `const` in the type system not marked as direct - pub struct Bar3([u8; core::direct_const_arg!(T::PRIVATE)]); + pub struct Bar3([u8; gca!(T::PRIVATE)]); //~^ ERROR: use of `const` in the type system not marked as direct } diff --git a/tests/ui/const-generics/mgca/suggest-direct-const.stderr b/tests/ui/const-generics/mgca/suggest-direct-const.stderr index 69eeee156675d..d2cef03c3c3f2 100644 --- a/tests/ui/const-generics/mgca/suggest-direct-const.stderr +++ b/tests/ui/const-generics/mgca/suggest-direct-const.stderr @@ -1,5 +1,5 @@ error[E0449]: visibility qualifiers are not permitted here - --> $DIR/suggest-direct-const.rs:37:9 + --> $DIR/suggest-direct-const.rs:40:9 | LL | pub const PUBLIC: usize; | ^^^ help: remove the qualifier @@ -7,7 +7,7 @@ LL | pub const PUBLIC: usize; = note: trait items always share the visibility of their trait error[E0449]: visibility qualifiers are not permitted here - --> $DIR/suggest-direct-const.rs:39:9 + --> $DIR/suggest-direct-const.rs:42:9 | LL | pub(crate) const RESTRICTED: usize; | ^^^^^^^^^^ help: remove the qualifier @@ -15,76 +15,76 @@ LL | pub(crate) const RESTRICTED: usize; = note: trait items always share the visibility of their trait error: use of `const` in the type system not marked as direct - --> $DIR/suggest-direct-const.rs:14:50 + --> $DIR/suggest-direct-const.rs:15:31 | -LL | pub struct Foo1([u8; core::direct_const_arg!(Bar::PUBLIC)]); - | ^^^^^^^^^^^ +LL | pub struct Foo1([u8; gca!(Bar::PUBLIC)]); + | ^^^^^^^^^^^ | -help: add direct_const_arg!() to the right-hand side of the constant +help: add gca!() to the right-hand side of the constant | -LL | pub const PUBLIC: usize = core::direct_const_arg!(1); - | ++++++++++++++++++++++++ + +LL | pub const PUBLIC: usize = core::gca!(1); + | +++++++++++ + error: use of `const` in the type system not marked as direct - --> $DIR/suggest-direct-const.rs:16:50 + --> $DIR/suggest-direct-const.rs:17:31 | -LL | pub struct Foo2([u8; core::direct_const_arg!(Bar::RESTRICTED)]); - | ^^^^^^^^^^^^^^^ +LL | pub struct Foo2([u8; gca!(Bar::RESTRICTED)]); + | ^^^^^^^^^^^^^^^ | -help: add direct_const_arg!() to the right-hand side of the constant +help: add gca!() to the right-hand side of the constant | -LL | pub(crate) const RESTRICTED: usize = core::direct_const_arg!(1); - | ++++++++++++++++++++++++ + +LL | pub(crate) const RESTRICTED: usize = core::gca!(1); + | +++++++++++ + error: use of `const` in the type system not marked as direct - --> $DIR/suggest-direct-const.rs:18:50 + --> $DIR/suggest-direct-const.rs:19:31 | -LL | pub struct Foo3([u8; core::direct_const_arg!(Bar::PRIVATE)]); - | ^^^^^^^^^^^^ +LL | pub struct Foo3([u8; gca!(Bar::PRIVATE)]); + | ^^^^^^^^^^^^ | -help: add direct_const_arg!() to the right-hand side of the constant +help: add gca!() to the right-hand side of the constant | -LL | const PRIVATE: usize = core::direct_const_arg!(1); - | ++++++++++++++++++++++++ + +LL | const PRIVATE: usize = core::gca!(1); + | +++++++++++ + error: use of `const` in the type system not marked as direct - --> $DIR/suggest-direct-const.rs:27:50 + --> $DIR/suggest-direct-const.rs:29:31 | -LL | pub struct Foo1([u8; core::direct_const_arg!(PUBLIC)]); - | ^^^^^^ +LL | pub struct Foo1([u8; gca!(PUBLIC)]); + | ^^^^^^ | -help: add direct_const_arg!() to the right-hand side of the constant +help: add gca!() to the right-hand side of the constant | -LL | pub const PUBLIC: usize = core::direct_const_arg!(1); - | ++++++++++++++++++++++++ + +LL | pub const PUBLIC: usize = core::gca!(1); + | +++++++++++ + error: use of `const` in the type system not marked as direct - --> $DIR/suggest-direct-const.rs:29:50 + --> $DIR/suggest-direct-const.rs:31:31 | -LL | pub struct Foo2([u8; core::direct_const_arg!(RESTRICTED)]); - | ^^^^^^^^^^ +LL | pub struct Foo2([u8; gca!(RESTRICTED)]); + | ^^^^^^^^^^ | -help: add direct_const_arg!() to the right-hand side of the constant +help: add gca!() to the right-hand side of the constant | -LL | pub(crate) const RESTRICTED: usize = core::direct_const_arg!(1); - | ++++++++++++++++++++++++ + +LL | pub(crate) const RESTRICTED: usize = core::gca!(1); + | +++++++++++ + error: use of `const` in the type system not marked as direct - --> $DIR/suggest-direct-const.rs:31:50 + --> $DIR/suggest-direct-const.rs:33:31 | -LL | pub struct Foo3([u8; core::direct_const_arg!(PRIVATE)]); - | ^^^^^^^ +LL | pub struct Foo3([u8; gca!(PRIVATE)]); + | ^^^^^^^ | -help: add direct_const_arg!() to the right-hand side of the constant +help: add gca!() to the right-hand side of the constant | -LL | const PRIVATE: usize = core::direct_const_arg!(1); - | ++++++++++++++++++++++++ + +LL | const PRIVATE: usize = core::gca!(1); + | +++++++++++ + error: use of `const` in the type system not marked as direct - --> $DIR/suggest-direct-const.rs:44:57 + --> $DIR/suggest-direct-const.rs:47:38 | -LL | pub struct Bar([u8; core::direct_const_arg!(T::PUBLIC)]); - | ^^^^^^^^^ +LL | pub struct Bar([u8; gca!(T::PUBLIC)]); + | ^^^^^^^^^ | help: add `#[rustc_always_gca]` to the constant | @@ -92,10 +92,10 @@ LL | #[rustc_always_gca] pub const PUBLIC: usize; | +++++++++++++++++++ error: use of `const` in the type system not marked as direct - --> $DIR/suggest-direct-const.rs:46:58 + --> $DIR/suggest-direct-const.rs:49:39 | -LL | pub struct Bar2([u8; core::direct_const_arg!(T::RESTRICTED)]); - | ^^^^^^^^^^^^^ +LL | pub struct Bar2([u8; gca!(T::RESTRICTED)]); + | ^^^^^^^^^^^^^ | help: add `#[rustc_always_gca]` to the constant | @@ -103,10 +103,10 @@ LL | #[rustc_always_gca] pub(crate) const RESTRICTED: usize; | +++++++++++++++++++ error: use of `const` in the type system not marked as direct - --> $DIR/suggest-direct-const.rs:48:58 + --> $DIR/suggest-direct-const.rs:51:39 | -LL | pub struct Bar3([u8; core::direct_const_arg!(T::PRIVATE)]); - | ^^^^^^^^^^ +LL | pub struct Bar3([u8; gca!(T::PRIVATE)]); + | ^^^^^^^^^^ | help: add `#[rustc_always_gca]` to the constant | diff --git a/tests/ui/const-generics/mgca/syntactic-type-mismatch.rs b/tests/ui/const-generics/mgca/syntactic-type-mismatch.rs index 2fd3dea527370..bb0349ccb604a 100644 --- a/tests/ui/const-generics/mgca/syntactic-type-mismatch.rs +++ b/tests/ui/const-generics/mgca/syntactic-type-mismatch.rs @@ -4,10 +4,12 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] -const T0: _ = core::direct_const_arg!(()); +use std::gca; + +const T0: _ = gca!(()); //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for constants [E0121] -const T1 = core::direct_const_arg!([0]); +const T1 = gca!([0]); //~^ ERROR: missing type for `const` item fn main() {} diff --git a/tests/ui/const-generics/mgca/syntactic-type-mismatch.stderr b/tests/ui/const-generics/mgca/syntactic-type-mismatch.stderr index 6f0544c80a480..3d09bbdab6072 100644 --- a/tests/ui/const-generics/mgca/syntactic-type-mismatch.stderr +++ b/tests/ui/const-generics/mgca/syntactic-type-mismatch.stderr @@ -1,18 +1,18 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/syntactic-type-mismatch.rs:7:11 + --> $DIR/syntactic-type-mismatch.rs:9:11 | -LL | const T0: _ = core::direct_const_arg!(()); +LL | const T0: _ = gca!(()); | ^ not allowed in type signatures error: missing type for `const` item - --> $DIR/syntactic-type-mismatch.rs:10:9 + --> $DIR/syntactic-type-mismatch.rs:12:9 | -LL | const T1 = core::direct_const_arg!([0]); +LL | const T1 = gca!([0]); | ^ | help: provide a type for the item | -LL | const T1: = core::direct_const_arg!([0]); +LL | const T1: = gca!([0]); | ++++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/tuple_ctor_complex_args.rs b/tests/ui/const-generics/mgca/tuple_ctor_complex_args.rs index 8bdafd6c270f8..bd9d77eee3a85 100644 --- a/tests/ui/const-generics/mgca/tuple_ctor_complex_args.rs +++ b/tests/ui/const-generics/mgca/tuple_ctor_complex_args.rs @@ -1,6 +1,7 @@ #![feature(min_generic_const_args, macroless_generic_const_args, adt_const_params)] #![expect(incomplete_features)] +use std::gca; use std::marker::ConstParamTy; #[derive(Eq, PartialEq, ConstParamTy)] @@ -9,7 +10,7 @@ struct Point(u32, u32); fn with_point() {} fn test() { - with_point::<{ core::direct_const_arg!(Point(N + 1, N)) }>(); + with_point::<{ gca!(Point(N + 1, N)) }>(); //~^ ERROR complex const arguments must be placed inside of a `const` block with_point::<{ Point(const { N + 1 }, N) }>(); diff --git a/tests/ui/const-generics/mgca/tuple_ctor_complex_args.stderr b/tests/ui/const-generics/mgca/tuple_ctor_complex_args.stderr index 9b7c40d91515b..481afef0ee4e4 100644 --- a/tests/ui/const-generics/mgca/tuple_ctor_complex_args.stderr +++ b/tests/ui/const-generics/mgca/tuple_ctor_complex_args.stderr @@ -1,11 +1,11 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/tuple_ctor_complex_args.rs:12:50 + --> $DIR/tuple_ctor_complex_args.rs:13:31 | -LL | with_point::<{ core::direct_const_arg!(Point(N + 1, N)) }>(); - | ^^^^^ +LL | with_point::<{ gca!(Point(N + 1, N)) }>(); + | ^^^^^ error: generic parameters may not be used in const operations - --> $DIR/tuple_ctor_complex_args.rs:15:34 + --> $DIR/tuple_ctor_complex_args.rs:16:34 | LL | with_point::<{ Point(const { N + 1 }, N) }>(); | ^ diff --git a/tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs b/tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs index d121566868a95..abe225e3f9291 100644 --- a/tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs +++ b/tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs @@ -1,6 +1,7 @@ #![feature(min_generic_const_args, macroless_generic_const_args, adt_const_params)] #![expect(incomplete_features)] +use std::gca; use std::marker::ConstParamTy; #[derive(Eq, PartialEq, ConstParamTy)] @@ -12,7 +13,7 @@ enum MyEnum { Unit, } -const CONST_ITEM: u32 = core::direct_const_arg!(42); +const CONST_ITEM: u32 = gca!(42); fn accepts_point() {} fn accepts_enum>() {} diff --git a/tests/ui/const-generics/mgca/tuple_ctor_erroneous.stderr b/tests/ui/const-generics/mgca/tuple_ctor_erroneous.stderr index b9bbfcc37469d..56b11b2894aa2 100644 --- a/tests/ui/const-generics/mgca/tuple_ctor_erroneous.stderr +++ b/tests/ui/const-generics/mgca/tuple_ctor_erroneous.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find function, tuple struct or tuple variant `UnresolvedIdent` in this scope - --> $DIR/tuple_ctor_erroneous.rs:29:23 + --> $DIR/tuple_ctor_erroneous.rs:30:23 | LL | accepts_point::<{ UnresolvedIdent(N, N) }>(); | ^^^^^^^^^^^^^^^ not found in this scope @@ -10,61 +10,61 @@ LL | fn test_errors() { | +++++++++++++++++++++++++++++++++++ error: tuple constructor has 2 arguments but 1 were provided - --> $DIR/tuple_ctor_erroneous.rs:23:23 + --> $DIR/tuple_ctor_erroneous.rs:24:23 | LL | accepts_point::<{ Point(N) }>(); | ^^^^^^^^ error: tuple constructor has 2 arguments but 3 were provided - --> $DIR/tuple_ctor_erroneous.rs:26:23 + --> $DIR/tuple_ctor_erroneous.rs:27:23 | LL | accepts_point::<{ Point(N, N, N) }>(); | ^^^^^^^^^^^^^^ error: tuple constructor with invalid base path - --> $DIR/tuple_ctor_erroneous.rs:29:23 + --> $DIR/tuple_ctor_erroneous.rs:30:23 | LL | accepts_point::<{ UnresolvedIdent(N, N) }>(); | ^^^^^^^^^^^^^^^^^^^^^ error: function items cannot be used as const args - --> $DIR/tuple_ctor_erroneous.rs:33:23 + --> $DIR/tuple_ctor_erroneous.rs:34:23 | LL | accepts_point::<{ non_ctor(N, N) }>(); | ^^^^^^^^ error: tuple constructor with invalid base path - --> $DIR/tuple_ctor_erroneous.rs:33:23 + --> $DIR/tuple_ctor_erroneous.rs:34:23 | LL | accepts_point::<{ non_ctor(N, N) }>(); | ^^^^^^^^^^^^^^ error: tuple constructor with invalid base path - --> $DIR/tuple_ctor_erroneous.rs:37:23 + --> $DIR/tuple_ctor_erroneous.rs:38:23 | LL | accepts_point::<{ CONST_ITEM(N, N) }>(); | ^^^^^^^^^^^^^^^^ error: the constant `Point` is not of type `Point` - --> $DIR/tuple_ctor_erroneous.rs:40:23 + --> $DIR/tuple_ctor_erroneous.rs:41:23 | LL | accepts_point::<{ Point }>(); | ^^^^^ expected `Point`, found struct constructor | note: required by a const generic parameter in `accepts_point` - --> $DIR/tuple_ctor_erroneous.rs:17:18 + --> $DIR/tuple_ctor_erroneous.rs:18:18 | LL | fn accepts_point() {} | ^^^^^^^^^^^^^^ required by this const generic parameter in `accepts_point` error: the constant `MyEnum::::Variant` is not of type `MyEnum` - --> $DIR/tuple_ctor_erroneous.rs:43:22 + --> $DIR/tuple_ctor_erroneous.rs:44:22 | LL | accepts_enum::<{ MyEnum::Variant:: }>(); | ^^^^^^^^^^^^^^^^^^^^^^ expected `MyEnum`, found enum constructor | note: required by a const generic parameter in `accepts_enum` - --> $DIR/tuple_ctor_erroneous.rs:18:17 + --> $DIR/tuple_ctor_erroneous.rs:19:17 | LL | fn accepts_enum>() {} | ^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `accepts_enum` diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs index c932fdd248dae..ea0edad9e673f 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs @@ -1,6 +1,8 @@ #![feature(min_generic_const_args, adt_const_params, unsized_const_params)] #![expect(incomplete_features)] +use std::gca; + trait Trait { #[rustc_always_gca] const ASSOC: usize; @@ -10,11 +12,11 @@ fn takes_tuple() {} fn takes_nested_tuple() {} fn generic_caller() { - takes_tuple::<{ core::direct_const_arg!((N, N + 1)) }>(); //~ ERROR complex const arguments must be placed inside of a `const` block - takes_tuple::<{ core::direct_const_arg!((N, T::ASSOC + 1)) }>(); //~ ERROR complex const arguments must be placed inside of a `const` block + takes_tuple::<{ gca!((N, N + 1)) }>(); //~ ERROR complex const arguments must be placed inside of a `const` block + takes_tuple::<{ gca!((N, T::ASSOC + 1)) }>(); //~ ERROR complex const arguments must be placed inside of a `const` block - takes_nested_tuple::<{ core::direct_const_arg!((N, (N, N + 1))) }>(); //~ ERROR complex const arguments must be placed inside of a `const` block - takes_nested_tuple::<{ core::direct_const_arg!((N, (N, const { N + 1 }))) }>(); //~ ERROR generic parameters may not be used in const operations + takes_nested_tuple::<{ gca!((N, (N, N + 1))) }>(); //~ ERROR complex const arguments must be placed inside of a `const` block + takes_nested_tuple::<{ gca!((N, (N, const { N + 1 }))) }>(); //~ ERROR generic parameters may not be used in const operations } fn main() {} diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr index 1ab93b1995749..045b9dd790919 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr @@ -1,26 +1,26 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/tuple_expr_arg_complex.rs:13:49 + --> $DIR/tuple_expr_arg_complex.rs:15:30 | -LL | takes_tuple::<{ core::direct_const_arg!((N, N + 1)) }>(); - | ^^^^^ +LL | takes_tuple::<{ gca!((N, N + 1)) }>(); + | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/tuple_expr_arg_complex.rs:14:49 + --> $DIR/tuple_expr_arg_complex.rs:16:30 | -LL | takes_tuple::<{ core::direct_const_arg!((N, T::ASSOC + 1)) }>(); - | ^^^^^^^^^^^^ +LL | takes_tuple::<{ gca!((N, T::ASSOC + 1)) }>(); + | ^^^^^^^^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/tuple_expr_arg_complex.rs:16:60 + --> $DIR/tuple_expr_arg_complex.rs:18:41 | -LL | takes_nested_tuple::<{ core::direct_const_arg!((N, (N, N + 1))) }>(); - | ^^^^^ +LL | takes_nested_tuple::<{ gca!((N, (N, N + 1))) }>(); + | ^^^^^ error: generic parameters may not be used in const operations - --> $DIR/tuple_expr_arg_complex.rs:17:68 + --> $DIR/tuple_expr_arg_complex.rs:19:49 | -LL | takes_nested_tuple::<{ core::direct_const_arg!((N, (N, const { N + 1 }))) }>(); - | ^ +LL | takes_nested_tuple::<{ gca!((N, (N, const { N + 1 }))) }>(); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs b/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs index 70ca61c63c538..b4e664e1ca680 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs @@ -3,6 +3,8 @@ #![feature(min_generic_const_args, adt_const_params, unsized_const_params)] #![expect(incomplete_features)] +use std::gca; + trait Trait { #[rustc_always_gca] const ASSOC: u32; @@ -12,11 +14,11 @@ fn takes_tuple() {} fn takes_nested_tuple() {} fn generic_caller() { - takes_tuple::<{ core::direct_const_arg!((N, N2)) }>(); - takes_tuple::<{ core::direct_const_arg!((N, T::ASSOC)) }>(); + takes_tuple::<{ gca!((N, N2)) }>(); + takes_tuple::<{ gca!((N, T::ASSOC)) }>(); - takes_nested_tuple::<{ core::direct_const_arg!((N, (N, N2))) }>(); - takes_nested_tuple::<{ core::direct_const_arg!((N, (N, T::ASSOC))) }>(); + takes_nested_tuple::<{ gca!((N, (N, N2))) }>(); + takes_nested_tuple::<{ gca!((N, (N, T::ASSOC))) }>(); } fn main() {} diff --git a/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.rs b/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.rs index 7b9923994b0ac..d41110e594514 100644 --- a/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.rs +++ b/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.rs @@ -3,6 +3,8 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] +use std::gca; + trait Tr { #[rustc_always_gca] const SIZE: usize; @@ -13,7 +15,7 @@ struct T; impl Tr for T { const SIZE: usize; //~^ ERROR associated constant in `impl` without body - //~| ERROR implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS + //~| ERROR implementation of a `#[rustc_always_gca]` must have a `gca!` RHS } fn main() {} diff --git a/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.stderr b/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.stderr index 7425c09bb8a6a..ac0a3054d000f 100644 --- a/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.stderr +++ b/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.stderr @@ -1,19 +1,19 @@ error: associated constant in `impl` without body - --> $DIR/type-const-assoc-const-without-body.rs:14:5 + --> $DIR/type-const-assoc-const-without-body.rs:16:5 | LL | const SIZE: usize; | ^^^^^^^^^^^^^^^^^- | | | help: provide a definition for the constant: `= ;` -error: implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS - --> $DIR/type-const-assoc-const-without-body.rs:14:5 +error: implementation of a `#[rustc_always_gca]` must have a `gca!` RHS + --> $DIR/type-const-assoc-const-without-body.rs:16:5 | LL | const SIZE: usize; | ^^^^^^^^^^^^^^^^^ | note: trait declaration of const is marked as `#[rustc_always_gca]` - --> $DIR/type-const-assoc-const-without-body.rs:8:5 + --> $DIR/type-const-assoc-const-without-body.rs:10:5 | LL | const SIZE: usize; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/const-generics/mgca/type-const-associated-default.rs b/tests/ui/const-generics/mgca/type-const-associated-default.rs index a6d7869261b24..f2591248269cc 100644 --- a/tests/ui/const-generics/mgca/type-const-associated-default.rs +++ b/tests/ui/const-generics/mgca/type-const-associated-default.rs @@ -1,8 +1,9 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] +use std::gca; trait Trait { #[rustc_always_gca] - const N: usize = core::direct_const_arg!(10); + const N: usize = gca!(10); //~^ ERROR associated type defaults are unstable } diff --git a/tests/ui/const-generics/mgca/type-const-associated-default.stderr b/tests/ui/const-generics/mgca/type-const-associated-default.stderr index e2443d4e288e0..e08a8c75bc68e 100644 --- a/tests/ui/const-generics/mgca/type-const-associated-default.stderr +++ b/tests/ui/const-generics/mgca/type-const-associated-default.stderr @@ -1,8 +1,8 @@ error[E0658]: associated type defaults are unstable - --> $DIR/type-const-associated-default.rs:5:5 + --> $DIR/type-const-associated-default.rs:6:5 | -LL | const N: usize = core::direct_const_arg!(10); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const N: usize = gca!(10); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #29661 for more information = help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable diff --git a/tests/ui/const-generics/mgca/type-const-ctor-148953.rs b/tests/ui/const-generics/mgca/type-const-ctor-148953.rs index 2c5ce1a3f260d..774cab562cb61 100644 --- a/tests/ui/const-generics/mgca/type-const-ctor-148953.rs +++ b/tests/ui/const-generics/mgca/type-const-ctor-148953.rs @@ -10,13 +10,14 @@ #![feature(min_generic_const_args, adt_const_params)] #![expect(incomplete_features)] +use std::gca; use std::marker::ConstParamTy; #[derive(ConstParamTy, PartialEq, Eq)] struct S; impl S { - const N: S = core::direct_const_arg!(S); + const N: S = gca!(S); } #[derive(ConstParamTy, PartialEq, Eq)] @@ -25,7 +26,7 @@ enum E { } impl E { - const M: E = core::direct_const_arg!({ E::V }); + const M: E = gca!({ E::V }); } fn main() {} diff --git a/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.rs b/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.rs index 31f5ce56f3979..3b76abd2edc3c 100644 --- a/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.rs +++ b/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.rs @@ -2,10 +2,12 @@ #![feature(min_generic_const_args)] -const X: usize = core::direct_const_arg!(const { N }); +use std::gca; + +const X: usize = gca!(const { N }); //~^ ERROR type annotations needed -const N: usize = core::direct_const_arg!("this isn't a usize"); +const N: usize = gca!("this isn't a usize"); //~^ ERROR the constant `"this isn't a usize"` is not of type `usize` fn main() {} diff --git a/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.stderr b/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.stderr index f8655132e9574..60dd8699d180f 100644 --- a/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.stderr +++ b/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.stderr @@ -1,15 +1,15 @@ error[E0284]: type annotations needed - --> $DIR/type-const-free-anon-const-mismatch.rs:5:1 + --> $DIR/type-const-free-anon-const-mismatch.rs:7:1 | -LL | const X: usize = core::direct_const_arg!(const { N }); +LL | const X: usize = gca!(const { N }); | ^^^^^^^^^^^^^^ cannot infer the value of the constant `_` | = note: cannot satisfy `X::{constant#0} == _` error: the constant `"this isn't a usize"` is not of type `usize` - --> $DIR/type-const-free-anon-const-mismatch.rs:8:1 + --> $DIR/type-const-free-anon-const-mismatch.rs:10:1 | -LL | const N: usize = core::direct_const_arg!("this isn't a usize"); +LL | const N: usize = gca!("this isn't a usize"); | ^^^^^^^^^^^^^^ expected `usize`, found `&'static str` error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.current.stderr b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.current.stderr index 425de1e1b1d4b..a2bd54b0b2b21 100644 --- a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.current.stderr +++ b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.current.stderr @@ -1,11 +1,11 @@ error: the constant `"this isn't a usize"` is not of type `usize` - --> $DIR/type-const-free-value-type-mismatch.rs:8:1 + --> $DIR/type-const-free-value-type-mismatch.rs:10:1 | -LL | const N: usize = core::direct_const_arg!("this isn't a usize"); +LL | const N: usize = gca!("this isn't a usize"); | ^^^^^^^^^^^^^^ expected `usize`, found `&'static str` error[E0308]: mismatched types - --> $DIR/type-const-free-value-type-mismatch.rs:11:11 + --> $DIR/type-const-free-value-type-mismatch.rs:13:11 | LL | fn f() -> [u8; const { N }] {} | - ^^^^^^^^^^^^^^^^^ expected `[u8; const { N }]`, found `()` diff --git a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.next.stderr b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.next.stderr index 74fb8ab8999d9..d6b719115cad3 100644 --- a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.next.stderr +++ b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.next.stderr @@ -1,11 +1,11 @@ error: the constant `"this isn't a usize"` is not of type `usize` - --> $DIR/type-const-free-value-type-mismatch.rs:8:1 + --> $DIR/type-const-free-value-type-mismatch.rs:10:1 | -LL | const N: usize = core::direct_const_arg!("this isn't a usize"); +LL | const N: usize = gca!("this isn't a usize"); | ^^^^^^^^^^^^^^ expected `usize`, found `&'static str` error[E0284]: type annotations needed - --> $DIR/type-const-free-value-type-mismatch.rs:11:11 + --> $DIR/type-const-free-value-type-mismatch.rs:13:11 | LL | fn f() -> [u8; const { N }] {} | ^^^^^^^^^^^^^^^^^ cannot infer the value of the constant `_` @@ -13,7 +13,7 @@ LL | fn f() -> [u8; const { N }] {} = note: cannot satisfy `f::{constant#0} == _` error[E0308]: mismatched types - --> $DIR/type-const-free-value-type-mismatch.rs:11:11 + --> $DIR/type-const-free-value-type-mismatch.rs:13:11 | LL | fn f() -> [u8; const { N }] {} | - ^^^^^^^^^^^^^^^^^ expected `[u8; _]`, found `()` diff --git a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.rs b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.rs index 7cb465d114935..f49ac09ea3fcc 100644 --- a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.rs +++ b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.rs @@ -5,7 +5,9 @@ //@[next] compile-flags: -Znext-solver //@ compile-flags: -Zvalidate-mir -const N: usize = core::direct_const_arg!("this isn't a usize"); +use std::gca; + +const N: usize = gca!("this isn't a usize"); //~^ ERROR the constant `"this isn't a usize"` is not of type `usize` fn f() -> [u8; const { N }] {} diff --git a/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.rs b/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.rs index c1e0044b0947c..509bf3debc878 100644 --- a/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.rs +++ b/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.rs @@ -4,10 +4,12 @@ //@ compile-flags: --emit=mir -const CONST: usize = core::direct_const_arg!(1u32); +use std::gca; + +const CONST: usize = gca!(1u32); //~^ ERROR the constant `1` is not of type `usize` -const S: bool = core::direct_const_arg!(1i32); +const S: bool = gca!(1i32); //~^ ERROR the constant `1` is not of type `bool` fn main() { diff --git a/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.stderr b/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.stderr index 1e20f48b7515c..a03b3db0a73f3 100644 --- a/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.stderr +++ b/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.stderr @@ -1,13 +1,13 @@ error: the constant `1` is not of type `usize` - --> $DIR/type-const-free-value-used-in-body.rs:7:1 + --> $DIR/type-const-free-value-used-in-body.rs:9:1 | -LL | const CONST: usize = core::direct_const_arg!(1u32); +LL | const CONST: usize = gca!(1u32); | ^^^^^^^^^^^^^^^^^^ expected `usize`, found `u32` error: the constant `1` is not of type `bool` - --> $DIR/type-const-free-value-used-in-body.rs:10:1 + --> $DIR/type-const-free-value-used-in-body.rs:12:1 | -LL | const S: bool = core::direct_const_arg!(1i32); +LL | const S: bool = gca!(1i32); | ^^^^^^^^^^^^^ expected `bool`, found `i32` error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.current.stderr b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.current.stderr index 017bc22d7fe0f..1b87914503453 100644 --- a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.current.stderr +++ b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.current.stderr @@ -1,11 +1,11 @@ error: the constant `"this isn't a usize"` is not of type `usize` - --> $DIR/type-const-inherent-value-type-mismatch.rs:13:5 + --> $DIR/type-const-inherent-value-type-mismatch.rs:15:5 | -LL | const N: usize = core::direct_const_arg!("this isn't a usize"); +LL | const N: usize = gca!("this isn't a usize"); | ^^^^^^^^^^^^^^ expected `usize`, found `&'static str` error[E0308]: mismatched types - --> $DIR/type-const-inherent-value-type-mismatch.rs:17:11 + --> $DIR/type-const-inherent-value-type-mismatch.rs:19:11 | LL | fn f() -> [u8; const { Struct::N }] {} | - ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; const { Struct::N }]`, found `()` diff --git a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.next.stderr b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.next.stderr index 111a1801d7adb..0da310a55c369 100644 --- a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.next.stderr +++ b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.next.stderr @@ -1,5 +1,5 @@ error[E0284]: type annotations needed - --> $DIR/type-const-inherent-value-type-mismatch.rs:17:11 + --> $DIR/type-const-inherent-value-type-mismatch.rs:19:11 | LL | fn f() -> [u8; const { Struct::N }] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the constant `_` @@ -7,13 +7,13 @@ LL | fn f() -> [u8; const { Struct::N }] {} = note: cannot satisfy `f::{constant#0} == _` error: the constant `"this isn't a usize"` is not of type `usize` - --> $DIR/type-const-inherent-value-type-mismatch.rs:13:5 + --> $DIR/type-const-inherent-value-type-mismatch.rs:15:5 | -LL | const N: usize = core::direct_const_arg!("this isn't a usize"); +LL | const N: usize = gca!("this isn't a usize"); | ^^^^^^^^^^^^^^ expected `usize`, found `&'static str` error[E0308]: mismatched types - --> $DIR/type-const-inherent-value-type-mismatch.rs:17:11 + --> $DIR/type-const-inherent-value-type-mismatch.rs:19:11 | LL | fn f() -> [u8; const { Struct::N }] {} | - ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; _]`, found `()` diff --git a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.rs b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.rs index a08f31e686f2f..3a0fdd6bfd0ea 100644 --- a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.rs +++ b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.rs @@ -7,10 +7,12 @@ #![feature(min_generic_const_args)] +use std::gca; + struct Struct; impl Struct { - const N: usize = core::direct_const_arg!("this isn't a usize"); + const N: usize = gca!("this isn't a usize"); //~^ ERROR the constant `"this isn't a usize"` is not of type `usize` } diff --git a/tests/ui/const-generics/mgca/type-const-used-in-trait.rs b/tests/ui/const-generics/mgca/type-const-used-in-trait.rs index 71bdc472e2e22..1f921960710c5 100644 --- a/tests/ui/const-generics/mgca/type-const-used-in-trait.rs +++ b/tests/ui/const-generics/mgca/type-const-used-in-trait.rs @@ -3,7 +3,9 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] -const N: usize = core::direct_const_arg!(2); +use std::gca; + +const N: usize = gca!(2); trait CollectArray { fn inner_array(&mut self) -> [A; N]; diff --git a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.current.stderr b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.current.stderr index 614946eb7dc0f..dc7f73f2549e8 100644 --- a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.current.stderr +++ b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.current.stderr @@ -1,11 +1,11 @@ error[E0053]: method `arr` has an incompatible type for trait - --> $DIR/type-const-value-type-mismatch.rs:22:5 + --> $DIR/type-const-value-type-mismatch.rs:24:5 | LL | fn arr() -> [u8; const { Self::LEN }] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an array with a size of 0, found one with a size of const { Self::LEN } | note: type in trait - --> $DIR/type-const-value-type-mismatch.rs:15:5 + --> $DIR/type-const-value-type-mismatch.rs:17:5 | LL | fn arr() -> [u8; Self::LEN]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,13 +13,13 @@ LL | fn arr() -> [u8; Self::LEN]; found signature `fn() -> [u8; const { Self::LEN }]` error: the constant `0` is not of type `usize` - --> $DIR/type-const-value-type-mismatch.rs:19:5 + --> $DIR/type-const-value-type-mismatch.rs:21:5 | -LL | const LEN: usize = core::direct_const_arg!(0u8); +LL | const LEN: usize = gca!(0u8); | ^^^^^^^^^^^^^^^^ expected `usize`, found `u8` error[E0308]: mismatched types - --> $DIR/type-const-value-type-mismatch.rs:22:17 + --> $DIR/type-const-value-type-mismatch.rs:24:17 | LL | fn arr() -> [u8; const { Self::LEN }] {} | --- ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; const { Self::LEN }]`, found `()` diff --git a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.next.stderr b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.next.stderr index 9180bf19727cf..8e006112641a3 100644 --- a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.next.stderr +++ b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.next.stderr @@ -1,17 +1,17 @@ error[E0271]: type mismatch resolving `::LEN == _` - --> $DIR/type-const-value-type-mismatch.rs:22:5 + --> $DIR/type-const-value-type-mismatch.rs:24:5 | LL | fn arr() -> [u8; const { Self::LEN }] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ error: the constant `0` is not of type `usize` - --> $DIR/type-const-value-type-mismatch.rs:19:5 + --> $DIR/type-const-value-type-mismatch.rs:21:5 | -LL | const LEN: usize = core::direct_const_arg!(0u8); +LL | const LEN: usize = gca!(0u8); | ^^^^^^^^^^^^^^^^ expected `usize`, found `u8` error[E0284]: type annotations needed - --> $DIR/type-const-value-type-mismatch.rs:22:17 + --> $DIR/type-const-value-type-mismatch.rs:24:17 | LL | fn arr() -> [u8; const { Self::LEN }] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the constant `_` @@ -19,7 +19,7 @@ LL | fn arr() -> [u8; const { Self::LEN }] {} = note: cannot satisfy `::arr::{constant#0}::{constant#0} == _` error[E0308]: mismatched types - --> $DIR/type-const-value-type-mismatch.rs:22:17 + --> $DIR/type-const-value-type-mismatch.rs:24:17 | LL | fn arr() -> [u8; const { Self::LEN }] {} | --- ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; _]`, found `()` diff --git a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.rs b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.rs index 5609924575693..0a9f90e90de7f 100644 --- a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.rs +++ b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.rs @@ -7,6 +7,8 @@ #![feature(min_generic_const_args, macroless_generic_const_args)] +use std::gca; + pub struct A; pub trait Array { @@ -16,7 +18,7 @@ pub trait Array { } impl Array for A { - const LEN: usize = core::direct_const_arg!(0u8); + const LEN: usize = gca!(0u8); //~^ ERROR the constant `0` is not of type `usize` fn arr() -> [u8; const { Self::LEN }] {} diff --git a/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.rs b/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.rs index 4d4fcdb03164b..421b6b4cb5993 100644 --- a/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.rs +++ b/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.rs @@ -5,9 +5,11 @@ #![feature(macroless_generic_const_args)] #![feature(generic_const_items)] -const ADD1: usize = core::direct_const_arg!(const { N + 1 }); +use std::gca; + +const ADD1: usize = gca!(const { N + 1 }); //~^ ERROR: unconstrained generic constant -const AliasFnUnused: ADD1 = core::direct_const_arg!(ADD1::<{ Some:: {} }>); +const AliasFnUnused: ADD1 = gca!(ADD1::<{ Some:: {} }>); //~^ ERROR: cannot find type `ADD1` in this scope [E0573] //~| ERROR: struct expression with missing field initialiser for `0` diff --git a/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.stderr b/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.stderr index 7a5a299320459..623ae087687f5 100644 --- a/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.stderr +++ b/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.stderr @@ -1,27 +1,27 @@ error[E0573]: cannot find type `ADD1` in this scope - --> $DIR/type_const-adt-expr-missing-field.rs:10:22 + --> $DIR/type_const-adt-expr-missing-field.rs:12:22 | -LL | const AliasFnUnused: ADD1 = core::direct_const_arg!(ADD1::<{ Some:: {} }>); +LL | const AliasFnUnused: ADD1 = gca!(ADD1::<{ Some:: {} }>); | ^^^^ not found in this scope | = note: a constant named `ADD1` exists in another namespace error: unconstrained generic constant - --> $DIR/type_const-adt-expr-missing-field.rs:8:1 + --> $DIR/type_const-adt-expr-missing-field.rs:10:1 | -LL | const ADD1: usize = core::direct_const_arg!(const { N + 1 }); +LL | const ADD1: usize = gca!(const { N + 1 }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: try adding a `where` bound | -LL | const ADD1: usize where [(); const { N + 1 }]: = core::direct_const_arg!(const { N + 1 }); +LL | const ADD1: usize where [(); const { N + 1 }]: = gca!(const { N + 1 }); | ++++++++++++++++++++++++++++ error: struct expression with missing field initialiser for `0` - --> $DIR/type_const-adt-expr-missing-field.rs:10:62 + --> $DIR/type_const-adt-expr-missing-field.rs:12:43 | -LL | const AliasFnUnused: ADD1 = core::direct_const_arg!(ADD1::<{ Some:: {} }>); - | ^^^^^^^^^^^^^^^^ +LL | const AliasFnUnused: ADD1 = gca!(ADD1::<{ Some:: {} }>); + | ^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-array-return.rs b/tests/ui/const-generics/mgca/type_const-array-return.rs index 5b8f50925529d..ed27f0df8599b 100644 --- a/tests/ui/const-generics/mgca/type_const-array-return.rs +++ b/tests/ui/const-generics/mgca/type_const-array-return.rs @@ -3,6 +3,8 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args, macroless_generic_const_args)] +use std::gca; + pub struct A; pub trait Array { @@ -12,7 +14,7 @@ pub trait Array { } impl Array for A { - const LEN: usize = core::direct_const_arg!(4); + const LEN: usize = gca!(4); #[allow(unused_braces)] fn arr() -> [u8; const { Self::LEN }] { diff --git a/tests/ui/const-generics/mgca/type_const-generic-param-in-type.nogate.stderr b/tests/ui/const-generics/mgca/type_const-generic-param-in-type.nogate.stderr index 03251f4c7bd2b..46be38bb1a53d 100644 --- a/tests/ui/const-generics/mgca/type_const-generic-param-in-type.nogate.stderr +++ b/tests/ui/const-generics/mgca/type_const-generic-param-in-type.nogate.stderr @@ -1,37 +1,37 @@ error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:12:1 + --> $DIR/type_const-generic-param-in-type.rs:13:1 | -LL | const FOO: [T; 0] = core::direct_const_arg!([]); +LL | const FOO: [T; 0] = gca!([]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[T; 0]` must not depend on other generic parameter error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:15:1 + --> $DIR/type_const-generic-param-in-type.rs:16:1 | -LL | const BAR: StructWithConstParam = +LL | const BAR: StructWithConstParam = gca!(StructWithConstParam::); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `StructWithConstParam` must not depend on other generic parameter error[E0770]: the type of const parameters must not depend on other generic parameters --> $DIR/type_const-generic-param-in-type.rs:19:1 | -LL | const BAZ<'a>: [&'a (); 0] = core::direct_const_arg!([]); +LL | const BAZ<'a>: [&'a (); 0] = gca!([]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[&'a (); 0]` must not depend on other generic parameter error[E0770]: the type of const parameters must not depend on other generic parameters --> $DIR/type_const-generic-param-in-type.rs:37:5 | -LL | const ASSOC: [T; 0] = core::direct_const_arg!([]); +LL | const ASSOC: [T; 0] = gca!([]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[T; 0]` must not depend on other generic parameter error[E0770]: the type of const parameters must not depend on other generic parameters --> $DIR/type_const-generic-param-in-type.rs:40:5 | -LL | const ASSOC_CONST: StructWithConstParam = +LL | const ASSOC_CONST: StructWithConstParam = gca!(StructWithConstParam::); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `StructWithConstParam` must not depend on other generic parameter error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:44:5 + --> $DIR/type_const-generic-param-in-type.rs:43:5 | -LL | const ASSOC_LT<'a>: [&'a (); 0] = core::direct_const_arg!([]); +LL | const ASSOC_LT<'a>: [&'a (); 0] = gca!([]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the type `[&'a (); 0]` must not depend on other generic parameter error[E0770]: the type of const parameters must not depend on other generic parameters diff --git a/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs b/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs index e5e36b79eca57..d8c1627858257 100644 --- a/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs +++ b/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs @@ -4,19 +4,19 @@ #![feature(adt_const_params, unsized_const_params, min_generic_const_args, generic_const_items)] #![cfg_attr(gate, feature(generic_const_parameter_types))] +use std::gca; use std::marker::ConstParamTy; #[derive(ConstParamTy, PartialEq, Eq, Debug)] struct StructWithConstParam; -const FOO: [T; 0] = core::direct_const_arg!([]); +const FOO: [T; 0] = gca!([]); //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters -const BAR: StructWithConstParam = - //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters - core::direct_const_arg!(StructWithConstParam::); +const BAR: StructWithConstParam = gca!(StructWithConstParam::); +//[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters -const BAZ<'a>: [&'a (); 0] = core::direct_const_arg!([]); +const BAZ<'a>: [&'a (); 0] = gca!([]); //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters trait Tr { @@ -34,14 +34,13 @@ trait Tr { } impl Tr for () { - const ASSOC: [T; 0] = core::direct_const_arg!([]); + const ASSOC: [T; 0] = gca!([]); //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters - const ASSOC_CONST: StructWithConstParam = - //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters - core::direct_const_arg!(StructWithConstParam::); + const ASSOC_CONST: StructWithConstParam = gca!(StructWithConstParam::); + //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters - const ASSOC_LT<'a>: [&'a (); 0] = core::direct_const_arg!([]); + const ASSOC_LT<'a>: [&'a (); 0] = gca!([]); //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters } diff --git a/tests/ui/const-generics/mgca/type_const-incemental-compile.rs b/tests/ui/const-generics/mgca/type_const-incemental-compile.rs index 59581327cbb2d..7f82050044fad 100644 --- a/tests/ui/const-generics/mgca/type_const-incemental-compile.rs +++ b/tests/ui/const-generics/mgca/type_const-incemental-compile.rs @@ -6,5 +6,7 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -const TYPE_CONST: usize = core::direct_const_arg!(0); +use std::gca; + +const TYPE_CONST: usize = gca!(0); fn main() {} diff --git a/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.rs b/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.rs index 81c567f034e1e..32d052204ee27 100644 --- a/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.rs +++ b/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.rs @@ -1,10 +1,12 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] +use std::gca; + struct A; impl A { - const B = core::direct_const_arg!(4); + const B = gca!(4); //~^ ERROR: missing type for `const` item //~| ERROR: type annotations needed for the literal } diff --git a/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.stderr b/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.stderr index 742e5aff86285..04f8051509ab1 100644 --- a/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.stderr +++ b/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.stderr @@ -1,19 +1,19 @@ error: missing type for `const` item - --> $DIR/type_const-inherent-const-omitted-type.rs:7:12 + --> $DIR/type_const-inherent-const-omitted-type.rs:9:12 | -LL | const B = core::direct_const_arg!(4); +LL | const B = gca!(4); | ^ | help: provide a type for the item | -LL | const B: = core::direct_const_arg!(4); +LL | const B: = gca!(4); | ++++++++ error: type annotations needed for the literal - --> $DIR/type_const-inherent-const-omitted-type.rs:7:39 + --> $DIR/type_const-inherent-const-omitted-type.rs:9:20 | -LL | const B = core::direct_const_arg!(4); - | ^ +LL | const B = gca!(4); + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs index af59430e5b6ef..620c49cc6fe0f 100644 --- a/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs +++ b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs @@ -2,10 +2,13 @@ //! //@ incremental #![feature(min_generic_const_args)] -const R: usize = core::direct_const_arg!(1_i32); //~ ERROR: the constant `1` is not of type `usize` -const U: usize = core::direct_const_arg!(-1_i32); //~ ERROR: the constant `-1` is not of type `usize` -const S: bool = core::direct_const_arg!(1i32); //~ ERROR: the constant `1` is not of type `bool` -const T: bool = core::direct_const_arg!(-1i32); //~ ERROR: the constant `-1` is not of type `bool` + +use std::gca; + +const R: usize = gca!(1_i32); //~ ERROR: the constant `1` is not of type `usize` +const U: usize = gca!(-1_i32); //~ ERROR: the constant `-1` is not of type `usize` +const S: bool = gca!(1i32); //~ ERROR: the constant `1` is not of type `bool` +const T: bool = gca!(-1i32); //~ ERROR: the constant `-1` is not of type `bool` fn main() { R; diff --git a/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr index 86c807d9df356..2b05fe422b4a6 100644 --- a/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr +++ b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr @@ -1,25 +1,25 @@ error: the constant `1` is not of type `usize` - --> $DIR/type_const-mismatched-type-incremental.rs:5:1 + --> $DIR/type_const-mismatched-type-incremental.rs:8:1 | -LL | const R: usize = core::direct_const_arg!(1_i32); +LL | const R: usize = gca!(1_i32); | ^^^^^^^^^^^^^^ expected `usize`, found `i32` error: the constant `-1` is not of type `usize` - --> $DIR/type_const-mismatched-type-incremental.rs:6:1 + --> $DIR/type_const-mismatched-type-incremental.rs:9:1 | -LL | const U: usize = core::direct_const_arg!(-1_i32); +LL | const U: usize = gca!(-1_i32); | ^^^^^^^^^^^^^^ expected `usize`, found `i32` error: the constant `1` is not of type `bool` - --> $DIR/type_const-mismatched-type-incremental.rs:7:1 + --> $DIR/type_const-mismatched-type-incremental.rs:10:1 | -LL | const S: bool = core::direct_const_arg!(1i32); +LL | const S: bool = gca!(1i32); | ^^^^^^^^^^^^^ expected `bool`, found `i32` error: the constant `-1` is not of type `bool` - --> $DIR/type_const-mismatched-type-incremental.rs:8:1 + --> $DIR/type_const-mismatched-type-incremental.rs:11:1 | -LL | const T: bool = core::direct_const_arg!(-1i32); +LL | const T: bool = gca!(-1i32); | ^^^^^^^^^^^^^ expected `bool`, found `i32` error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-mismatched-types.rs b/tests/ui/const-generics/mgca/type_const-mismatched-types.rs index 9dbba436520c6..d4169868903b2 100644 --- a/tests/ui/const-generics/mgca/type_const-mismatched-types.rs +++ b/tests/ui/const-generics/mgca/type_const-mismatched-types.rs @@ -1,10 +1,12 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -const FREE: u32 = core::direct_const_arg!(5_usize); +use std::gca; + +const FREE: u32 = gca!(5_usize); //~^ ERROR the constant `5` is not of type `u32` -const FREE2: isize = core::direct_const_arg!(FREE); +const FREE2: isize = gca!(FREE); //~^ ERROR the constant `5` is not of type `u32` //~| ERROR the constant `5` is not of type `isize` @@ -14,7 +16,7 @@ trait Tr { } impl Tr for () { - const N: usize = core::direct_const_arg!(false); + const N: usize = gca!(false); //~^ ERROR the constant `false` is not of type `usize` } diff --git a/tests/ui/const-generics/mgca/type_const-mismatched-types.stderr b/tests/ui/const-generics/mgca/type_const-mismatched-types.stderr index e4b3e39180361..3cba92197dcae 100644 --- a/tests/ui/const-generics/mgca/type_const-mismatched-types.stderr +++ b/tests/ui/const-generics/mgca/type_const-mismatched-types.stderr @@ -1,25 +1,25 @@ error: the constant `5` is not of type `u32` - --> $DIR/type_const-mismatched-types.rs:4:1 + --> $DIR/type_const-mismatched-types.rs:6:1 | -LL | const FREE: u32 = core::direct_const_arg!(5_usize); +LL | const FREE: u32 = gca!(5_usize); | ^^^^^^^^^^^^^^^ expected `u32`, found `usize` error: the constant `5` is not of type `u32` - --> $DIR/type_const-mismatched-types.rs:7:1 + --> $DIR/type_const-mismatched-types.rs:9:1 | -LL | const FREE2: isize = core::direct_const_arg!(FREE); +LL | const FREE2: isize = gca!(FREE); | ^^^^^^^^^^^^^^^^^^ expected `u32`, found `usize` error: the constant `5` is not of type `isize` - --> $DIR/type_const-mismatched-types.rs:7:1 + --> $DIR/type_const-mismatched-types.rs:9:1 | -LL | const FREE2: isize = core::direct_const_arg!(FREE); +LL | const FREE2: isize = gca!(FREE); | ^^^^^^^^^^^^^^^^^^ expected `isize`, found `usize` error: the constant `false` is not of type `usize` - --> $DIR/type_const-mismatched-types.rs:17:5 + --> $DIR/type_const-mismatched-types.rs:19:5 | -LL | const N: usize = core::direct_const_arg!(false); +LL | const N: usize = gca!(false); | ^^^^^^^^^^^^^^ expected `usize`, found `bool` error: aborting due to 4 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-not-constparamty.rs b/tests/ui/const-generics/mgca/type_const-not-constparamty.rs index 27debb924ffd6..bc26ee967f573 100644 --- a/tests/ui/const-generics/mgca/type_const-not-constparamty.rs +++ b/tests/ui/const-generics/mgca/type_const-not-constparamty.rs @@ -1,11 +1,13 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] +use std::gca; + struct S; // FIXME(mgca): need support for ctors without anon const // (we use a const-block to trigger an anon const here) -const FREE: S = core::direct_const_arg!(const { S }); +const FREE: S = gca!(const { S }); //~^ ERROR `S` must implement `ConstParamTy` to be used as the type of a const generic parameter trait Tr { @@ -17,7 +19,7 @@ trait Tr { impl Tr for S { // FIXME(mgca): need support for ctors without anon const // (we use a const-block to trigger an anon const here) - const N: S = core::direct_const_arg!(const { S }); + const N: S = gca!(const { S }); //~^ ERROR `S` must implement `ConstParamTy` to be used as the type of a const generic parameter } diff --git a/tests/ui/const-generics/mgca/type_const-not-constparamty.stderr b/tests/ui/const-generics/mgca/type_const-not-constparamty.stderr index 7492432119943..9c55277eb3b39 100644 --- a/tests/ui/const-generics/mgca/type_const-not-constparamty.stderr +++ b/tests/ui/const-generics/mgca/type_const-not-constparamty.stderr @@ -1,7 +1,7 @@ error[E0741]: `S` must implement `ConstParamTy` to be used as the type of a const generic parameter - --> $DIR/type_const-not-constparamty.rs:8:13 + --> $DIR/type_const-not-constparamty.rs:10:13 | -LL | const FREE: S = core::direct_const_arg!(const { S }); +LL | const FREE: S = gca!(const { S }); | ^ | help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct @@ -11,9 +11,9 @@ LL | struct S; | error[E0741]: `S` must implement `ConstParamTy` to be used as the type of a const generic parameter - --> $DIR/type_const-not-constparamty.rs:20:14 + --> $DIR/type_const-not-constparamty.rs:22:14 | -LL | const N: S = core::direct_const_arg!(const { S }); +LL | const N: S = gca!(const { S }); | ^ | help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct @@ -23,7 +23,7 @@ LL | struct S; | error[E0741]: `S` must implement `ConstParamTy` to be used as the type of a const generic parameter - --> $DIR/type_const-not-constparamty.rs:13:14 + --> $DIR/type_const-not-constparamty.rs:15:14 | LL | const N: S; | ^ diff --git a/tests/ui/const-generics/mgca/type_const-on-generic-expr.rs b/tests/ui/const-generics/mgca/type_const-on-generic-expr.rs index 574a5febadaac..ce6ca6cf01bf0 100644 --- a/tests/ui/const-generics/mgca/type_const-on-generic-expr.rs +++ b/tests/ui/const-generics/mgca/type_const-on-generic-expr.rs @@ -1,10 +1,12 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args, generic_const_items)] -const FREE1: usize = core::direct_const_arg!(const { std::mem::size_of::() }); +use std::gca; + +const FREE1: usize = gca!(const { std::mem::size_of::() }); //~^ ERROR generic parameters may not be used in const operations -const FREE2: usize = core::direct_const_arg!(const { I + 1 }); +const FREE2: usize = gca!(const { I + 1 }); //~^ ERROR generic parameters may not be used in const operations fn main() {} diff --git a/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr b/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr index 1e11af4de9571..545675ead06a5 100644 --- a/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr +++ b/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr @@ -1,16 +1,16 @@ error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic-expr.rs:4:77 + --> $DIR/type_const-on-generic-expr.rs:6:58 | -LL | const FREE1: usize = core::direct_const_arg!(const { std::mem::size_of::() }); - | ^ +LL | const FREE1: usize = gca!(const { std::mem::size_of::() }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic-expr.rs:7:70 + --> $DIR/type_const-on-generic-expr.rs:9:51 | -LL | const FREE2: usize = core::direct_const_arg!(const { I + 1 }); - | ^ +LL | const FREE2: usize = gca!(const { I + 1 }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item diff --git a/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.rs b/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.rs index b82eb2f046485..59898c76f4e78 100644 --- a/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.rs +++ b/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.rs @@ -1,6 +1,8 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args, generic_const_items)] +use std::gca; + pub trait Tr { #[rustc_always_gca] const N1: usize; @@ -13,11 +15,11 @@ pub trait Tr { pub struct S; impl Tr for S { - const N1: usize = core::direct_const_arg!(const { std::mem::size_of::() }); + const N1: usize = gca!(const { std::mem::size_of::() }); //~^ ERROR generic parameters may not be used in const operations - const N2: usize = core::direct_const_arg!(const { I + 1 }); + const N2: usize = gca!(const { I + 1 }); //~^ ERROR generic parameters may not be used in const operations - const N3: usize = core::direct_const_arg!(const { 2 & X }); + const N3: usize = gca!(const { 2 & X }); //~^ ERROR generic parameters may not be used in const operations } diff --git a/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr b/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr index cac6858b937c0..4eb207e110fdb 100644 --- a/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr +++ b/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr @@ -1,24 +1,24 @@ error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic_expr-2.rs:16:78 + --> $DIR/type_const-on-generic_expr-2.rs:18:59 | -LL | const N1: usize = core::direct_const_arg!(const { std::mem::size_of::() }); - | ^ +LL | const N1: usize = gca!(const { std::mem::size_of::() }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic_expr-2.rs:18:71 + --> $DIR/type_const-on-generic_expr-2.rs:20:52 | -LL | const N2: usize = core::direct_const_arg!(const { I + 1 }); - | ^ +LL | const N2: usize = gca!(const { I + 1 }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic_expr-2.rs:20:59 + --> $DIR/type_const-on-generic_expr-2.rs:22:40 | -LL | const N3: usize = core::direct_const_arg!(const { 2 & X }); - | ^ +LL | const N3: usize = gca!(const { 2 & X }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item diff --git a/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.rs b/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.rs index 853eb37aae3f0..5a716807fc3e4 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.rs +++ b/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.rs @@ -1,6 +1,8 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] +use std::gca; + trait BadTr { const NUM: usize; } @@ -8,10 +10,10 @@ trait BadTr { struct GoodS; impl BadTr for GoodS { - const NUM: = core::direct_const_arg!(84); + const NUM: = gca!(84); //~^ ERROR: missing type for `const` item //~| ERROR: type annotations needed for the literal - //~| ERROR: implementation of a regular const cannot have a `direct_const_arg!` RHS + //~| ERROR: implementation of a regular const cannot have a `gca!` RHS } fn accept_bad_tr>(_x: &T) {} diff --git a/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.stderr b/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.stderr index 445d5d4a2efd9..18dc857d1deb0 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.stderr +++ b/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.stderr @@ -1,29 +1,29 @@ error: missing type for `const` item - --> $DIR/type_const-only-in-impl-omitted-type.rs:11:15 + --> $DIR/type_const-only-in-impl-omitted-type.rs:13:15 | -LL | const NUM: = core::direct_const_arg!(84); +LL | const NUM: = gca!(84); | ^ help: provide a type for the associated constant: `usize` error: type annotations needed for the literal - --> $DIR/type_const-only-in-impl-omitted-type.rs:11:42 + --> $DIR/type_const-only-in-impl-omitted-type.rs:13:23 | -LL | const NUM: = core::direct_const_arg!(84); - | ^^ +LL | const NUM: = gca!(84); + | ^^ -error: implementation of a regular const cannot have a `direct_const_arg!` RHS - --> $DIR/type_const-only-in-impl-omitted-type.rs:11:5 +error: implementation of a regular const cannot have a `gca!` RHS + --> $DIR/type_const-only-in-impl-omitted-type.rs:13:5 | -LL | const NUM: = core::direct_const_arg!(84); +LL | const NUM: = gca!(84); | ^^^^^^^^^^ | note: trait declaration of const is not marked as `#[rustc_always_gca]` - --> $DIR/type_const-only-in-impl-omitted-type.rs:5:5 + --> $DIR/type_const-only-in-impl-omitted-type.rs:7:5 | LL | const NUM: usize; | ^^^^^^^^^^^^^^^^ error: use of trait associated const not defined as `#[rustc_always_gca]` - --> $DIR/type_const-only-in-impl-omitted-type.rs:17:43 + --> $DIR/type_const-only-in-impl-omitted-type.rs:19:43 | LL | fn accept_bad_tr>(_x: &T) {} | ^^^^^^^^^^^ diff --git a/tests/ui/const-generics/mgca/type_const-only-in-impl.rs b/tests/ui/const-generics/mgca/type_const-only-in-impl.rs index 3f8b924af0799..f536e810348d8 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-impl.rs +++ b/tests/ui/const-generics/mgca/type_const-only-in-impl.rs @@ -1,6 +1,8 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] +use std::gca; + trait BadTr { const NUM: usize; } @@ -8,8 +10,8 @@ trait BadTr { struct GoodS; impl BadTr for GoodS { - const NUM: usize = core::direct_const_arg!(84); - //~^ ERROR implementation of a regular const cannot have a `direct_const_arg!` RHS + const NUM: usize = gca!(84); + //~^ ERROR implementation of a regular const cannot have a `gca!` RHS } fn accept_bad_tr>(_x: &T) {} diff --git a/tests/ui/const-generics/mgca/type_const-only-in-impl.stderr b/tests/ui/const-generics/mgca/type_const-only-in-impl.stderr index cc32eafad40fc..99b49c6e8bdcd 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-impl.stderr +++ b/tests/ui/const-generics/mgca/type_const-only-in-impl.stderr @@ -1,17 +1,17 @@ -error: implementation of a regular const cannot have a `direct_const_arg!` RHS - --> $DIR/type_const-only-in-impl.rs:11:5 +error: implementation of a regular const cannot have a `gca!` RHS + --> $DIR/type_const-only-in-impl.rs:13:5 | -LL | const NUM: usize = core::direct_const_arg!(84); +LL | const NUM: usize = gca!(84); | ^^^^^^^^^^^^^^^^ | note: trait declaration of const is not marked as `#[rustc_always_gca]` - --> $DIR/type_const-only-in-impl.rs:5:5 + --> $DIR/type_const-only-in-impl.rs:7:5 | LL | const NUM: usize; | ^^^^^^^^^^^^^^^^ error: use of trait associated const not defined as `#[rustc_always_gca]` - --> $DIR/type_const-only-in-impl.rs:15:43 + --> $DIR/type_const-only-in-impl.rs:17:43 | LL | fn accept_bad_tr>(_x: &T) {} | ^^^^^^^^^^^ diff --git a/tests/ui/const-generics/mgca/type_const-only-in-trait.rs b/tests/ui/const-generics/mgca/type_const-only-in-trait.rs index 82c5a6f8417a5..687adf8371272 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-trait.rs +++ b/tests/ui/const-generics/mgca/type_const-only-in-trait.rs @@ -1,6 +1,8 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] +use std::gca; + trait GoodTr { #[rustc_always_gca] const NUM: usize; @@ -10,7 +12,7 @@ struct BadS; impl GoodTr for BadS { const NUM: usize = 42; - //~^ ERROR implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS + //~^ ERROR implementation of a `#[rustc_always_gca]` must have a `gca!` RHS } fn accept_good_tr>(_x: &T) {} diff --git a/tests/ui/const-generics/mgca/type_const-only-in-trait.stderr b/tests/ui/const-generics/mgca/type_const-only-in-trait.stderr index e2ba59133925f..cab3f9b08aec1 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-trait.stderr +++ b/tests/ui/const-generics/mgca/type_const-only-in-trait.stderr @@ -1,11 +1,11 @@ -error: implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS - --> $DIR/type_const-only-in-trait.rs:12:5 +error: implementation of a `#[rustc_always_gca]` must have a `gca!` RHS + --> $DIR/type_const-only-in-trait.rs:14:5 | LL | const NUM: usize = 42; | ^^^^^^^^^^^^^^^^ | note: trait declaration of const is marked as `#[rustc_always_gca]` - --> $DIR/type_const-only-in-trait.rs:6:5 + --> $DIR/type_const-only-in-trait.rs:8:5 | LL | const NUM: usize; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/const-generics/mgca/type_const-pub.rs b/tests/ui/const-generics/mgca/type_const-pub.rs index 36936e22726d4..9499e7e952384 100644 --- a/tests/ui/const-generics/mgca/type_const-pub.rs +++ b/tests/ui/const-generics/mgca/type_const-pub.rs @@ -5,7 +5,9 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -pub const TYPE_CONST: usize = core::direct_const_arg!(1); +use std::gca; + +pub const TYPE_CONST: usize = gca!(1); fn main() { print!("{}", TYPE_CONST) } diff --git a/tests/ui/const-generics/mgca/type_const-recursive.rs b/tests/ui/const-generics/mgca/type_const-recursive.rs index 1963cdce9fe4c..c7178da8f437c 100644 --- a/tests/ui/const-generics/mgca/type_const-recursive.rs +++ b/tests/ui/const-generics/mgca/type_const-recursive.rs @@ -1,7 +1,9 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -const A: u8 = core::direct_const_arg!(A); +use std::gca; + +const A: u8 = gca!(A); //~^ ERROR: cycle detected when computing the type-level value for `A` [E0391] fn main() {} diff --git a/tests/ui/const-generics/mgca/type_const-recursive.stderr b/tests/ui/const-generics/mgca/type_const-recursive.stderr index 2dd4102b472bc..551fc016b2c73 100644 --- a/tests/ui/const-generics/mgca/type_const-recursive.stderr +++ b/tests/ui/const-generics/mgca/type_const-recursive.stderr @@ -1,7 +1,7 @@ error[E0391]: cycle detected when computing the type-level value for `A` - --> $DIR/type_const-recursive.rs:4:1 + --> $DIR/type_const-recursive.rs:6:1 | -LL | const A: u8 = core::direct_const_arg!(A); +LL | const A: u8 = gca!(A); | ^^^^^^^^^^^ | = note: ...which immediately requires computing the type-level value for `A` again diff --git a/tests/ui/const-generics/mgca/type_const-use.rs b/tests/ui/const-generics/mgca/type_const-use.rs index cef0d10f0c4ed..e8900e0d4e69e 100644 --- a/tests/ui/const-generics/mgca/type_const-use.rs +++ b/tests/ui/const-generics/mgca/type_const-use.rs @@ -3,7 +3,9 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -const CONST: usize = core::direct_const_arg!(1); +use std::gca; + +const CONST: usize = gca!(1); fn uses_const() { CONST; diff --git a/tests/ui/const-generics/mgca/type_const_in_pattern.rs b/tests/ui/const-generics/mgca/type_const_in_pattern.rs index 01fae246f9293..52d824343c2a6 100644 --- a/tests/ui/const-generics/mgca/type_const_in_pattern.rs +++ b/tests/ui/const-generics/mgca/type_const_in_pattern.rs @@ -3,12 +3,14 @@ #![expect(incomplete_features)] #![allow(irrefutable_let_patterns)] -const CONST: usize = core::direct_const_arg!(1_usize); +use std::gca; + +const CONST: usize = gca!(1_usize); struct Inherent; impl Inherent { - const BAR: usize = core::direct_const_arg!(1_usize); + const BAR: usize = gca!(1_usize); } trait Trait { @@ -19,7 +21,7 @@ trait Trait { struct Assoc; impl Trait for Assoc { - const BAZ: usize = core::direct_const_arg!(1_usize); + const BAZ: usize = gca!(1_usize); } fn main() { diff --git a/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.rs b/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.rs index e341727407143..9e6370c485a0b 100644 --- a/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.rs +++ b/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.rs @@ -1,5 +1,7 @@ #![feature(adt_const_params)] +use std::gca; + #[derive(Eq, PartialEq, std::marker::ConstParamTy)] struct Inner; @@ -32,9 +34,9 @@ fn generic() { const NON_TYPE_CONST: usize = const { 1 }; -const TYPE_CONST: usize = core::direct_const_arg!(const { 1 }); +const TYPE_CONST: usize = gca!(const { 1 }); //~^ ERROR: use of unstable library feature `min_generic_const_args` [E0658] -//~| ERROR: expected expression, found `direct_const_arg!()` constant +//~| ERROR: expected expression, found `gca!()` constant static STATIC: usize = const { 1 }; diff --git a/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.stderr b/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.stderr index bd2b5238a9356..8467c3abdc942 100644 --- a/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.stderr +++ b/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.stderr @@ -1,15 +1,15 @@ error[E0658]: use of unstable library feature `min_generic_const_args` - --> $DIR/unbraced_const_block_const_arg_gated.rs:35:27 + --> $DIR/unbraced_const_block_const_arg_gated.rs:37:27 | -LL | const TYPE_CONST: usize = core::direct_const_arg!(const { 1 }); - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | const TYPE_CONST: usize = gca!(const { 1 }); + | ^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: unbraced const blocks as const args are experimental - --> $DIR/unbraced_const_block_const_arg_gated.rs:7:27 + --> $DIR/unbraced_const_block_const_arg_gated.rs:9:27 | LL | const PARAM_TY: Inner, | ^^^^^^^^^^^ @@ -19,7 +19,7 @@ LL | const PARAM_TY: Inner, = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: unbraced const blocks as const args are experimental - --> $DIR/unbraced_const_block_const_arg_gated.rs:9:28 + --> $DIR/unbraced_const_block_const_arg_gated.rs:11:28 | LL | const DEFAULT: usize = const { 1 }, | ^^^^^^^^^^^ @@ -29,7 +29,7 @@ LL | const DEFAULT: usize = const { 1 }, = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: unbraced const blocks as const args are experimental - --> $DIR/unbraced_const_block_const_arg_gated.rs:14:23 + --> $DIR/unbraced_const_block_const_arg_gated.rs:16:23 | LL | type NormalTy = Inner; | ^^^^^^^^^^^ @@ -39,7 +39,7 @@ LL | type NormalTy = Inner; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: unbraced const blocks as const args are experimental - --> $DIR/unbraced_const_block_const_arg_gated.rs:22:18 + --> $DIR/unbraced_const_block_const_arg_gated.rs:24:18 | LL | let _: Inner; | ^^^^^^^^^^^ @@ -49,7 +49,7 @@ LL | let _: Inner; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: unbraced const blocks as const args are experimental - --> $DIR/unbraced_const_block_const_arg_gated.rs:28:19 + --> $DIR/unbraced_const_block_const_arg_gated.rs:30:19 | LL | generic::(); | ^^^^^^^^^^^ @@ -58,11 +58,11 @@ LL | generic::(); = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: expected expression, found `direct_const_arg!()` constant - --> $DIR/unbraced_const_block_const_arg_gated.rs:35:27 +error: expected expression, found `gca!()` constant + --> $DIR/unbraced_const_block_const_arg_gated.rs:37:27 | -LL | const TYPE_CONST: usize = core::direct_const_arg!(const { 1 }); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const TYPE_CONST: usize = gca!(const { 1 }); + | ^^^^^^^^^^^^^^^^^ error: aborting due to 7 previous errors diff --git a/tests/ui/const-generics/mgca/unmarked-free-const.rs b/tests/ui/const-generics/mgca/unmarked-free-const.rs index e118b486f2c77..04cf63b71ed07 100644 --- a/tests/ui/const-generics/mgca/unmarked-free-const.rs +++ b/tests/ui/const-generics/mgca/unmarked-free-const.rs @@ -3,9 +3,11 @@ #![feature(min_generic_const_args)] #![allow(incomplete_features)] +use std::gca; + const N: usize = 4; fn main() { - let x = [(); core::direct_const_arg!(N)]; + let x = [(); gca!(N)]; //~^ ERROR use of `const` in the type system not marked as direct } diff --git a/tests/ui/const-generics/mgca/unmarked-free-const.stderr b/tests/ui/const-generics/mgca/unmarked-free-const.stderr index 246a8200247c1..de797a46f33ce 100644 --- a/tests/ui/const-generics/mgca/unmarked-free-const.stderr +++ b/tests/ui/const-generics/mgca/unmarked-free-const.stderr @@ -1,13 +1,13 @@ error: use of `const` in the type system not marked as direct - --> $DIR/unmarked-free-const.rs:9:42 + --> $DIR/unmarked-free-const.rs:11:23 | -LL | let x = [(); core::direct_const_arg!(N)]; - | ^ +LL | let x = [(); gca!(N)]; + | ^ | -help: add direct_const_arg!() to the right-hand side of the constant +help: add gca!() to the right-hand side of the constant | -LL | const N: usize = core::direct_const_arg!(4); - | ++++++++++++++++++++++++ + +LL | const N: usize = core::gca!(4); + | +++++++++++ + error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/type-const-ice-issue-151631.rs b/tests/ui/const-generics/type-const-ice-issue-151631.rs index 8112d21a923f0..6133feba70a3b 100644 --- a/tests/ui/const-generics/type-const-ice-issue-151631.rs +++ b/tests/ui/const-generics/type-const-ice-issue-151631.rs @@ -3,6 +3,8 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] +use std::gca; + trait SuperTrait {} trait Trait: SuperTrait { #[rustc_always_gca] @@ -10,7 +12,7 @@ trait Trait: SuperTrait { } impl Trait for () { //~^ ERROR: the trait bound `(): SuperTrait` is not satisfied - const K: u32 = core::direct_const_arg!(const { 1 }); + const K: u32 = gca!(const { 1 }); } fn check(_: impl Trait) {} diff --git a/tests/ui/const-generics/type-const-ice-issue-151631.stderr b/tests/ui/const-generics/type-const-ice-issue-151631.stderr index aa934b91fb5a4..2a42518efc790 100644 --- a/tests/ui/const-generics/type-const-ice-issue-151631.stderr +++ b/tests/ui/const-generics/type-const-ice-issue-151631.stderr @@ -1,22 +1,22 @@ error[E0277]: the trait bound `(): SuperTrait` is not satisfied - --> $DIR/type-const-ice-issue-151631.rs:11:16 + --> $DIR/type-const-ice-issue-151631.rs:13:16 | LL | impl Trait for () { | ^^ the trait `SuperTrait` is not implemented for `()` | help: this trait has no implementations, consider adding one - --> $DIR/type-const-ice-issue-151631.rs:6:1 + --> $DIR/type-const-ice-issue-151631.rs:8:1 | LL | trait SuperTrait {} | ^^^^^^^^^^^^^^^^ note: required by a bound in `Trait` - --> $DIR/type-const-ice-issue-151631.rs:7:14 + --> $DIR/type-const-ice-issue-151631.rs:9:14 | LL | trait Trait: SuperTrait { | ^^^^^^^^^^ required by this bound in `Trait` error[E0271]: type mismatch resolving `<() as Trait>::K == 0` - --> $DIR/type-const-ice-issue-151631.rs:19:11 + --> $DIR/type-const-ice-issue-151631.rs:21:11 | LL | check(()); | ----- ^^ expected `0`, found `1` @@ -26,7 +26,7 @@ LL | check(()); = note: expected constant `0` found constant `1` note: required by a bound in `check` - --> $DIR/type-const-ice-issue-151631.rs:16:24 + --> $DIR/type-const-ice-issue-151631.rs:18:24 | LL | fn check(_: impl Trait) {} | ^^^^^ required by this bound in `check` diff --git a/tests/ui/const-generics/type-relative-path-144547.rs b/tests/ui/const-generics/type-relative-path-144547.rs index 399918ec6cffc..35722efd17fd4 100644 --- a/tests/ui/const-generics/type-relative-path-144547.rs +++ b/tests/ui/const-generics/type-relative-path-144547.rs @@ -22,7 +22,7 @@ struct Info; impl LevelInfo for Info { #[cfg(mgca)] - const SUPPORTED_SLOTS: usize = core::direct_const_arg!(1); + const SUPPORTED_SLOTS: usize = std::gca!(1); #[cfg(not(mgca))] const SUPPORTED_SLOTS: usize = 1; diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155125.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155125.stderr index 30aad09279447..290c5a492fa90 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155125.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155125.stderr @@ -1,5 +1,5 @@ error[E0428]: the name `foo` is defined multiple times - --> $DIR/hir-crate-items-before-lowering-ices.rs:13:17 + --> $DIR/hir-crate-items-before-lowering-ices.rs:14:17 | LL | fn foo() {} | -------- previous definition of the value `foo` here @@ -9,10 +9,10 @@ LL | reuse foo; = note: `foo` must be defined only once in the value namespace of this block error: complex const arguments must be placed inside of a `const` block - --> $DIR/hir-crate-items-before-lowering-ices.rs:11:37 + --> $DIR/hir-crate-items-before-lowering-ices.rs:12:18 | -LL | core::direct_const_arg!({ - | _____________________________________^ +LL | gca!({ + | __________________^ LL | | fn foo() {} LL | | reuse foo; LL | | 2 diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr index e38645655a8a5..571a0f7198df9 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155127.stderr @@ -1,5 +1,5 @@ error: the `deprecated` attribute cannot be used on delegations - --> $DIR/hir-crate-items-before-lowering-ices.rs:27:11 + --> $DIR/hir-crate-items-before-lowering-ices.rs:28:11 | LL | #[deprecated] | ^^^^^^^^^^ diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155128.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155128.stderr index 674035c79f019..9f1e95d570b53 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155128.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155128.stderr @@ -1,5 +1,5 @@ error: delegation's target expression is specified for function with no params - --> $DIR/hir-crate-items-before-lowering-ices.rs:37:18 + --> $DIR/hir-crate-items-before-lowering-ices.rs:38:18 | LL | reuse a as b { | __________________^ @@ -10,7 +10,7 @@ LL | | } | |_____^ error[E0061]: this function takes 0 arguments but 1 argument was supplied - --> $DIR/hir-crate-items-before-lowering-ices.rs:37:11 + --> $DIR/hir-crate-items-before-lowering-ices.rs:38:11 | LL | reuse a as b { | ___________^______- @@ -21,7 +21,7 @@ LL | | } | |_____- unexpected argument of type `fn() {foo::<_>}` | note: function defined here - --> $DIR/hir-crate-items-before-lowering-ices.rs:35:8 + --> $DIR/hir-crate-items-before-lowering-ices.rs:36:8 | LL | fn a() {} | ^ diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155164.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155164.stderr index b44a3c4174540..132c93b6c5532 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155164.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155164.stderr @@ -1,8 +1,8 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/hir-crate-items-before-lowering-ices.rs:48:37 + --> $DIR/hir-crate-items-before-lowering-ices.rs:50:18 | -LL | core::direct_const_arg!({ - | _____________________________________^ +LL | gca!({ + | __________________^ LL | | LL | | struct W; LL | | impl W { diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155202.stderr b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155202.stderr index 5012905807597..d331191ac24e0 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155202.stderr +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.ice_155202.stderr @@ -1,5 +1,5 @@ error: function cannot return without recursing - --> $DIR/hir-crate-items-before-lowering-ices.rs:67:22 + --> $DIR/hir-crate-items-before-lowering-ices.rs:69:22 | LL | reuse Trait::bar { | ^^^ @@ -9,7 +9,7 @@ LL | reuse Trait::bar { | = help: a `loop` may express intention better if this is on purpose note: the lint level is defined here - --> $DIR/hir-crate-items-before-lowering-ices.rs:61:8 + --> $DIR/hir-crate-items-before-lowering-ices.rs:63:8 | LL | #[deny(unconditional_recursion)] | ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/delegation/hir-crate-items-before-lowering-ices.rs b/tests/ui/delegation/hir-crate-items-before-lowering-ices.rs index 5689a29cafe11..cbe6cdd06df7e 100644 --- a/tests/ui/delegation/hir-crate-items-before-lowering-ices.rs +++ b/tests/ui/delegation/hir-crate-items-before-lowering-ices.rs @@ -5,10 +5,11 @@ #[cfg(ice_155125)] mod ice_155125 { + use std::gca; struct S; impl S< - core::direct_const_arg!({ //[ice_155125]~ ERROR: complex const arguments must be placed inside of a `const` block + gca!({ //[ice_155125]~ ERROR: complex const arguments must be placed inside of a `const` block fn foo() {} reuse foo; //[ice_155125]~ ERROR: the name `foo` is defined multiple times 2 @@ -43,9 +44,10 @@ mod ice_155128 { #[cfg(ice_155164)] mod ice_155164 { + use std::gca; struct X { inner: std::iter::Map< - core::direct_const_arg!({ + gca!({ //[ice_155164]~^ ERROR: complex const arguments must be placed inside of a `const` block struct W; impl W { diff --git a/tests/ui/delegation/inside-const-body-ice-155300.rs b/tests/ui/delegation/inside-const-body-ice-155300.rs index 2d13007bc807b..224f84845b354 100644 --- a/tests/ui/delegation/inside-const-body-ice-155300.rs +++ b/tests/ui/delegation/inside-const-body-ice-155300.rs @@ -1,11 +1,13 @@ #![feature(min_generic_const_args)] #![feature(fn_delegation)] +use std::gca; + pub struct S; impl S< - core::direct_const_arg!({ + gca!({ //~^ ERROR: complex const arguments must be placed inside of a `const` block fn foo() {} reuse foo::<> as bar; diff --git a/tests/ui/delegation/inside-const-body-ice-155300.stderr b/tests/ui/delegation/inside-const-body-ice-155300.stderr index f0cb830109f8a..d30f240556ac4 100644 --- a/tests/ui/delegation/inside-const-body-ice-155300.stderr +++ b/tests/ui/delegation/inside-const-body-ice-155300.stderr @@ -1,5 +1,5 @@ error[E0428]: the name `bar` is defined multiple times - --> $DIR/inside-const-body-ice-155300.rs:12:13 + --> $DIR/inside-const-body-ice-155300.rs:14:13 | LL | reuse foo::<> as bar; | --------------------- previous definition of the value `bar` here @@ -9,10 +9,10 @@ LL | reuse bar; = note: `bar` must be defined only once in the value namespace of this block error: complex const arguments must be placed inside of a `const` block - --> $DIR/inside-const-body-ice-155300.rs:8:33 + --> $DIR/inside-const-body-ice-155300.rs:10:14 | -LL | core::direct_const_arg!({ - | _________________________________^ +LL | gca!({ + | ______________^ LL | | LL | | fn foo() {} LL | | reuse foo::<> as bar; diff --git a/tests/ui/delegation/wrong-fn-kind-ice-159127.rs b/tests/ui/delegation/wrong-fn-kind-ice-159127.rs index e117826ef099c..e1cde084600fd 100644 --- a/tests/ui/delegation/wrong-fn-kind-ice-159127.rs +++ b/tests/ui/delegation/wrong-fn-kind-ice-159127.rs @@ -1,9 +1,11 @@ #![feature(fn_delegation)] #![feature(min_generic_const_args)] +use std::gca; + impl - core::direct_const_arg!({ - //~^ ERROR: expected type, found `direct_const_arg!()` constant + gca!({ + //~^ ERROR: expected type, found `gca!()` constant fn foo() {} reuse foo::<>as bar; reuse bar; diff --git a/tests/ui/delegation/wrong-fn-kind-ice-159127.stderr b/tests/ui/delegation/wrong-fn-kind-ice-159127.stderr index bc218f39ab65a..8afa2c45bdc4b 100644 --- a/tests/ui/delegation/wrong-fn-kind-ice-159127.stderr +++ b/tests/ui/delegation/wrong-fn-kind-ice-159127.stderr @@ -1,5 +1,5 @@ error[E0428]: the name `bar` is defined multiple times - --> $DIR/wrong-fn-kind-ice-159127.rs:9:9 + --> $DIR/wrong-fn-kind-ice-159127.rs:11:9 | LL | reuse foo::<>as bar; | -------------------- previous definition of the value `bar` here @@ -8,10 +8,10 @@ LL | reuse bar; | = note: `bar` must be defined only once in the value namespace of this block -error: expected type, found `direct_const_arg!()` constant - --> $DIR/wrong-fn-kind-ice-159127.rs:5:5 +error: expected type, found `gca!()` constant + --> $DIR/wrong-fn-kind-ice-159127.rs:7:5 | -LL | / core::direct_const_arg!({ +LL | / gca!({ LL | | LL | | fn foo() {} LL | | reuse foo::<>as bar; diff --git a/tests/ui/feature-gates/feature-gate-generic-const-args.rs b/tests/ui/feature-gates/feature-gate-generic-const-args.rs index c9403a269a8bc..e5bc617d96e4d 100644 --- a/tests/ui/feature-gates/feature-gate-generic-const-args.rs +++ b/tests/ui/feature-gates/feature-gate-generic-const-args.rs @@ -1,7 +1,9 @@ #![feature(generic_const_items, min_generic_const_args)] #![expect(incomplete_features)] -const INC: usize = core::direct_const_arg!(const { N + 1 }); +use std::gca; + +const INC: usize = gca!(const { N + 1 }); //~^ ERROR generic parameters may not be used in const operations //~| HELP add `#![feature(generic_const_args)]` diff --git a/tests/ui/feature-gates/feature-gate-generic-const-args.stderr b/tests/ui/feature-gates/feature-gate-generic-const-args.stderr index 6094430968f51..7d4c5a67c56a6 100644 --- a/tests/ui/feature-gates/feature-gate-generic-const-args.stderr +++ b/tests/ui/feature-gates/feature-gate-generic-const-args.stderr @@ -1,8 +1,8 @@ error: generic parameters may not be used in const operations - --> $DIR/feature-gate-generic-const-args.rs:4:68 + --> $DIR/feature-gate-generic-const-args.rs:6:49 | -LL | const INC: usize = core::direct_const_arg!(const { N + 1 }); - | ^ +LL | const INC: usize = gca!(const { N + 1 }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item diff --git a/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs b/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs index 9737d9c521ac7..8da5824d9c49c 100644 --- a/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs +++ b/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs @@ -1,6 +1,6 @@ -const FOO: u8 = core::direct_const_arg!(10); +const FOO: u8 = std::gca!(10); //~^ ERROR use of unstable library feature `min_generic_const_args` [E0658] -//~| ERROR expected expression, found `direct_const_arg!()` constant +//~| ERROR expected expression, found `gca!()` constant trait Bar { #[rustc_always_gca] @@ -9,10 +9,10 @@ trait Bar { } impl Bar for bool { - const BAR: bool = core::direct_const_arg!(false); + const BAR: bool = std::gca!(false); //~^ ERROR use of unstable library feature `min_generic_const_args` [E0658] - //~| ERROR expected expression, found `direct_const_arg!()` constant - //~| ERROR implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS + //~| ERROR expected expression, found `gca!()` constant + //~| ERROR implementation of a `#[rustc_always_gca]` must have a `gca!` RHS } fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.stderr b/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.stderr index 2daf2e1056b95..3ee23f4883e05 100644 --- a/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.stderr +++ b/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.stderr @@ -1,8 +1,8 @@ error[E0658]: use of unstable library feature `min_generic_const_args` --> $DIR/feature-gate-mgca-type-const-syntax.rs:1:17 | -LL | const FOO: u8 = core::direct_const_arg!(10); - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | const FOO: u8 = std::gca!(10); + | ^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable @@ -11,18 +11,18 @@ LL | const FOO: u8 = core::direct_const_arg!(10); error[E0658]: use of unstable library feature `min_generic_const_args` --> $DIR/feature-gate-mgca-type-const-syntax.rs:12:23 | -LL | const BAR: bool = core::direct_const_arg!(false); - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | const BAR: bool = std::gca!(false); + | ^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: expected expression, found `direct_const_arg!()` constant +error: expected expression, found `gca!()` constant --> $DIR/feature-gate-mgca-type-const-syntax.rs:1:17 | -LL | const FOO: u8 = core::direct_const_arg!(10); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const FOO: u8 = std::gca!(10); + | ^^^^^^^^^^^^^ error[E0658]: the `rustc_always_gca` attribute is an experimental feature --> $DIR/feature-gate-mgca-type-const-syntax.rs:6:7 @@ -34,16 +34,16 @@ LL | #[rustc_always_gca] = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: expected expression, found `direct_const_arg!()` constant +error: expected expression, found `gca!()` constant --> $DIR/feature-gate-mgca-type-const-syntax.rs:12:23 | -LL | const BAR: bool = core::direct_const_arg!(false); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const BAR: bool = std::gca!(false); + | ^^^^^^^^^^^^^^^^ -error: implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS +error: implementation of a `#[rustc_always_gca]` must have a `gca!` RHS --> $DIR/feature-gate-mgca-type-const-syntax.rs:12:5 | -LL | const BAR: bool = core::direct_const_arg!(false); +LL | const BAR: bool = std::gca!(false); | ^^^^^^^^^^^^^^^ | note: trait declaration of const is marked as `#[rustc_always_gca]` diff --git a/tests/ui/feature-gates/feature-gate-min-generic-const-args.rs b/tests/ui/feature-gates/feature-gate-min-generic-const-args.rs index a39d07eca0ee7..07f278f04591a 100644 --- a/tests/ui/feature-gates/feature-gate-min-generic-const-args.rs +++ b/tests/ui/feature-gates/feature-gate-min-generic-const-args.rs @@ -5,10 +5,10 @@ trait Trait { } // FIXME(mgca): add suggestion for mgca to this error -fn foo() -> [u8; core::direct_const_arg!(::ASSOC)] { +fn foo() -> [u8; std::gca!(::ASSOC)] { //~^ ERROR generic parameters may not be used in const operations //~| ERROR: use of unstable library feature `min_generic_const_args` [E0658] - //~| ERROR: expected expression, found `direct_const_arg!()` + //~| ERROR: expected expression, found `gca!()` loop {} } diff --git a/tests/ui/feature-gates/feature-gate-min-generic-const-args.stderr b/tests/ui/feature-gates/feature-gate-min-generic-const-args.stderr index eac9545d29681..f709affb8a819 100644 --- a/tests/ui/feature-gates/feature-gate-min-generic-const-args.stderr +++ b/tests/ui/feature-gates/feature-gate-min-generic-const-args.stderr @@ -1,18 +1,18 @@ error[E0658]: use of unstable library feature `min_generic_const_args` --> $DIR/feature-gate-min-generic-const-args.rs:8:28 | -LL | fn foo() -> [u8; core::direct_const_arg!(::ASSOC)] { - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | fn foo() -> [u8; std::gca!(::ASSOC)] { + | ^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: generic parameters may not be used in const operations - --> $DIR/feature-gate-min-generic-const-args.rs:8:53 + --> $DIR/feature-gate-min-generic-const-args.rs:8:39 | -LL | fn foo() -> [u8; core::direct_const_arg!(::ASSOC)] { - | ^ cannot perform const operation using `T` +LL | fn foo() -> [u8; std::gca!(::ASSOC)] { + | ^ cannot perform const operation using `T` | = note: type parameters may not be used in const expressions = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions @@ -28,11 +28,11 @@ LL | #[rustc_always_gca] = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: expected expression, found `direct_const_arg!()` constant +error: expected expression, found `gca!()` constant --> $DIR/feature-gate-min-generic-const-args.rs:8:28 | -LL | fn foo() -> [u8; core::direct_const_arg!(::ASSOC)] { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn foo() -> [u8; std::gca!(::ASSOC)] { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 4 previous errors diff --git a/tests/ui/generic-const-items/assoc-const-bindings.rs b/tests/ui/generic-const-items/assoc-const-bindings.rs index 596c47de98f86..2e0929a56867c 100644 --- a/tests/ui/generic-const-items/assoc-const-bindings.rs +++ b/tests/ui/generic-const-items/assoc-const-bindings.rs @@ -4,6 +4,7 @@ #![feature(adt_const_params, const_param_ty_trait, generic_const_parameter_types)] #![expect(incomplete_features)] +use std::gca; use std::marker::{ConstParamTy, ConstParamTy_}; trait Owner { @@ -16,9 +17,9 @@ trait Owner { } impl Owner for () { - const C: u32 = core::direct_const_arg!(N); - const K: u32 = core::direct_const_arg!(const { 99 + 1 }); - const Q: Maybe = core::direct_const_arg!(Maybe::Nothing::); + const C: u32 = gca!(N); + const K: u32 = gca!(const { 99 + 1 }); + const Q: Maybe = gca!(Maybe::Nothing::); } fn take0(_: impl Owner = { N }>) {} diff --git a/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs b/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs index 31bca180df8a8..d1b88db9466ef 100644 --- a/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs +++ b/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs @@ -4,13 +4,15 @@ #![feature(associated_type_defaults)] #![allow(incomplete_features)] +use std::gca; + pub struct NoPin; impl Pins for NoPin {} pub trait PinA { #[rustc_always_gca] - const A: &'static () = core::direct_const_arg!(const { &() }); + const A: &'static () = gca!(const { &() }); } pub trait Pins {} @@ -18,7 +20,7 @@ pub trait Pins {} impl Pins for T //~^ ERROR conflicting implementations of trait `Pins<_>` for type `NoPin` where - T: PinA + T: PinA { } diff --git a/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr b/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr index 515ee3f0af8be..65ec6a2c4e46e 100644 --- a/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr +++ b/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Pins<_>` for type `NoPin` - --> $DIR/assoc-const-no-infer-ice-115806.rs:18:1 + --> $DIR/assoc-const-no-infer-ice-115806.rs:20:1 | LL | impl Pins for NoPin {} | --------------------------- first implementation here @@ -7,8 +7,8 @@ LL | impl Pins for NoPin {} LL | / impl Pins for T LL | | LL | | where -LL | | T: PinA - | |__________________________________________________________________^ conflicting implementation for `NoPin` +LL | | T: PinA + | |_______________________________________________^ conflicting implementation for `NoPin` | = note: downstream crates may implement trait `PinA<_>` for type `NoPin` diff --git a/tests/ui/generic-const-items/type-const-nested-assoc-const.rs b/tests/ui/generic-const-items/type-const-nested-assoc-const.rs index 64df0183f101e..4d91d7edc8f16 100644 --- a/tests/ui/generic-const-items/type-const-nested-assoc-const.rs +++ b/tests/ui/generic-const-items/type-const-nested-assoc-const.rs @@ -3,7 +3,9 @@ #![feature(generic_const_items, min_generic_const_args)] #![allow(incomplete_features)] -const CT: usize = core::direct_const_arg!(::N); +use std::gca; + +const CT: usize = gca!(::N); trait Trait { #[rustc_always_gca] @@ -11,7 +13,7 @@ trait Trait { } impl Trait for T { - const N: usize = core::direct_const_arg!(0); + const N: usize = gca!(0); } fn f(_x: [(); CT::<()>]) {} diff --git a/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.rs b/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.rs index 4b415a230cbd4..8e77c40b113d9 100644 --- a/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.rs +++ b/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.rs @@ -13,10 +13,12 @@ #![expect(incomplete_features)] mod own { + use std::gca; + // the lifetime comes from the own generics struct Parent; impl Parent { - const CT<'a, T: 'a + super::AbideBy<'a> + ?Sized>: usize = core::direct_const_arg!(0); + const CT<'a, T: 'a + super::AbideBy<'a> + ?Sized>: usize = gca!(0); } // FIXME: Ideally, we would deduce `dyn Trait + 'r` from the bound `'a` on ty param `T` of @@ -31,10 +33,12 @@ mod own { } mod parent { + use std::gca; + // the lifetime comes from the parent generics struct Parent<'a>(&'a ()); impl<'a> Parent<'a> { - const CT + ?Sized>: usize = core::direct_const_arg!(0); + const CT + ?Sized>: usize = gca!(0); } //FIXME: Ideally, we would deduce `dyn Trait + 'r` from the bound `'a` on ty param `T` of diff --git a/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.stderr b/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.stderr index 1461caea1bbed..97d5fcd582681 100644 --- a/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.stderr +++ b/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.stderr @@ -1,5 +1,5 @@ error[E0228]: cannot deduce the lifetime bound for this trait object type from context - --> $DIR/object-lifetime-default-inherent-gac.rs:27:31 + --> $DIR/object-lifetime-default-inherent-gac.rs:29:31 | LL | [(); Parent::CT::<'r, dyn super::Trait>]:, | ^^^^^^^^^^^^^^^^ @@ -10,7 +10,7 @@ LL | [(); Parent::CT::<'r, dyn super::Trait + /* 'a */>]:, | ++++++++++ error[E0228]: cannot deduce the lifetime bound for this trait object type from context - --> $DIR/object-lifetime-default-inherent-gac.rs:45:33 + --> $DIR/object-lifetime-default-inherent-gac.rs:49:33 | LL | [(); Parent::<'r>::CT::]:, | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs b/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs index 113ef41f532f0..6db3ebceb1cff 100644 --- a/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs +++ b/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs @@ -7,9 +7,11 @@ #![feature(min_generic_const_args, macroless_generic_const_args, associated_type_defaults)] #![expect(incomplete_features)] +use std::gca; + trait Trait { #[rustc_always_gca] - const N: usize = core::direct_const_arg!(0); + const N: usize = gca!(0); fn process(&self, _: [u8; Self::N]) {} } diff --git a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs index a57e86127da7b..33b3aa4cd2430 100644 --- a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs +++ b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs @@ -2,12 +2,14 @@ #![feature(min_generic_const_args, specialization)] +use std::gca; + pub trait IsVoid { #[rustc_always_gca] const IS_VOID: bool; } impl IsVoid for T { - default const IS_VOID: bool = core::direct_const_arg!(false); + default const IS_VOID: bool = gca!(false); } pub trait NotVoid {} diff --git a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr index 3ec3e83cc1d44..eda6b57ca8f7a 100644 --- a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr +++ b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Maybe<()>` for type `()` - --> $DIR/overlap-due-to-unsatisfied-const-bound.rs:18:1 + --> $DIR/overlap-due-to-unsatisfied-const-bound.rs:20:1 | LL | impl Maybe for T {} | ---------------------- first implementation here diff --git a/tests/ui/supertrait-shadowing/assoc-const.rs b/tests/ui/supertrait-shadowing/assoc-const.rs index 0fd798217d77a..9e49004e7c836 100644 --- a/tests/ui/supertrait-shadowing/assoc-const.rs +++ b/tests/ui/supertrait-shadowing/assoc-const.rs @@ -4,6 +4,8 @@ #![feature(min_generic_const_args)] #![allow(dead_code)] +use std::gca; + trait A { const CONST: i32; } @@ -16,7 +18,7 @@ trait B: A { const CONST: i32; } impl B for T { - const CONST: i32 = core::direct_const_arg!(2); + const CONST: i32 = gca!(2); } trait C: B {} diff --git a/tests/ui/supertrait-shadowing/common-ancestor-2.rs b/tests/ui/supertrait-shadowing/common-ancestor-2.rs index b1ff2e895eb48..4844b0a43aa89 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor-2.rs +++ b/tests/ui/supertrait-shadowing/common-ancestor-2.rs @@ -6,6 +6,7 @@ #![warn(shadowing_supertrait_items)] #![allow(dead_code)] +use std::gca; use std::mem::size_of; trait A { @@ -45,7 +46,7 @@ trait C: A + B { } impl C for T { type Assoc = i32; - const CONST: i32 = core::direct_const_arg!(3); + const CONST: i32 = gca!(3); } fn main() { diff --git a/tests/ui/supertrait-shadowing/common-ancestor-2.stderr b/tests/ui/supertrait-shadowing/common-ancestor-2.stderr index 3e47a33991007..35f8a434fe861 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor-2.stderr +++ b/tests/ui/supertrait-shadowing/common-ancestor-2.stderr @@ -1,11 +1,11 @@ warning: trait item `hello` from `C` shadows identically named item from supertrait - --> $DIR/common-ancestor-2.rs:36:5 + --> $DIR/common-ancestor-2.rs:37:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: items from several supertraits are shadowed: `B` and `A` - --> $DIR/common-ancestor-2.rs:12:5 + --> $DIR/common-ancestor-2.rs:13:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,13 +19,13 @@ LL | #![warn(shadowing_supertrait_items)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: trait item `Assoc` from `C` shadows identically named item from supertrait - --> $DIR/common-ancestor-2.rs:40:5 + --> $DIR/common-ancestor-2.rs:41:5 | LL | type Assoc; | ^^^^^^^^^^ | note: items from several supertraits are shadowed: `B` and `A` - --> $DIR/common-ancestor-2.rs:15:5 + --> $DIR/common-ancestor-2.rs:16:5 | LL | type Assoc; | ^^^^^^^^^^ @@ -34,13 +34,13 @@ LL | type Assoc; | ^^^^^^^^^^ warning: trait item `CONST` from `C` shadows identically named item from supertrait - --> $DIR/common-ancestor-2.rs:43:5 + --> $DIR/common-ancestor-2.rs:44:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ | note: items from several supertraits are shadowed: `B` and `A` - --> $DIR/common-ancestor-2.rs:16:5 + --> $DIR/common-ancestor-2.rs:17:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ @@ -49,18 +49,18 @@ LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ warning: trait item `hello` from `C` shadows identically named item from supertrait - --> $DIR/common-ancestor-2.rs:52:19 + --> $DIR/common-ancestor-2.rs:53:19 | LL | assert_eq!(().hello(), "C"); | ^^^^^ | note: item from `C` shadows a supertrait item - --> $DIR/common-ancestor-2.rs:36:5 + --> $DIR/common-ancestor-2.rs:37:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: items from several supertraits are shadowed: `A` and `B` - --> $DIR/common-ancestor-2.rs:12:5 + --> $DIR/common-ancestor-2.rs:13:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/supertrait-shadowing/common-ancestor-3.rs b/tests/ui/supertrait-shadowing/common-ancestor-3.rs index ba8689d3a43f2..c815919c7e318 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor-3.rs +++ b/tests/ui/supertrait-shadowing/common-ancestor-3.rs @@ -6,6 +6,7 @@ #![warn(shadowing_supertrait_items)] #![allow(dead_code)] +use std::gca; use std::mem::size_of; trait A { @@ -45,7 +46,7 @@ trait C: A + B { } impl C for T { type Assoc = i32; - const CONST: i32 = core::direct_const_arg!(3); + const CONST: i32 = gca!(3); } // `D` extends `C` which extends `B` and `A` @@ -63,7 +64,7 @@ trait D: C { } impl D for T { type Assoc = i64; - const CONST: i32 = core::direct_const_arg!(4); + const CONST: i32 = gca!(4); } fn main() { diff --git a/tests/ui/supertrait-shadowing/common-ancestor-3.stderr b/tests/ui/supertrait-shadowing/common-ancestor-3.stderr index 2fd7ff0003c74..b18355f1a7920 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor-3.stderr +++ b/tests/ui/supertrait-shadowing/common-ancestor-3.stderr @@ -1,11 +1,11 @@ warning: trait item `hello` from `C` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:36:5 + --> $DIR/common-ancestor-3.rs:37:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: items from several supertraits are shadowed: `B` and `A` - --> $DIR/common-ancestor-3.rs:12:5 + --> $DIR/common-ancestor-3.rs:13:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -19,13 +19,13 @@ LL | #![warn(shadowing_supertrait_items)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: trait item `Assoc` from `C` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:40:5 + --> $DIR/common-ancestor-3.rs:41:5 | LL | type Assoc; | ^^^^^^^^^^ | note: items from several supertraits are shadowed: `B` and `A` - --> $DIR/common-ancestor-3.rs:15:5 + --> $DIR/common-ancestor-3.rs:16:5 | LL | type Assoc; | ^^^^^^^^^^ @@ -34,13 +34,13 @@ LL | type Assoc; | ^^^^^^^^^^ warning: trait item `CONST` from `C` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:43:5 + --> $DIR/common-ancestor-3.rs:44:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ | note: items from several supertraits are shadowed: `B` and `A` - --> $DIR/common-ancestor-3.rs:16:5 + --> $DIR/common-ancestor-3.rs:17:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ @@ -49,13 +49,13 @@ LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ warning: trait item `hello` from `D` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:54:5 + --> $DIR/common-ancestor-3.rs:55:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: items from several supertraits are shadowed: `C`, `B`, and `A` - --> $DIR/common-ancestor-3.rs:12:5 + --> $DIR/common-ancestor-3.rs:13:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,13 +67,13 @@ LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: trait item `Assoc` from `D` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:58:5 + --> $DIR/common-ancestor-3.rs:59:5 | LL | type Assoc; | ^^^^^^^^^^ | note: items from several supertraits are shadowed: `C`, `B`, and `A` - --> $DIR/common-ancestor-3.rs:15:5 + --> $DIR/common-ancestor-3.rs:16:5 | LL | type Assoc; | ^^^^^^^^^^ @@ -85,13 +85,13 @@ LL | type Assoc; | ^^^^^^^^^^ warning: trait item `CONST` from `D` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:61:5 + --> $DIR/common-ancestor-3.rs:62:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ | note: items from several supertraits are shadowed: `C`, `B`, and `A` - --> $DIR/common-ancestor-3.rs:16:5 + --> $DIR/common-ancestor-3.rs:17:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ @@ -103,18 +103,18 @@ LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ warning: trait item `hello` from `D` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:70:19 + --> $DIR/common-ancestor-3.rs:71:19 | LL | assert_eq!(().hello(), "D"); | ^^^^^ | note: item from `D` shadows a supertrait item - --> $DIR/common-ancestor-3.rs:54:5 + --> $DIR/common-ancestor-3.rs:55:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: items from several supertraits are shadowed: `A`, `B`, and `C` - --> $DIR/common-ancestor-3.rs:12:5 + --> $DIR/common-ancestor-3.rs:13:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/supertrait-shadowing/common-ancestor.rs b/tests/ui/supertrait-shadowing/common-ancestor.rs index 7acc4bcad56ca..e89167c9215fd 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor.rs +++ b/tests/ui/supertrait-shadowing/common-ancestor.rs @@ -6,6 +6,7 @@ #![warn(shadowing_supertrait_items)] #![allow(dead_code)] +use std::gca; use std::mem::size_of; trait A { @@ -33,7 +34,7 @@ trait B: A { } impl B for T { type Assoc = i16; - const CONST: i32 = core::direct_const_arg!(2); + const CONST: i32 = gca!(2); } fn main() { diff --git a/tests/ui/supertrait-shadowing/common-ancestor.stderr b/tests/ui/supertrait-shadowing/common-ancestor.stderr index a0b885b58eb5f..99ea66a166dbd 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor.stderr +++ b/tests/ui/supertrait-shadowing/common-ancestor.stderr @@ -1,11 +1,11 @@ warning: trait item `hello` from `B` shadows identically named item from supertrait - --> $DIR/common-ancestor.rs:24:5 + --> $DIR/common-ancestor.rs:25:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: item from `A` is shadowed by a subtrait item - --> $DIR/common-ancestor.rs:12:5 + --> $DIR/common-ancestor.rs:13:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -16,42 +16,42 @@ LL | #![warn(shadowing_supertrait_items)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: trait item `Assoc` from `B` shadows identically named item from supertrait - --> $DIR/common-ancestor.rs:28:5 + --> $DIR/common-ancestor.rs:29:5 | LL | type Assoc; | ^^^^^^^^^^ | note: item from `A` is shadowed by a subtrait item - --> $DIR/common-ancestor.rs:15:5 + --> $DIR/common-ancestor.rs:16:5 | LL | type Assoc; | ^^^^^^^^^^ warning: trait item `CONST` from `B` shadows identically named item from supertrait - --> $DIR/common-ancestor.rs:31:5 + --> $DIR/common-ancestor.rs:32:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ | note: item from `A` is shadowed by a subtrait item - --> $DIR/common-ancestor.rs:16:5 + --> $DIR/common-ancestor.rs:17:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ warning: trait item `hello` from `B` shadows identically named item from supertrait - --> $DIR/common-ancestor.rs:40:19 + --> $DIR/common-ancestor.rs:41:19 | LL | assert_eq!(().hello(), "B"); | ^^^^^ | note: item from `B` shadows a supertrait item - --> $DIR/common-ancestor.rs:24:5 + --> $DIR/common-ancestor.rs:25:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: item from `A` is shadowed by a subtrait item - --> $DIR/common-ancestor.rs:12:5 + --> $DIR/common-ancestor.rs:13:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/supertrait-shadowing/no-common-ancestor-2.rs b/tests/ui/supertrait-shadowing/no-common-ancestor-2.rs index 64d34ccb8c9ae..3462ac4e37d4d 100644 --- a/tests/ui/supertrait-shadowing/no-common-ancestor-2.rs +++ b/tests/ui/supertrait-shadowing/no-common-ancestor-2.rs @@ -1,6 +1,7 @@ #![feature(supertrait_item_shadowing)] #![feature(min_generic_const_args)] +use std::gca; use std::mem::size_of; trait A { @@ -37,7 +38,7 @@ trait C: A + B { } impl C for T { type Assoc = i32; - const CONST: i32 = core::direct_const_arg!(3); + const CONST: i32 = gca!(3); } // Since `D` is not a subtrait of `C`, @@ -53,7 +54,7 @@ trait D: B { } impl D for T { type Assoc = i64; - const CONST: i32 = core::direct_const_arg!(4); + const CONST: i32 = gca!(4); } fn main() { diff --git a/tests/ui/supertrait-shadowing/no-common-ancestor-2.stderr b/tests/ui/supertrait-shadowing/no-common-ancestor-2.stderr index 85c0937c03d9c..220a26d7757a0 100644 --- a/tests/ui/supertrait-shadowing/no-common-ancestor-2.stderr +++ b/tests/ui/supertrait-shadowing/no-common-ancestor-2.stderr @@ -1,26 +1,26 @@ error[E0034]: multiple applicable items in scope - --> $DIR/no-common-ancestor-2.rs:60:8 + --> $DIR/no-common-ancestor-2.rs:61:8 | LL | ().hello(); | ^^^^^ multiple `hello` found | note: candidate #1 is defined in an impl of the trait `A` for the type `T` - --> $DIR/no-common-ancestor-2.rs:7:5 + --> $DIR/no-common-ancestor-2.rs:8:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: candidate #2 is defined in an impl of the trait `B` for the type `T` - --> $DIR/no-common-ancestor-2.rs:19:5 + --> $DIR/no-common-ancestor-2.rs:20:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: candidate #3 is defined in an impl of the trait `C` for the type `T` - --> $DIR/no-common-ancestor-2.rs:31:5 + --> $DIR/no-common-ancestor-2.rs:32:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: candidate #4 is defined in an impl of the trait `D` for the type `T` - --> $DIR/no-common-ancestor-2.rs:47:5 + --> $DIR/no-common-ancestor-2.rs:48:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL + D::hello(&()); | error[E0221]: ambiguous associated type `Assoc` in bounds of `T` - --> $DIR/no-common-ancestor-2.rs:66:23 + --> $DIR/no-common-ancestor-2.rs:67:23 | LL | type Assoc; | ---------- ambiguous `Assoc` from `A` @@ -85,28 +85,28 @@ LL + let _ = size_of::<::Assoc>(); | error[E0034]: multiple applicable items in scope - --> $DIR/no-common-ancestor-2.rs:68:16 + --> $DIR/no-common-ancestor-2.rs:69:16 | LL | let _ = T::CONST; | ^^^^^ multiple `CONST` found | note: candidate #1 is defined in the trait `A` - --> $DIR/no-common-ancestor-2.rs:11:5 + --> $DIR/no-common-ancestor-2.rs:12:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ note: candidate #2 is defined in the trait `B` - --> $DIR/no-common-ancestor-2.rs:23:5 + --> $DIR/no-common-ancestor-2.rs:24:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ note: candidate #3 is defined in the trait `C` - --> $DIR/no-common-ancestor-2.rs:36:5 + --> $DIR/no-common-ancestor-2.rs:37:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ note: candidate #4 is defined in the trait `D` - --> $DIR/no-common-ancestor-2.rs:52:5 + --> $DIR/no-common-ancestor-2.rs:53:5 | LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/supertrait-shadowing/out-of-scope.rs b/tests/ui/supertrait-shadowing/out-of-scope.rs index 11c7477cc3f8a..fc967e525dc40 100644 --- a/tests/ui/supertrait-shadowing/out-of-scope.rs +++ b/tests/ui/supertrait-shadowing/out-of-scope.rs @@ -6,6 +6,7 @@ use std::mem::size_of; mod out_of_scope { + use std::gca; pub trait Subtrait: super::Supertrait { fn hello(&self) -> &'static str { "subtrait" @@ -16,7 +17,7 @@ mod out_of_scope { } impl Subtrait for T { type Assoc = i16; - const CONST: i32 = core::direct_const_arg!(2); + const CONST: i32 = gca!(2); } } diff --git a/tests/ui/supertrait-shadowing/type-dependent.rs b/tests/ui/supertrait-shadowing/type-dependent.rs index 0287bb7ad43a8..b2c31b352deee 100644 --- a/tests/ui/supertrait-shadowing/type-dependent.rs +++ b/tests/ui/supertrait-shadowing/type-dependent.rs @@ -6,6 +6,7 @@ #![feature(supertrait_item_shadowing)] #![allow(dead_code)] +use std::gca; use std::mem::size_of; trait A { @@ -30,7 +31,7 @@ trait B: A { } impl B for T { type Assoc = i16; - const CONST: i32 = core::direct_const_arg!(2); + const CONST: i32 = gca!(2); } fn foo() -> &'static str { diff --git a/tests/ui/traits/next-solver/normalize-const-item-type.rs b/tests/ui/traits/next-solver/normalize-const-item-type.rs index 873b0bb690e4c..3b70e8718488b 100644 --- a/tests/ui/traits/next-solver/normalize-const-item-type.rs +++ b/tests/ui/traits/next-solver/normalize-const-item-type.rs @@ -3,6 +3,7 @@ #![feature(min_generic_const_args)] #![feature(generic_const_args)] +use std::gca; use std::marker::PhantomData; trait Project1<'a> { @@ -21,14 +22,15 @@ impl> Project2 for PhantomData { type Assoc2 = usize; } -const N: as Project2>::Assoc2 = 2_usize; +const N: as Project2>::Assoc2 = 2_usize; -fn func(_: [(); core::direct_const_arg!(N::)]) +fn func(_: [(); gca!(N::)]) //~^ ERROR: type mismatch resolving `N == _` [E0271] //~| ERROR: the type `[(); N::]` is not well-formed //~| ERROR: type mismatch resolving `N == _` [E0271] where for<'a> u32: Project1<'a>, -{} +{ +} fn main() {} diff --git a/tests/ui/traits/next-solver/normalize-const-item-type.stderr b/tests/ui/traits/next-solver/normalize-const-item-type.stderr index 67f4f596f40bf..926ba7e43b2f5 100644 --- a/tests/ui/traits/next-solver/normalize-const-item-type.stderr +++ b/tests/ui/traits/next-solver/normalize-const-item-type.stderr @@ -1,20 +1,20 @@ error[E0271]: type mismatch resolving `N == _` - --> $DIR/normalize-const-item-type.rs:26:12 + --> $DIR/normalize-const-item-type.rs:27:12 | -LL | fn func(_: [(); core::direct_const_arg!(N::)]) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ +LL | fn func(_: [(); gca!(N::)]) + | ^^^^^^^^^^^^^^^^^^^^ types differ error: the type `[(); N::]` is not well-formed - --> $DIR/normalize-const-item-type.rs:26:12 + --> $DIR/normalize-const-item-type.rs:27:12 | -LL | fn func(_: [(); core::direct_const_arg!(N::)]) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn func(_: [(); gca!(N::)]) + | ^^^^^^^^^^^^^^^^^^^^ error[E0271]: type mismatch resolving `N == _` - --> $DIR/normalize-const-item-type.rs:26:12 + --> $DIR/normalize-const-item-type.rs:27:12 | -LL | fn func(_: [(); core::direct_const_arg!(N::)]) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ +LL | fn func(_: [(); gca!(N::)]) + | ^^^^^^^^^^^^^^^^^^^^ types differ | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`