-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Better diagnostic for fn items in variadic functions #133538
base: master
Are you sure you want to change the base?
Conversation
r? @davidtwco rustbot has assigned @davidtwco. Use |
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.
This is not how you coerce a function item to a function pointer. Instead, you've suggested to turn something into a pointer-to-a-fn-item (i.e. a pointer to a ZST). You need to use as fn()
to coerce a function item to a function pointer.
Please fix this, and also squash this into one commit.
let span = arg.span; | ||
let (sugg_span, replace) = | ||
if let Ok(snippet) = sess.source_map().span_to_snippet(span) { | ||
(Some(span), format!("&{snippet}")) |
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.
nit: you also don't need to format the suggestion as a snippet. You can use span.shrink_to_{hi,lo}()
to get just the beginning or end of the span to add just the part you needed (in this case &
, but in the corrected case as ...
)
The job Click to see the possible cause of the failure (guessed by this bot)
|
@@ -79,6 +79,11 @@ hir_typeck_field_multiply_specified_in_initializer = | |||
.label = used more than once | |||
.previous_use_label = first use of `{$ident}` | |||
hir_typeck_fn_item_to_variadic_function = can't pass a function item to a variadic function | |||
.suggestion = use a function pointer instead | |||
.help = a function item is zero-sized and needs to be casted into a pointer-sized function pointer to be used in FFI |
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.
also, the past participle of cast is "cast"
.help = a function item is zero-sized and needs to be casted into a pointer-sized function pointer to be used in FFI | |
.help = a function item is zero-sized and needs to be cast into a function pointer to be used in FFI |
Also, the fact that it's zero-sized doesn't seem to me to be the most important part of this issue. The issue here is more that the intention is wrong, since you're not passing a function pointer like you expect.
closes #69232