11 changes: 4 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
sudo: false
language: rust

rust:
- nightly
- stable
- beta
- 1.31.0

before_script:
- set -o errexit

Expand Down Expand Up @@ -37,6 +30,10 @@ matrix:
- rustup component add rustc-dev
script:
- cargo test --all-features --release
- rust: nightly
- rust: stable
- rust: beta
- rust: 1.31.0
- rust: nightly
name: Examples
script:
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "syn"
version = "1.0.11" # don't forget to update html_root_url and syn.json
version = "1.0.17" # don't forget to update html_root_url and syn.json
authors = ["David Tolnay <dtolnay@gmail.com>"]
license = "MIT OR Apache-2.0"
description = "Parser for Rust source code"
Expand Down Expand Up @@ -34,7 +34,7 @@ extra-traits = []
proc-macro = ["proc-macro2/proc-macro", "quote/proc-macro"]

[dependencies]
proc-macro2 = { version = "1.0", default-features = false }
proc-macro2 = { version = "1.0.7", default-features = false }
quote = { version = "1.0", optional = true, default-features = false }
unicode-xid = "0.2"

Expand All @@ -45,7 +45,7 @@ insta = "0.12"
rayon = "1.0"
ref-cast = "1.0"
regex = "1.0"
reqwest = { version = "0.10.0-alpha.2", features = ["blocking"] }
reqwest = { version = "0.10", features = ["blocking"] }
tar = "0.4"
termcolor = "1.0"
walkdir = "2.1"
Expand All @@ -61,6 +61,7 @@ required-features = ["full", "parsing"]

[package.metadata.docs.rs]
all-features = true
targets = ["x86_64-unknown-linux-gnu"]

[package.metadata.playground]
all-features = true
Expand Down
7 changes: 7 additions & 0 deletions benches/file.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
// $ cargo bench --features full --bench file

#![feature(rustc_private, test)]
#![recursion_limit = "1024"]

extern crate test;

#[macro_use]
#[path = "../tests/macros/mod.rs"]
mod macros;

#[path = "../tests/common/mod.rs"]
mod common;
#[path = "../tests/repo/mod.rs"]
pub mod repo;

Expand Down
32 changes: 22 additions & 10 deletions benches/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
// $ RUSTFLAGS='--cfg syn_only' cargo build --release --features full --bench rust

#![cfg_attr(not(syn_only), feature(rustc_private))]
#![recursion_limit = "1024"]

#[macro_use]
#[path = "../tests/macros/mod.rs"]
mod macros;

#[path = "../tests/common/mod.rs"]
mod common;
#[path = "../tests/repo/mod.rs"]
mod repo;

