Change Str to Repr operator to explicit

This commit is contained in:
David Tolnay 2020-03-01 20:20:10 -08:00
parent 404d689e95
commit baae443ae2
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 11 additions and 5 deletions

View File

@ -191,8 +191,10 @@ fn write_cxx_function_shim(out: &mut OutFile, efn: &ExternFn, types: &Types) {
write!(out, "(");
} else if let Some(ret) = &efn.ret {
write!(out, "return ");
if let Type::Ref(_) = ret {
write!(out, "&");
match ret {
Type::Ref(_) => write!(out, "&"),
Type::Str(_) => write!(out, "::rust::Str::Repr("),
_ => {}
}
}
write!(out, "{}$(", efn.ident);
@ -216,6 +218,7 @@ fn write_cxx_function_shim(out: &mut OutFile, efn: &ExternFn, types: &Types) {
match &efn.ret {
Some(Type::RustBox(_)) => write!(out, ".into_raw()"),
Some(Type::UniquePtr(_)) => write!(out, ".release()"),
Some(Type::Str(_)) => write!(out, ")"),
_ => {}
}
if indirect_return {
@ -293,13 +296,16 @@ fn write_rust_function_shim(out: &mut OutFile, efn: &ExternFn, types: &Types) {
if i > 0 {
write!(out, ", ");
}
if types.needs_indirect_abi(&arg.ty) {
write!(out, "&");
match &arg.ty {
Type::Str(_) => write!(out, "::rust::Str::Repr("),
ty if types.needs_indirect_abi(ty) => write!(out, "&"),
_ => {}
}
write!(out, "{}", arg.ident);
match arg.ty {
Type::RustBox(_) => write!(out, ".into_raw()"),
Type::UniquePtr(_) => write!(out, ".release()"),
Type::Str(_) => write!(out, ")"),
_ => {}
}
}

View File

@ -53,7 +53,7 @@ public:
size_t len;
};
Str(Repr repr) noexcept;
operator Repr() noexcept;
explicit operator Repr() noexcept;
private:
Repr repr;