1
Fork 0

Use c"lit" for CStrings without unwrap

This commit is contained in:
Kornel 2024-11-30 20:32:00 +00:00
parent 3bff51ea91
commit eadea7764e
No known key found for this signature in database
14 changed files with 38 additions and 50 deletions

View file

@ -148,7 +148,7 @@ fn prepare_lto(
// __llvm_profile_counter_bias is pulled in at link time by an undefined reference to
// __llvm_profile_runtime, therefore we won't know until link time if this symbol
// should have default visibility.
symbols_below_threshold.push(CString::new("__llvm_profile_counter_bias").unwrap());
symbols_below_threshold.push(c"__llvm_profile_counter_bias".to_owned());
Ok((symbols_below_threshold, upstream_modules))
}

View file

@ -509,7 +509,7 @@ fn get_pgo_sample_use_path(config: &ModuleConfig) -> Option<CString> {
}
fn get_instr_profile_output_path(config: &ModuleConfig) -> Option<CString> {
config.instrument_coverage.then(|| CString::new("default_%m_%p.profraw").unwrap())
config.instrument_coverage.then(|| c"default_%m_%p.profraw".to_owned())
}
pub(crate) unsafe fn llvm_optimize(

View file

@ -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;
printf(c"test\n".as_ptr());
let fmt = CString::new("test\n").unwrap();
printf(fmt.as_ptr());
printf(c"number = %d\n".as_ptr(), 3);
let fmt = CString::new("number = %d\n").unwrap();
printf(fmt.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);
}
# }
```