I wanted to add a modifier for variables that are callable for a while now. Motivated by when creating a fn pointer or a closure the variable name in call expression not being colorized.
For plain fn pointer and closures I have something kinda working on a local branch
I have 2 questions:
Do you need a modifier though?
Can't you just use "Function" tag?
Hm, I guess function and local would be in conflict, and a modifer might be indeed better...
You can use this method to determine if a type is a callable or not: https://github.com/rust-analyzer/rust-analyzer/blob/0d45802d671f94cb768b93a64882733396cfbe2d/crates/hir/src/code_model.rs#L1450
And I think other code in highlighting already fetches types for locals to underly &mut
Thanks a bunch!! I'll send a PR as soon as I can
It seems that as_callable only returns Some in case of FnDef, Closure and FnPtr
In the case of generics of Fn traits as_callable returns None
So how do I check if a Type implements FnOnce/FnMut/Fn?
Hm, I think thats a bug
the thing should return
Some for generics
the function "callable_sig" returns Some when TypeCtor::FnPtr, TypeCtor::FnDef and TypeCtor::Closure, but I'm not exactly comfortable with the code of "callable_sig", so maybe I'm the one missing something
Hm, yeah, it feels like that should also handle Ty::PLaceholder
@Florian Diebold might be the right person to ask this :-)
Fn traits aren't handled by
callable_sig because they need some more involved handling during inference. A function with the signature of
Ty::callable_sig can't actually check for the Fn trait because it needs the environment (also note that the expected number of args is actually relevant for inference). I think this needs separate and slightly different handling outside of inference, similar to that function and to the way we check for
Future, for example. I'd be a bit worried about doing so many trait solves, but if you just do it for type parameters it'd probably be ok
(and I don't think a helper method on
Ty should be doing any trait solving in general)
The code to check if implements Fn traits is somewhat similar to the code in impls_future?
If yes what is the string I have to pass to
Should I make lang_item_name public or just use "fn_once"?
actually, you could just use
True, I missed that