Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum SelfSemantic {
No,
}

/// Is `#[splat]` allowed semantically in a function or closure?
/// Is `#[arg_splat]` allowed semantically in a function or closure?
/// Only applies to the function kind and header, the parameters are checked elsewhere.
enum SplatSemantic {
Yes,
Expand Down Expand Up @@ -439,7 +439,7 @@ impl<'a> AstValidator<'a> {

/// Emits an error if a function declaration has more than one splatted argument, with a
/// C-variadic parameter, or a splat at an unsupported index (for performance).
/// Example: `fn foo(#[splat] x: (), #[splat] y: ())` will emit an error.
/// Example: `fn foo(#[arg_splat] x: (), #[arg_splat] y: ())` will emit an error.
fn check_decl_splatting(
&self,
fn_decl: &FnDecl,
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_ast_passes/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,46 +125,46 @@ pub(crate) struct FnParamCVarArgsNotLast {

#[derive(Diagnostic)]
#[diag(
"`#[splat]` is only supported on argument index {$max_valid_splatted_arg_index} or less, this `#[splat]` is on index {$first_invalid_splatted_arg_index}"
"`#[arg_splat]` is only supported on argument index {$max_valid_splatted_arg_index} or less, this `#[arg_splat]` is on index {$first_invalid_splatted_arg_index}"
)]
#[help("remove `#[splat]`, or use it on an argument closer to the start of the argument list")]
#[help("remove `#[arg_splat]`, or use it on an argument closer to the start of the argument list")]
pub(crate) struct InvalidSplattedArgs {
pub max_valid_splatted_arg_index: u16,

pub first_invalid_splatted_arg_index: u16,

#[primary_span]
#[label("`#[splat]` is not supported here")]
#[label("`#[arg_splat]` is not supported here")]
pub spans: Vec<Span>,
}

#[derive(Diagnostic)]
#[diag("multiple `#[splat]`s are not allowed in the same function argument list")]
#[help("remove `#[splat]` from all but one argument")]
#[diag("multiple `#[arg_splat]`s are not allowed in the same function argument list")]
#[help("remove `#[arg_splat]` from all but one argument")]
pub(crate) struct DuplicateSplattedArgs {
#[primary_span]
pub spans: Vec<Span>,
}

#[derive(Diagnostic)]
#[diag("`...` and `#[splat]` are not allowed in the same function argument list")]
#[help("remove `#[splat]` or remove `...`")]
#[diag("`...` and `#[arg_splat]` are not allowed in the same function argument list")]
#[help("remove `#[arg_splat]` or remove `...`")]
pub(crate) struct CVarArgsAndSplat {
#[primary_span]
pub spans: Vec<Span>,
}

#[derive(Diagnostic)]
#[diag("`#[splat]` is not allowed on closure arguments")]
#[help("remove `#[splat]` or turn the closure into a function")]
#[diag("`#[arg_splat]` is not allowed on closure arguments")]
#[help("remove `#[arg_splat]` or turn the closure into a function")]
pub(crate) struct SplatNotAllowedOnClosures {
#[primary_span]
pub spans: Vec<Span>,
}

#[derive(Diagnostic)]
#[diag("`#[splat]` is not allowed in the arguments of functions with the `{$abi}` ABI")]
#[help("remove `#[splat]` or change the ABI")]
#[diag("`#[arg_splat]` is not allowed in the arguments of functions with the `{$abi}` ABI")]
#[help("remove `#[arg_splat]` or change the ABI")]
pub(crate) struct SplatNotAllowedOnAbiCall {
#[primary_span]
pub spans: Vec<Span>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
gate_all!(pin_ergonomics, "pinned reference syntax is experimental");
gate_all!(postfix_match, "postfix match is experimental");
gate_all!(return_type_notation, "return type notation is experimental");
gate_all!(splat, "`fn(#[splat] (a, ...))` is incomplete", "call as func((a, ...)) instead");
gate_all!(splat, "`fn(#[arg_splat] (a, ...))` is incomplete", "call as func((a, ...)) instead");
gate_all!(super_let, "`super let` is experimental");
gate_all!(try_blocks_heterogeneous, "`try bikeshed` expression is experimental");
gate_all!(unnamed_enum_variants, "unnamed enum variants are experimental");
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/splat.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Attribute parsing for the `#[splat]` function argument overloading attribute.
//! Attribute parsing for the `#[arg_splat]` function argument overloading attribute.
//! This attribute modifies typecheck to support overload resolution, then modifies codegen for performance.

use rustc_feature::AttributeStability;
Expand All @@ -11,6 +11,6 @@ impl NoArgsAttributeParser for SplatParser {
const PATH: &[Symbol] = &[sym::splat];
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Param)]);
const STABILITY: AttributeStability =
unstable!(splat, "the `#[splat]` attribute is experimental");
unstable!(splat, "the `#[arg_splat]` attribute is experimental");
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Splat;
}
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
// - https://github.com/rust-lang/rust/issues/130494
sym::pin_v2,

