Skip to content

Commit f847ee7

Browse files
committed
codegen: Wrap unsafe functions as unsafe
1 parent 7445dbb commit f847ee7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/codegen/function.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ pub fn generate(
9292

9393
let unsafe_ = if analysis.unsafe_ { "unsafe " } else { "" };
9494
let declaration = declaration(env, analysis);
95-
let suffix = if only_declaration { ";" } else { " {" };
95+
let suffix = if only_declaration {
96+
";"
97+
} else if analysis.unsafe_ {
98+
" { unsafe {"
99+
} else {
100+
" {"
101+
};
96102

97103
writeln!(w)?;
98104
cfg_deprecated(w, env, None, analysis.deprecated_version, commented, indent)?;
@@ -153,6 +159,9 @@ pub fn generate(
153159
for s in body {
154160
writeln!(w, "{}{}", tabs(indent), s)?;
155161
}
162+
if analysis.unsafe_ {
163+
writeln!(w, "}}")?;
164+
}
156165
}
157166

158167
if analysis.async_future.is_some() {

0 commit comments

Comments
 (0)