Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnay
Use generic `NonZero` internally. Tracking issue: https://github.com/rust-lang/rust/issues/120257
This commit is contained in:
commit
1be468815c
144 changed files with 636 additions and 628 deletions
|
@ -2,13 +2,13 @@
|
|||
|
||||
use std::collections::BTreeMap;
|
||||
use std::hash::Hash;
|
||||
use std::num::NonZeroU32;
|
||||
use std::num::NonZero;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
use super::fxhash::FxHashMap;
|
||||
|
||||
pub(super) type Handle = NonZeroU32;
|
||||
pub(super) type Handle = NonZero<u32>;
|
||||
|
||||
/// A store that associates values of type `T` with numeric handles. A value can
|
||||
/// be looked up using its handle.
|
||||
|
@ -20,7 +20,7 @@ pub(super) struct OwnedStore<T: 'static> {
|
|||
impl<T> OwnedStore<T> {
|
||||
pub(super) fn new(counter: &'static AtomicU32) -> Self {
|
||||
// Ensure the handle counter isn't 0, which would panic later,
|
||||
// when `NonZeroU32::new` (aka `Handle::new`) is called in `alloc`.
|
||||
// when `NonZero::new` (aka `Handle::new`) is called in `alloc`.
|
||||
assert_ne!(counter.load(Ordering::SeqCst), 0);
|
||||
|
||||
OwnedStore { counter, data: BTreeMap::new() }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::any::Any;
|
||||
use std::io::Write;
|
||||
use std::num::NonZeroU32;
|
||||
use std::num::NonZero;
|
||||
use std::str;
|
||||
|
||||
pub(super) type Writer = super::buffer::Buffer;
|
||||
|
@ -157,13 +157,13 @@ impl<S> DecodeMut<'_, '_, S> for char {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> Encode<S> for NonZeroU32 {
|
||||
impl<S> Encode<S> for NonZero<u32> {
|
||||
fn encode(self, w: &mut Writer, s: &mut S) {
|
||||
self.get().encode(w, s);
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> DecodeMut<'_, '_, S> for NonZeroU32 {
|
||||
impl<S> DecodeMut<'_, '_, S> for NonZero<u32> {
|
||||
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
|
||||
Self::new(u32::decode(r, s)).unwrap()
|
||||
}
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
//! proc_macro, this module should probably be removed or simplified.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::num::NonZeroU32;
|
||||
use std::num::NonZero;
|
||||
use std::str;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Handle for a symbol string stored within the Interner.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Symbol(NonZeroU32);
|
||||
pub struct Symbol(NonZero<u32>);
|
||||
|
||||
impl !Send for Symbol {}
|
||||
impl !Sync for Symbol {}
|
||||
|
@ -137,7 +137,7 @@ thread_local! {
|
|||
names: fxhash::FxHashMap::default(),
|
||||
strings: Vec::new(),
|
||||
// Start with a base of 1 to make sure that `NonZeroU32` works.
|
||||
sym_base: NonZeroU32::new(1).unwrap(),
|
||||
sym_base: NonZero::new(1).unwrap(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ struct Interner {
|
|||
// The offset to apply to symbol names stored in the interner. This is used
|
||||
// to ensure that symbol names are not re-used after the interner is
|
||||
// cleared.
|
||||
sym_base: NonZeroU32,
|
||||
sym_base: NonZero<u32>,
|
||||
}
|
||||
|
||||
impl Interner {
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#![feature(staged_api)]
|
||||
#![feature(allow_internal_unstable)]
|
||||
#![feature(decl_macro)]
|
||||
#![feature(generic_nonzero)]
|
||||
#![feature(maybe_uninit_write_slice)]
|
||||
#![feature(negative_impls)]
|
||||
#![feature(new_uninit)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue