Skip to content

Commit 0b2c356

Browse files
authored
Auto merge of #37090 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 9 pull requests - Successful merges: #36679, #36699, #36997, #37040, #37060, #37065, #37072, #37073, #37081 - Failed merges:
2 parents 304d0c8 + 30164c2 commit 0b2c356

File tree

16 files changed

+839
-241
lines changed

16 files changed

+839
-241
lines changed

src/doc/book/lifetimes.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ To fix this, we have to make sure that step four never happens after step
5656
three. The ownership system in Rust does this through a concept called
5757
lifetimes, which describe the scope that a reference is valid for.
5858

59-
When we have a function that takes an argument by reference, we can be
60-
implicit or explicit about the lifetime of the reference:
59+
**Note** It's important to understand that lifetime annotations are
60+
_descriptive_, not _prescriptive_. This means that how long a reference is valid
61+
is determined by the code, not by the annotations. The annotations, however,
62+
give information about lifetimes to the compiler that uses them to check the
63+
validity of references. The compiler can do so without annotations in simple
64+
cases, but needs the programmers support in complex scenarios.
6165

6266
```rust
6367
// implicit

src/libcollections/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@
327327
//! format := '{' [ argument ] [ ':' format_spec ] '}'
328328
//! argument := integer | identifier
329329
//!
330-
//! format_spec := [[fill]align][sign]['#'][0][width]['.' precision][type]
330+
//! format_spec := [[fill]align][sign]['#']['0'][width]['.' precision][type]
331331
//! fill := character
332332
//! align := '<' | '^' | '>'
333333
//! sign := '+' | '-'

src/libcollections/str.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1789,4 +1789,24 @@ impl str {
17891789
String::from_utf8_unchecked(slice.into_vec())
17901790
}
17911791
}
1792+
1793+
/// Create a [`String`] by repeating a string `n` times.
1794+
///
1795+
/// [`String`]: string/struct.String.html
1796+
///
1797+
/// # Examples
1798+
///
1799+
/// Basic usage:
1800+
///
1801+
/// ```
1802+
/// #![feature(repeat_str)]
1803+
///
1804+
/// assert_eq!("abc".repeat(4), String::from("abcabcabcabc"));
1805+
/// ```
1806+
#[unstable(feature = "repeat_str", issue = "37079")]
1807+
pub fn repeat(&self, n: usize) -> String {
1808+
let mut s = String::with_capacity(self.len() * n);
1809+
s.extend((0..n).map(|_| self));
1810+
s
1811+
}
17921812
}

src/libcollections/string.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
//! [`ToString`]s, and several error types that may result from working with
1515
//! [`String`]s.
1616
//!
17-
//! [`String`]: struct.String.html
1817
//! [`ToString`]: trait.ToString.html
1918
//!
2019
//! # Examples
2120
//!
22-
//! There are multiple ways to create a new `String` from a string literal:
21+
//! There are multiple ways to create a new [`String`] from a string literal:
2322
//!
2423
//! ```
2524
//! let s = "Hello".to_string();
@@ -28,9 +27,11 @@
2827
//! let s: String = "also this".into();
2928
//! ```
3029
//!
31-
//! You can create a new `String` from an existing one by concatenating with
30+
//! You can create a new [`String`] from an existing one by concatenating with
3231
//! `+`:
3332
//!
33+
//! [`String`]: struct.String.html
34+
//!
3435
//! ```
3536
//! let s = "Hello".to_string();
3637
//!

src/libcollectionstest/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#![feature(enumset)]
2020
#![feature(pattern)]
2121
#![feature(rand)]
22+
#![feature(repeat_str)]
2223
#![feature(step_by)]
2324
#![feature(str_escape)]
2425
#![feature(str_replacen)]

src/libcollectionstest/str.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,13 @@ fn test_cow_from() {
12861286
}
12871287
}
12881288

1289+
#[test]
1290+
fn test_repeat() {
1291+
assert_eq!("".repeat(3), "");
1292+
assert_eq!("abc".repeat(0), "");
1293+
assert_eq!("α".repeat(3), "ααα");
1294+
}
1295+
12891296
mod pattern {
12901297
use std::str::pattern::Pattern;
12911298
use std::str::pattern::{Searcher, ReverseSearcher};

src/librustc_const_eval/check_match.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1238,8 +1238,10 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> {
12381238
match pat.node {
12391239
PatKind::Binding(.., ref subpat) => {
12401240
if !self.bindings_allowed {
1241-
span_err!(self.cx.tcx.sess, pat.span, E0303,
1242-
"pattern bindings are not allowed after an `@`");
1241+
struct_span_err!(self.cx.tcx.sess, pat.span, E0303,
1242+
"pattern bindings are not allowed after an `@`")
1243+
.span_label(pat.span, &format!("not allowed after `@`"))
1244+
.emit();
12431245
}
12441246

12451247
if subpat.is_some() {

0 commit comments

Comments
 (0)