Skip to content

Commit 20fc02f

Browse files
committed
Auto merge of #71356 - Dylan-DPC:rollup-liockhk, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #71250 (Replace big JS dict with JSON parsing) - #71270 (Fix `has_no_input_arg` check and rename it to `has_only_self_parameter`) - #71284 (fix -Zast-json to output correct JSON form) - #71328 (Stabilize PathBuf capacity methods) - #71334 (Update pattern docs.) Failed merges: r? @ghost
2 parents 8ce3f84 + b921587 commit 20fc02f

File tree

11 files changed

+223
-60
lines changed

11 files changed

+223
-60
lines changed

src/libcore/str/mod.rs

+115-36
Original file line numberDiff line numberDiff line change
@@ -3010,6 +3010,12 @@ impl str {
30103010
///
30113011
/// Returns `false` if it does not.
30123012
///
3013+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3014+
/// function or closure that determines if a character matches.
3015+
///
3016+
/// [`char`]: primitive.char.html
3017+
/// [pattern]: str/pattern/index.html
3018+
///
30133019
/// # Examples
30143020
///
30153021
/// Basic usage:
@@ -3031,6 +3037,12 @@ impl str {
30313037
///
30323038
/// Returns `false` if it does not.
30333039
///
3040+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3041+
/// function or closure that determines if a character matches.
3042+
///
3043+
/// [`char`]: primitive.char.html
3044+
/// [pattern]: str/pattern/index.html
3045+
///
30343046
/// # Examples
30353047
///
30363048
/// Basic usage:
@@ -3051,6 +3063,12 @@ impl str {
30513063
///
30523064
/// Returns `false` if it does not.
30533065
///
3066+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3067+
/// function or closure that determines if a character matches.
3068+
///
3069+
/// [`char`]: primitive.char.html
3070+
/// [pattern]: str/pattern/index.html
3071+
///
30543072
/// # Examples
30553073
///
30563074
/// Basic usage:
@@ -3074,10 +3092,12 @@ impl str {
30743092
///
30753093
/// Returns [`None`] if the pattern doesn't match.
30763094
///
3077-
/// The pattern can be a `&str`, [`char`], or a closure that determines if
3078-
/// a character matches.
3095+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3096+
/// function or closure that determines if a character matches.
30793097
///
30803098
/// [`None`]: option/enum.Option.html#variant.None
3099+
/// [`char`]: primitive.char.html
3100+
/// [pattern]: str/pattern/index.html
30813101
///
30823102
/// # Examples
30833103
///
@@ -3121,10 +3141,12 @@ impl str {
31213141
///
31223142
/// Returns [`None`] if the pattern doesn't match.
31233143
///
3124-
/// The pattern can be a `&str`, [`char`], or a closure that determines if
3125-
/// a character matches.
3144+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3145+
/// function or closure that determines if a character matches.
31263146
///
31273147
/// [`None`]: option/enum.Option.html#variant.None
3148+
/// [`char`]: primitive.char.html
3149+
/// [pattern]: str/pattern/index.html
31283150
///
31293151
/// # Examples
31303152
///
@@ -3166,8 +3188,11 @@ impl str {
31663188
/// An iterator over substrings of this string slice, separated by
31673189
/// characters matched by a pattern.
31683190
///
3169-
/// The pattern can be any type that implements the Pattern trait. Notable
3170-
/// examples are `&str`, [`char`], and closures that determines the split.
3191+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3192+
/// function or closure that determines if a character matches.
3193+
///
3194+
/// [`char`]: primitive.char.html
3195+
/// [pattern]: str/pattern/index.html
31713196
///
31723197
/// # Iterator behavior
31733198
///
@@ -3285,6 +3310,12 @@ impl str {
32853310
/// `split` in that `split_inclusive` leaves the matched part as the
32863311
/// terminator of the substring.
32873312
///
3313+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3314+
/// function or closure that determines if a character matches.
3315+
///
3316+
/// [`char`]: primitive.char.html
3317+
/// [pattern]: str/pattern/index.html
3318+
///
32883319
/// # Examples
32893320
///
32903321
/// ```
@@ -3319,8 +3350,11 @@ impl str {
33193350
/// An iterator over substrings of the given string slice, separated by
33203351
/// characters matched by a pattern and yielded in reverse order.
33213352
///
3322-
/// The pattern can be any type that implements the Pattern trait. Notable
3323-
/// examples are `&str`, [`char`], and closures that determines the split.
3353+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3354+
/// function or closure that determines if a character matches.
3355+
///
3356+
/// [`char`]: primitive.char.html
3357+
/// [pattern]: str/pattern/index.html
33243358
///
33253359
/// # Iterator behavior
33263360
///
@@ -3370,8 +3404,11 @@ impl str {
33703404
/// An iterator over substrings of the given string slice, separated by
33713405
/// characters matched by a pattern.
33723406
///
3373-
/// The pattern can be any type that implements the Pattern trait. Notable
3374-
/// examples are `&str`, [`char`], and closures that determines the split.
3407+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3408+
/// function or closure that determines if a character matches.
3409+
///
3410+
/// [`char`]: primitive.char.html
3411+
/// [pattern]: str/pattern/index.html
33753412
///
33763413
/// Equivalent to [`split`], except that the trailing substring
33773414
/// is skipped if empty.
@@ -3414,10 +3451,11 @@ impl str {
34143451
/// An iterator over substrings of `self`, separated by characters
34153452
/// matched by a pattern and yielded in reverse order.
34163453
///
3417-
/// The pattern can be any type that implements the Pattern trait. Notable
3418-
/// examples are `&str`, [`char`], and closures that determines the split.
3419-
/// Additional libraries might provide more complex patterns like
3420-
/// regular expressions.
3454+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3455+
/// function or closure that determines if a character matches.
3456+
///
3457+
/// [`char`]: primitive.char.html
3458+
/// [pattern]: str/pattern/index.html
34213459
///
34223460
/// Equivalent to [`split`], except that the trailing substring is
34233461
/// skipped if empty.
@@ -3462,8 +3500,11 @@ impl str {
34623500
/// If `n` substrings are returned, the last substring (the `n`th substring)
34633501
/// will contain the remainder of the string.
34643502
///
3465-
/// The pattern can be any type that implements the Pattern trait. Notable
3466-
/// examples are `&str`, [`char`], and closures that determines the split.
3503+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3504+
/// function or closure that determines if a character matches.
3505+
///
3506+
/// [`char`]: primitive.char.html
3507+
/// [pattern]: str/pattern/index.html
34673508
///
34683509
/// # Iterator behavior
34693510
///
@@ -3512,8 +3553,11 @@ impl str {
35123553
/// If `n` substrings are returned, the last substring (the `n`th substring)
35133554
/// will contain the remainder of the string.
35143555
///
3515-
/// The pattern can be any type that implements the Pattern trait. Notable
3516-
/// examples are `&str`, [`char`], and closures that determines the split.
3556+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3557+
/// function or closure that determines if a character matches.
3558+
///
3559+
/// [`char`]: primitive.char.html
3560+
/// [pattern]: str/pattern/index.html
35173561
///
35183562
/// # Iterator behavior
35193563
///
@@ -3557,8 +3601,11 @@ impl str {
35573601
/// An iterator over the disjoint matches of a pattern within the given string
35583602
/// slice.
35593603
///
3560-
/// The pattern can be a `&str`, [`char`], or a closure that determines if
3561-
/// a character matches.
3604+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3605+
/// function or closure that determines if a character matches.
3606+
///
3607+
/// [`char`]: primitive.char.html
3608+
/// [pattern]: str/pattern/index.html
35623609
///
35633610
/// # Iterator behavior
35643611
///
@@ -3593,8 +3640,11 @@ impl str {
35933640
/// An iterator over the disjoint matches of a pattern within this string slice,
35943641
/// yielded in reverse order.
35953642
///
3596-
/// The pattern can be a `&str`, [`char`], or a closure that determines if
3597-
/// a character matches.
3643+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3644+
/// function or closure that determines if a character matches.
3645+
///
3646+
/// [`char`]: primitive.char.html
3647+
/// [pattern]: str/pattern/index.html
35983648
///
35993649
/// # Iterator behavior
36003650
///
@@ -3634,8 +3684,11 @@ impl str {
36343684
/// For matches of `pat` within `self` that overlap, only the indices
36353685
/// corresponding to the first match are returned.
36363686
///
3637-
/// The pattern can be a `&str`, [`char`], or a closure that determines
3638-
/// if a character matches.
3687+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3688+
/// function or closure that determines if a character matches.
3689+
///
3690+
/// [`char`]: primitive.char.html
3691+
/// [pattern]: str/pattern/index.html
36393692
///
36403693
/// # Iterator behavior
36413694
///
@@ -3676,8 +3729,11 @@ impl str {
36763729
/// For matches of `pat` within `self` that overlap, only the indices
36773730
/// corresponding to the last match are returned.
36783731
///
3679-
/// The pattern can be a `&str`, [`char`], or a closure that determines if a
3680-
/// character matches.
3732+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
3733+
/// function or closure that determines if a character matches.
3734+
///
3735+
/// [`char`]: primitive.char.html
3736+
/// [pattern]: str/pattern/index.html
36813737
///
36823738
/// # Iterator behavior
36833739
///
@@ -3894,8 +3950,11 @@ impl str {
38943950
/// Returns a string slice with all prefixes and suffixes that match a
38953951
/// pattern repeatedly removed.
38963952
///
3897-
/// The pattern can be a [`char`] or a closure that determines if a
3898-
/// character matches.
3953+
/// The [pattern] can be a [`char`], a slice of [`char`]s, or a function
3954+
/// or closure that determines if a character matches.
3955+
///
3956+
/// [`char`]: primitive.char.html
3957+
/// [pattern]: str/pattern/index.html
38993958
///
39003959
/// # Examples
39013960
///
@@ -3939,8 +3998,11 @@ impl str {
39393998
/// Returns a string slice with all prefixes that match a pattern
39403999
/// repeatedly removed.
39414000
///
3942-
/// The pattern can be a `&str`, [`char`], or a closure that determines if
3943-
/// a character matches.
4001+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
4002+
/// function or closure that determines if a character matches.
4003+
///
4004+
/// [`char`]: primitive.char.html
4005+
/// [pattern]: str/pattern/index.html
39444006
///
39454007
/// # Text directionality
39464008
///
@@ -3981,6 +4043,12 @@ impl str {
39814043
///
39824044
/// If the string does not start with `prefix`, `None` is returned.
39834045
///
4046+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
4047+
/// function or closure that determines if a character matches.
4048+
///
4049+
/// [`char`]: primitive.char.html
4050+
/// [pattern]: str/pattern/index.html
4051+
///
39844052
/// # Examples
39854053
///
39864054
/// ```
@@ -4005,6 +4073,12 @@ impl str {
40054073
///
40064074
/// If the string does not end with `suffix`, `None` is returned.
40074075
///
4076+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
4077+
/// function or closure that determines if a character matches.
4078+
///
4079+
/// [`char`]: primitive.char.html
4080+
/// [pattern]: str/pattern/index.html
4081+
///
40084082
/// # Examples
40094083
///
40104084
/// ```
@@ -4027,8 +4101,11 @@ impl str {
40274101
/// Returns a string slice with all suffixes that match a pattern
40284102
/// repeatedly removed.
40294103
///
4030-
/// The pattern can be a `&str`, [`char`], or a closure that
4031-
/// determines if a character matches.
4104+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
4105+
/// function or closure that determines if a character matches.
4106+
///
4107+
/// [`char`]: primitive.char.html
4108+
/// [pattern]: str/pattern/index.html
40324109
///
40334110
/// # Text directionality
40344111
///
@@ -4073,10 +4150,11 @@ impl str {
40734150
/// Returns a string slice with all prefixes that match a pattern
40744151
/// repeatedly removed.
40754152
///
4076-
/// The pattern can be a `&str`, [`char`], or a closure that determines if
4077-
/// a character matches.
4153+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
4154+
/// function or closure that determines if a character matches.
40784155
///
40794156
/// [`char`]: primitive.char.html
4157+
/// [pattern]: str/pattern/index.html
40804158
///
40814159
/// # Text directionality
40824160
///
@@ -4109,10 +4187,11 @@ impl str {
41094187
/// Returns a string slice with all suffixes that match a pattern
41104188
/// repeatedly removed.
41114189
///
4112-
/// The pattern can be a `&str`, [`char`], or a closure that
4113-
/// determines if a character matches.
4190+
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
4191+
/// function or closure that determines if a character matches.
41144192
///
41154193
/// [`char`]: primitive.char.html
4194+
/// [pattern]: str/pattern/index.html
41164195
///
41174196
/// # Text directionality
41184197
///

src/libcore/str/pattern.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
11
//! The string Pattern API.
22
//!
3+
//! The Pattern API provides a generic mechanism for using different pattern
4+
//! types when searching through a string.
5+
//!
36
//! For more details, see the traits [`Pattern`], [`Searcher`],
47
//! [`ReverseSearcher`], and [`DoubleEndedSearcher`].
8+
//!
9+
//! Although this API is unstable, it is exposed via stable APIs on the
10+
//! [`str`] type.
11+
//!
12+
//! # Examples
13+
//!
14+
//! [`Pattern`] is [implemented][pattern-impls] in the stable API for
15+
//! [`&str`], [`char`], slices of [`char`], and functions and closures
16+
//! implementing `FnMut(char) -> bool`.
17+
//!
18+
//! ```
19+
//! let s = "Can you find a needle in a haystack?";
20+
//!
21+
//! // &str pattern
22+
//! assert_eq!(s.find("you"), Some(4));
23+
//! // char pattern
24+
//! assert_eq!(s.find('n'), Some(2));
25+
//! // slice of chars pattern
26+
//! assert_eq!(s.find(&['a', 'e', 'i', 'o', 'u'][..]), Some(1));
27+
//! // closure pattern
28+
//! assert_eq!(s.find(|c: char| c.is_ascii_punctuation()), Some(35));
29+
//! ```
30+
//!
31+
//! [`&str`]: ../../../std/primitive.str.html
32+
//! [`char`]: ../../../std/primitive.char.html
33+
//! [`str`]: ../../../std/primitive.str.html
34+
//! [`DoubleEndedSearcher`]: trait.DoubleEndedSearcher.html
35+
//! [`Pattern`]: trait.Pattern.html
36+
//! [`ReverseSearcher`]: trait.ReverseSearcher.html
37+
//! [`Searcher`]: trait.Searcher.html
38+
//! [pattern-impls]: trait.Pattern.html#implementors
539
640
#![unstable(
741
feature = "pattern",
@@ -702,7 +736,7 @@ unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> {
702736

703737
impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {}
704738

705-
/// Searches for chars that are equal to any of the chars in the array.
739+
/// Searches for chars that are equal to any of the chars in the slice.
706740
///
707741
/// # Examples
708742
///

src/librustc_ast/ast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2211,14 +2211,14 @@ rustc_index::newtype_index! {
22112211
}
22122212

22132213
impl rustc_serialize::Encodable for AttrId {
2214-
fn encode<S: Encoder>(&self, _: &mut S) -> Result<(), S::Error> {
2215-
Ok(())
2214+
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
2215+
s.emit_unit()
22162216
}
22172217
}
22182218

22192219
impl rustc_serialize::Decodable for AttrId {
2220-
fn decode<D: Decoder>(_: &mut D) -> Result<AttrId, D::Error> {
2221-
Ok(crate::attr::mk_attr_id())
2220+
fn decode<D: Decoder>(d: &mut D) -> Result<AttrId, D::Error> {
2221+
d.read_nil().map(|_| crate::attr::mk_attr_id())
22222222
}
22232223
}
22242224

0 commit comments

Comments
 (0)