Update example code to 2018 edition
diff --git a/src/attr.rs b/src/attr.rs
index 8494265..da12047 100644
--- a/src/attr.rs
+++ b/src/attr.rs
@@ -70,10 +70,7 @@
/// [`Attribute::parse_inner`]: #method.parse_inner
///
/// ```
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{Attribute, Ident, Result};
+ /// use syn::{Attribute, Ident, Result, Token};
/// use syn::parse::{Parse, ParseStream};
///
/// // Parses a unit struct with attributes.
@@ -97,8 +94,6 @@
/// })
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
pub struct Attribute #manual_extra_traits {
pub pound_token: Token![#],
@@ -488,13 +483,10 @@
/// as type `AttributeArgs`.
///
/// ```rust
-/// #[macro_use]
-/// extern crate syn;
-///
/// extern crate proc_macro;
///
/// use proc_macro::TokenStream;
-/// use syn::{AttributeArgs, ItemFn};
+/// use syn::{parse_macro_input, AttributeArgs, ItemFn};
///
/// # const IGNORE: &str = stringify! {
/// #[proc_macro_attribute]
@@ -506,8 +498,6 @@
/// /* ... */
/// # "".parse().unwrap()
/// }
-/// #
-/// # fn main() {}
/// ```
pub type AttributeArgs = Vec<NestedMeta>;
diff --git a/src/error.rs b/src/error.rs
index 13095cc..e3bc304 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -52,10 +52,7 @@
/// # Example
///
/// ```
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{Error, Ident, LitStr, Result};
+ /// use syn::{Error, Ident, LitStr, Result, Token};
/// use syn::parse::ParseStream;
///
/// // Parses input that looks like `name = "string"` where the key must be
@@ -72,8 +69,6 @@
/// let s: LitStr = input.parse()?;
/// Ok(s)
/// }
- /// #
- /// # fn main() {}
/// ```
pub fn new<T: Display>(span: Span, message: T) -> Self {
Error {
diff --git a/src/expr.rs b/src/expr.rs
index 62c4832..d07070f 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -2292,10 +2292,7 @@
/// # Example
///
/// ```
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{token, Attribute, Block, Ident, Result, Stmt};
+ /// use syn::{braced, token, Attribute, Block, Ident, Result, Stmt, Token};
/// use syn::parse::{Parse, ParseStream};
///
/// // Parse a function with no generics or parameter list.
@@ -2337,8 +2334,6 @@
/// })
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
pub fn parse_within(input: ParseStream) -> Result<Vec<Stmt>> {
let mut stmts = Vec::new();
diff --git a/src/ext.rs b/src/ext.rs
index 16d0dbf..38c7a2c 100644
--- a/src/ext.rs
+++ b/src/ext.rs
@@ -18,10 +18,7 @@
/// identifiers.
///
/// ```rust
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{Error, Ident, Result};
+ /// use syn::{Error, Ident, Result, Token};
/// use syn::ext::IdentExt;
/// use syn::parse::ParseStream;
///
@@ -41,8 +38,6 @@
/// let name = input.call(Ident::parse_any)?;
/// Ok(name)
/// }
- /// #
- /// # fn main() {}
/// ```
fn parse_any(input: ParseStream) -> Result<Self>;
}
diff --git a/src/file.rs b/src/file.rs
index f1f7034..caa1565 100644
--- a/src/file.rs
+++ b/src/file.rs
@@ -11,8 +11,6 @@
/// representation of the syntax tree.
///
/// ```
- /// # extern crate syn;
- /// #
/// use std::env;
/// use std::fs::File;
/// use std::io::Read;
diff --git a/src/generics.rs b/src/generics.rs
index b73d786..8119385 100644
--- a/src/generics.rs
+++ b/src/generics.rs
@@ -293,13 +293,11 @@
/// for that type.
///
/// ```
- /// # #[macro_use]
+ /// # extern crate proc_macro2;
/// # extern crate quote;
/// #
- /// # extern crate proc_macro2;
- /// # extern crate syn;
- /// #
/// # use proc_macro2::{Span, Ident};
+ /// # use quote::quote;
/// #
/// # fn main() {
/// # let generics: syn::Generics = Default::default();
diff --git a/src/group.rs b/src/group.rs
index 026ece4..d2cbd3e 100644
--- a/src/group.rs
+++ b/src/group.rs
@@ -95,13 +95,10 @@
/// # Example
///
/// ```rust
-/// # #[macro_use]
/// # extern crate quote;
+/// # use quote::quote;
/// #
-/// #[macro_use]
-/// extern crate syn;
-///
-/// use syn::{token, Ident, Result, Type};
+/// use syn::{parenthesized, token, Ident, Result, Token, Type};
/// use syn::parse::{Parse, ParseStream};
/// use syn::punctuated::Punctuated;
///
@@ -156,12 +153,10 @@
/// # Example
///
/// ```rust
-/// # #[macro_use]
/// # extern crate quote;
+/// # use quote::quote;
/// #
-/// #[macro_use]
-/// extern crate syn;
-/// use syn::{token, Ident, Result, Type};
+/// use syn::{braced, token, Ident, Result, Token, Type};
/// use syn::parse::{Parse, ParseStream};
/// use syn::punctuated::Punctuated;
///
@@ -237,16 +232,13 @@
/// # Example
///
/// ```rust
-/// # #[macro_use]
+/// # extern crate proc_macro2;
/// # extern crate quote;
/// #
-/// #[macro_use]
-/// extern crate syn;
-///
-/// extern crate proc_macro2;
-///
+/// # use quote::quote;
+/// #
/// use proc_macro2::TokenStream;
-/// use syn::{token, Result};
+/// use syn::{bracketed, token, Result, Token};
/// use syn::parse::{Parse, ParseStream};
///
/// // Parse an outer attribute like:
diff --git a/src/keyword.rs b/src/keyword.rs
index 9bfb260..54aba98 100644
--- a/src/keyword.rs
+++ b/src/keyword.rs
@@ -8,14 +8,9 @@
/// with a `kw::` or `keyword::` prefix.
///
/// ```
-/// # #[macro_use]
-/// # extern crate syn;
-/// #
/// mod kw {
-/// custom_keyword!(whatever);
+/// syn::custom_keyword!(whatever);
/// }
-/// #
-/// # fn main() {}
/// ```
///
/// The generated syntax tree node supports the following operations just like
@@ -49,15 +44,12 @@
/// by crates that need to use them as such.
///
/// ```
-/// #[macro_use]
-/// extern crate syn;
-///
-/// use syn::{LitBool, LitStr, Result};
+/// use syn::{LitBool, LitStr, Result, Token};
/// use syn::parse::{Parse, ParseStream};
///
/// mod kw {
-/// custom_keyword!(bool);
-/// custom_keyword!(str);
+/// syn::custom_keyword!(bool);
+/// syn::custom_keyword!(str);
/// }
///
/// enum Argument {
@@ -93,8 +85,6 @@
/// }
/// }
/// }
-/// #
-/// # fn main() {}
/// ```
#[macro_export(local_inner_macros)]
macro_rules! custom_keyword {
diff --git a/src/lib.rs b/src/lib.rs
index 12802e9..382e504 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -65,15 +65,13 @@
//! ```
//!
//! ```rust
-//! #[macro_use]
-//! extern crate quote;
-//! #[macro_use]
-//! extern crate syn;
-//!
+//! # extern crate quote;
+//! #
//! extern crate proc_macro;
//!
//! use proc_macro::TokenStream;
-//! use syn::DeriveInput;
+//! use quote::quote;
+//! use syn::{parse_macro_input, DeriveInput};
//!
//! # const IGNORE_TOKENS: &str = stringify! {
//! #[proc_macro_derive(MyMacro)]
@@ -90,8 +88,6 @@
//! // Hand the output tokens back to the compiler
//! TokenStream::from(expanded)
//! }
-//! #
-//! # fn main() {}
//! ```
//!
//! The [`heapsize`] example directory shows a complete working Macros 1.1
@@ -589,13 +585,12 @@
/// # Examples
///
/// ```rust
-/// #[macro_use]
-/// extern crate quote;
-///
+/// # extern crate quote;
+/// #
/// extern crate proc_macro;
-/// extern crate syn;
///
/// use proc_macro::TokenStream;
+/// use quote::quote;
/// use syn::DeriveInput;
///
/// # const IGNORE_TOKENS: &str = stringify! {
@@ -613,8 +608,6 @@
/// // Convert into a token stream and return it
/// expanded.into()
/// }
-/// #
-/// # fn main() {}
/// ```
#[cfg(all(
not(all(target_arch = "wasm32", target_os = "unknown")),
@@ -654,8 +647,6 @@
/// # Examples
///
/// ```rust
-/// # extern crate syn;
-/// #
/// use syn::{Expr, Result};
///
/// fn run() -> Result<()> {
@@ -665,7 +656,9 @@
/// Ok(())
/// }
/// #
-/// # fn main() { run().unwrap() }
+/// # fn main() {
+/// # run().unwrap();
+/// # }
/// ```
#[cfg(feature = "parsing")]
pub fn parse_str<T: parse::Parse>(s: &str) -> Result<T> {
@@ -688,8 +681,6 @@
/// # Examples
///
/// ```rust,no_run
-/// # extern crate syn;
-/// #
/// use std::error::Error;
/// use std::fs::File;
/// use std::io::Read;
@@ -708,7 +699,9 @@
/// Ok(())
/// }
/// #
-/// # fn main() { run().unwrap() }
+/// # fn main() {
+/// # run().unwrap();
+/// # }
/// ```
#[cfg(all(feature = "parsing", feature = "full"))]
pub fn parse_file(mut content: &str) -> Result<File> {
diff --git a/src/lifetime.rs b/src/lifetime.rs
index dbf01a9..9572a61 100644
--- a/src/lifetime.rs
+++ b/src/lifetime.rs
@@ -37,7 +37,6 @@
///
/// ```
/// # extern crate proc_macro2;
- /// # extern crate syn;
/// #
/// # use proc_macro2::Span;
/// # use syn::Lifetime;
diff --git a/src/lit.rs b/src/lit.rs
index a39cd3c..9fd87e8 100644
--- a/src/lit.rs
+++ b/src/lit.rs
@@ -123,7 +123,6 @@
///
/// ```
/// # extern crate proc_macro2;
- /// # extern crate syn;
/// #
/// use proc_macro2::Span;
/// use syn::{Attribute, Error, Ident, Lit, Meta, MetaNameValue, Path, Result};
diff --git a/src/lookahead.rs b/src/lookahead.rs
index c8fdbc8..10cd023 100644
--- a/src/lookahead.rs
+++ b/src/lookahead.rs
@@ -22,10 +22,7 @@
/// # Example
///
/// ```
-/// #[macro_use]
-/// extern crate syn;
-///
-/// use syn::{ConstParam, Ident, Lifetime, LifetimeDef, Result, TypeParam};
+/// use syn::{ConstParam, Ident, Lifetime, LifetimeDef, Result, Token, TypeParam};
/// use syn::parse::{Parse, ParseStream};
///
/// // A generic parameter, a single one of the comma-separated elements inside
@@ -59,8 +56,6 @@
/// }
/// }
/// }
-/// #
-/// # fn main() {}
/// ```
pub struct Lookahead1<'a> {
scope: Span,
diff --git a/src/parse.rs b/src/parse.rs
index 80e0004..34bbf0a 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -26,13 +26,10 @@
//! [`parse_macro_input!`]: ../macro.parse_macro_input.html
//!
//! ```
-//! #[macro_use]
-//! extern crate syn;
-//!
//! extern crate proc_macro;
//!
//! use proc_macro::TokenStream;
-//! use syn::{token, Field, Ident, Result};
+//! use syn::{braced, parse_macro_input, token, Field, Ident, Result, Token};
//! use syn::parse::{Parse, ParseStream};
//! use syn::punctuated::Punctuated;
//!
@@ -90,8 +87,6 @@
//! /* ... */
//! # "".parse().unwrap()
//! }
-//! #
-//! # fn main() {}
//! ```
//!
//! # The `syn::parse*` functions
@@ -139,7 +134,6 @@
//!
//! ```compile_fail
//! # extern crate proc_macro;
-//! # extern crate syn;
//! #
//! # use syn::punctuated::Punctuated;
//! # use syn::{PathSegment, Result, Token};
@@ -161,15 +155,12 @@
//! [`Parser`]: trait.Parser.html
//!
//! ```
-//! #[macro_use]
-//! extern crate syn;
-//!
-//! extern crate proc_macro2;
-//!
+//! # extern crate proc_macro2;
+//! #
//! use proc_macro2::TokenStream;
//! use syn::parse::Parser;
//! use syn::punctuated::Punctuated;
-//! use syn::{Attribute, Expr, PathSegment};
+//! use syn::{Attribute, Expr, PathSegment, Token};
//!
//! # fn run_parsers() -> syn::Result<()> {
//! # let tokens = TokenStream::new().into();
@@ -191,8 +182,6 @@
//! #
//! # Ok(())
//! # }
-//! #
-//! # fn main() {}
//! ```
//!
//! ---
@@ -306,7 +295,6 @@
///
/// ```
/// # extern crate proc_macro2;
-/// # extern crate syn;
/// #
/// use proc_macro2::TokenTree;
/// use syn::Result;
@@ -330,7 +318,6 @@
/// })
/// }
/// #
-/// #
/// # fn remainder_after_skipping_past_next_at(
/// # input: ParseStream,
/// # ) -> Result<proc_macro2::TokenStream> {
@@ -443,10 +430,7 @@
/// [`Attribute::parse_outer`]: ../struct.Attribute.html#method.parse_outer
///
/// ```
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{Attribute, Ident, Result};
+ /// use syn::{Attribute, Ident, Result, Token};
/// use syn::parse::{Parse, ParseStream};
///
/// // Parses a unit struct with attributes.
@@ -470,8 +454,6 @@
/// })
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
pub fn call<T>(&self, function: fn(ParseStream) -> Result<T>) -> Result<T> {
function(self)
@@ -499,10 +481,7 @@
/// token in the input is either `where` or an opening curly brace.
///
/// ```
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{token, Generics, Ident, Result, TypeParamBound};
+ /// use syn::{braced, token, Generics, Ident, Result, Token, TypeParamBound};
/// use syn::parse::{Parse, ParseStream};
/// use syn::punctuated::Punctuated;
///
@@ -550,8 +529,6 @@
/// })
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
pub fn peek<T: Peek>(&self, token: T) -> bool {
let _ = token;
@@ -571,10 +548,7 @@
/// }`. In other words `union` is a contextual keyword.
///
/// ```
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{Ident, ItemUnion, Macro, Result};
+ /// use syn::{Ident, ItemUnion, Macro, Result, Token};
/// use syn::parse::{Parse, ParseStream};
///
/// // Parses either a union or a macro invocation.
@@ -594,8 +568,6 @@
/// }
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
pub fn peek2<T: Peek>(&self, token: T) -> bool {
let ahead = self.fork();
@@ -617,13 +589,10 @@
/// # Example
///
/// ```rust
- /// # #[macro_use]
/// # extern crate quote;
+ /// # use quote::quote;
/// #
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{token, Ident, Result, Type};
+ /// use syn::{parenthesized, token, Ident, Result, Token, Type};
/// use syn::parse::{Parse, ParseStream};
/// use syn::punctuated::Punctuated;
///
@@ -673,10 +642,7 @@
/// # Example
///
/// ```rust
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{token, Ident, Item, Result};
+ /// use syn::{braced, token, Ident, Item, Result, Token};
/// use syn::parse::{Parse, ParseStream};
///
/// // Parses a Rust `mod m { ... }` containing zero or more items.
@@ -704,8 +670,6 @@
/// })
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
pub fn is_empty(&self) -> bool {
self.cursor().eof()
@@ -717,10 +681,7 @@
/// # Example
///
/// ```
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{ConstParam, Ident, Lifetime, LifetimeDef, Result, TypeParam};
+ /// use syn::{ConstParam, Ident, Lifetime, LifetimeDef, Result, Token, TypeParam};
/// use syn::parse::{Parse, ParseStream};
///
/// // A generic parameter, a single one of the comma-separated elements inside
@@ -754,8 +715,6 @@
/// }
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
pub fn lookahead1(&self) -> Lookahead1<'a> {
lookahead::new(self.scope, self.cursor())
@@ -826,10 +785,7 @@
/// work performed against the forked parse stream.
///
/// ```
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{token, Ident, Path, Result};
+ /// use syn::{parenthesized, token, Ident, Path, Result, Token};
/// use syn::ext::IdentExt;
/// use syn::parse::{Parse, ParseStream};
///
@@ -883,8 +839,6 @@
/// })
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
pub fn fork(&self) -> Self {
ParseBuffer {
@@ -902,10 +856,7 @@
/// # Example
///
/// ```
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{Expr, Result};
+ /// use syn::{Expr, Result, Token};
/// use syn::parse::{Parse, ParseStream};
///
/// // Some kind of loop: `while` or `for` or `loop`.
@@ -927,8 +878,6 @@
/// }
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
pub fn error<T: Display>(&self, message: T) -> Error {
error::new_at(self.scope, self.cursor(), message)
@@ -945,7 +894,6 @@
///
/// ```
/// # extern crate proc_macro2;
- /// # extern crate syn;
/// #
/// use proc_macro2::TokenTree;
/// use syn::Result;
diff --git a/src/parse_macro_input.rs b/src/parse_macro_input.rs
index 6b3785b..e38c711 100644
--- a/src/parse_macro_input.rs
+++ b/src/parse_macro_input.rs
@@ -9,13 +9,10 @@
/// # Intended usage
///
/// ```rust
-/// #[macro_use]
-/// extern crate syn;
-///
/// extern crate proc_macro;
///
/// use proc_macro::TokenStream;
-/// use syn::Result;
+/// use syn::{parse_macro_input, Result};
/// use syn::parse::{Parse, ParseStream};
///
/// struct MyMacroInput {
@@ -38,8 +35,6 @@
/// /* ... */
/// # "".parse().unwrap()
/// }
-/// #
-/// # fn main() {}
/// ```
#[macro_export(local_inner_macros)]
macro_rules! parse_macro_input {
diff --git a/src/parse_quote.rs b/src/parse_quote.rs
index 5d4045b..13ba95b 100644
--- a/src/parse_quote.rs
+++ b/src/parse_quote.rs
@@ -9,12 +9,10 @@
/// [`Parse`]: parse/trait.Parse.html
///
/// ```
-/// #[macro_use]
-/// extern crate quote;
-/// #[macro_use]
-/// extern crate syn;
-///
-/// use syn::Stmt;
+/// # extern crate quote;
+/// #
+/// use quote::quote;
+/// use syn::{parse_quote, Stmt};
///
/// fn main() {
/// let name = quote!(v);
@@ -38,12 +36,7 @@
/// parameter `T` in the input generics.
///
/// ```
-#[cfg_attr(not(syn_can_call_macro_by_path), doc = " #[macro_use]")]
-#[cfg_attr(not(syn_can_call_macro_by_path), doc = " extern crate quote;")]
-/// #[macro_use]
-/// extern crate syn;
-///
-/// use syn::{Generics, GenericParam};
+/// use syn::{parse_quote, Generics, GenericParam};
///
/// // Add a bound `T: HeapSize` to every type parameter T.
/// fn add_trait_bounds(mut generics: Generics) -> Generics {
@@ -54,8 +47,6 @@
/// }
/// generics
/// }
-/// #
-/// # fn main() {}
/// ```
///
/// # Special cases
diff --git a/src/path.rs b/src/path.rs
index 97ba58c..f35c111 100644
--- a/src/path.rs
+++ b/src/path.rs
@@ -359,10 +359,7 @@
/// # Example
///
/// ```
- /// #[macro_use]
- /// extern crate syn;
- ///
- /// use syn::{Path, Result};
+ /// use syn::{Path, Result, Token};
/// use syn::parse::{Parse, ParseStream};
///
/// // A simplified single `use` statement like:
@@ -386,8 +383,6 @@
/// })
/// }
/// }
- /// #
- /// # fn main() {}
/// ```
pub fn parse_mod_style(input: ParseStream) -> Result<Self> {
Ok(Path {
diff --git a/src/spanned.rs b/src/spanned.rs
index a1a2a9a..a6a2120 100644
--- a/src/spanned.rs
+++ b/src/spanned.rs
@@ -23,13 +23,11 @@
//! ```
//! # extern crate proc_macro;
//! # extern crate proc_macro2;
-//! # extern crate syn;
+//! # extern crate quote;
//! #
-//! #[macro_use]
-//! extern crate quote;
-//!
//! use proc_macro::TokenStream;
//! use proc_macro2::Span;
+//! use quote::quote_spanned;
//! use syn::Type;
//! use syn::spanned::Spanned;
//!
@@ -51,8 +49,6 @@
//! # fn get_a_type() -> Type {
//! # unimplemented!()
//! # }
-//! #
-//! # fn main() {}
//! ```
//!
//! By inserting this `assert_sync` fragment into the output code generated by
diff --git a/src/token.rs b/src/token.rs
index 6409c51..8dc6e24 100644
--- a/src/token.rs
+++ b/src/token.rs
@@ -13,10 +13,7 @@
//! [`ItemStatic`]: ../struct.ItemStatic.html
//!
//! ```
-//! # #[macro_use]
-//! # extern crate syn;
-//! #
-//! # use syn::{Attribute, Expr, Ident, Type, Visibility};
+//! # use syn::{Attribute, Expr, Ident, Token, Type, Visibility};
//! #
//! pub struct ItemStatic {
//! pub attrs: Vec<Attribute>,
@@ -30,8 +27,6 @@
//! pub expr: Box<Expr>,
//! pub semi_token: Token![;],
//! }
-//! #
-//! # fn main() {}
//! ```
//!
//! # Parsing
@@ -46,8 +41,6 @@
//! [`braced!`]: ../macro.braced.html
//!
//! ```
-//! # extern crate syn;
-//! #
//! use syn::{Attribute, Result};
//! use syn::parse::{Parse, ParseStream};
//! #
@@ -74,8 +67,6 @@
//! # unimplemented!()
//! }
//! }
-//! #
-//! # fn main() {}
//! ```
use std;