This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +53
-7
lines changed
compiler/rustc_middle/src/ty
src/doc/unstable-book/src/language-features Expand file tree Collapse file tree 4 files changed +53
-7
lines changed Original file line number Diff line number Diff line change @@ -445,6 +445,8 @@ Oliver Scherer <oli-obk@users.noreply.github.com> <public.oliver.schneider@kit.e
445445Oliver Scherer <oli-obk@users.noreply.github.com> <oliver.schneider@kit.edu>
446446Oliver Scherer <oli-obk@users.noreply.github.com> <obk8176014uqher834@olio-obk.de>
447447Oliver Scherer <oli-obk@users.noreply.github.com>
448+ Onur Özkan <onurozkan.dev@outlook.com> <work@onurozkan.dev>
449+ Onur Özkan <onurozkan.dev@outlook.com>
448450Ömer Sinan Ağacan <omeragacan@gmail.com>
449451Ophir LOJKINE <pere.jobs@gmail.com>
450452Ožbolt Menegatti <ozbolt.menegatti@gmail.com> gareins <ozbolt.menegatti@gmail.com>
Original file line number Diff line number Diff line change @@ -2848,7 +2848,7 @@ impl<'tcx> Ty<'tcx> {
28482848 /// Returning true means the type is known to be pure and `Copy+Clone`.
28492849 /// Returning `false` means nothing -- could be `Copy`, might not be.
28502850 ///
2851- /// This is mostly useful for optimizations, as there are the types
2851+ /// This is mostly useful for optimizations, as these are the types
28522852 /// on which we can replace cloning with dereferencing.
28532853 pub fn is_trivially_pure_clone_copy ( self ) -> bool {
28542854 match self . kind ( ) {
Original file line number Diff line number Diff line change @@ -618,12 +618,11 @@ pub trait TryInto<T>: Sized {
618618/// For example, there is no way to convert an [`i64`] into an [`i32`]
619619/// using the [`From`] trait, because an [`i64`] may contain a value
620620/// that an [`i32`] cannot represent and so the conversion would lose data.
621- /// This might be handled by truncating the [`i64`] to an [`i32`] (essentially
622- /// giving the [`i64`]'s value modulo [`i32::MAX`]) or by simply returning
623- /// [`i32::MAX`], or by some other method. The [`From`] trait is intended
624- /// for perfect conversions, so the `TryFrom` trait informs the
625- /// programmer when a type conversion could go bad and lets them
626- /// decide how to handle it.
621+ /// This might be handled by truncating the [`i64`] to an [`i32`] or by
622+ /// simply returning [`i32::MAX`], or by some other method. The [`From`]
623+ /// trait is intended for perfect conversions, so the `TryFrom` trait
624+ /// informs the programmer when a type conversion could go bad and lets
625+ /// them decide how to handle it.
627626///
628627/// # Generic Implementations
629628///
Original file line number Diff line number Diff line change 1+ # ` string_deref_patterns `
2+
3+ The tracking issue for this feature is: [ #87121 ]
4+
5+ [ #87121 ] : https://github.com/rust-lang/rust/issues/87121
6+
7+ ------------------------
8+
9+ This feature permits pattern matching ` String ` to ` &str ` through [ its ` Deref ` implementation] .
10+
11+ ``` rust
12+ #![feature(string_deref_patterns)]
13+
14+ pub enum Value {
15+ String (String ),
16+ Number (u32 ),
17+ }
18+
19+ pub fn is_it_the_answer (value : Value ) -> bool {
20+ match value {
21+ Value :: String (" 42" ) => true ,
22+ Value :: Number (42 ) => true ,
23+ _ => false ,
24+ }
25+ }
26+ ```
27+
28+ Without this feature other constructs such as match guards have to be used.
29+
30+ ``` rust
31+ # pub enum Value {
32+ # String (String ),
33+ # Number (u32 ),
34+ # }
35+ #
36+ pub fn is_it_the_answer (value : Value ) -> bool {
37+ match value {
38+ Value :: String (s ) if s == " 42" => true ,
39+ Value :: Number (42 ) => true ,
40+ _ => false ,
41+ }
42+ }
43+ ```
44+
45+ [ its `Deref` implementation ] : https://doc.rust-lang.org/std/string/struct.String.html#impl-Deref-for-String
You can’t perform that action at this time.
0 commit comments