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

Changes needed for rust 2024 edition #1635

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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 src/codegen/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl FromGlib<{sys_crate_name}::{ffi_name}> for {name} {{

#[inline]
unsafe fn from_value(value: &'a {gvalue}) -> Self {{
{assert}from_glib({glib}(value.to_glib_none().0))
{assert}unsafe {{ from_glib({glib}(value.to_glib_none().0)) }}
}}
}}",
name = enum_.name,
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl FromGlib<{sys_crate_name}::{ffi_name}> for {name} {{

#[inline]
unsafe fn from_value(value: &'a {gvalue}) -> Self {{
{assert}from_glib({glib}(value.to_glib_none().0))
{assert}unsafe {{ from_glib({glib}(value.to_glib_none().0)) }}
}}
}}",
name = flags.name,
Expand Down
8 changes: 6 additions & 2 deletions src/codegen/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn generate(

let unsafe_ = if analysis.unsafe_ { "unsafe " } else { "" };
let declaration = declaration(env, analysis);
let suffix = if only_declaration { ";" } else { " {" };
let suffix = if only_declaration { ";" } else if analysis.unsafe_ { " { unsafe {" } else { " {" };

writeln!(w)?;
cfg_deprecated(w, env, None, analysis.deprecated_version, commented, indent)?;
Expand Down Expand Up @@ -187,7 +187,11 @@ pub fn generate(
writeln!(w)?;
}
}
writeln!(w, "{}{}}}", tabs(indent), comment_prefix)?;
if analysis.unsafe_ {
writeln!(w, "{}{}}}}}", tabs(indent), comment_prefix)?;
} else {
writeln!(w, "{}{}}}", tabs(indent), comment_prefix)?;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/codegen/function_body_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,11 @@ impl Builder {
is_mut: false,
value: Box::new(Chunk::Custom(
if is_destroy || trampoline.scope.is_async() {
format!("Box_::from_raw({} as *mut {})", func, trampoline.bound_name)
format!("unsafe {{ Box_::from_raw({} as *mut {}) }}", func, trampoline.bound_name)
} else if trampoline.scope.is_call() {
format!("{} as *mut {}", func, trampoline.bound_name)
} else {
format!("&*({} as *mut {})", func, trampoline.bound_name)
format!("unsafe {{ &*({} as *mut {}) }}", func, trampoline.bound_name)
},
)),
type_: None,
Expand Down
8 changes: 4 additions & 4 deletions src/codegen/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ fn define_boxed_type_internal(
};
writeln!(
w,
"\t\tcopy => |ptr| {}::{}({}),",
"\t\tcopy => |ptr| unsafe {{ {}::{}({}) }},",
sys_crate_name, copy_fn.glib_name, mut_ov
)?;
writeln!(w, "\t\tfree => |ptr| {sys_crate_name}::{free_fn}(ptr),")?;
writeln!(w, "\t\tfree => |ptr| unsafe {{ {sys_crate_name}::{free_fn}(ptr) }},")?;

if let (
Some(init_function_expression),
Expand Down Expand Up @@ -613,8 +613,8 @@ fn define_shared_type_internal(
)?;
writeln!(w)?;
writeln!(w, "\tmatch fn {{")?;
writeln!(w, "\t\tref => |ptr| {sys_crate_name}::{ref_fn}(ptr),")?;
writeln!(w, "\t\tunref => |ptr| {sys_crate_name}::{unref_fn}(ptr),")?;
writeln!(w, "\t\tref => |ptr| unsafe {{ {sys_crate_name}::{ref_fn}(ptr) }},")?;
writeln!(w, "\t\tunref => |ptr| unsafe {{ {sys_crate_name}::{unref_fn}(ptr) }},")?;
if let Some(get_type_fn) = get_type_fn {
writeln!(w, "\t\ttype_ => || {sys_crate_name}::{get_type_fn}(),")?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/sys/lib_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn generate_lib(w: &mut dyn Write, env: &Env) -> Result<()> {
}

if !env.namespaces.main().shared_libs.is_empty() {
writeln!(w, "extern \"C\" {{")?;
writeln!(w, "unsafe extern \"C\" {{")?;
functions::generate_enums_funcs(w, env, &enums)?;
functions::generate_bitfields_funcs(w, env, &bitfields)?;
functions::generate_unions_funcs(w, env, &unions)?;
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn generate(

writeln!(
w,
"{}unsafe extern \"C\" fn {}<{}F: {}>({}, f: {}){} {{",
"{}unsafe extern \"C\" fn {}<{}F: {}>({}, f: {}){} {{ unsafe {{",
prepend,
analysis.name,
self_bound,
Expand All @@ -58,7 +58,7 @@ pub fn generate(
transformation_vars(w, env, analysis, &prepend)?;
let call = trampoline_call_func(env, analysis, in_trait);
writeln!(w, "{prepend}\t{call}")?;
writeln!(w, "{prepend}}}")?;
writeln!(w, "{prepend}}}}}")?;

Ok(())
}
Expand Down
Loading