Commit b26e6983 by Sean Marshallsay

chore: update for binder master

parent bb90f12c
Pipeline #7959651 passed with stages
in 22 minutes 17 seconds
......@@ -68,21 +68,21 @@ impl TypeFactory {
/// ```
///
/// . `assoc` is therefore the thing which the function pointer "wraps".
pub fn rust_to_c(&self,
ty: &ast::Ty,
assoc: &str,
session: Option<&Session>)
-> Result<String, Stop> {
pub fn rust_to_c(
&self,
ty: &ast::Ty,
assoc: &str,
session: Option<&Session>,
) -> Result<String, Stop> {
match ty.node {
// Function pointers make life an absolute pain here.
ast::TyKind::BareFn(ref bare_fn) => self.fn_ptr_to_c(bare_fn, ty.span, assoc, session),
// All other types just have a name associated with them.
_ => {
Ok(format!("{} {}",
try!(self.anon_rust_to_c(ty, session)),
assoc))
}
_ => Ok(format!(
"{} {}",
try!(self.anon_rust_to_c(ty, session)),
assoc,
)),
}
}
......@@ -91,13 +91,13 @@ impl TypeFactory {
fn anon_rust_to_c(&self, ty: &ast::Ty, session: Option<&Session>) -> Result<String, Stop> {
match ty.node {
// Function pointers should not be in this function.
ast::TyKind::BareFn(..) => {
Err(session.map_or(Stop::Fail, |s| {
s.span_err(ty.span,
"C function pointers must have a name or function declaration \
associated with them")
}))
}
ast::TyKind::BareFn(..) => Err(session.map_or(
Stop::Fail,
|s| s.span_err(
ty.span,
"C function pointers must have a name or function declaration associated with them",
),
)),
// Standard pointers.
ast::TyKind::Ptr(ref ptr) => self.ptr_to_c(ptr, session),
// Plain old types.
......@@ -203,23 +203,29 @@ impl TypeFactory {
/// types in `libc` which we special case.
fn path_to_c(&self, path: &ast::Path, session: Option<&Session>, span: codemap::Span) -> Result<String, Stop> {
for s in &path.segments {
if !s.parameters.is_empty() {
return Err(session.map_or(Stop::Fail, |s| {
s.span_err(span,
&format!("{} is a generic type", Self::path_to_string(&path.segments)))
}));
if !s.parameters.is_none() {
return Err(session.map_or(
Stop::Fail,
|s| s.span_err(
span,
&format!("{} is a generic type", Self::path_to_string(&path.segments)),
),
));
}
}
// I don't think this is possible.
if path.segments.is_empty() {
Err(session.map_or(Stop::Fail,
|s| s.fatal("what the fuck have you done to this type?!")))
// Types in modules, `my_mod::MyType`.
Err(session.map_or(
Stop::Fail,
|s| s.fatal("what the fuck have you done to this type?!"),
))
// Types in modules, `my_mod::MyType`.
} else {
if path.segments.len() > 1 {
let (ty, module) = path.segments
.split_last()
.expect("There are 2 elements");
.expect("there are 2 elements");
let p = Self::path_to_string(module);
if let Some(ref m) = self.custom_type_modules
.iter()
......@@ -228,7 +234,7 @@ impl TypeFactory {
return Ok(m(&*ty.identifier.name.as_str()).into());
}
}
let (ty, module) = path.segments.split_last().expect("Segments are not empty");
let (ty, module) = path.segments.split_last().expect("segments are not empty");
if let Some(Include { module_name, type_name }) = self.match_type_to_include(ty, module) {
if let Some(ref m) = self.custom_type_modules
.iter()
......@@ -319,7 +325,7 @@ impl TypeFactory {
&ast::ViewPath_::ViewPathList(ref p, ref items) => {
items.iter()
.filter_map(|item| {
if item.node.name.name.as_str() == "self" {
if &*item.node.name.name.as_str() == "self" {
let (ty, module) = p.segments.split_last().unwrap();
if let Some(ref rename) = item.node.rename {
if rename.name == i.name {
......@@ -380,7 +386,9 @@ impl TypeFactory {
}
fn path_to_string(p: &[ast::PathSegment]) -> String {
p.iter().map(|p| (&*p.identifier.name.as_str()).to_owned()).join("::")
p.iter()
.filter(|p| &*p.identifier.name.as_str() != "{{root}}")
.map(|p| (&*p.identifier.name.as_str()).to_owned()).join("::")
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment