Skip to content

Commit afa1cf4

Browse files
rcseacordPLeVasseur
authored andcommitted
Fix formatting and update Rust examples in guidelines
1 parent e860707 commit afa1cf4

1 file changed

Lines changed: 22 additions & 20 deletions

File tree

src/coding-guidelines/attributes/gui_ZDLZzjeOwLSU.rst.inc

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
This noncompliant example requires Rust Edition 2021 or earlier to compile.
7676
7777
.. rust-example::
78+
:compile_fail:
7879
7980
// Undefined behavior by the linker or loader is possible
8081
// if another 'something' function is defined.
@@ -98,26 +99,27 @@
9899
This noncompliant example requires Rust Edition 2021 or earlier to compile.
99100
100101
.. rust-example::
101-
102-
use std::ffi;
103-
104-
extern "C" {
105-
// If 'malloc' is otherwise defined with a 'usize' argument, the compiler
106-
// may generate code for calls to this function using this incompatible declaration,
107-
// resulting in undefined behavior.
108-
fn malloc(size: f32) -> *mut ffi::c_void;
109-
}
110-
111-
fn main() {
112-
// Call the extern "C" function (requires an 'unsafe' block)
113-
unsafe {
114-
let ptr = malloc(1024.0);
115-
if !ptr.is_null() {
116-
// Use the allocated memory then free it with 'libc::free'
117-
println!("malloc returned: {:?}", ptr);
118-
}
119-
}
120-
}
102+
:compile_fail:
103+
104+
use std::ffi;
105+
106+
extern "C" {
107+
// If 'malloc' is otherwise defined with a 'usize' argument, the compiler
108+
// may generate code for calls to this function using this incompatible declaration,
109+
// resulting in undefined behavior.
110+
fn malloc(size: f32) -> *mut ffi::c_void;
111+
}
112+
113+
fn main() {
114+
// Call the extern "C" function (requires an 'unsafe' block)
115+
unsafe {
116+
let ptr = malloc(1024.0);
117+
if !ptr.is_null() {
118+
// Use the allocated memory then free it with 'libc::free'
119+
println!("malloc returned: {:?}", ptr);
120+
}
121+
}
122+
}
121123
122124
.. non_compliant_example::
123125
:id: non_compl_ex_Hk3mNp5qRs7t

0 commit comments

Comments
 (0)