softdevteam / grmtools

Rust grammar tool libraries and binaries
Other
507 stars 31 forks source link

Generated code incompatible with `-D rust-2018-idioms` #364

Closed shayne-fletcher closed 1 year ago

shayne-fletcher commented 1 year ago

With -D rust-2018-idioms and warnings as errors hidden lifetime parameters in generated code are causing compilation failures e.g.

603 |                       mut __gt_args: ::std::vec::Drain<'_, ::lrpar::parser::AStackType<lrlex::lexemes::DefaultLexeme<u8>, __GtActionsKind<'input>>>,
    |                                                        +++
error: hidden lifetime parameters in types are deprecated

I'd disable this by injecting #![allow(elided_lifetimes_in_paths)] at the start of the generated module but I can't find a way to do this (is there one?)

shayne-fletcher commented 1 year ago

never mind, i think i'm just using the tool in an unexpected way :)

ratmice commented 1 year ago

FWIW, I had a look using the quick start/calc example from the grmtools book, and rustc 1.64, and wasn't able to reproduce with RUSTFLAGS="-D rust-2018-idioms" cargo build, so if it is something that we want to support, I haven't been able to reproduce it yet

ratmice commented 1 year ago

I'd disable this by injecting #![allow(elided_lifetimes_in_paths)] at the start of the generated module but I can't find a way to do this (is there one?)

Forgot to respond to this, I think there used to be a hack (I'm not sure if it still works, I seem to recall it might not), that you could do something to the effect of:

mod _tmp_ {
    #![allow(elided_lifetimes_in_paths)]
   lrpar_mod!("calc.y");
}
use _tmp_::*;

To add attributes at the start of a module, it might be worth trying that.

shayne-fletcher commented 1 year ago

thanks for taking a look!

i expect it would be nice to sort out.

i have straightened out my usage scheme and a workaround. here's how i'm doing it (in case it helps somebody in some way). i'm building a crate asdl. the crate root is asdl.rs:

// ---
// asdl.rs
#![allow(elided_lifetimes_in_paths)]  
pub mod lexer;
pub mod parser;

// ---
// lexer.rs
include!(env!("asdl_l"));                                                                 
pub use asdl_l::*;                                                                        

// ---
// parser.rs
include!(env!("asdl_y"));
pub use asdl_y::*;

in the presence of the lint group -Drust-2018-idioms (or equivalently the flag -Delided-lifetimes-in-paths) and without the #![allow(elided_lifetimes_in_paths)] the error manifests.

seems i'm using rustc 1.64.0-dev.

shayne-fletcher commented 1 year ago

thanks again @ratmice. i'm having a great experience with these tools! 😀

shayne-fletcher commented 1 year ago

I'd disable this by injecting #![allow(elided_lifetimes_in_paths)] at the start of the generated module but I can't find a way to do this (is there one?)

Forgot to respond to this, I think there used to be a hack (I'm not sure if it still works, I seem to recall it might not), that you could do something to the effect of:

mod _tmp_ {
    #![allow(elided_lifetimes_in_paths)]
   lrpar_mod!("calc.y");
}
use _tmp_::*;

To add attributes at the start of a module, it might be worth trying that.

lol. great minds think alike! ;)

ratmice commented 1 year ago

in #367 we did change the code generation so this should work with that lint without hacks in the next release.