Skip to content

Commit 2428cc4

Browse files
committed
Auto merge of #84842 - blkerby:null_lowercase, r=joshtriplett
Replace 'NULL' with 'null' This replaces occurrences of "NULL" with "null" in docs, comments, and compiler error/lint messages. This is for the sake of consistency, as the lowercase "null" is already the dominant form in Rust. The all-caps NULL looks like the C macro (or SQL keyword), which seems out of place in a Rust context, given that NULL does not exist in the Rust language or standard library (instead having [`ptr::null()`](https://doc.rust-lang.org/stable/std/ptr/fn.null.html)).
2 parents 59f551a + 6679f5c commit 2428cc4

37 files changed

+75
-75
lines changed

compiler/rustc_codegen_llvm/src/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn search_meta_section<'a>(
6666
let mut name_buf = None;
6767
let name_len = llvm::LLVMRustGetSectionName(si.llsi, &mut name_buf);
6868
let name = name_buf.map_or_else(
69-
String::new, // We got a NULL ptr, ignore `name_len`.
69+
String::new, // We got a null ptr, ignore `name_len`.
7070
|buf| {
7171
String::from_utf8(
7272
slice::from_raw_parts(buf.as_ptr() as *const u8, name_len as usize)

compiler/rustc_lint/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@ const HAS_MIN_FEATURES: &[Symbol] = &[sym::specialization];
23282328

23292329
declare_lint! {
23302330
/// The `invalid_value` lint detects creating a value that is not valid,
2331-
/// such as a NULL reference.
2331+
/// such as a null reference.
23322332
///
23332333
/// ### Example
23342334
///
@@ -2359,7 +2359,7 @@ declare_lint! {
23592359
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
23602360
pub INVALID_VALUE,
23612361
Warn,
2362-
"an invalid value is being created (such as a NULL reference)"
2362+
"an invalid value is being created (such as a null reference)"
23632363
}
23642364

23652365
declare_lint_pass!(InvalidValue => [INVALID_VALUE]);

compiler/rustc_metadata/src/dynamic_lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ mod dl {
105105
return Ok(ret.cast());
106106
}
107107

108-
// A NULL return from `dlopen` indicates that an error has definitely occurred, so if
108+
// A null return from `dlopen` indicates that an error has definitely occurred, so if
109109
// nothing is in `dlerror`, we are racing with another thread that has stolen our error
110110
// message. See the explanation on the `dl::error` module for more information.
111111
dlerror.get().and_then(|()| Err("Unknown error".to_string()))
@@ -117,7 +117,7 @@ mod dl {
117117
) -> Result<*mut u8, String> {
118118
let mut dlerror = error::lock();
119119

120-
// Unlike `dlopen`, it's possible for `dlsym` to return NULL without overwriting `dlerror`.
120+
// Unlike `dlopen`, it's possible for `dlsym` to return null without overwriting `dlerror`.
121121
// Because of this, we clear `dlerror` before calling `dlsym` to avoid picking up a stale
122122
// error message by accident.
123123
dlerror.clear();
@@ -128,7 +128,7 @@ mod dl {
128128
return Ok(ret.cast());
129129
}
130130

131-
// If `dlsym` returns NULL but there is nothing in `dlerror` it means one of two things:
131+
// If `dlsym` returns null but there is nothing in `dlerror` it means one of two things:
132132
// - We tried to load a symbol mapped to address 0. This is not technically an error but is
133133
// unlikely to occur in practice and equally unlikely to be handled correctly by calling
134134
// code. Therefore we treat it as an error anyway.

compiler/rustc_middle/src/mir/interpret/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl fmt::Display for CheckInAllocMsg {
185185
"{}",
186186
match *self {
187187
CheckInAllocMsg::MemoryAccessTest => "memory access",
188-
CheckInAllocMsg::NullPointerTest => "NULL pointer test",
188+
CheckInAllocMsg::NullPointerTest => "null pointer test",
189189
CheckInAllocMsg::PointerArithmeticTest => "pointer arithmetic",
190190
CheckInAllocMsg::InboundsTest => "inbounds test",
191191
}
@@ -309,7 +309,7 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
309309
allocation_size.bytes()
310310
),
311311
DanglingIntPointer(_, CheckInAllocMsg::NullPointerTest) => {
312-
write!(f, "NULL pointer is not allowed for this operation")
312+
write!(f, "null pointer is not allowed for this operation")
313313
}
314314
DanglingIntPointer(i, msg) => {
315315
write!(f, "{} failed: 0x{:x} is not a valid pointer", msg, i)

compiler/rustc_middle/src/mir/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl UnsafetyViolationDetails {
8181
),
8282
DerefOfRawPointer => (
8383
"dereference of raw pointer",
84-
"raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules \
84+
"raw pointers may be null, dangling or unaligned; they can violate aliasing rules \
8585
and cause data races: all of these are undefined behavior",
8686
),
8787
AssignToDroppingUnionField => (

compiler/rustc_mir/src/interpret/intrinsics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
348348
let b = self.read_immediate(&args[1])?.to_scalar()?;
349349

350350
// Special case: if both scalars are *equal integers*
351-
// and not NULL, we pretend there is an allocation of size 0 right there,
352-
// and their offset is 0. (There's never a valid object at NULL, making it an
351+
// and not null, we pretend there is an allocation of size 0 right there,
352+
// and their offset is 0. (There's never a valid object at null, making it an
353353
// exception from the exception.)
354354
// This is the dual to the special exception for offset-by-0
355355
// in the inbounds pointer offset operation (see the Miri code, `src/operator.rs`).
@@ -501,7 +501,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
501501

502502
/// Offsets a pointer by some multiple of its type, returning an error if the pointer leaves its
503503
/// allocation. For integer pointers, we consider each of them their own tiny allocation of size
504-
/// 0, so offset-by-0 (and only 0) is okay -- except that NULL cannot be offset by _any_ value.
504+
/// 0, so offset-by-0 (and only 0) is okay -- except that null cannot be offset by _any_ value.
505505
pub fn ptr_offset_inbounds(
506506
&self,
507507
ptr: Scalar<M::PointerTag>,
@@ -521,7 +521,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
521521
// pointers to be properly aligned (unlike a read/write operation).
522522
let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr };
523523
let size = offset_bytes.unsigned_abs();
524-
// This call handles checking for integer/NULL pointers.
524+
// This call handles checking for integer/null pointers.
525525
self.memory.check_ptr_access_align(
526526
min_ptr,
527527
Size::from_bytes(size),

compiler/rustc_mir/src/interpret/memory.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! Generally, we use `Pointer` to denote memory addresses. However, some operations
44
//! have a "size"-like parameter, and they take `Scalar` for the address because
5-
//! if the size is 0, then the pointer can also be a (properly aligned, non-NULL)
5+
//! if the size is 0, then the pointer can also be a (properly aligned, non-null)
66
//! integer. It is crucial that these operations call `check_align` *before*
77
//! short-circuiting the empty case!
88
@@ -105,7 +105,7 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
105105
/// Map for "extra" function pointers.
106106
extra_fn_ptr_map: FxHashMap<AllocId, M::ExtraFnVal>,
107107

108-
/// To be able to compare pointers with NULL, and to check alignment for accesses
108+
/// To be able to compare pointers with null, and to check alignment for accesses
109109
/// to ZSTs (where pointers may dangle), we keep track of the size even for allocations
110110
/// that do not exist any more.
111111
// FIXME: this should not be public, but interning currently needs access to it
@@ -391,7 +391,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
391391
Ok(bits) => {
392392
let bits = u64::try_from(bits).unwrap(); // it's ptr-sized
393393
assert!(size.bytes() == 0);
394-
// Must be non-NULL.
394+
// Must be non-null.
395395
if bits == 0 {
396396
throw_ub!(DanglingIntPointer(0, msg))
397397
}
@@ -404,7 +404,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
404404
Err(ptr) => {
405405
let (allocation_size, alloc_align) =
406406
self.get_size_and_align(ptr.alloc_id, AllocCheck::Dereferenceable)?;
407-
// Test bounds. This also ensures non-NULL.
407+
// Test bounds. This also ensures non-null.
408408
// It is sufficient to check this for the end pointer. The addition
409409
// checks for overflow.
410410
let end_ptr = ptr.offset(size, self)?;
@@ -436,7 +436,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
436436
})
437437
}
438438

439-
/// Test if the pointer might be NULL.
439+
/// Test if the pointer might be null.
440440
pub fn ptr_may_be_null(&self, ptr: Pointer<M::PointerTag>) -> bool {
441441
let (size, _align) = self
442442
.get_size_and_align(ptr.alloc_id, AllocCheck::MaybeDead)

compiler/rustc_mir/src/interpret/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ where
375375
assert!(place.mplace.align <= align, "dynamic alignment less strict than static one?");
376376
// Check (stricter) dynamic alignment, unless forced otherwise.
377377
place.mplace.align = force_align.unwrap_or(align);
378-
// When dereferencing a pointer, it must be non-NULL, aligned, and live.
378+
// When dereferencing a pointer, it must be non-null, aligned, and live.
379379
if let Some(ptr) = self.check_mplace_access(&place, Some(size))? {
380380
place.mplace.ptr = ptr.into();
381381
}

compiler/rustc_mir/src/interpret/validity.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
427427
has.bytes()
428428
},
429429
err_ub!(DanglingIntPointer(0, _)) =>
430-
{ "a NULL {}", kind },
430+
{ "a null {}", kind },
431431
err_ub!(DanglingIntPointer(i, _)) =>
432432
{ "a dangling {} (address 0x{:x} is unallocated)", kind, i },
433433
err_ub!(PointerOutOfBounds { .. }) =>
@@ -662,10 +662,10 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
662662
let bits = match value.to_bits_or_ptr(op.layout.size, self.ecx) {
663663
Err(ptr) => {
664664
if lo == 1 && hi == max_hi {
665-
// Only NULL is the niche. So make sure the ptr is NOT NULL.
665+
// Only null is the niche. So make sure the ptr is NOT null.
666666
if self.ecx.memory.ptr_may_be_null(ptr) {
667667
throw_validation_failure!(self.path,
668-
{ "a potentially NULL pointer" }
668+
{ "a potentially null pointer" }
669669
expected {
670670
"something that cannot possibly fail to be {}",
671671
wrapping_range_format(valid_range, max_hi)

library/alloc/src/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
//! /* Returns ownership to the caller */
8585
//! struct Foo* foo_new(void);
8686
//!
87-
//! /* Takes ownership from the caller; no-op when invoked with NULL */
87+
//! /* Takes ownership from the caller; no-op when invoked with null */
8888
//! void foo_delete(struct Foo*);
8989
//! ```
9090
//!

library/core/src/intrinsics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ extern "rust-intrinsic" {
17731773
/// [violate memory safety][read-ownership].
17741774
///
17751775
/// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1776-
/// `0`, the pointers must be non-NULL and properly aligned.
1776+
/// `0`, the pointers must be non-null and properly aligned.
17771777
///
17781778
/// [`read`]: crate::ptr::read
17791779
/// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value
@@ -1857,7 +1857,7 @@ extern "rust-intrinsic" {
18571857
/// [violate memory safety][read-ownership].
18581858
///
18591859
/// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1860-
/// `0`, the pointers must be non-NULL and properly aligned.
1860+
/// `0`, the pointers must be non-null and properly aligned.
18611861
///
18621862
/// [`read`]: crate::ptr::read
18631863
/// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value
@@ -1928,7 +1928,7 @@ pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
19281928
/// invalid value of `T` is undefined behavior.
19291929
///
19301930
/// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1931-
/// `0`, the pointer must be non-NULL and properly aligned.
1931+
/// `0`, the pointer must be non-null and properly aligned.
19321932
///
19331933
/// [valid]: crate::ptr#safety
19341934
///

library/core/src/mem/maybe_uninit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::ptr;
1010
///
1111
/// The compiler, in general, assumes that a variable is properly initialized
1212
/// according to the requirements of the variable's type. For example, a variable of
13-
/// reference type must be aligned and non-NULL. This is an invariant that must
13+
/// reference type must be aligned and non-null. This is an invariant that must
1414
/// *always* be upheld, even in unsafe code. As a consequence, zero-initializing a
1515
/// variable of reference type causes instantaneous [undefined behavior][ub],
1616
/// no matter whether that reference ever gets used to access memory:

library/core/src/ptr/const_ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<T: ?Sized> *const T {
6666
///
6767
/// # Safety
6868
///
69-
/// When calling this method, you have to ensure that *either* the pointer is NULL *or*
69+
/// When calling this method, you have to ensure that *either* the pointer is null *or*
7070
/// all of the following is true:
7171
///
7272
/// * The pointer must be properly aligned.
@@ -130,7 +130,7 @@ impl<T: ?Sized> *const T {
130130
///
131131
/// # Safety
132132
///
133-
/// When calling this method, you have to ensure that *either* the pointer is NULL *or*
133+
/// When calling this method, you have to ensure that *either* the pointer is null *or*
134134
/// all of the following is true:
135135
///
136136
/// * The pointer must be properly aligned.
@@ -974,7 +974,7 @@ impl<T> *const [T] {
974974
///
975975
/// # Safety
976976
///
977-
/// When calling this method, you have to ensure that *either* the pointer is NULL *or*
977+
/// When calling this method, you have to ensure that *either* the pointer is null *or*
978978
/// all of the following is true:
979979
///
980980
/// * The pointer must be [valid] for reads for `ptr.len() * mem::size_of::<T>()` many bytes,

library/core/src/ptr/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ mod mut_ptr;
149149
/// again. [`write()`] can be used to overwrite data without causing it to be
150150
/// dropped.
151151
///
152-
/// Note that even if `T` has size `0`, the pointer must be non-NULL and properly aligned.
152+
/// Note that even if `T` has size `0`, the pointer must be non-null and properly aligned.
153153
///
154154
/// [valid]: self#safety
155155
///
@@ -315,7 +315,7 @@ pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
315315
///
316316
/// * Both `x` and `y` must be properly aligned.
317317
///
318-
/// Note that even if `T` has size `0`, the pointers must be non-NULL and properly aligned.
318+
/// Note that even if `T` has size `0`, the pointers must be non-null and properly aligned.
319319
///
320320
/// [valid]: self#safety
321321
///
@@ -394,7 +394,7 @@ pub const unsafe fn swap<T>(x: *mut T, y: *mut T) {
394394
/// beginning at `y` with the same size.
395395
///
396396
/// Note that even if the effectively copied size (`count * size_of::<T>()`) is `0`,
397-
/// the pointers must be non-NULL and properly aligned.
397+
/// the pointers must be non-null and properly aligned.
398398
///
399399
/// [valid]: self#safety
400400
///
@@ -540,7 +540,7 @@ const unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
540540
///
541541
/// * `dst` must point to a properly initialized value of type `T`.
542542
///
543-
/// Note that even if `T` has size `0`, the pointer must be non-NULL and properly aligned.
543+
/// Note that even if `T` has size `0`, the pointer must be non-null and properly aligned.
544544
///
545545
/// [valid]: self#safety
546546
///
@@ -588,7 +588,7 @@ pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
588588
///
589589
/// * `src` must point to a properly initialized value of type `T`.
590590
///
591-
/// Note that even if `T` has size `0`, the pointer must be non-NULL and properly aligned.
591+
/// Note that even if `T` has size `0`, the pointer must be non-null and properly aligned.
592592
///
593593
/// # Examples
594594
///
@@ -713,7 +713,7 @@ pub const unsafe fn read<T>(src: *const T) -> T {
713713
/// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the returned
714714
/// value and the value at `*src` can [violate memory safety][read-ownership].
715715
///
716-
/// Note that even if `T` has size `0`, the pointer must be non-NULL.
716+
/// Note that even if `T` has size `0`, the pointer must be non-null.
717717
///
718718
/// [read-ownership]: read#ownership-of-the-returned-value
719719
/// [valid]: self#safety
@@ -818,7 +818,7 @@ pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
818818
/// * `dst` must be properly aligned. Use [`write_unaligned`] if this is not the
819819
/// case.
820820
///
821-
/// Note that even if `T` has size `0`, the pointer must be non-NULL and properly aligned.
821+
/// Note that even if `T` has size `0`, the pointer must be non-null and properly aligned.
822822
///
823823
/// [valid]: self#safety
824824
///
@@ -910,7 +910,7 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
910910
///
911911
/// * `dst` must be [valid] for writes.
912912
///
913-
/// Note that even if `T` has size `0`, the pointer must be non-NULL.
913+
/// Note that even if `T` has size `0`, the pointer must be non-null.
914914
///
915915
/// [valid]: self#safety
916916
///
@@ -1024,7 +1024,7 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
10241024
/// However, storing non-[`Copy`] types in volatile memory is almost certainly
10251025
/// incorrect.
10261026
///
1027-
/// Note that even if `T` has size `0`, the pointer must be non-NULL and properly aligned.
1027+
/// Note that even if `T` has size `0`, the pointer must be non-null and properly aligned.
10281028
///
10291029
/// [valid]: self#safety
10301030
/// [read-ownership]: read#ownership-of-the-returned-value
@@ -1094,7 +1094,7 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
10941094
///
10951095
/// * `dst` must be properly aligned.
10961096
///
1097-
/// Note that even if `T` has size `0`, the pointer must be non-NULL and properly aligned.
1097+
/// Note that even if `T` has size `0`, the pointer must be non-null and properly aligned.
10981098
///
10991099
/// [valid]: self#safety
11001100
///
@@ -1496,7 +1496,7 @@ fnptr_impls_args! { A, B, C, D, E, F, G, H, I, J, K, L }
14961496
///
14971497
/// Note, however, that the `expr` in `addr_of!(expr)` is still subject to all
14981498
/// the usual rules. In particular, `addr_of!(*ptr::null())` is Undefined
1499-
/// Behavior because it dereferences a NULL pointer.
1499+
/// Behavior because it dereferences a null pointer.
15001500
///
15011501
/// # Example
15021502
///
@@ -1536,7 +1536,7 @@ pub macro addr_of($place:expr) {
15361536
///
15371537
/// Note, however, that the `expr` in `addr_of_mut!(expr)` is still subject to all
15381538
/// the usual rules. In particular, `addr_of_mut!(*ptr::null_mut())` is Undefined
1539-
/// Behavior because it dereferences a NULL pointer.
1539+
/// Behavior because it dereferences a null pointer.
15401540
///
15411541
/// # Examples
15421542
///

0 commit comments

Comments
 (0)