Skip to content

Commit 7b9f9e5

Browse files
committed
Use cstr! macro.
1 parent 3697b4d commit 7b9f9e5

File tree

15 files changed

+22
-68
lines changed

15 files changed

+22
-68
lines changed

Cargo.lock

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,16 +1023,6 @@ dependencies = [
10231023
"winapi",
10241024
]
10251025

1026-
[[package]]
1027-
name = "cstr"
1028-
version = "0.2.8"
1029-
source = "registry+https://github.com/rust-lang/crates.io-index"
1030-
checksum = "c11a39d776a3b35896711da8a04dc1835169dcd36f710878187637314e47941b"
1031-
dependencies = [
1032-
"proc-macro2",
1033-
"quote",
1034-
]
1035-
10361026
[[package]]
10371027
name = "curl"
10381028
version = "0.4.43"
@@ -3275,7 +3265,6 @@ name = "rustc_codegen_llvm"
32753265
version = "0.0.0"
32763266
dependencies = [
32773267
"bitflags",
3278-
"cstr",
32793268
"libc",
32803269
"measureme",
32813270
"object 0.29.0",

compiler/rustc_codegen_llvm/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ test = false
88

99
[dependencies]
1010
bitflags = "1.0"
11-
cstr = "0.2"
1211
libc = "0.2"
1312
measureme = "10.0.0"
1413
object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "archive", "coff", "elf", "macho", "pe"] }

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use crate::context::CodegenCx;
1919
use crate::llvm;
2020
use crate::value::Value;
2121

22-
use cstr::cstr;
23-
2422
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
2523
use rustc_codegen_ssa::mono_item::MonoItemExt;
2624
use rustc_codegen_ssa::traits::*;
@@ -34,6 +32,7 @@ use rustc_session::config::DebugInfo;
3432
use rustc_span::symbol::Symbol;
3533
use rustc_target::spec::SanitizerSet;
3634

35+
use std::ffi::cstr;
3736
use std::time::Instant;
3837

3938
pub struct ValueIter<'ll> {

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock};
66
use crate::type_::Type;
77
use crate::type_of::LayoutLlvmExt;
88
use crate::value::Value;
9-
use cstr::cstr;
109
use libc::{c_char, c_uint};
1110
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, SynchronizationScope, TypeKind};
1211
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
@@ -23,7 +22,7 @@ use rustc_span::Span;
2322
use rustc_target::abi::{self, call::FnAbi, Align, Size, WrappingRange};
2423
use rustc_target::spec::{HasTargetSpec, Target};
2524
use std::borrow::Cow;
26-
use std::ffi::CStr;
25+
use std::ffi::{cstr, CStr};
2726
use std::iter;
2827
use std::ops::Deref;
2928
use std::ptr;
@@ -44,7 +43,7 @@ impl Drop for Builder<'_, '_, '_> {
4443
}
4544

4645
// FIXME(eddyb) use a checked constructor when they become `const fn`.
47-
const EMPTY_C_STR: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"\0") };
46+
const EMPTY_C_STR: &CStr = cstr!();
4847

4948
/// Empty string, to be used where LLVM expects an instruction name, indicating
5049
/// that the instruction is to be left unnamed (i.e. numbered, in textual IR).

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::llvm_util;
66
use crate::type_::Type;
77
use crate::type_of::LayoutLlvmExt;
88
use crate::value::Value;
9-
use cstr::cstr;
109
use libc::c_uint;
1110
use rustc_codegen_ssa::traits::*;
1211
use rustc_hir::def_id::DefId;
@@ -22,6 +21,7 @@ use rustc_middle::{bug, span_bug};
2221
use rustc_target::abi::{
2322
AddressSpace, Align, HasDataLayout, Primitive, Scalar, Size, WrappingRange,
2423
};
24+
use std::ffi::cstr;
2525
use std::ops::Range;
2626

2727
pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<'_>) -> &'ll Value {

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::llvm_util;
88
use crate::type_::Type;
99
use crate::value::Value;
1010

11-
use cstr::cstr;
1211
use rustc_codegen_ssa::base::wants_msvc_seh;
1312
use rustc_codegen_ssa::traits::*;
1413
use rustc_data_structures::base_n;
@@ -33,7 +32,7 @@ use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
3332
use smallvec::SmallVec;
3433

3534
use std::cell::{Cell, RefCell};
36-
use std::ffi::CStr;
35+
use std::ffi::{cstr, CStr};
3736
use std::str;
3837

3938
/// There is one `CodegenCx` per compilation unit. Each one has its own LLVM

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::llvm::debuginfo::{
2020
};
2121
use crate::value::Value;
2222

23-
use cstr::cstr;
2423
use rustc_codegen_ssa::debuginfo::type_names::cpp_like_debuginfo;
2524
use rustc_codegen_ssa::debuginfo::type_names::VTableNameKind;
2625
use rustc_codegen_ssa::traits::*;
@@ -45,6 +44,7 @@ use smallvec::smallvec;
4544

4645
use libc::{c_char, c_longlong, c_uint};
4746
use std::borrow::Cow;
47+
use std::ffi::cstr;
4848
use std::fmt::{self, Write};
4949
use std::hash::{Hash, Hasher};
5050
use std::iter;

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(let_chains)]
1010
#![feature(extern_types)]
1111
#![feature(once_cell)]
12+
#![feature(cstr_macro)]
1213
#![feature(iter_intersperse)]
1314
#![recursion_limit = "256"]
1415
#![allow(rustc::potential_query_instability)]

library/core/src/ffi/c_str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl fmt::Debug for CStr {
177177
}
178178
}
179179

180-
/// Converts a string or byte literal to a `&'static Cstr`.
180+
/// Converts a `const` string or byte slice to a `&'static Cstr`.
181181
///
182182
/// # Examples
183183
///
@@ -208,7 +208,7 @@ macro_rules! __cstr_macro_impl {
208208
() => {
209209
__cstr_macro_impl!("")
210210
};
211-
($s:literal) => {{
211+
($s:expr) => {{
212212
const BYTES: &[u8] = $crate::ffi::__cstr_macro_impl_as_bytes($s);
213213
const BYTES_WITH_NUL: [u8; { BYTES.len() + 1 }] =
214214
$crate::ffi::__cstr_macro_impl_to_bytes_with_nul(BYTES);

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@
314314
#![feature(maybe_uninit_uninit_array)]
315315
#![feature(const_maybe_uninit_uninit_array)]
316316
#![feature(const_waker)]
317+
#![feature(cstr_macro)]
317318
//
318319
// Library features (alloc):
319320
#![feature(alloc_layout_extra)]

0 commit comments

Comments
 (0)