@@ -485,9 +485,7 @@ impl String {
485485 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
486486 #[ must_use]
487487 pub fn with_capacity ( capacity : usize ) -> String {
488- String {
489- vec : Vec :: with_capacity ( capacity) ,
490- }
488+ String { vec : Vec :: with_capacity ( capacity) }
491489 }
492490
493491 /// Creates a new empty `String` with at least the specified capacity.
@@ -500,9 +498,7 @@ impl String {
500498 #[ inline]
501499 #[ unstable( feature = "try_with_capacity" , issue = "91913" ) ]
502500 pub fn try_with_capacity ( capacity : usize ) -> Result < String , TryReserveError > {
503- Ok ( String {
504- vec : Vec :: try_with_capacity ( capacity) ?,
505- } )
501+ Ok ( String { vec : Vec :: try_with_capacity ( capacity) ? } )
506502 }
507503
508504 /// Converts a vector of bytes to a `String`.
@@ -567,10 +563,7 @@ impl String {
567563 pub fn from_utf8 ( vec : Vec < u8 > ) -> Result < String , FromUtf8Error > {
568564 match str:: from_utf8 ( & vec) {
569565 Ok ( ..) => Ok ( String { vec } ) ,
570- Err ( e) => Err ( FromUtf8Error {
571- bytes : vec,
572- error : e,
573- } ) ,
566+ Err ( e) => Err ( FromUtf8Error { bytes : vec, error : e } ) ,
574567 }
575568 }
576569
@@ -797,9 +790,7 @@ impl String {
797790 let ( chunks, [ ] ) = v. as_chunks :: < 2 > ( ) else {
798791 return Err ( FromUtf16Error ( ( ) ) ) ;
799792 } ;
800- match ( cfg ! ( target_endian = "little" ) , unsafe {
801- v. align_to :: < u16 > ( )
802- } ) {
793+ match ( cfg ! ( target_endian = "little" ) , unsafe { v. align_to :: < u16 > ( ) } ) {
803794 ( true , ( [ ] , v, [ ] ) ) => Self :: from_utf16 ( v) ,
804795 _ => char:: decode_utf16 ( chunks. iter ( ) . copied ( ) . map ( u16:: from_le_bytes) )
805796 . collect :: < Result < _ , _ > > ( )
@@ -835,21 +826,15 @@ impl String {
835826 #[ cfg( not( no_global_oom_handling) ) ]
836827 #[ unstable( feature = "str_from_utf16_endian" , issue = "116258" ) ]
837828 pub fn from_utf16le_lossy ( v : & [ u8 ] ) -> String {
838- match ( cfg ! ( target_endian = "little" ) , unsafe {
839- v. align_to :: < u16 > ( )
840- } ) {
829+ match ( cfg ! ( target_endian = "little" ) , unsafe { v. align_to :: < u16 > ( ) } ) {
841830 ( true , ( [ ] , v, [ ] ) ) => Self :: from_utf16_lossy ( v) ,
842831 ( true , ( [ ] , v, [ _remainder] ) ) => Self :: from_utf16_lossy ( v) + "\u{FFFD} " ,
843832 _ => {
844833 let ( chunks, remainder) = v. as_chunks :: < 2 > ( ) ;
845834 let string = char:: decode_utf16 ( chunks. iter ( ) . copied ( ) . map ( u16:: from_le_bytes) )
846835 . map ( |r| r. unwrap_or ( char:: REPLACEMENT_CHARACTER ) )
847836 . collect ( ) ;
848- if remainder. is_empty ( ) {
849- string
850- } else {
851- string + "\u{FFFD} "
852- }
837+ if remainder. is_empty ( ) { string } else { string + "\u{FFFD} " }
853838 }
854839 }
855840 }
@@ -924,11 +909,7 @@ impl String {
924909 let string = char:: decode_utf16 ( chunks. iter ( ) . copied ( ) . map ( u16:: from_be_bytes) )
925910 . map ( |r| r. unwrap_or ( char:: REPLACEMENT_CHARACTER ) )
926911 . collect ( ) ;
927- if remainder. is_empty ( ) {
928- string
929- } else {
930- string + "\u{FFFD} "
931- }
912+ if remainder. is_empty ( ) { string } else { string + "\u{FFFD} " }
932913 }
933914 }
934915 }
@@ -1011,11 +992,7 @@ impl String {
1011992 #[ inline]
1012993 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1013994 pub unsafe fn from_raw_parts ( buf : * mut u8 , length : usize , capacity : usize ) -> String {
1014- unsafe {
1015- String {
1016- vec : Vec :: from_raw_parts ( buf, length, capacity) ,
1017- }
1018- }
995+ unsafe { String { vec : Vec :: from_raw_parts ( buf, length, capacity) } }
1019996 }
1020997
1021998 /// Converts a vector of bytes to a `String` without checking that the
@@ -1547,11 +1524,7 @@ impl String {
15471524 let next = idx + ch. len_utf8 ( ) ;
15481525 let len = self . len ( ) ;
15491526 unsafe {
1550- ptr:: copy (
1551- self . vec . as_ptr ( ) . add ( next) ,
1552- self . vec . as_mut_ptr ( ) . add ( idx) ,
1553- len - next,
1554- ) ;
1527+ ptr:: copy ( self . vec . as_ptr ( ) . add ( next) , self . vec . as_mut_ptr ( ) . add ( idx) , len - next) ;
15551528 self . vec . set_len ( len - ( next - idx) ) ;
15561529 }
15571530 ch
@@ -1601,9 +1574,7 @@ impl String {
16011574 Some ( ( prev_front, start) )
16021575 } )
16031576 . collect ( ) ;
1604- rejections
1605- . into_iter ( )
1606- . chain ( core:: iter:: once ( ( front, self . len ( ) ) ) )
1577+ rejections. into_iter ( ) . chain ( core:: iter:: once ( ( front, self . len ( ) ) ) )
16071578 } ;
16081579
16091580 let mut len = 0 ;
@@ -1677,11 +1648,7 @@ impl String {
16771648 }
16781649
16791650 let len = self . len ( ) ;
1680- let mut guard = SetLenOnDrop {
1681- s : self ,
1682- idx : 0 ,
1683- del_bytes : 0 ,
1684- } ;
1651+ let mut guard = SetLenOnDrop { s : self , idx : 0 , del_bytes : 0 } ;
16851652
16861653 while guard. idx < len {
16871654 let ch =
@@ -1812,11 +1779,7 @@ impl String {
18121779 // ahead. This is safe because sufficient capacity was just reserved, and `idx`
18131780 // is a char boundary.
18141781 unsafe {
1815- ptr:: copy (
1816- self . vec . as_ptr ( ) . add ( idx) ,
1817- self . vec . as_mut_ptr ( ) . add ( idx + amt) ,
1818- len - idx,
1819- ) ;
1782+ ptr:: copy ( self . vec . as_ptr ( ) . add ( idx) , self . vec . as_mut_ptr ( ) . add ( idx + amt) , len - idx) ;
18201783 }
18211784
18221785 // SAFETY: Copy the new string slice into the vacated region if `idx != len`,
@@ -2017,12 +1980,7 @@ impl String {
20171980 // SAFETY: `slice::range` and `is_char_boundary` do the appropriate bounds checks.
20181981 let chars_iter = unsafe { self . get_unchecked ( start..end) } . chars ( ) ;
20191982
2020- Drain {
2021- start,
2022- end,
2023- iter : chars_iter,
2024- string : self_ptr,
2025- }
1983+ Drain { start, end, iter : chars_iter, string : self_ptr }
20261984 }
20271985
20281986 /// Converts a `String` into an iterator over the [`char`]s of the string.
@@ -2077,9 +2035,7 @@ impl String {
20772035 #[ must_use = "`self` will be dropped if the result is not used" ]
20782036 #[ unstable( feature = "string_into_chars" , issue = "133125" ) ]
20792037 pub fn into_chars ( self ) -> IntoChars {
2080- IntoChars {
2081- bytes : self . into_bytes ( ) . into_iter ( ) ,
2082- }
2038+ IntoChars { bytes : self . into_bytes ( ) . into_iter ( ) }
20832039 }
20842040
20852041 /// Removes the specified range in the string,
@@ -2331,9 +2287,7 @@ impl Error for FromUtf16Error {}
23312287#[ stable( feature = "rust1" , since = "1.0.0" ) ]
23322288impl Clone for String {
23332289 fn clone ( & self ) -> Self {
2334- String {
2335- vec : self . vec . clone ( ) ,
2336- }
2290+ String { vec : self . vec . clone ( ) }
23372291 }
23382292
23392293 /// Clones the contents of `source` into `self`.
@@ -3538,9 +3492,10 @@ impl From<char> for String {
35383492#[ cfg( kani) ]
35393493#[ unstable( feature = "kani" , issue = "none" ) ]
35403494mod verify {
3541- use super :: * ;
35423495 use core:: kani;
35433496
3497+ use super :: * ;
3498+
35443499 /// Helper: create a symbolic ASCII string of arbitrary length up to N bytes.
35453500 /// All bytes are constrained to be valid ASCII (0..=127), ensuring valid UTF-8.
35463501 fn any_ascii_string < const N : usize > ( ) -> String {
0 commit comments