diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 2c3365028844a..09aa639db9312 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -20,11 +20,11 @@ //! This API is completely unstable and subject to change. // tidy-alphabetical-start +#![cfg_attr(bootstrap, feature(titlecase))] #![feature(default_field_values)] #![feature(deref_patterns)] #![feature(iter_order_by)] #![feature(option_into_flat_iter)] -#![feature(titlecase)] #![feature(try_blocks)] // tidy-alphabetical-end diff --git a/compiler/rustc_mir_transform/src/check_enums.rs b/compiler/rustc_mir_transform/src/check_enums.rs index 82945c8974827..72eb09663c9eb 100644 --- a/compiler/rustc_mir_transform/src/check_enums.rs +++ b/compiler/rustc_mir_transform/src/check_enums.rs @@ -47,7 +47,9 @@ impl<'tcx> crate::MirPass<'tcx> for CheckEnums { for check in finder.into_found_enums() { debug!("Inserting enum check"); - let new_block = split_block(basic_blocks, location); + // Note: this split inserts a Goto(new_block) terminator, + // which we later overwrite when we insert the check. + let new_block = split_block(basic_blocks, location, source_info); match check { EnumCheckType::Direct { op_size, .. } @@ -60,10 +62,6 @@ impl<'tcx> crate::MirPass<'tcx> for CheckEnums { source_info.span, "cannot build enum discriminant from zero-sized type", ); - basic_blocks[block].terminator = Some(Terminator { - source_info, - kind: TerminatorKind::goto(new_block), - }); } EnumCheckType::Direct { source_op, discr, op_size, valid_discrs } => { insert_direct_enum_check( @@ -240,17 +238,21 @@ impl<'a, 'tcx> Visitor<'tcx> for EnumFinder<'a, 'tcx> { fn split_block( basic_blocks: &mut IndexVec>, location: Location, + source_info: SourceInfo, ) -> BasicBlock { - let block_data = &mut basic_blocks[location.block]; + basic_blocks.push_with(|new_block_idx, basic_blocks| { + let block_data = &mut basic_blocks[location.block]; - // Drain every statement after this one and move the current terminator to a new basic block. - let new_block = BasicBlockData::maybe_unterminated_stmts( - block_data.statements.split_off(location.statement_index), - block_data.terminator.take(), - block_data.is_cleanup, - ); + // Drain every statement after this one + let remaining_stmts = block_data.statements.split_off(location.statement_index); + + // replace the old terminator with a goto to the new block + let new_terminator = Terminator { source_info, kind: TerminatorKind::goto(new_block_idx) }; + let old_terminator = std::mem::replace(block_data.terminator_mut(), new_terminator); - basic_blocks.push(new_block) + // move the old terminator to the new basic block + BasicBlockData::new_stmts(remaining_stmts, old_terminator, block_data.is_cleanup) + }) } /// Inserts the cast of an operand (any type) to a u128 value that holds the discriminant value. @@ -335,6 +337,7 @@ fn insert_discr_cast_to_u128<'tcx>( discr } +// note: This function replaces the current_block terminator. fn insert_direct_enum_check<'tcx>( tcx: TyCtxt<'tcx>, local_decls: &mut IndexVec>, @@ -418,6 +421,7 @@ fn insert_direct_enum_check<'tcx>( }); } +// Note: this function replaces the block's terminator fn insert_uninhabited_enum_check<'tcx>( tcx: TyCtxt<'tcx>, local_decls: &mut IndexVec>, @@ -463,6 +467,7 @@ fn insert_uninhabited_enum_check<'tcx>( }); } +// Note: this function replaces the block's terminator. fn insert_niche_check<'tcx>( tcx: TyCtxt<'tcx>, local_decls: &mut IndexVec>, diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 7bd8dac3f6084..b56cdbc611da8 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -99,7 +99,6 @@ #![feature(byte_str)] #![feature(byte_str_internals)] #![feature(can_vector)] -#![feature(case_ignorable)] #![feature(cast_maybe_uninit)] #![feature(cell_get_cloned)] #![feature(char_internals)] @@ -175,7 +174,6 @@ #![feature(slice_range)] #![feature(std_internals)] #![feature(temporary_niche_types)] -#![feature(titlecase)] #![feature(transmutability)] #![feature(trivial_clone)] #![feature(trusted_fused)] diff --git a/library/alloc/src/rcs/arc.rs b/library/alloc/src/rcs/arc.rs index b76001e55ae65..53f50ad7267cf 100644 --- a/library/alloc/src/rcs/arc.rs +++ b/library/alloc/src/rcs/arc.rs @@ -2247,7 +2247,7 @@ impl Arc { } /// Returns `true` if the two `Arc`s point to the same allocation in a vein similar to - /// [`ptr::eq`]. This function ignores the metadata of `dyn Trait` pointers. + /// [`ptr::addr_eq`]. This function ignores the metadata of wide pointers. /// /// # Examples /// @@ -3522,9 +3522,9 @@ impl Weak { } } - /// Returns `true` if the two `Weak`s point to the same allocation similar to [`ptr::eq`], or if + /// Returns `true` if the two `Weak`s point to the same allocation similar to [`ptr::addr_eq`], or if /// both don't point to any allocation (because they were created with `Weak::new()`). However, - /// this function ignores the metadata of `dyn Trait` pointers. + /// this function ignores the metadata of wide pointers. /// /// # Notes /// diff --git a/library/alloc/src/rcs/rc.rs b/library/alloc/src/rcs/rc.rs index 1874441f3f920..bb9587e03f805 100644 --- a/library/alloc/src/rcs/rc.rs +++ b/library/alloc/src/rcs/rc.rs @@ -2153,7 +2153,7 @@ impl Rc { #[inline] #[stable(feature = "ptr_eq", since = "1.17.0")] /// Returns `true` if the two `Rc`s point to the same allocation in a vein similar to - /// [`ptr::eq`]. This function ignores the metadata of `dyn Trait` pointers. + /// [`ptr::addr_eq`]. This function ignores the metadata of wide pointers. /// /// # Examples /// @@ -3773,9 +3773,9 @@ impl Weak { } } - /// Returns `true` if the two `Weak`s point to the same allocation similar to [`ptr::eq`], or if + /// Returns `true` if the two `Weak`s point to the same allocation similar to [`ptr::addr_eq`], or if /// both don't point to any allocation (because they were created with `Weak::new()`). However, - /// this function ignores the metadata of `dyn Trait` pointers. + /// this function ignores the metadata of wide pointers. /// /// # Notes /// diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 7997e0c053dc9..e5f332fe72f11 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -515,7 +515,7 @@ impl str { /// Basic usage: /// /// ``` - /// #![feature(titlecase)] + /// #![feature(word_to_titlecase)] /// let s = "HELLO WORLD"; /// /// assert_eq!("Hello world", s.word_to_titlecase()); @@ -524,7 +524,7 @@ impl str { /// The first *cased* letter is uppercased: /// /// ``` - /// #![feature(titlecase)] + /// #![feature(word_to_titlecase)] /// let the_night_before_christmas = "'twas"; /// /// assert_eq!("'Twas", the_night_before_christmas.word_to_titlecase()); @@ -533,7 +533,7 @@ impl str { /// Languages without case are not changed: /// /// ``` - /// #![feature(titlecase)] + /// #![feature(word_to_titlecase)] /// let new_year = "农历新年"; /// /// assert_eq!(new_year, new_year.word_to_titlecase()); @@ -542,7 +542,7 @@ impl str { /// Georgian uppercase ("Mtavruli") letters are not used in titlecase: /// /// ``` - /// #![feature(titlecase)] + /// #![feature(word_to_titlecase)] /// let georgian = "ერთობაშია"; /// /// assert_eq!(georgian, georgian.word_to_titlecase()); @@ -552,7 +552,7 @@ impl str { /// so only the first cased letter in the whole string gets uppercased: /// /// ``` - /// #![feature(titlecase)] + /// #![feature(word_to_titlecase)] /// let blazingly_fast = "ferris and I"; /// /// assert_eq!("Ferris and i", blazingly_fast.word_to_titlecase()); @@ -561,7 +561,7 @@ impl str { /// Tricky examples, with sigma: /// /// ``` - /// #![feature(titlecase)] + /// #![feature(word_to_titlecase)] /// let odysseus = "ὈΔΥΣΣΕΎΣ"; /// /// assert_eq!("Ὀδυσσεύς", odysseus.word_to_titlecase()); @@ -574,7 +574,7 @@ impl str { #[rustc_allow_incoherent_impl] #[must_use = "this returns the titlecase word as a new String, \ without modifying the original"] - #[unstable(feature = "titlecase", issue = "153892")] + #[unstable(feature = "word_to_titlecase", issue = "166361")] pub fn word_to_titlecase(&self) -> String { let mut s = String::with_capacity(self.len()); let mut chars = self.char_indices(); diff --git a/library/alloctests/tests/lib.rs b/library/alloctests/tests/lib.rs index 46970a45be8f0..2b65f6cff1f54 100644 --- a/library/alloctests/tests/lib.rs +++ b/library/alloctests/tests/lib.rs @@ -52,7 +52,6 @@ #![feature(string_replace_in_place)] #![feature(test)] #![feature(thin_box)] -#![feature(titlecase)] #![feature(trusted_len)] #![feature(try_reserve_kind)] #![feature(try_with_capacity)] @@ -60,6 +59,7 @@ #![feature(unique_rc_arc)] #![feature(vec_deque_retain_range)] #![feature(vec_peek_mut)] +#![feature(word_to_titlecase)] #![feature(write_all_vectored)] // tidy-alphabetical-end diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 137e2e2d767b2..c7e3dfbda5b77 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -818,13 +818,12 @@ impl char { /// Basic usage: /// /// ``` - /// #![feature(titlecase)] /// assert!('A'.is_cased()); /// assert!('a'.is_cased()); /// assert!(!'京'.is_cased()); /// ``` #[must_use] - #[unstable(feature = "titlecase", issue = "153892")] + #[stable(feature = "cased", since = "CURRENT_RUSTC_VERSION")] #[inline] pub fn is_cased(self) -> bool { match self { @@ -843,7 +842,7 @@ impl char { /// # Examples /// /// ``` - /// #![feature(titlecase)] + /// #![feature(char_case)] /// use core::char::CharCase; /// assert_eq!('a'.case(), Some(CharCase::Lower)); /// assert_eq!('δ'.case(), Some(CharCase::Lower)); @@ -853,7 +852,7 @@ impl char { /// assert_eq!('中'.case(), None); /// ``` #[must_use] - #[unstable(feature = "titlecase", issue = "153892")] + #[unstable(feature = "char_case", issue = "166360")] #[inline] pub fn case(self) -> Option { match self { @@ -925,7 +924,6 @@ impl char { /// Basic usage: /// /// ``` - /// #![feature(titlecase)] /// assert!('Dž'.is_titlecase()); /// assert!('ῼ'.is_titlecase()); /// assert!(!'D'.is_titlecase()); @@ -934,7 +932,7 @@ impl char { /// assert!(!' '.is_titlecase()); /// ``` #[must_use] - #[unstable(feature = "titlecase", issue = "153892")] + #[stable(feature = "titlecase", since = "CURRENT_RUSTC_VERSION")] #[inline] pub fn is_titlecase(self) -> bool { match self { @@ -1368,9 +1366,24 @@ impl char { /// [specified]: https://www.unicode.org/reports/tr44/#Case_Ignorable /// [`DerivedCoreProperties.txt`]: https://www.unicode.org/Public/UCD/latest/ucd/DerivedCoreProperties.txt /// [`to_lowercase()`]: Self::to_lowercase() + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// assert!('.'.is_case_ignorable()); + /// assert!('\u{AD}'.is_case_ignorable()); // SOFT HYPHEN + /// assert!('ʰ'.is_case_ignorable()); // MODIFIER LETTER SMALL H + /// assert!('\u{0300}'.is_case_ignorable()); // COMBINING GRAVE ACCENT + /// assert!('\u{0345}'.is_case_ignorable()); // COMBINING GREEK YPOGEGRAMMENI + /// assert!(!'a'.is_case_ignorable()); + /// assert!(!' '.is_case_ignorable()); + /// assert!(!';'.is_case_ignorable()); + /// ``` #[must_use] #[inline] - #[unstable(feature = "case_ignorable", issue = "154848")] + #[stable(feature = "case_ignorable", since = "CURRENT_RUSTC_VERSION")] pub fn is_case_ignorable(self) -> bool { if self.is_ascii() { matches!(self, '\'' | '.' | ':' | '^' | '`') @@ -1536,7 +1549,6 @@ impl char { /// As an iterator: /// /// ``` - /// #![feature(titlecase)] /// for c in 'ß'.to_titlecase() { /// print!("{c}"); /// } @@ -1546,7 +1558,6 @@ impl char { /// Using `println!` directly: /// /// ``` - /// #![feature(titlecase)] /// println!("{}", 'ß'.to_titlecase()); /// ``` /// @@ -1559,7 +1570,6 @@ impl char { /// Using [`to_string`](../std/string/trait.ToString.html#tymethod.to_string): /// /// ``` - /// #![feature(titlecase)] /// assert_eq!('c'.to_titlecase().to_string(), "C"); /// assert_eq!('ა'.to_titlecase().to_string(), "ა"); /// assert_eq!('dž'.to_titlecase().to_string(), "Dž"); @@ -1589,7 +1599,6 @@ impl char { /// will return the mtavruli form, but `to_titlecase()` will return the mkhedruli form. /// /// ``` - /// #![feature(titlecase)] /// let ani = 'ა'; // First letter of the Georgian alphabet, in mkhedruli form /// /// // Titlecasing mkhedruli maps it to itself... @@ -1653,7 +1662,6 @@ impl char { /// Note that the lowercase dotted 'i' is the same codepoint as the Latin. Therefore: /// /// ``` - /// #![feature(titlecase)] /// let upper_i = 'i'.to_titlecase().to_string(); /// ``` /// @@ -1662,7 +1670,6 @@ impl char { /// be `"İ"`. `to_titlecase()` does not take this into account, and so: /// /// ``` - /// #![feature(titlecase)] /// let upper_i = 'i'.to_titlecase().to_string(); /// /// assert_eq!(upper_i, "I"); @@ -1673,7 +1680,7 @@ impl char { /// [`to_uppercase()`]: Self::to_uppercase() #[must_use = "this returns the titlecased character as a new iterator, \ without modifying the original"] - #[unstable(feature = "titlecase", issue = "153892")] + #[stable(feature = "titlecase", since = "CURRENT_RUSTC_VERSION")] #[inline] pub fn to_titlecase(self) -> ToTitlecase { ToTitlecase(CaseMappingIter::new(conversions::to_title(self))) diff --git a/library/core/src/char/mod.rs b/library/core/src/char/mod.rs index 28bd0929c1141..872161dca22e8 100644 --- a/library/core/src/char/mod.rs +++ b/library/core/src/char/mod.rs @@ -490,11 +490,11 @@ casemappingiter_impls! { } casemappingiter_impls! { - #[unstable(feature = "titlecase", issue = "153892")] - #[unstable(feature = "titlecase", issue = "153892")] - #[unstable(feature = "titlecase", issue = "153892")] - #[unstable(feature = "titlecase", issue = "153892")] - #[unstable(feature = "titlecase", issue = "153892")] + #[stable(feature = "titlecase", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "titlecase", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "titlecase", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "titlecase", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "titlecase", since = "CURRENT_RUSTC_VERSION")] /// Returns an iterator that yields the titlecase equivalent of a `char`. /// /// This `struct` is created by the [`to_titlecase`] method on [`char`]. See @@ -664,7 +664,7 @@ impl Error for TryFromCharError {} /// the most significant bit represents whether the case /// conceptually starts as uppercase, while the least significant bit /// represents whether it conceptually ends as uppercase. -#[unstable(feature = "titlecase", issue = "153892")] +#[unstable(feature = "char_case", issue = "166360")] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum CharCase { /// Lowercase. Corresponds to the `Lowercase` Unicode property. diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index 224f316fcbc8f..84a56da00a044 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -16,6 +16,7 @@ #![feature(casefold)] #![feature(cfg_overflow_checks)] #![feature(cfg_target_has_reliable_f16_f128)] +#![feature(char_case)] #![feature(char_internals)] #![feature(char_is_xid)] #![feature(clamp_magnitude)] @@ -124,7 +125,6 @@ #![feature(step_trait)] #![feature(str_internals)] #![feature(strict_provenance_lints)] -#![feature(titlecase)] #![feature(trusted_len)] #![feature(trusted_random_access)] #![feature(try_blocks)] diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 4eb3796ac026d..9703d41009f9c 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -1344,23 +1344,26 @@ impl PathBuf { let buf = self.inner.as_encoded_bytes(); let mut need_sep = buf.last().map(|c| !is_sep_byte(*c)).unwrap_or(false); - // in the special case of `C:` on Windows, do *not* add a separator - let comps = self.components(); + let self_comps = self.components(); + let self_prefix_len = self_comps.prefix_len(); - if comps.prefix_len() > 0 - && comps.prefix_len() == comps.path.len() - && comps.prefix.unwrap().is_drive() + // in the special case of `C:` on Windows, do *not* add a separator + if self_prefix_len > 0 + && self_prefix_len == self_comps.path.len() + && self_comps.prefix.unwrap().is_drive() { need_sep = false } - let need_clear = if cfg!(target_os = "cygwin") { - // If path is absolute and its prefix is none, it is like `/foo`, - // and will be handled below. - path.prefix().is_some() + let path_comps = path.components(); + + let need_clear = if cfg!(any(target_os = "windows", target_os = "cygwin")) { + // Windows/Cygwin: If path is absolute and its prefix is none, it is like `\foo` + // (Windows) or `/foo` (Cygwin), and will be handled below. + path_comps.prefix.is_some() } else { // On Unix: prefix is always None. - path.is_absolute() || path.prefix().is_some() + path.is_absolute() || path_comps.prefix.is_some() }; // absolute `path` replaces `self` @@ -1368,9 +1371,9 @@ impl PathBuf { self.inner.clear(); // verbatim paths need . and .. removed - } else if comps.prefix_verbatim() && !path.inner.is_empty() { - let mut buf: Vec<_> = comps.collect(); - for c in path.components() { + } else if self_comps.prefix_verbatim() && !path.inner.is_empty() { + let mut buf: Vec<_> = self_comps.collect(); + for c in path_comps { match c { Component::RootDir => { buf.truncate(1); @@ -1394,23 +1397,15 @@ impl PathBuf { res.push(MAIN_SEPARATOR_STR); } res.push(c.as_os_str()); - - need_sep = match c { - Component::RootDir => false, - Component::Prefix(prefix) => { - !prefix.parsed.is_drive() && prefix.parsed.len() > 0 - } - _ => true, - } + need_sep = c != Component::RootDir; } self.inner = res; return; // `path` has a root but no prefix, e.g., `\windows` (Windows only) - } else if path.has_root() { - let prefix_len = self.components().prefix_remaining(); - self.inner.truncate(prefix_len); + } else if path_comps.has_root() { + self.inner.truncate(self_prefix_len); // `path` is a pure relative path } else if need_sep { @@ -2575,6 +2570,7 @@ impl Path { !self.is_absolute() } + #[cfg(not(target_os = "uefi"))] pub(crate) fn prefix(&self) -> Option> { self.components().prefix }