Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variadic check only on last parameter #2850

Closed
0xn4utilus opened this issue Feb 13, 2024 · 0 comments · Fixed by #2851
Closed

Variadic check only on last parameter #2850

0xn4utilus opened this issue Feb 13, 2024 · 0 comments · Fixed by #2851
Labels

Comments

@0xn4utilus
Copy link
Contributor

I tried this code: https://godbolt.org/z/4r5KGPYeE

// test case 1
fn myfun0(...,_:i32) {}

// test case 2
fn myfun1(a:i32,...,_:i32) {}

// test case 3
struct z {
    x: f64,
    y: f64,
}

impl z {
    fn new(x: f64, ..., y: f64) -> z {
        z { x: x, y: y }
    }
}

I expected to see compilation error as seen when the below code is run.

fn myfun0(_:i32,...) {}

Instead, this happened:

    5 | fn myfun0(...,_:i32) {}
      |    ^~~~~~
<source>:7:4: warning: function is never used: 'myfun1'
    7 | fn myfun1(a:i32,...,_:i32) {}
      |    ^~~~~~
<source>:9:1: warning: struct is never constructed: 'z'
    9 | struct z {
      | ^~~~~~
<source>:15:8: warning: associated function is never used: 'new'
   15 |     fn new(x: f64, ..., y: f64) -> z {
      |        ^~~
<source>:7:11: warning: unused name 'a' [-Wunused-variable]
    7 | fn myfun1(a:i32,...,_:i32) {}
      |           ^
Compiler returned: 0
@0xn4utilus 0xn4utilus added the bug label Feb 13, 2024
0xn4utilus added a commit to 0xn4utilus/gccrs that referenced this issue Feb 13, 2024
gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add variadic check on all parameters.

Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant