-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fill match arms replaces whole impl block with proc macro attribute #10573
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
Comments
That's when we enabled attribute proc macros. You can still disable them to work around this issue. |
Can you run the |
Yes, disabling attribute proc macros produces the expected behavior for this action. I've trimmed down our code and I can reproduce it with this minimal impl block: #[payload]
impl Payload {
fn test(&mut self) {
match self.trigger_mode {
}
}
} This expands to the following: // Recursive expansion of payload! macro
// ======================================
impl Payload {
fn test(&mut self){
match self.trigger_mode{}
}
fn handle_frame(&mut self,frame: &Frame) -> Result<(),Error>{
use loki_payload::crsf::types::FramePayload;
match frame.payload(){
FramePayload::Ping(c) => self.com.handle_ping_request(*c),
FramePayload::Type => self.com.send_frame(&Frame::new_type_response(Payload::id(),Payload::version(),Payload::features(),)),
FramePayload::Authenticate(data) => self.com.handle_authenticate_request(data,Payload::id(),Payload::version(),Payload::features(),),
_ => {
Err(loki_payload::error::Error::UnknownFrameType(frame.type_id()))
}
}
}
} |
Ye looks like we fail to map the |
Just for my personal understanding. You are saying that rust-analyzer fails to map the If I wanted to poke around in the rust-analyzer code about this issue, do you know where I should start looking? |
The problem is that we find the match expression in the expanded code, we then want to map it back up to the text range of the original one so we edit it, but we fail in doing so for some reason. And currently if we fail this mapping we fall back to the entire macro invocation, which in this case is the impl with the attribute. The part that tries to get the correct range is this here, |
Thanks for the details 🙂 |
This problem seems to appear when using the syn and quote crate. This works #[proc_macro_attribute]
pub fn payload(_args: TokenStream, input: TokenStream) -> TokenStream {
input
} But this does not work #[proc_macro_attribute]
pub fn payload(_args: TokenStream, input: TokenStream) -> TokenStream {
let item = parse_macro_input!(input as Item);
let output = quote! {
#item
};
output.into()
} |
This actually already works with rustc 1.56. It will work with other rustc versions in the next release. Problem was us not shipping some span method implementations for other proc-macro abis. cc #10378 |
Ah good to hear 👍 |
Yep, next monday(tomorrow nightly) or if you run rustc 1.56 now. |
Excellent, thanks a lot! 🙂 |
I have some code that I unfortunately can't share where the "fill match arms" replaces a whole impl block.
I think it is related to the fact that I use a proc-macro attribute:
When I use the "fill match arms" action it replaces the whole impl block and I am left with this:
This might be a recent regression, I don't remember having any problems before 2 or 3 weeks ago. I have been trying to reproduce this with a small self-contained example but haven't been able to yet. I'll see if I can find some example code that triggers this behavior so that I can share it.
In the meantime, if I can provide any more useful information let me know.
The text was updated successfully, but these errors were encountered: