Skip to content

Commit 69545c0

Browse files
authored
Use Self where possible (#5892)
1 parent 05013e3 commit 69545c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+738
-825
lines changed

common/src/atomic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<T> Default for OncePtr<T> {
6565
impl<T> OncePtr<T> {
6666
#[inline]
6767
pub fn new() -> Self {
68-
OncePtr {
68+
Self {
6969
inner: Radium::new(ptr::null_mut()),
7070
}
7171
}

common/src/boxvec.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ macro_rules! panic_oob {
3838
}
3939

4040
impl<T> BoxVec<T> {
41-
pub fn new(n: usize) -> BoxVec<T> {
42-
BoxVec {
41+
pub fn new(n: usize) -> Self {
42+
Self {
4343
xs: Box::new_uninit_slice(n),
4444
len: 0,
4545
}
@@ -593,7 +593,7 @@ where
593593
T: Clone,
594594
{
595595
fn clone(&self) -> Self {
596-
let mut new = BoxVec::new(self.capacity());
596+
let mut new = Self::new(self.capacity());
597597
new.extend(self.iter().cloned());
598598
new
599599
}
@@ -676,8 +676,8 @@ pub struct CapacityError<T = ()> {
676676

677677
impl<T> CapacityError<T> {
678678
/// Create a new `CapacityError` from `element`.
679-
pub const fn new(element: T) -> CapacityError<T> {
680-
CapacityError { element }
679+
pub const fn new(element: T) -> Self {
680+
Self { element }
681681
}
682682

683683
/// Extract the overflowing element

common/src/cformat.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ pub enum CFormatType {
103103
impl CFormatType {
104104
pub const fn to_char(self) -> char {
105105
match self {
106-
CFormatType::Number(x) => x as u8 as char,
107-
CFormatType::Float(x) => x as u8 as char,
108-
CFormatType::Character(x) => x as u8 as char,
109-
CFormatType::String(x) => x as u8 as char,
106+
Self::Number(x) => x as u8 as char,
107+
Self::Float(x) => x as u8 as char,
108+
Self::Character(x) => x as u8 as char,
109+
Self::String(x) => x as u8 as char,
110110
}
111111
}
112112
}
@@ -119,7 +119,7 @@ pub enum CFormatPrecision {
119119

120120
impl From<CFormatQuantity> for CFormatPrecision {
121121
fn from(quantity: CFormatQuantity) -> Self {
122-
CFormatPrecision::Quantity(quantity)
122+
Self::Quantity(quantity)
123123
}
124124
}
125125

@@ -338,7 +338,7 @@ impl CFormatSpec {
338338
_ => &num_chars,
339339
};
340340
let fill_chars_needed = width.saturating_sub(num_chars);
341-
let fill_string: T = CFormatSpec::compute_fill_string(fill_char, fill_chars_needed);
341+
let fill_string: T = Self::compute_fill_string(fill_char, fill_chars_needed);
342342

343343
if !fill_string.is_empty() {
344344
if self.flags.contains(CConversionFlags::LEFT_ADJUST) {
@@ -361,7 +361,7 @@ impl CFormatSpec {
361361
_ => &num_chars,
362362
};
363363
let fill_chars_needed = width.saturating_sub(num_chars);
364-
let fill_string: T = CFormatSpec::compute_fill_string(fill_char, fill_chars_needed);
364+
let fill_string: T = Self::compute_fill_string(fill_char, fill_chars_needed);
365365

366366
if !fill_string.is_empty() {
367367
// Don't left-adjust if precision-filling: that will always be prepending 0s to %d
@@ -721,13 +721,13 @@ pub enum CFormatPart<T> {
721721
impl<T> CFormatPart<T> {
722722
#[inline]
723723
pub const fn is_specifier(&self) -> bool {
724-
matches!(self, CFormatPart::Spec { .. })
724+
matches!(self, Self::Spec { .. })
725725
}
726726

727727
#[inline]
728728
pub const fn has_key(&self) -> bool {
729729
match self {
730-
CFormatPart::Spec(s) => s.mapping_key.is_some(),
730+
Self::Spec(s) => s.mapping_key.is_some(),
731731
_ => false,
732732
}
733733
}

common/src/format.rs

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ impl FormatParse for FormatConversion {
3838
}
3939

4040
impl FormatConversion {
41-
pub fn from_char(c: CodePoint) -> Option<FormatConversion> {
41+
pub fn from_char(c: CodePoint) -> Option<Self> {
4242
match c.to_char_lossy() {
43-
's' => Some(FormatConversion::Str),
44-
'r' => Some(FormatConversion::Repr),
45-
'a' => Some(FormatConversion::Ascii),
46-
'b' => Some(FormatConversion::Bytes),
43+
's' => Some(Self::Str),
44+
'r' => Some(Self::Repr),
45+
'a' => Some(Self::Ascii),
46+
'b' => Some(Self::Bytes),
4747
_ => None,
4848
}
4949
}
5050

51-
fn from_string(text: &Wtf8) -> Option<FormatConversion> {
51+
fn from_string(text: &Wtf8) -> Option<Self> {
5252
let mut chars = text.code_points();
5353
if chars.next()? != '!' {
5454
return None;
5555
}
5656

57-
FormatConversion::from_char(chars.next()?)
57+
Self::from_char(chars.next()?)
5858
}
5959
}
6060

@@ -67,12 +67,12 @@ pub enum FormatAlign {
6767
}
6868

6969
impl FormatAlign {
70-
fn from_char(c: CodePoint) -> Option<FormatAlign> {
70+
fn from_char(c: CodePoint) -> Option<Self> {
7171
match c.to_char_lossy() {
72-
'<' => Some(FormatAlign::Left),
73-
'>' => Some(FormatAlign::Right),
74-
'=' => Some(FormatAlign::AfterSign),
75-
'^' => Some(FormatAlign::Center),
72+
'<' => Some(Self::Left),
73+
'>' => Some(Self::Right),
74+
'=' => Some(Self::AfterSign),
75+
'^' => Some(Self::Center),
7676
_ => None,
7777
}
7878
}
@@ -141,7 +141,7 @@ pub enum FormatType {
141141
}
142142

143143
impl From<&FormatType> for char {
144-
fn from(from: &FormatType) -> char {
144+
fn from(from: &FormatType) -> Self {
145145
match from {
146146
FormatType::String => 's',
147147
FormatType::Binary => 'b',
@@ -299,7 +299,7 @@ impl FormatSpec {
299299
align = align.or(Some(FormatAlign::AfterSign));
300300
}
301301

302-
Ok(FormatSpec {
302+
Ok(Self {
303303
conversion,
304304
fill,
305305
align,
@@ -327,7 +327,7 @@ impl FormatSpec {
327327
let magnitude_int_str = parts.next().unwrap().to_string();
328328
let dec_digit_cnt = magnitude_str.len() as i32 - magnitude_int_str.len() as i32;
329329
let int_digit_cnt = disp_digit_cnt - dec_digit_cnt;
330-
let mut result = FormatSpec::separate_integer(magnitude_int_str, inter, sep, int_digit_cnt);
330+
let mut result = Self::separate_integer(magnitude_int_str, inter, sep, int_digit_cnt);
331331
if let Some(part) = parts.next() {
332332
result.push_str(&format!(".{part}"))
333333
}
@@ -350,11 +350,11 @@ impl FormatSpec {
350350
// separate with 0 padding
351351
let padding = "0".repeat(diff as usize);
352352
let padded_num = format!("{padding}{magnitude_str}");
353-
FormatSpec::insert_separator(padded_num, inter, sep, sep_cnt)
353+
Self::insert_separator(padded_num, inter, sep, sep_cnt)
354354
} else {
355355
// separate without padding
356356
let sep_cnt = (magnitude_len - 1) / inter;
357-
FormatSpec::insert_separator(magnitude_str, inter, sep, sep_cnt)
357+
Self::insert_separator(magnitude_str, inter, sep, sep_cnt)
358358
}
359359
}
360360

@@ -412,12 +412,7 @@ impl FormatSpec {
412412
let magnitude_len = magnitude_str.len();
413413
let width = self.width.unwrap_or(magnitude_len) as i32 - prefix.len() as i32;
414414
let disp_digit_cnt = cmp::max(width, magnitude_len as i32);
415-
FormatSpec::add_magnitude_separators_for_char(
416-
magnitude_str,
417-
inter,
418-
sep,
419-
disp_digit_cnt,
420-
)
415+
Self::add_magnitude_separators_for_char(magnitude_str, inter, sep, disp_digit_cnt)
421416
}
422417
None => magnitude_str,
423418
}
@@ -640,27 +635,26 @@ impl FormatSpec {
640635
"{}{}{}",
641636
sign_str,
642637
magnitude_str,
643-
FormatSpec::compute_fill_string(fill_char, fill_chars_needed)
638+
Self::compute_fill_string(fill_char, fill_chars_needed)
644639
),
645640
FormatAlign::Right => format!(
646641
"{}{}{}",
647-
FormatSpec::compute_fill_string(fill_char, fill_chars_needed),
642+
Self::compute_fill_string(fill_char, fill_chars_needed),
648643
sign_str,
649644
magnitude_str
650645
),
651646
FormatAlign::AfterSign => format!(
652647
"{}{}{}",
653648
sign_str,
654-
FormatSpec::compute_fill_string(fill_char, fill_chars_needed),
649+
Self::compute_fill_string(fill_char, fill_chars_needed),
655650
magnitude_str
656651
),
657652
FormatAlign::Center => {
658653
let left_fill_chars_needed = fill_chars_needed / 2;
659654
let right_fill_chars_needed = fill_chars_needed - left_fill_chars_needed;
660-
let left_fill_string =
661-
FormatSpec::compute_fill_string(fill_char, left_fill_chars_needed);
655+
let left_fill_string = Self::compute_fill_string(fill_char, left_fill_chars_needed);
662656
let right_fill_string =
663-
FormatSpec::compute_fill_string(fill_char, right_fill_chars_needed);
657+
Self::compute_fill_string(fill_char, right_fill_chars_needed);
664658
format!("{left_fill_string}{sign_str}{magnitude_str}{right_fill_string}")
665659
}
666660
})
@@ -725,7 +719,7 @@ pub enum FormatParseError {
725719
impl FromStr for FormatSpec {
726720
type Err = FormatSpecError;
727721
fn from_str(s: &str) -> Result<Self, Self::Err> {
728-
FormatSpec::parse(s)
722+
Self::parse(s)
729723
}
730724
}
731725

@@ -739,7 +733,7 @@ pub enum FieldNamePart {
739733
impl FieldNamePart {
740734
fn parse_part(
741735
chars: &mut impl PeekingNext<Item = CodePoint>,
742-
) -> Result<Option<FieldNamePart>, FormatParseError> {
736+
) -> Result<Option<Self>, FormatParseError> {
743737
chars
744738
.next()
745739
.map(|ch| match ch.to_char_lossy() {
@@ -751,7 +745,7 @@ impl FieldNamePart {
751745
if attribute.is_empty() {
752746
Err(FormatParseError::EmptyAttribute)
753747
} else {
754-
Ok(FieldNamePart::Attribute(attribute))
748+
Ok(Self::Attribute(attribute))
755749
}
756750
}
757751
'[' => {
@@ -761,9 +755,9 @@ impl FieldNamePart {
761755
return if index.is_empty() {
762756
Err(FormatParseError::EmptyAttribute)
763757
} else if let Some(index) = parse_usize(&index) {
764-
Ok(FieldNamePart::Index(index))
758+
Ok(Self::Index(index))
765759
} else {
766-
Ok(FieldNamePart::StringIndex(index))
760+
Ok(Self::StringIndex(index))
767761
};
768762
}
769763
index.push(ch);
@@ -794,7 +788,7 @@ fn parse_usize(s: &Wtf8) -> Option<usize> {
794788
}
795789

796790
impl FieldName {
797-
pub fn parse(text: &Wtf8) -> Result<FieldName, FormatParseError> {
791+
pub fn parse(text: &Wtf8) -> Result<Self, FormatParseError> {
798792
let mut chars = text.code_points().peekable();
799793
let first: Wtf8Buf = chars
800794
.peeking_take_while(|ch| *ch != '.' && *ch != '[')
@@ -813,7 +807,7 @@ impl FieldName {
813807
parts.push(part)
814808
}
815809

816-
Ok(FieldName { field_type, parts })
810+
Ok(Self { field_type, parts })
817811
}
818812
}
819813

@@ -854,7 +848,7 @@ impl FormatString {
854848
let mut cur_text = text;
855849
let mut result_string = Wtf8Buf::new();
856850
while !cur_text.is_empty() {
857-
match FormatString::parse_literal_single(cur_text) {
851+
match Self::parse_literal_single(cur_text) {
858852
Ok((next_char, remaining)) => {
859853
result_string.push(next_char);
860854
cur_text = remaining;
@@ -968,7 +962,7 @@ impl FormatString {
968962
}
969963
if let Some(pos) = end_bracket_pos {
970964
let right = &text[pos..];
971-
let format_part = FormatString::parse_part_in_brackets(&left)?;
965+
let format_part = Self::parse_part_in_brackets(&left)?;
972966
Ok((format_part, &right[1..]))
973967
} else {
974968
Err(FormatParseError::UnmatchedBracket)
@@ -990,14 +984,14 @@ impl<'a> FromTemplate<'a> for FormatString {
990984
while !cur_text.is_empty() {
991985
// Try to parse both literals and bracketed format parts until we
992986
// run out of text
993-
cur_text = FormatString::parse_literal(cur_text)
994-
.or_else(|_| FormatString::parse_spec(cur_text))
987+
cur_text = Self::parse_literal(cur_text)
988+
.or_else(|_| Self::parse_spec(cur_text))
995989
.map(|(part, new_text)| {
996990
parts.push(part);
997991
new_text
998992
})?;
999993
}
1000-
Ok(FormatString {
994+
Ok(Self {
1001995
format_parts: parts,
1002996
})
1003997
}

common/src/linked_list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ unsafe impl<T: Sync> Sync for Pointers<T> {}
140140

141141
impl<L, T> LinkedList<L, T> {
142142
/// Creates an empty linked list.
143-
pub const fn new() -> LinkedList<L, T> {
144-
LinkedList {
143+
pub const fn new() -> Self {
144+
Self {
145145
head: None,
146146
// tail: None,
147147
_marker: PhantomData,
@@ -323,8 +323,8 @@ where
323323

324324
impl<T> Pointers<T> {
325325
/// Create a new set of empty pointers
326-
pub fn new() -> Pointers<T> {
327-
Pointers {
326+
pub fn new() -> Self {
327+
Self {
328328
inner: UnsafeCell::new(PointersInner {
329329
prev: None,
330330
next: None,

common/src/lock/cell_lock.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct RawCellMutex {
1111

1212
unsafe impl RawMutex for RawCellMutex {
1313
#[allow(clippy::declare_interior_mutable_const)]
14-
const INIT: Self = RawCellMutex {
14+
const INIT: Self = Self {
1515
locked: Cell::new(false),
1616
};
1717

@@ -61,7 +61,7 @@ impl RawCellRwLock {
6161

6262
unsafe impl RawRwLock for RawCellRwLock {
6363
#[allow(clippy::declare_interior_mutable_const)]
64-
const INIT: Self = RawCellRwLock {
64+
const INIT: Self = Self {
6565
state: Cell::new(0),
6666
};
6767

@@ -203,7 +203,7 @@ fn deadlock(lock_kind: &str, ty: &str) -> ! {
203203

204204
pub struct SingleThreadId(());
205205
unsafe impl GetThreadId for SingleThreadId {
206-
const INIT: Self = SingleThreadId(());
206+
const INIT: Self = Self(());
207207
fn nonzero_thread_id(&self) -> NonZero<usize> {
208208
NonZero::new(1).unwrap()
209209
}

common/src/lock/thread_mutex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct RawThreadMutex<R: RawMutex, G: GetThreadId> {
2121

2222
impl<R: RawMutex, G: GetThreadId> RawThreadMutex<R, G> {
2323
#[allow(clippy::declare_interior_mutable_const)]
24-
pub const INIT: Self = RawThreadMutex {
24+
pub const INIT: Self = Self {
2525
owner: AtomicUsize::new(0),
2626
mutex: R::INIT,
2727
get_thread_id: G::INIT,
@@ -79,7 +79,7 @@ pub struct ThreadMutex<R: RawMutex, G: GetThreadId, T: ?Sized> {
7979

8080
impl<R: RawMutex, G: GetThreadId, T> ThreadMutex<R, G, T> {
8181
pub fn new(val: T) -> Self {
82-
ThreadMutex {
82+
Self {
8383
raw: RawThreadMutex::INIT,
8484
data: UnsafeCell::new(val),
8585
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy