diff options
| author | Kornel <kornel@geekhood.net> | 2024-11-30 20:32:00 +0000 |
|---|---|---|
| committer | Kornel <kornel@geekhood.net> | 2024-12-02 18:16:36 +0000 |
| commit | eadea7764ee49e11165ed041e529cbe79707a31c (patch) | |
| tree | 9e7727f211eb7676cd1961df8a58a28aa565e10b /compiler/rustc_error_codes | |
| parent | 3bff51ea912d4dfd9caa1e3bc6f68352618208a7 (diff) | |
| download | rust-eadea7764ee49e11165ed041e529cbe79707a31c.tar.gz rust-eadea7764ee49e11165ed041e529cbe79707a31c.zip | |
Use c"lit" for CStrings without unwrap
Diffstat (limited to 'compiler/rustc_error_codes')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0060.md | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0060.md b/compiler/rustc_error_codes/src/error_codes/E0060.md index 54b10c886cc..a6831c881e3 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0060.md +++ b/compiler/rustc_error_codes/src/error_codes/E0060.md @@ -15,7 +15,7 @@ unsafe { printf(); } // error! Using this declaration, it must be called with at least one argument, so simply calling `printf()` is invalid. But the following uses are allowed: -``` +```rust,edition2021 # use std::os::raw::{c_char, c_int}; # #[cfg_attr(all(windows, target_env = "msvc"), # link(name = "legacy_stdio_definitions", @@ -23,16 +23,11 @@ simply calling `printf()` is invalid. But the following uses are allowed: # extern "C" { fn printf(_: *const c_char, ...) -> c_int; } # fn main() { unsafe { - use std::ffi::CString; - - let fmt = CString::new("test\n").unwrap(); - printf(fmt.as_ptr()); + printf(c"test\n".as_ptr()); - let fmt = CString::new("number = %d\n").unwrap(); - printf(fmt.as_ptr(), 3); + printf(c"number = %d\n".as_ptr(), 3); - let fmt = CString::new("%d, %d\n").unwrap(); - printf(fmt.as_ptr(), 10, 5); + printf(c"%d, %d\n".as_ptr(), 10, 5); } # } ``` |
