Skip to content
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

Bump syntex_syntax to 0.27.0 to fix build on nightly rustc #55

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ name = "cheddar"
doc = false

[dependencies]
syntex_syntax = "0.24.0"
syntex_syntax = "0.27.0"
toml = "0.1.25"
clap = "1"
33 changes: 24 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ impl std::fmt::Display for Error {
impl std::error::Error for Error {
fn description(&self) -> &str {
match self.level {
Level::Bug => "internal error",
Level::Fatal | Level::Error => "error",
Level::Bug | Level::Cancelled => "internal error",
Level::Fatal | Level::Error | Level::PhaseFatal => "error",
Level::Warning => "warning",
Level::Note => "note",
Level::Help => "help",
Expand All @@ -333,20 +333,34 @@ impl Error {
if let Some(span) = self.span {
match self.level {
Level::Bug => { sess.span_diagnostic.span_bug(span, &self.message); },
Level::Fatal => { sess.span_diagnostic.span_fatal(span, &self.message); },
Level::Fatal | Level::PhaseFatal => {
sess.span_diagnostic.span_fatal(span, &self.message);
},
Level::Error => { sess.span_diagnostic.span_err(span, &self.message); },
Level::Warning => { sess.span_diagnostic.span_warn(span, &self.message); },
Level::Note => { sess.span_diagnostic.span_note(span, &self.message); },
Level::Help => { sess.span_diagnostic.span_help(span, &self.message); },
Level::Note => {
sess.span_diagnostic.emit(Some(&span.into()), &self.message, Level::Note);
},
Level::Help => {
sess.span_diagnostic.emit(Some(&span.into()), &self.message, Level::Help);
},
Level::Cancelled => {}
};
} else {
match self.level {
Level::Bug => { sess.span_diagnostic.bug(&self.message); },
Level::Fatal => { sess.span_diagnostic.fatal(&self.message); },
Level::Fatal | Level::PhaseFatal => {
sess.span_diagnostic.fatal(&self.message);
},
Level::Error => { sess.span_diagnostic.err(&self.message); },
Level::Warning => { sess.span_diagnostic.warn(&self.message); },
Level::Note => { sess.span_diagnostic.note(&self.message); },
Level::Help => { sess.span_diagnostic.help(&self.message); },
Level::Note => {
sess.span_diagnostic.emit(None, &self.message, Level::Note);
},
Level::Help => {
sess.span_diagnostic.emit(None, &self.message, Level::Help);
},
Level::Cancelled => {}
};
}
}
Expand Down Expand Up @@ -472,7 +486,8 @@ impl Cheddar {
module.into(),
);

if let Ok(path) = parser.parse_path(syntax::parse::parser::PathParsingMode::NoTypesAllowed) {
let path = parser.parse_path(syntax::parse::parser::PathParsingMode::NoTypesAllowed);
if let Ok(path) = path {
self.module = Some(path);
Ok(self)
} else {
Expand Down
44 changes: 22 additions & 22 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use Level;

/// Check that an expected path has been `pub use`d.
fn check_pub_use(item: &ast::Item, expected: &ast::Path) -> bool {
if let ast::Item_::ItemUse(ref path) = item.node {
if let ast::ItemKind::Use(ref path) = item.node {
// API has to be public to be used.
if let ast::Visibility::Public = item.vis {
// Easiest way to ensure all of API has been brought into scope.
Expand Down Expand Up @@ -58,7 +58,7 @@ pub fn parse_crate(krate: &ast::Crate, path: &ast::Path) -> Result<String, Vec<E
for module in &path.segments {
let mut found = false;
for item in &current_module.items {
if let ast::Item_::ItemMod(ref new_module) = item.node {
if let ast::ItemKind::Mod(ref new_module) = item.node {
if module.identifier == item.ident {
current_module = new_module;
found = true;
Expand Down Expand Up @@ -95,10 +95,10 @@ pub fn parse_mod(module: &ast::Mod) -> Result<String, Vec<Error>> {
// TODO: Check for ItemStatic and ItemConst as well.
// - How would this work?
// - Is it even possible?
ast::Item_::ItemTy(..) => parse_ty(item),
ast::Item_::ItemEnum(..) => parse_enum(item),
ast::Item_::ItemStruct(..) => parse_struct(item),
ast::Item_::ItemFn(..) => parse_fn(item),
ast::ItemKind::Ty(..) => parse_ty(item),
ast::ItemKind::Enum(..) => parse_enum(item),
ast::ItemKind::Struct(..) => parse_struct(item),
ast::ItemKind::Fn(..) => parse_fn(item),
_ => Ok(None),
};

Expand Down Expand Up @@ -129,7 +129,7 @@ fn parse_ty(item: &ast::Item) -> Result<Option<String>, Error> {

let name = item.ident.name.as_str();
let new_type = match item.node {
ast::Item_::ItemTy(ref ty, ref generics) => {
ast::ItemKind::Ty(ref ty, ref generics) => {
// Can not yet convert generics.
if generics.is_parameterized() { return Ok(None); }

Expand All @@ -139,7 +139,7 @@ fn parse_ty(item: &ast::Item) -> Result<Option<String>, Error> {
return Err(Error {
level: Level::Bug,
span: Some(item.span),
message: "`parse_ty` called on wrong `Item_`".into(),
message: "`parse_ty` called on wrong `ItemKind`".into(),
});
},
};
Expand All @@ -165,7 +165,7 @@ fn parse_enum(item: &ast::Item) -> Result<Option<String>, Error> {

let name = item.ident.name.as_str();
buffer.push_str(&format!("typedef enum {} {{\n", name));
if let ast::Item_::ItemEnum(ref definition, ref generics) = item.node {
if let ast::ItemKind::Enum(ref definition, ref generics) = item.node {
if generics.is_parameterized() {
return Err(Error {
level: Level::Error,
Expand All @@ -192,7 +192,7 @@ fn parse_enum(item: &ast::Item) -> Result<Option<String>, Error> {
return Err(Error {
level: Level::Bug,
span: Some(item.span),
message: "`parse_enum` called on wrong `Item_`".into(),
message: "`parse_enum` called on wrong `ItemKind`".into(),
});
}

Expand All @@ -218,7 +218,7 @@ fn parse_struct(item: &ast::Item) -> Result<Option<String>, Error> {
let name = item.ident.name.as_str();
buffer.push_str(&format!("typedef struct {}", name));

if let ast::Item_::ItemStruct(ref variants, ref generics) = item.node {
if let ast::ItemKind::Struct(ref variants, ref generics) = item.node {
if generics.is_parameterized() {
return Err(Error {
level: Level::Error,
Expand Down Expand Up @@ -256,7 +256,7 @@ fn parse_struct(item: &ast::Item) -> Result<Option<String>, Error> {
return Err(Error {
level: Level::Bug,
span: Some(item.span),
message: "`parse_struct` called on wrong `Item_`".into(),
message: "`parse_struct` called on wrong `ItemKind`".into(),
});
}

Expand All @@ -280,7 +280,7 @@ fn parse_fn(item: &ast::Item) -> Result<Option<String>, Error> {
let name = item.ident.name.as_str();
buffer.push_str(&docs);

if let ast::Item_::ItemFn(ref fn_decl, _, _, abi, ref generics, _) = item.node {
if let ast::ItemKind::Fn(ref fn_decl, _, _, abi, ref generics, _) = item.node {
use syntax::abi::Abi;
match abi {
// If it doesn't have a C ABI it can't be called from C.
Expand Down Expand Up @@ -335,15 +335,15 @@ fn parse_fn(item: &ast::Item) -> Result<Option<String>, Error> {

let output_type = &fn_decl.output;
let full_declaration = match *output_type {
ast::FunctionRetTy::NoReturn(span) => {
ast::FunctionRetTy::None(span) => {
return Err(Error {
level: Level::Error,
span: Some(span),
message: "panics across a C boundary are naughty!".into(),
});
},
ast::FunctionRetTy::DefaultReturn(..) => format!("void {}", buf_without_return),
ast::FunctionRetTy::Return(ref ty) => try_some!(types::rust_to_c(&*ty, &buf_without_return)),
ast::FunctionRetTy::Default(..) => format!("void {}", buf_without_return),
ast::FunctionRetTy::Ty(ref ty) => try_some!(types::rust_to_c(&*ty, &buf_without_return)),
};

buffer.push_str(&full_declaration);
Expand All @@ -352,7 +352,7 @@ fn parse_fn(item: &ast::Item) -> Result<Option<String>, Error> {
return Err(Error {
level: Level::Bug,
span: Some(item.span),
message: "`parse_fn` called on wrong `Item_`".into(),
message: "`parse_fn` called on wrong `ItemKind`".into(),
});
}

Expand Down Expand Up @@ -384,10 +384,10 @@ fn parse_attr<C, R>(attrs: &[ast::Attribute], check: C, retrieve: R) -> (bool, S
/// Check the attribute is #[repr(C)].
fn check_repr_c(attr: &ast::Attribute) -> bool {
match attr.node.value.node {
ast::MetaItem_::MetaList(ref name, ref word) if *name == "repr" => match word.first() {
ast::MetaItemKind::List(ref name, ref word) if *name == "repr" => match word.first() {
Some(word) => match word.node {
// Return true only if attribute is #[repr(C)].
ast::MetaItem_::MetaWord(ref name) if *name == "C" => true,
ast::MetaItemKind::Word(ref name) if *name == "C" => true,
_ => false,
},
_ => false,
Expand All @@ -399,17 +399,17 @@ fn check_repr_c(attr: &ast::Attribute) -> bool {
/// Check the attribute is #[no_mangle].
fn check_no_mangle(attr: &ast::Attribute) -> bool {
match attr.node.value.node {
ast::MetaItem_::MetaWord(ref name) if *name == "no_mangle" => true,
ast::MetaItemKind::Word(ref name) if *name == "no_mangle" => true,
_ => false,
}
}

/// If the attribute is a docstring, indent it the required amount and return it.
fn retrieve_docstring(attr: &ast::Attribute, prepend: &str) -> Option<String> {
match attr.node.value.node {
ast::MetaItem_::MetaNameValue(ref name, ref val) if *name == "doc" => match val.node {
ast::MetaItemKind::NameValue(ref name, ref val) if *name == "doc" => match val.node {
// Docstring attributes omit the trailing newline.
ast::Lit_::LitStr(ref docs, _) => Some(format!("{}{}\n", prepend, docs)),
ast::LitKind::Str(ref docs, _) => Some(format!("{}{}\n", prepend, docs)),
_ => unreachable!("docs must be literal strings"),
},
_ => None,
Expand Down
21 changes: 11 additions & 10 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Level;
pub fn rust_to_c(ty: &ast::Ty, assoc: &str) -> Result<Option<String>, Error> {
match ty.node {
// Function pointers make life an absolute pain here.
ast::Ty_::TyBareFn(ref bare_fn) => fn_ptr_to_c(bare_fn, ty.span, assoc),
ast::TyKind::BareFn(ref bare_fn) => fn_ptr_to_c(bare_fn, ty.span, assoc),
// All other types just have a name associated with them.
_ => Ok(Some(format!("{} {}", try_some!(anon_rust_to_c(ty)), assoc))),
}
Expand All @@ -21,15 +21,15 @@ pub fn rust_to_c(ty: &ast::Ty, assoc: &str) -> Result<Option<String>, Error> {
fn anon_rust_to_c(ty: &ast::Ty) -> Result<Option<String>, Error> {
match ty.node {
// Function pointers should not be in this function.
ast::Ty_::TyBareFn(..) => Err(Error {
ast::TyKind::BareFn(..) => Err(Error {
level: Level::Error,
span: Some(ty.span),
message: "C function pointers must have a name or function declaration associated with them".into(),
}),
// Standard pointers.
ast::Ty_::TyPtr(ref ptr) => ptr_to_c(ptr),
ast::TyKind::Ptr(ref ptr) => ptr_to_c(ptr),
// Plain old types.
ast::Ty_::TyPath(None, ref path) => path_to_c(path),
ast::TyKind::Path(None, ref path) => path_to_c(path),
// Possibly void, likely not.
_ => {
let new_type = print::pprust::ty_to_string(ty);
Expand All @@ -51,9 +51,9 @@ fn ptr_to_c(ty: &ast::MutTy) -> Result<Option<String>, Error> {
let new_type = try_some!(anon_rust_to_c(&ty.ty));
let const_spec = match ty.mutbl {
// *const T
ast::Mutability::MutImmutable => " const" ,
ast::Mutability::Immutable => " const" ,
// *mut T
ast::Mutability::MutMutable => "",
ast::Mutability::Mutable => "",
};

Ok(Some(format!("{}{}*", new_type, const_spec)))
Expand Down Expand Up @@ -115,15 +115,15 @@ fn fn_ptr_to_c(fn_ty: &ast::BareFnTy, fn_span: codemap::Span, inner: &str) -> Re

let output_type = &fn_decl.output;
let full_declaration = match *output_type {
ast::FunctionRetTy::NoReturn(span) => {
ast::FunctionRetTy::None(span) => {
return Err(Error {
level: Level::Error,
span: Some(span),
message: "panics across a C boundary are naughty!".into(),
});
},
ast::FunctionRetTy::DefaultReturn(..) => format!("void {}", buf_without_return),
ast::FunctionRetTy::Return(ref ty) => try_some!(rust_to_c(&*ty, &buf_without_return)),
ast::FunctionRetTy::Default(..) => format!("void {}", buf_without_return),
ast::FunctionRetTy::Ty(ref ty) => try_some!(rust_to_c(&*ty, &buf_without_return)),
};


Expand Down Expand Up @@ -251,7 +251,8 @@ mod test {
source.into(),
);

match parser.parse_ty() {
let ty = parser.parse_ty();
match ty {
Ok(p) => (*p).clone(),
_ => panic!("internal testing error: could not parse type from {:?}", source),
}
Expand Down