Skip to content

Commit 4331c15

Browse files
committed
Auto merge of rust-lang#116757 - matthiaskrgr:rollup-3c25ogw, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#116594 (Fix `std::convert::TryFrom` doc) - rust-lang#116741 (Document `string_deref_patterns` feature) - rust-lang#116748 (Fix a spot I wrote the wrong word) - rust-lang#116753 (add 'Onur Özkan' to .mailmap) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ab73de7 + 2873977 commit 4331c15

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

.mailmap

+2
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ Oliver Scherer <[email protected]> <[email protected]
445445
446446
447447
Oliver Scherer <[email protected]>
448+
449+
Onur Özkan <[email protected]>
448450
Ömer Sinan Ağacan <[email protected]>
449451
Ophir LOJKINE <[email protected]>
450452
Ožbolt Menegatti <[email protected]> gareins <[email protected]>

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff 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() {

library/core/src/convert/mod.rs

+5-6
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

0 commit comments

Comments
 (0)