From e15e9a673e6770ae35d2d738aaaff304db9e5616 Mon Sep 17 00:00:00 2001 From: tae-soo-kim <117524309+tae-soo-kim@users.noreply.github.com> Date: Tue, 10 Oct 2023 07:05:25 +0000 Subject: [PATCH 1/4] Update mod.rs --- library/core/src/convert/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index fc8d19d1a58e2..9407c1609c27f 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -618,12 +618,11 @@ pub trait TryInto: Sized { /// For example, there is no way to convert an [`i64`] into an [`i32`] /// using the [`From`] trait, because an [`i64`] may contain a value /// that an [`i32`] cannot represent and so the conversion would lose data. -/// This might be handled by truncating the [`i64`] to an [`i32`] (essentially -/// giving the [`i64`]'s value modulo [`i32::MAX`]) or by simply returning -/// [`i32::MAX`], or by some other method. The [`From`] trait is intended -/// for perfect conversions, so the `TryFrom` trait informs the -/// programmer when a type conversion could go bad and lets them -/// decide how to handle it. +/// This might be handled by truncating the [`i64`] to an [`i32`] or by +/// simply returning [`i32::MAX`], or by some other method. The [`From`] +/// trait is intended for perfect conversions, so the `TryFrom` trait +/// informs the programmer when a type conversion could go bad and lets +/// them decide how to handle it. /// /// # Generic Implementations /// From 318813def9fbc6ec75a4017d840e169a2bf5df0f Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:41:00 +0200 Subject: [PATCH 2/4] Document `string_deref_patterns` feature --- .../string-deref-patterns.md | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/doc/unstable-book/src/language-features/string-deref-patterns.md diff --git a/src/doc/unstable-book/src/language-features/string-deref-patterns.md b/src/doc/unstable-book/src/language-features/string-deref-patterns.md new file mode 100644 index 0000000000000..3723830751e80 --- /dev/null +++ b/src/doc/unstable-book/src/language-features/string-deref-patterns.md @@ -0,0 +1,45 @@ +# `string_deref_patterns` + +The tracking issue for this feature is: [#87121] + +[#87121]: https://github.com/rust-lang/rust/issues/87121 + +------------------------ + +This feature permits pattern matching `String` to `&str` through [its `Deref` implementation]. + +```rust +#![feature(string_deref_patterns)] + +pub enum Value { + String(String), + Number(u32), +} + +pub fn is_it_the_answer(value: Value) -> bool { + match value { + Value::String("42") => true, + Value::Number(42) => true, + _ => false, + } +} +``` + +Without this feature other constructs such as match guards have to be used. + +```rust +# pub enum Value { +# String(String), +# Number(u32), +# } +# +pub fn is_it_the_answer(value: Value) -> bool { + match value { + Value::String(s) if s == "42" => true, + Value::Number(42) => true, + _ => false, + } +} +``` + +[its `Deref` implementation]: https://doc.rust-lang.org/std/string/struct.String.html#impl-Deref-for-String From 5e572c720716a8348020b4399143abd149c2fd84 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 14 Oct 2023 15:22:41 -0700 Subject: [PATCH 3/4] Fix a spot I wrote the wrong word --- compiler/rustc_middle/src/ty/sty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index e5f418bbb4b11..5ecc66b11f3eb 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -2848,7 +2848,7 @@ impl<'tcx> Ty<'tcx> { /// Returning true means the type is known to be pure and `Copy+Clone`. /// Returning `false` means nothing -- could be `Copy`, might not be. /// - /// This is mostly useful for optimizations, as there are the types + /// This is mostly useful for optimizations, as these are the types /// on which we can replace cloning with dereferencing. pub fn is_trivially_pure_clone_copy(self) -> bool { match self.kind() { From 97b7b847be384be0f8900222e86175a7deb01834 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sun, 15 Oct 2023 09:24:09 +0300 Subject: [PATCH 4/4] =?UTF-8?q?add=20'Onur=20=C3=96zkan'=20to=20.mailmap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: onur-ozkan --- .mailmap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.mailmap b/.mailmap index 26d6be9f0c600..dea660a8fe98b 100644 --- a/.mailmap +++ b/.mailmap @@ -445,6 +445,8 @@ Oliver Scherer Oliver Scherer Oliver Scherer +Onur Özkan +Onur Özkan Ömer Sinan Ağacan Ophir LOJKINE Ožbolt Menegatti gareins