-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Detect attempt to use var-args in closure #146581
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
Changes from 3 commits
9405e76
0e290e4
a84c8de
c916e88
ed85f98
8306a2f
e9270e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,26 +10,14 @@ error: unexpected `...` | |
LL | let f = |...| {}; | ||
| ^^^ not a valid pattern | ||
| | ||
help: for a rest pattern, use `..` instead of `...` | ||
| | ||
LL - let f = |...| {}; | ||
LL + let f = |..| {}; | ||
| | ||
= note: C-variadic type `...` is not allowed here | ||
|
||
error[E0743]: C-variadic type `...` may not be nested inside another type | ||
|
||
--> $DIR/no-closure.rs:14:17 | ||
--> $DIR/no-closure.rs:13:17 | ||
| | ||
LL | let f = |_: ...| {}; | ||
| ^^^ | ||
|
||
error: `..` patterns are not allowed here | ||
--> $DIR/no-closure.rs:10:14 | ||
| | ||
LL | let f = |...| {}; | ||
| ^^^ | ||
| | ||
= note: only allowed in tuple, tuple struct, and slice patterns | ||
|
||
error: aborting due to 4 previous errors | ||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0743`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// var-args are not supported in closures, ensure we don't misdirect people (#146489) | ||
#![feature(c_variadic)] | ||
|
||
unsafe extern "C" fn thats_not_a_pattern(mut ap: ...) -> u32 { | ||
let mut lol = |...| (); //~ ERROR: unexpected `...` | ||
unsafe { ap.arg::<u32>() } //~^ NOTE: C-variadic type `...` is not allowed here | ||
//~| NOTE: not a valid pattern | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: unexpected `...` | ||
--> $DIR/varargs-in-closure-isnt-supported.rs:5:20 | ||
| | ||
LL | let mut lol = |...| (); | ||
| ^^^ not a valid pattern | ||
| | ||
= note: C-variadic type `...` is not allowed here | ||
|
||
error: aborting due to 1 previous error | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, surprised we don't have a way to silence a lint by passing in an
ErrorGuaranteed
. We could then dothough maybe even better... change this function to return
Result<Diag, ErrorGuaranteed>
and avoid creating a diagnostic at all edit: seems annoying to do 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the rationale for
downgrade_to_delayed_bug
itself not taking anErrorGuarantee
is because itself is kind of an error guarantee already :)The guarantee is more critical for anything that could cause a binary to be emitted otherwise.