-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat: Add assist to generate a type alias for a function #18385
Conversation
No idea how this slipped past me
None => "".into(), | ||
}; | ||
|
||
let fn_unsafe = if func_node.unsafe_token().is_some() { "unsafe " } else { "" }; |
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.
There are more qualifiers to handle, const
and async
(keep ordering in mind, the qualifiers allow only a specific order)
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.
Function pointers cannot be const
nor async
. I suppose I could generate an alias returning Future
for async
functions, let me know if this is desirable. I'm not really sure of an equivalent for a const
functions, but a non-const
function pointer should accept a const
function as an argument, so I think it's fine to just ignore a const
qualifier.
That's fine. One thing that would be nice to have though is that any generic parameters declared on the function are lifted to the type alias, that is:
Yes thats fine that way I'd say |
Unless I misunderstand, this code does that. For example, the test fn foo<A, B>(a: A, b: B) -> i32 { return 42; } into type FooFn<A, B> = fn(A, B) -> i32; |
Thanks! |
closes #18343
Technically this doesn't support generating
for <...>
lifetimes, but I'm not very familiar with them, and they seem a bit outside of the scope of an assist like this. If somebody has a way to generate them feel free to add it.Also, when generating aliases with self parameters, they are left unnamed even in the
generate_fn_type_alias_named
assist. I think this behavior makes the most sense but you could also name them something likethis
and add a placeholder to change the name if that's desired.