syn
syn copied to clipboard
Demonstrate parse_quote in the crate-level documentation
This macro is commonly useful for building a syntax tree and should be featured more prominently.
// Add a trait bound to every type parameter
for param in &mut generics.params {
if let GenericParam::Type(ref mut type_param) = *param {
type_param.bounds.push(parse_quote!(diesel::query_builder::QueryId));
}
}
Do we also show along with the examples that parse_quote!
requires an explicit dependency on quote
crate in user's code?
Since macro reexport is unstable and has a lot of issues at this moment I suggest that the documentation should inform its readers about this unfortunate consequence of using external macros in macro expansions.
For example, this code fails to compile today if there is no dependencies.quote
entry in Cargo.toml and no #[macro_use] extern crate quote;
in main.rs:
#[macro_use]
extern crate syn;
fn main() {
let _x: syn::Path = parse_quote!(core::iter::Iterator);
}
Even though the first example in the parse_quote!
docs has #[macro_use] extern crate quote;
, in my opinion it doesn't stand out enough to notice that. On top of that the docs don't mention anything about Cargo.toml.
It does not require a direct quote
dependency as of #512.