// The `#[splat]` attribute is part of the `splat` experiment
// The `#[arg_splat]` attribute is part of the `splat` experiment
// that improves the ergonomics of function overloading, tracked in:
//
// - https://github.com/rust-lang/rust/issues/153629
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ declare_features! (
/// Allows specialization of implementations (RFC 1210).
(incomplete, specialization, "1.7.0", Some(31844)),
/// Experimental "splatting" of function call arguments at the call site.
/// e.g. `foo(a, b, c)` calls `#[splat] fn foo((a: A, b: B, c: C))`.
/// e.g. `foo(a, b, c)` calls `#[arg_splat] fn foo((a: A, b: B, c: C))`.
(incomplete, splat, "1.98.0", Some(153629)),
/// Allows using `#[rustc_align_static(...)]` on static items.
(unstable, static_align, "1.91.0", Some(146177)),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/attrs/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ pub enum AttributeKind {
reason: Option<Symbol>,
},

/// Represents `#[splat]`
/// Represents `#[arg_splat]`
Splat(Span),

/// Represents `#[stable]`, `#[unstable]` and `#[rustc_allowed_through_unstable_modules]`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ fn fn_sig_suggestion<'tcx>(
.iter()
.enumerate()
.map(|(i, ty)| {
let splat = if splatted_arg_index == Some(i) { "#[splat] " } else { "" };
let splat = if splatted_arg_index == Some(i) { "#[arg_splat] " } else { "" };
let arg_ty = match ty.kind() {
ty::Param(_) if assoc.is_method() && i == 0 => "self".to_string(),
ty::Ref(reg, ref_ty, mutability) if i == 0 => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,7 @@ impl<'a> State<'a> {
let mut i = 0;
let mut print_arg = |s: &mut Self, ty: Option<&hir::Ty<'_>>| {
if Some(i) == decl.splatted().map(usize::from) {
s.word("#[splat]");
s.word("#[arg_splat]");
}
if i == 0 && decl.implicit_self().has_implicit_self() {
s.print_implicit_self(&decl.implicit_self());
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ rustc_index::newtype_index! {
pub(crate) struct GenericIdx {}
}

/// Outcome of checking arguments that are tupled by "rust-call" or `#[splat]`.
/// Outcome of checking arguments that are tupled by "rust-call" or `#[arg_splat]`.
#[derive(Debug, Clone, Eq, PartialEq)]
struct TupledArgCheckOutcome<'tcx> {
/// The error code to emit if the arguments are not compatible.
Expand Down Expand Up @@ -559,7 +559,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

/// Check arguments that are tupled by "rust-call" or `#[splat]`.
/// Check arguments that are tupled by "rust-call" or `#[arg_splat]`.
fn check_tupled_arguments(
&self,
// Span enclosing the call site
Expand Down Expand Up @@ -593,10 +593,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// The argument difference can range from -1 to u16::MAX - 1, so we count the number
// of tupled arguments instead.
// (An empty argument list becomes a unit tuple in the callee.)
// 0: f() -> f(#[splat] _: ())
// 1: f(a) -> f(#[splat] _: (A,))
// 2: f(a, b) -> f(#[splat] _: (A, B))
// The Fn* traits ensure this by construction, and `#[splat]` can only be applied to
// 0: f() -> f(#[arg_splat] _: ())
// 1: f(a) -> f(#[arg_splat] _: (A,))
// 2: f(a, b) -> f(#[arg_splat] _: (A, B))
// The Fn* traits ensure this by construction, and `#[arg_splat]` can only be applied to
// an actual argument.
let tupled_args_count = (1 + provided_args.len()).checked_sub(formal_input_tys.len());
debug!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
let mut input_iter = inputs.iter().copied();
if let Some(index) = splatted_arg_index {
self.comma_sep((&mut input_iter).take(usize::from(index)))?;
write!(self, ", #[splat]")?;
write!(self, ", #[arg_splat]")?;
self.comma_sep(input_iter)?;
} else {
self.comma_sep(input_iter)?;
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
hir::ExprKind::MethodCall(segment, receiver, args, fn_span) => {
if self.typeck_results.is_splatted_call(expr) {
// The callee has a splatted tuple argument.
// rewrite `receiver.f(a, u, v)` into `receiver.f(a, #[splat] (u, v))`
// rewrite `receiver.f(a, u, v)` into `receiver.f(a, #[arg_splat] (u, v))`
self.convert_splatted_callee(expr, fn_span, args, Some(receiver))
} else {
// Rewrite a.b(c) into UFCS form like Trait::b(a, c)
Expand Down Expand Up @@ -425,7 +425,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
}
} else if self.typeck_results.is_splatted_call(expr) {
// The callee has a splatted tuple argument.
// rewrite `f(a, u, v)` into `f(a, #[splat] (u, v))`
// rewrite `f(a, u, v)` into `f(a, #[arg_splat] (u, v))`
self.convert_splatted_callee(expr, fun.span, args, None)
} else {
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
Expand Down Expand Up @@ -1288,7 +1288,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
}

/// The callee has a splatted tuple argument.
/// Rewrite a splatted call `receiver.f(a, u, v)` into `receiver.f(a, #[splat] (u, v))`.
/// Rewrite a splatted call `receiver.f(a, u, v)` into `receiver.f(a, #[arg_splat] (u, v))`.
/// The receiver is optional.
fn convert_splatted_callee(
&mut self,
Expand All @@ -1304,7 +1304,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
let tupled_arg_index = usize::from(tupled_arg_index);
let tupled_args_count = usize::from(tupled_args_count);

// Splatting an empty tuple is permitted: `a.f() -> Trait::f(a, #[splat] ())`.
// Splatting an empty tuple is permitted: `a.f() -> Trait::f(a, #[arg_splat] ())`.
// In that case, the tupled arg index is one past the end of the args.
if tupled_arg_index + tupled_args_count > args.len() {
span_bug!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_public/src/unstable/convert/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl RustcInternal for FnSig {
tables: &mut Tables<'_, BridgeTys>,
tcx: impl InternalCx<'tcx>,
) -> Self::T<'tcx> {
// FIXME(splat): When `#[splat]` is complete (or stable), add splatted to the public FnSig
// FIXME(splat): When `#[arg_splat]` is complete (or stable), add splatted to the public FnSig
let fn_sig_kind = rustc_ty::FnSigKind::default()
.set_abi(self.abi.internal(tables, tcx))
.set_safety(self.safety.internal(tables, tcx))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ symbols! {
specialization,
speed,
spirv,
splat,
splat: "arg_splat",
splatted_index,
spotlight,
sqrtf16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,11 +829,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
for (i, (l, r)) in iter::zip(sig1.inputs(), sig2.inputs()).enumerate() {
self.push_comma(&mut values.0, &mut values.1, i);
if Some(i) == splatted_arg_index1 {
values.0.push("#[splat]", splatted_arg_index1 != splatted_arg_index2);
values.0.push("#[arg_splat]", splatted_arg_index1 != splatted_arg_index2);
values.0.push_normal(" ");
}
if Some(i) == splatted_arg_index2 {
values.1.push("#[splat]", splatted_arg_index1 != splatted_arg_index2);
values.1.push("#[arg_splat]", splatted_arg_index1 != splatted_arg_index2);
values.1.push_normal(" ");
}
let (x1, x2) = self.cmp(*l, *r);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/ty_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ impl<I: Interner> fmt::Debug for FnSig<I> {
write!(f, ", ")?;
}
if Some(i) == fn_sig_kind.splatted().map(usize::from) {
write!(f, "#[splat] ")?;
write!(f, "#[arg_splat] ")?;
}
write!(f, "{ty:?}")?;
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/mem/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ pub struct FnPtr {
pub is_splatted: bool,

/// The index of the splatted function argument in `inputs`, only valid if `is_splatted` is true.
/// e.g. in `fn overload(a: u8, #[splat] b: (f32, usize))` the index is 1, and it can be called
/// e.g. in `fn overload(a: u8, #[arg_splat] b: (f32, usize))` the index is 1, and it can be called
/// as `overload(a, 1.0, 2)`.
pub splatted_index: u8,
}
Expand Down
2 changes: 1 addition & 1 deletion library/coretests/tests/mem/fn_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn test_variadic() {
#[test]
fn test_splat() {
#[rustfmt::skip]
let TypeKind::FnPtr(fn_ptr_ty) = &(const { Type::of::<fn(#[splat] (String, u8))>().kind }) else {
let TypeKind::FnPtr(fn_ptr_ty) = &(const { Type::of::<fn(#[arg_splat] (String, u8))>().kind }) else {
panic!();
};
let FnPtr {
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/symbol-mangling/v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ Remaining primitives are encoded as a crate production, e.g. `C4f128`.

Note that a zero-length tuple (unit) is encoded with the `u` *[basic-type]*.

* `w` — A [splatted type][tracking-splat] `#[splat] T`.
* `w` — A [splatted type][tracking-splat] `#[arg_splat] T`.

> <span id="splatted-type">splatted-type</span> → `w` {*[type]*}

Expand Down
1 change: 0 additions & 1 deletion src/tools/rustfmt/tests/source/reorder_modules/ABCD/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/tools/rustfmt/tests/source/reorder_modules/ZYXW/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/tools/rustfmt/tests/target/reorder_modules/ABCD/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/tools/rustfmt/tests/target/reorder_modules/ZYXW/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ See [Tracking issue for specialization (RFC 1210) #31844](https://github.com/rus

## `tests/ui/splat`

Tests for the `#![feature(splat)]` attribute.
Tests for the `#![feature(arg_splat)]` attribute.

See [Tracking Issue for argument splatting #153629](https://github.com/rust-lang/rust/issues/153629).

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/feature-gates/feature-gate-splat.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[rustfmt::skip]
fn tuple_args(
#[splat] //~ ERROR the `#[splat]` attribute is an experimental feature
#[arg_splat] //~ ERROR the `#[arg_splat]` attribute is an experimental feature
(a, b, c): (u32, i8, char),
) {
}
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/feature-gates/feature-gate-splat.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0658]: the `#[splat]` attribute is an experimental feature
error[E0658]: the `#[arg_splat]` attribute is an experimental feature
--> $DIR/feature-gate-splat.rs:3:5
|
LL | #[splat]
| ^^^^^^^^
LL | #[arg_splat]
| ^^^^^^^^^^^^
|
= note: see issue #153629 <https://github.com/rust-lang/rust/issues/153629> for more information
= help: add `#![feature(splat)]` to the crate attributes to enable
= help: add `#![feature(arg_splat)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= note: the `#[splat]` attribute is experimental
= note: the `#[arg_splat]` attribute is experimental

error: aborting due to 1 previous error

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/splat/arg-count-ice-issue-158482.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Checks that an incorrect number of arguments to splat doesn't panic.

#![feature(splat)]
#![feature(arg_splat)]
struct Foo {}
trait BarTrait {
fn trait_assoc<W>(w: W, #[splat] _s: (u32, u8));
fn trait_assoc<W>(w: W, #[arg_splat] _s: (u32, u8));
}
impl BarTrait for Foo {
fn trait_assoc<W>(_w: W, #[splat] _s: (u32, u8)) {}
fn trait_assoc<W>(_w: W, #[arg_splat] _s: (u32, u8)) {}
}
fn main() {
Foo::trait_assoc()
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/splat/reject-closure-issue-158605.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
//! Checks that closures and rust-call functions can't be splatted.
//! This should be rejected until we decide on sensible semantics.

#![feature(splat, unboxed_closures, tuple_trait)]
#![feature(arg_splat, unboxed_closures, tuple_trait)]
#![expect(incomplete_features)]

use std::marker::Tuple;

trait Trait: Tuple + Sized {
extern "rust-call" fn method(#[splat] self: Self);
//~^ ERROR: `#[splat]` is not allowed in the arguments of functions with the `rust-call` ABI
extern "rust-call" fn method(#[arg_splat] self: Self);
//~^ ERROR: `#[arg_splat]` is not allowed in the arguments of functions with the `rust-call` ABI
}

impl Trait for (i32, i64) {
extern "rust-call" fn method(#[splat] self: Self) {
//~^ ERROR: `#[splat]` is not allowed in the arguments of functions with the `rust-call` ABI
extern "rust-call" fn method(#[arg_splat] self: Self) {
//~^ ERROR: `#[arg_splat]` is not allowed in the arguments of functions with the `rust-call` ABI
println!("{self:?}");
}
}

fn main() {
(|#[splat] x: i32| {
//~^ ERROR `#[splat]` is not allowed on closure arguments
(|#[arg_splat] x: i32| {
//~^ ERROR `#[arg_splat]` is not allowed on closure arguments
println!("{x}");
})(1);

Expand Down
Loading
Loading