Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 18 additions & 13 deletions compiler/rustc_mir_transform/src/check_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. }
Expand All @@ -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(
Expand Down Expand Up @@ -240,17 +238,21 @@ impl<'a, 'tcx> Visitor<'tcx> for EnumFinder<'a, 'tcx> {
fn split_block(
basic_blocks: &mut IndexVec<BasicBlock, BasicBlockData<'_>>,
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.
Expand Down Expand Up @@ -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<Local, LocalDecl<'tcx>>,
Expand Down Expand Up @@ -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<Local, LocalDecl<'tcx>>,
Expand Down Expand Up @@ -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<Local, LocalDecl<'tcx>>,
Expand Down
2 changes: 0 additions & 2 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -175,7 +174,6 @@
#![feature(slice_range)]
#![feature(std_internals)]
#![feature(temporary_niche_types)]
#![feature(titlecase)]
#![feature(transmutability)]
#![feature(trivial_clone)]
#![feature(trusted_fused)]
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/rcs/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
}

/// 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
///
Expand Down Expand Up @@ -3522,9 +3522,9 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
}
}

/// 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
///
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/rcs/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
#[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
///
Expand Down Expand Up @@ -3773,9 +3773,9 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
}
}

/// 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
///
Expand Down
14 changes: 7 additions & 7 deletions library/alloc/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -561,7 +561,7 @@ impl str {
/// Tricky examples, with sigma:
///
/// ```
/// #![feature(titlecase)]
/// #![feature(word_to_titlecase)]
/// let odysseus = "ὈΔΥΣΣΕΎΣ";
///
/// assert_eq!("Ὀδυσσεύς", odysseus.word_to_titlecase());
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion library/alloctests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@
#![feature(string_replace_in_place)]
#![feature(test)]
#![feature(thin_box)]
#![feature(titlecase)]
#![feature(trusted_len)]
#![feature(try_reserve_kind)]
#![feature(try_with_capacity)]
#![feature(unboxed_closures)]
#![feature(unique_rc_arc)]
#![feature(vec_deque_retain_range)]
#![feature(vec_peek_mut)]
#![feature(word_to_titlecase)]
#![feature(write_all_vectored)]
// tidy-alphabetical-end

Expand Down
35 changes: 21 additions & 14 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
Expand All @@ -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<CharCase> {
match self {
Expand Down Expand Up @@ -925,7 +924,6 @@ impl char {
/// Basic usage:
///
/// ```
/// #![feature(titlecase)]
/// assert!('Dž'.is_titlecase());
/// assert!('ῼ'.is_titlecase());
/// assert!(!'D'.is_titlecase());
Expand All @@ -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 {
Expand Down Expand Up @@ -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, '\'' | '.' | ':' | '^' | '`')
Expand Down Expand Up @@ -1536,7 +1549,6 @@ impl char {
/// As an iterator:
///
/// ```
/// #![feature(titlecase)]
/// for c in 'ß'.to_titlecase() {
/// print!("{c}");
/// }
Expand All @@ -1546,7 +1558,6 @@ impl char {
/// Using `println!` directly:
///
/// ```
/// #![feature(titlecase)]
/// println!("{}", 'ß'.to_titlecase());
/// ```
///
Expand All @@ -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ž");
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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();
/// ```
///
Expand All @@ -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");
Expand All @@ -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)))
Expand Down
12 changes: 6 additions & 6 deletions library/core/src/char/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Loading
Loading