-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use $crate to refer to diesels macros #1956
Conversation
Enables direct macro imports for diesel macros. Removes #[macro_use] from diesel_cli crate to demonstrate.
@diesel-rs/core I think we should discuss where we want to expose those macros exactly.
Thinks to bikeshed: Maybe expose every macro just from |
Good point. I didn't think about this. From what I understand derive macros are not meant to be imported separately from their traits. On phone so I can't look it up but I remember a discussion about this where it was agreed importing them separately should be discouraged. Remember that macros have a different namespace than traits. // Import _both_ the derive macros and trait
use diesel::deserialize::Queryable; // import derive macro and trait separately
use diesel::derives::Queryable;
use diesel::deserialize::Queryable; |
@weiznich Why 2.0? This isn't a breaking change. No matter where we move the macro re-exports, |
Sure that's no breaking change, but I do not see that we get to a consense here before we released 1.4. The next planed version after that will be 2.0 😉 |
@sgrif @weiznich Any thoughts on how we want the macros? My basic proposal would be:
|
It's not, but this represents a pretty major change to the "normal" way to use Diesel, so I think it makes sense to include it as a major part of 2.0.
Derives should definitely not be a thing the user ever has to think about. They should for sure be exported with the trait in question. Almost all of those are already in prelude, any that aren't probably should be. This is especially important for derives that don't map to an individual trait, such as As for the bang macros, I think this should probably be considered on a case by case basis. I'd be interested in seeing an audit of all our public bang macros, and seeing how many of them are likely to appear in non-generated files, how much we think they'll appear in app code vs plugin code, and where we might think to put them.
Yeah, I think I agree with this. Glancing through the list of macros we export today (that I'm honestly not sure is complete because it's shorter than I remember), most of these have a vaguely clear place to put them. e.g. The only things I could see going into a |
#[macro_use] only brings derive macros at root into scope
Some bad news. Rust doesn't let you organize I did organize the |
At least something like this seems ~work. Unfortunately I've found no way to hide the documentation output in the crate root, at least not in 5 minutes playing around with that. (Maybe that's not possible and we should just try to make it possible in rustdoc?) cc @sgrif about that. mod macros {
#[macro_export]
macro_rules! foo {
($($tt:tt)*) => {}
}
}
pub mod public_macro {
#[doc(inline)]
pub use super::foo;
} |
Would be cool if this could be merged. Diesel currently doesn’t align with the Rust book, so it is hard for beginners to grasp, why we need to use |
@fbruetting This is planed for the next release, but it needs some work before it could be merged. Especially someone needs to figure out where exactly each macro should be exported (and make the documentation appear there). |
Enables direct macro imports for diesel macros. Removes #[macro_use] from diesel_cli crate to demonstrate.
$crate::
is only legal to be used in Rust 1.30+ but as of 1.4 diesel has a minimum rust version of 1.31.See rust-lang/rust#35896 (comment) for a good explanation of how to take advantage of the new macro import system.