Skip to content

Commit b6c9c9f

Browse files
committed
Use &self and self directly in generated functions
This makes the documentation clearer than `self: $Ty`.
1 parent e3c455b commit b6c9c9f

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

crates/header-translator/src/rust_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ impl Ty {
19941994

19951995
pub(crate) fn is_object_like_ptr(&self) -> bool {
19961996
if let Self::Pointer { pointee, .. } = self {
1997-
pointee.is_objc_type()
1997+
pointee.is_object_like()
19981998
} else {
19991999
false
20002000
}

crates/header-translator/src/stmt.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ impl Stmt {
18231823

18241824
let ty = value.guess_type(id.location());
18251825

1826-
if ty.is_cf_type_ptr() || ty.is_object_like_ptr() {
1826+
if ty.is_object_like_ptr() {
18271827
// cf_string! and ns_string! are not supported (since they cannot
18281828
// yet be used in `const`).
18291829
return None;
@@ -3024,15 +3024,24 @@ impl Stmt {
30243024
write!(f, "{vis} {unsafe_}{}fn {fn_name}(", abi.extern_outer())?;
30253025
for (i, (param, arg_ty)) in arguments.iter().enumerate() {
30263026
if i == 0 && *first_arg_is_self {
3027-
write!(f, "self: ")?;
3027+
// Might not be completely correct, but typeck
3028+
// should figure out for us when calling the
3029+
// inner function if the argument type isn't
3030+
// the same type this one.
3031+
if arg_ty.is_object_like_ptr() {
3032+
write!(f, "&self")?;
3033+
} else {
3034+
write!(f, "self")?;
3035+
}
30283036
} else {
30293037
let param = handle_reserved(&crate::to_snake_case(param));
30303038
write!(f, "{param}: ")?;
3031-
}
3032-
if let Some((converted_ty, _, _)) = arg_ty.fn_argument_converter() {
3033-
write!(f, "{converted_ty}")?;
3034-
} else {
3035-
write!(f, "{}", arg_ty.fn_argument())?;
3039+
3040+
if let Some((converted_ty, _, _)) = arg_ty.fn_argument_converter() {
3041+
write!(f, "{converted_ty}")?;
3042+
} else {
3043+
write!(f, "{}", arg_ty.fn_argument())?;
3044+
}
30363045
}
30373046
write!(f, ",")?;
30383047
}

generated

Submodule generated updated 169 files

0 commit comments

Comments
 (0)