Expand All @@ -29,30 +36,35 @@ mod syn_parse {

#[cfg(not(syn_only))]
mod libsyntax_parse {
extern crate rustc_ast;
extern crate rustc_data_structures;
extern crate syntax;
extern crate syntax_pos;
extern crate rustc_errors;
extern crate rustc_parse;
extern crate rustc_session;
extern crate rustc_span;

use rustc_data_structures::sync::Lrc;
use syntax::edition::Edition;
use syntax::errors::{emitter::Emitter, DiagnosticBuilder, Handler};
use syntax::parse::ParseSess;
use syntax::source_map::{FilePathMapping, SourceMap};
use syntax_pos::FileName;
use rustc_errors::{emitter::Emitter, Diagnostic, Handler};
use rustc_session::parse::ParseSess;
use rustc_span::source_map::{FilePathMapping, SourceMap};
use rustc_span::{edition::Edition, FileName};

pub fn bench(content: &str) -> Result<(), ()> {
struct SilentEmitter;

impl Emitter for SilentEmitter {
fn emit_diagnostic(&mut self, _db: &DiagnosticBuilder) {}
fn emit_diagnostic(&mut self, _diag: &Diagnostic) {}
fn source_map(&self) -> Option<&Lrc<SourceMap>> {
None
}
}

syntax::with_globals(Edition::Edition2018, || {
rustc_ast::with_globals(Edition::Edition2018, || {
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
let emitter = Box::new(SilentEmitter);
let handler = Handler::with_emitter(false, None, emitter);
let sess = ParseSess::with_span_handler(handler, cm);
if let Err(mut diagnostic) = syntax::parse::parse_crate_from_source_str(
if let Err(mut diagnostic) = rustc_parse::parse_crate_from_source_str(
FileName::Custom("bench".to_owned()),
content.to_owned(),
&sess,
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn rustc_version() -> Option<Compiler> {
};

Some(Compiler {
minor: minor,
minor,
nightly: version.contains("nightly"),
})
}
2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ indexmap = { version = "1.0", features = ["serde-1"] }
inflections = "1.1"
proc-macro2 = { version = "1.0", features = ["span-locations"] }
quote = "1.0"
rustfmt = { package = "rustfmt-nightly", git = "https://github.com/dtolnay/rustfmt", branch = "error" }
rustfmt = { package = "rustfmt_lib", git = "https://github.com/rust-lang-nursery/rustfmt" }
semver = { version = "0.9", features = ["serde"] }
serde = { version = "1.0.88", features = ["derive"] }
serde_json = "1.0.38"
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ fn do_load_file<P: AsRef<Path>>(
};

// Look up the submodule file, and recursively parse it.
// XXX: Only handles same-directory .rs file submodules.
// Only handles same-directory .rs file submodules for now.
let path = parent.join(&format!("{}.rs", item.ident));
load_file(path, &features, lookup)?;
}
Expand Down
1 change: 0 additions & 1 deletion codegen/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ pub fn generate(defs: &Definitions) -> Result<()> {

#full_macro

#[cfg(any(feature = "full", feature = "derive"))]
macro_rules! skip {
($($tt:tt)*) => {};
}
Expand Down
1 change: 0 additions & 1 deletion codegen/src/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ pub fn generate(defs: &Definitions) -> Result<()> {

#full_macro

#[cfg(any(feature = "full", feature = "derive"))]
macro_rules! skip {
($($tt:tt)*) => {};
}
Expand Down
3 changes: 3 additions & 0 deletions json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ serde = { version = "1.0.88", features = ["derive"] }

[dev-dependencies]
serde_json = "1.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
22 changes: 13 additions & 9 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl Attribute {
}

#[cfg(feature = "parsing")]
fn error_expected_args(attr: &Attribute) -> Error {
fn expected_parentheses(attr: &Attribute) -> String {
let style = match attr.style {
AttrStyle::Outer => "#",
AttrStyle::Inner(_) => "#!",
Expand All @@ -298,19 +298,23 @@ fn error_expected_args(attr: &Attribute) -> Error {
path += &segment.ident.to_string();
}

let msg = format!("expected attribute arguments: {}[{}(...)]", style, path);

#[cfg(feature = "printing")]
return Error::new_spanned(attr, msg);

#[cfg(not(feature = "printing"))]
return Error::new(attr.bracket_token.span, msg);
format!("{}[{}(...)]", style, path)
}

#[cfg(feature = "parsing")]
fn enter_args<'a>(attr: &Attribute, input: ParseStream<'a>) -> Result<ParseBuffer<'a>> {
if input.is_empty() {
return Err(error_expected_args(attr));
let expected = expected_parentheses(attr);
let msg = format!("expected attribute arguments in parentheses: {}", expected);
return Err(crate::error::new2(
attr.pound_token.span,
attr.bracket_token.span,
msg,
));
} else if input.peek(Token![=]) {
let expected = expected_parentheses(attr);
let msg = format!("expected parentheses: {}", expected);
return Err(input.error(msg));
};

let content;
Expand Down
20 changes: 20 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,26 @@ impl<'a> Cursor<'a> {
Entry::End(..) => Span::call_site(),
}
}

/// Skip over the next token without cloning it. Returns `None` if this
/// cursor points to eof.
///
/// This method treats `'lifetimes` as a single token.
pub(crate) fn skip(self) -> Option<Cursor<'a>> {
match self.entry() {
Entry::End(..) => None,

// Treat lifetimes as a single tt for the purposes of 'skip'.
Entry::Punct(op) if op.as_char() == '\'' && op.spacing() == Spacing::Joint => {
let next = unsafe { self.bump() };
match next.entry() {
Entry::Ident(_) => Some(unsafe { next.bump() }),
_ => Some(next),
}
}
_ => Some(unsafe { self.bump() }),
}
}
}

pub(crate) fn same_scope(a: Cursor, b: Cursor) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/custom_keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ macro_rules! custom_keyword {
}

#[doc(hidden)]
#[allow(non_snake_case)]
#[allow(dead_code, non_snake_case)]
pub fn $ident<__S: $crate::export::IntoSpans<[$crate::export::Span; 1]>>(
span: __S,
) -> $ident {
Expand Down
2 changes: 1 addition & 1 deletion src/custom_punctuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ macro_rules! custom_punctuation {
}

#[doc(hidden)]
#[allow(non_snake_case)]
#[allow(dead_code, non_snake_case)]
pub fn $ident<__S: $crate::export::IntoSpans<custom_punctuation_repr!($($tt)+)>>(
spans: __S,
) -> $ident {
Expand Down
4 changes: 3 additions & 1 deletion src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,10 @@ pub mod parsing {

impl Parse for Variant {
fn parse(input: ParseStream) -> Result<Self> {
let attrs = input.call(Attribute::parse_outer)?;
let _visibility: Visibility = input.parse()?;
Ok(Variant {
attrs: input.call(Attribute::parse_outer)?,
attrs,
ident: input.parse()?,
fields: {
if input.peek(token::Brace) {
Expand Down
12 changes: 11 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std;
use std::fmt::{self, Debug, Display};
use std::iter::FromIterator;
use std::slice;
Expand Down Expand Up @@ -250,6 +249,17 @@ pub fn new_at<T: Display>(scope: Span, cursor: Cursor, message: T) -> Error {
}
}

#[cfg(all(feature = "parsing", any(feature = "full", feature = "derive")))]
pub fn new2<T: Display>(start: Span, end: Span, message: T) -> Error {
Error {
messages: vec![ErrorMessage {
start_span: ThreadBound::new(start),
end_span: ThreadBound::new(end),
message: message.to_string(),
}],
}
}

impl Debug for Error {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
if self.messages.len() == 1 {
Expand Down
Loading