Skip to content

Commit 902d075

Browse files
committed
Add splat builtin attribute & feature gate
1 parent 06293ff commit 902d075

13 files changed

Lines changed: 151 additions & 0 deletions

File tree

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
500500
gate_all!(pin_ergonomics, "pinned reference syntax is experimental");
501501
gate_all!(postfix_match, "postfix match is experimental");
502502
gate_all!(return_type_notation, "return type notation is experimental");
503+
gate_all!(splat, "`fn(#[splat] (a, ...))` is incomplete", "call as func((a, ...)) instead");
503504
gate_all!(super_let, "`super let` is experimental");
504505
gate_all!(try_blocks_heterogeneous, "`try bikeshed` expression is experimental");
505506
gate_all!(unnamed_enum_variants, "unnamed enum variants are experimental");

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub(crate) mod rustc_allocator;
6868
pub(crate) mod rustc_dump;
6969
pub(crate) mod rustc_internal;
7070
pub(crate) mod semantics;
71+
pub(crate) mod splat;
7172
pub(crate) mod stability;
7273
pub(crate) mod test_attrs;
7374
pub(crate) mod traits;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Attribute parsing for the `#[splat]` function argument overloading attribute.
2+
//! This attribute modifies typecheck to support overload resolution, then modifies codegen for performance.
3+
4+
use rustc_feature::AttributeStability;
5+
6+
use super::prelude::*;
7+
8+
pub(crate) struct SplatParser;
9+
10+
impl NoArgsAttributeParser for SplatParser {
11+
const PATH: &[Symbol] = &[sym::splat];
12+
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
13+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
14+
// FIXME(splat): do we want to allow MacroCall if the macro creates an argument
15+
Allow(Target::Param),
16+
]);
17+
const STABILITY: AttributeStability =
18+
unstable!(splat, "the `#[splat]` attribute is experimental");
19+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Splat;
20+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use crate::attributes::rustc_allocator::*;
5757
use crate::attributes::rustc_dump::*;
5858
use crate::attributes::rustc_internal::*;
5959
use crate::attributes::semantics::*;
60+
use crate::attributes::splat::*;
6061
use crate::attributes::stability::*;
6162
use crate::attributes::test_attrs::*;
6263
use crate::attributes::traits::*;
@@ -322,6 +323,7 @@ attribute_parsers!(
322323
Single<WithoutArgs<RustcStrictCoherenceParser>>,
323324
Single<WithoutArgs<RustcTrivialFieldReadsParser>>,
324325
Single<WithoutArgs<RustcUnsafeSpecializationMarkerParser>>,
326+
Single<WithoutArgs<SplatParser>>,
325327
Single<WithoutArgs<ThreadLocalParser>>,
326328
Single<WithoutArgs<TrackCallerParser>>,
327329
// tidy-alphabetical-end

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[
326326
// - https://github.com/rust-lang/rust/issues/130494
327327
sym::pin_v2,
328328

329+
// The `#[splat]` attribute is part of the `splat` experiment
330+
// that improves the ergonomics of function overloading, tracked in:
331+
//
332+
// - https://github.com/rust-lang/rust/issues/153629
333+
sym::splat,
334+
329335
// ==========================================================================
330336
// Internal attributes: Stability, deprecation, and unsafe:
331337
// ==========================================================================

compiler/rustc_feature/src/unstable.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,9 @@ declare_features! (
721721
(unstable, sparc_target_feature, "1.84.0", Some(132783)),
722722
/// Allows specialization of implementations (RFC 1210).
723723
(incomplete, specialization, "1.7.0", Some(31844)),
724+
/// Experimental "splatting" of function call arguments at the call site.
725+
/// e.g. `foo(a, b, c)` calls `#[splat] fn foo((a: A, b: B, c: C))`.
726+
(incomplete, splat, "CURRENT_RUSTC_VERSION", Some(153629)),
724727
/// Allows using `#[rustc_align_static(...)]` on static items.
725728
(unstable, static_align, "1.91.0", Some(146177)),
726729
/// Allows attributes on expressions and non-item statements.

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,9 @@ pub enum AttributeKind {
15861586
reason: Option<Symbol>,
15871587
},
15881588

1589+
/// Represents `#[splat]`
1590+
Splat(Span),
1591+
15891592
/// Represents `#[stable]`, `#[unstable]` and `#[rustc_allowed_through_unstable_modules]`.
15901593
Stability {
15911594
stability: Stability,

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl AttributeKind {
191191
RustcUnsafeSpecializationMarker => No,
192192
Sanitize { .. } => No,
193193
ShouldPanic { .. } => No,
194+
Splat(..) => Yes,
194195
Stability { .. } => Yes,
195196
TargetFeature { .. } => No,
196197
TestRunner(..) => Yes,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
401401
AttributeKind::RustcUnsafeSpecializationMarker => (),
402402
AttributeKind::Sanitize { .. } => {}
403403
AttributeKind::ShouldPanic { .. } => (),
404+
AttributeKind::Splat(..) => (),
404405
AttributeKind::Stability { .. } => (),
405406
AttributeKind::TestRunner(..) => (),
406407
AttributeKind::ThreadLocal => (),

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,7 @@ symbols! {
19561956
specialization,
19571957
speed,
19581958
spirv,
1959+
splat,
19591960
spotlight,
19601961
sqrtf16,
19611962
sqrtf32,

0 commit comments

Comments
 (0)