Skip to content

#[splat] is allowed in closures and does nothing. #158605

Closed

Description

@theemathas

This code probably shouldn't compile, but it does.

#![feature(splat)]
#![expect(incomplete_features)]

fn main() {
    (|#[splat] x: i32| {
        println!("{x}");
    })(1);
}

cc @teor2345

Meta

Reproducible on the playground with version 1.98.0-nightly (2026-06-29 096694416a4184070914)

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 30, 2026
  2. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    F-splat`#![feature(splat)]` https://github.com/rust-lang/rust/issues/153629
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 30, 2026
  3. teor2345 commented on Jun 30, 2026

    @teor2345
    Member

    This definitely shouldn't work, it only typechecks due to the hidden tuple in the closure Fn trait call.

    I wonder if we should ban all splats within closures, even if they are applied to a tuple type or the Tuple trait?
    This was an open question that we didn't get to as part of the initial impl.

  4. theemathas commented on Jun 30, 2026

    @theemathas
    ContributorAuthor

    #[splat] self: Self also results in some strange compiler behavior, especially in an extern "rust-call" method.

  5. teor2345 commented on Jun 30, 2026

    @teor2345
    Member

    #[splat] self: Self also results in some strange compiler behavior,

    I'd expect splatting self to work, regardless of how the arguments are declared. Do you have an example?

    especially in an extern "rust-call" method.

    This should probably be banned along with the closure ban, because it's the internal implementation of closures.

  6. theemathas commented on Jun 30, 2026

    @theemathas
    ContributorAuthor

    This compiles:

    #![feature(splat)]
    #![expect(incomplete_features)]
    
    trait Trait {
        fn method(#[splat] self: Self);
    }
    
    impl Trait for (i32, i64) {
        fn method(#[splat] self: Self) {
            println!("{self:?}");
        }
    }
    
    fn main() {
        (1_i32, 2_i64).method();
        Trait::method(3_i32, 4_i64);
    }

    This compiles:

    #![feature(splat, unboxed_closures, tuple_trait)]
    #![expect(incomplete_features)]
    
    use std::marker::Tuple;
    
    trait Trait: Tuple + Sized {
        extern "rust-call" fn method(#[splat] self: Self);
    }
    
    impl Trait for (i32, i64) {
        extern "rust-call" fn method(#[splat] self: Self) {
            println!("{self:?}");
        }
    }
    
    fn main() {
        (1_i32, 2_i64).method();
        // Delete the below line to make it not compile.
        // Trait::method(3_i32, 4_i64);
    }
  7. teor2345 commented on Jun 30, 2026

    @teor2345
    Member

    I think the first is fine, the second is probably something we should reject until we decide semantics.

  8. teor2345 commented on Jul 1, 2026

    @teor2345
    Member

    @rustbot claim

  9. added a commit that references this issue on Jul 8, 2026
    f49b0ad
  10. added 3 commits that reference this issue on Jul 8, 2026
    dedef02
    a961881
    503c31d
  11. added a commit that references this issue on Jul 8, 2026
    95f4b33
  12. added 2 commits that reference this issue on Jul 9, 2026
    cdec7ed
    aa6ea68
  13. added a commit that references this issue on Jul 9, 2026
    cd1a567
  14. added 2 commits that reference this issue on Jul 9, 2026
    ecc5f4d
    c9333db
  15. added 2 commits that reference this issue on Jul 9, 2026
    027dd6a
    16a60ff
  16. added a commit that references this issue on Jul 10, 2026
    b6b8328
  17. added 2 commits that reference this issue on Jul 22, 2026
  18. added a commit that references this issue on Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-splat`#![feature(splat)]` https://github.com/rust-lang/rust/issues/153629T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions