Skip to content

Weird varargs-in-closures error messages #146489

@workingjubilee

Description

@workingjubilee

This is very low priority.

I tried this code:

#![feature(c_variadic)]

unsafe extern "C" fn thats_not_a_pattern(mut ap: ...) -> u32 {
    let mut lol = |...| ();
    unsafe { ap.arg::<u32>() }
}

I expected it to go off on me for trying to put varargs in a closure.

Instead, I got this:

   Compiling playground v0.0.1 (/playground)
error: unexpected `...`
 --> src/lib.rs:4:20
  |
4 |     let mut lol = |...| ();
  |                    ^^^ not a valid pattern
  |
help: for a rest pattern, use `..` instead of `...`
  |
4 -     let mut lol = |...| ();
4 +     let mut lol = |..| ();
  |

error: `..` patterns are not allowed here
 --> src/lib.rs:4:20
  |
4 |     let mut lol = |...| ();
  |                    ^^^
  |
  = note: only allowed in tuple, tuple struct, and slice patterns

error[E0282]: type annotations needed
 --> src/lib.rs:4:20
  |
4 |     let mut lol = |...| ();
  |                    ^^^
  |
help: consider giving this closure parameter an explicit type
  |
4 |     let mut lol = |...: /* Type */| ();
  |                       ++++++++++++

Note that one error message directly conflicts with another!

Weird!

Then I tried this:

unsafe extern "C" fn closures_cannot_varargs(mut ap: ...) -> u32 {
    let mut lol = |mut ap: ...| unsafe { ap.arg::<u32>() };
    lol(unsafe { ap.arg::<u32>() })
}

And I got this:

error[E0743]: C-variadic type ... may not be nested inside another type

so uh, lol

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.P-lowLow priorityT-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