File tree 4 files changed +53
-7
lines changed
compiler/rustc_middle/src/ty
src/doc/unstable-book/src/language-features
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
445
445
Oliver Scherer <oli-obk@users.noreply.github.com> <oliver.schneider@kit.edu>
446
446
Oliver Scherer <oli-obk@users.noreply.github.com> <obk8176014uqher834@olio-obk.de>
447
447
Oliver Scherer <oli-obk@users.noreply.github.com>
448
+ Onur Özkan <onurozkan.dev@outlook.com> <work@onurozkan.dev>
449
+ Onur Özkan <onurozkan.dev@outlook.com>
448
450
Ömer Sinan Ağacan <omeragacan@gmail.com>
449
451
Ophir LOJKINE <pere.jobs@gmail.com>
450
452
Ož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> {
2848
2848
/// Returning true means the type is known to be pure and `Copy+Clone`.
2849
2849
/// Returning `false` means nothing -- could be `Copy`, might not be.
2850
2850
///
2851
- /// This is mostly useful for optimizations, as there are the types
2851
+ /// This is mostly useful for optimizations, as these are the types
2852
2852
/// on which we can replace cloning with dereferencing.
2853
2853
pub fn is_trivially_pure_clone_copy ( self ) -> bool {
2854
2854
match self . kind ( ) {
Original file line number Diff line number Diff line change @@ -618,12 +618,11 @@ pub trait TryInto<T>: Sized {
618
618
/// For example, there is no way to convert an [`i64`] into an [`i32`]
619
619
/// using the [`From`] trait, because an [`i64`] may contain a value
620
620
/// 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.
627
626
///
628
627
/// # Generic Implementations
629
628
///
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