Skip to content
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

parse_item panics when given an incomplete impl trait block #59

Open
lilizoey opened this issue Dec 21, 2024 · 5 comments
Open

parse_item panics when given an incomplete impl trait block #59

lilizoey opened this issue Dec 21, 2024 · 5 comments

Comments

@lilizoey
Copy link

If you try to use parse_item on an impl trait block like this:

#[some_macro]
impl SomeTrait for Foo {
    fn re
}

Then venial will panic because of a call to Option::unwrap. I believe it is this call specifically.

This is a problem as a proc-macro panicking like this prevents RA from reliably autocompleting the code.

@PoignardAzur
Copy link
Owner

I'd honestly say this is a problem with RA and not this macro? If the block is invalid, then it shouldn't be fed to venial in the first place.

Making venial resilient to parsing errors would be a pretty deep change, much deeper than I'm willing to do.

@dtolnay
Copy link

dtolnay commented Dec 22, 2024

This was the upstream rust-analyzer bug. rust-lang/rust-analyzer#10468 (comment)

But I thought it got fixed as part of rust-lang/rust-analyzer#11014. Is the repro here really an attribute macro or were you using venial from a bang macro?

@PoignardAzur
Copy link
Owner

Wasn't expecting to see a reply from you. Out of curiosity, how did you get pinged about this?

@lilizoey
Copy link
Author

This was the upstream rust-analyzer bug. rust-lang/rust-analyzer#10468 (comment)

But I thought it got fixed as part of rust-lang/rust-analyzer#11014. Is the repro here really an attribute macro or were you using venial from a bang macro?

It sometimes works but very unreliably when the attribute macro panics. I've got it to autocomplete a function name, but also sometimes it just doesn't work at all. i'll see if i can make a smaller repro since i've been using a much bigger more complicated attribute macro, however the panic is what it complained about.

@lilizoey
Copy link
Author

Yes, using this proc macro code:

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn some_macro(_attr: TokenStream, _item: TokenStream) -> TokenStream {
    panic!("i failed!");
}

and this code:

use fucky_macros::some_macro;

pub trait Foo {
    fn my_function() {}
}

pub struct Bar;

#[some_macro]
impl Foo for Bar {
    fn m
}

the autocompletion fails:
Screenshot_20241222_182035

well in this case the correct function name shows up, but i'd expect the output that happens without the macro at all:
Screenshot_20241222_182022

and it does work when i replace the proc-macro with a noop like:

#[proc_macro_attribute]
pub fn some_macro(_attr: TokenStream, _item: TokenStream) -> TokenStream {
    // panic!("i failed!");
    _item
}

Screenshot_20241222_182643

in fact when the attribute macro panics, and i write fn i get this autocompletion:
Screenshot_20241222_182726
which seems strange

this is all with RA version v0.3.2220. the current pre-release gives the weird output with a noop attribute proc-macro too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants