Skip to content

Commit fb12219

Browse files
authored
Auto merge of #37896 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 8 pull requests - Successful merges: #37835, #37840, #37841, #37848, #37876, #37880, #37881, #37882 - Failed merges:
2 parents 8f8944e + b0354fe commit fb12219

File tree

13 files changed

+1183
-24
lines changed

13 files changed

+1183
-24
lines changed

Diff for: src/doc/book/lifetimes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ to it.
352352
Rust supports powerful local type inference in the bodies of functions but not in their item signatures.
353353
It's forbidden to allow reasoning about types based on the item signature alone.
354354
However, for ergonomic reasons, a very restricted secondary inference algorithm called
355-
“lifetime elision” does apply when judging lifetimes. Lifetime elision is concerned solely to infer
355+
“lifetime elision” does apply when judging lifetimes. Lifetime elision is concerned solely with inferring
356356
lifetime parameters using three easily memorizable and unambiguous rules. This means lifetime elision
357357
acts as a shorthand for writing an item signature, while not hiding
358358
away the actual types involved as full local inference would if applied to it.

Diff for: src/doc/reference.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -2474,18 +2474,19 @@ The currently implemented features of the reference compiler are:
24742474
internally without imposing on callers
24752475
(i.e. making them behave like function calls in
24762476
terms of encapsulation).
2477-
* - `default_type_parameter_fallback` - Allows type parameter defaults to
2478-
influence type inference.
24792477

2480-
* - `stmt_expr_attributes` - Allows attributes on expressions.
2478+
* `default_type_parameter_fallback` - Allows type parameter defaults to
2479+
influence type inference.
24812480

2482-
* - `type_ascription` - Allows type ascription expressions `expr: Type`.
2481+
* `stmt_expr_attributes` - Allows attributes on expressions.
24832482

2484-
* - `abi_vectorcall` - Allows the usage of the vectorcall calling convention
2485-
(e.g. `extern "vectorcall" func fn_();`)
2483+
* `type_ascription` - Allows type ascription expressions `expr: Type`.
24862484

2487-
* - `abi_sysv64` - Allows the usage of the system V AMD64 calling convention
2488-
(e.g. `extern "sysv64" func fn_();`)
2485+
* `abi_vectorcall` - Allows the usage of the vectorcall calling convention
2486+
(e.g. `extern "vectorcall" func fn_();`)
2487+
2488+
* `abi_sysv64` - Allows the usage of the system V AMD64 calling convention
2489+
(e.g. `extern "sysv64" func fn_();`)
24892490

24902491
If a feature is promoted to a language feature, then all existing programs will
24912492
start to receive compilation warnings about `#![feature]` directives which enabled

Diff for: src/libcollectionstest/str.rs

+16
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,14 @@ fn test_iterator_clone() {
814814
assert!(it.clone().zip(it).all(|(x,y)| x == y));
815815
}
816816

817+
#[test]
818+
fn test_iterator_last() {
819+
let s = "ศไทย中华Việt Nam";
820+
let mut it = s.chars();
821+
it.next();
822+
assert_eq!(it.last(), Some('m'));
823+
}
824+
817825
#[test]
818826
fn test_bytesator() {
819827
let s = "ศไทย中华Việt Nam";
@@ -911,6 +919,14 @@ fn test_char_indices_revator() {
911919
assert_eq!(pos, p.len());
912920
}
913921

922+
#[test]
923+
fn test_char_indices_last() {
924+
let s = "ศไทย中华Việt Nam";
925+
let mut it = s.char_indices();
926+
it.next();
927+
assert_eq!(it.last(), Some((27, 'm')));
928+
}
929+
914930
#[test]
915931
fn test_splitn_char_iterator() {
916932
let data = "\nMäry häd ä little lämb\nLittle lämb\n";

Diff for: src/libcore/str/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ impl<'a> Iterator for Chars<'a> {
432432
// `isize::MAX` (that's well below `usize::MAX`).
433433
((len + 3) / 4, Some(len))
434434
}
435+
436+
#[inline]
437+
fn last(mut self) -> Option<char> {
438+
// No need to go through the entire string.
439+
self.next_back()
440+
}
435441
}
436442

437443
#[stable(feature = "rust1", since = "1.0.0")]
@@ -505,6 +511,12 @@ impl<'a> Iterator for CharIndices<'a> {
505511
fn size_hint(&self) -> (usize, Option<usize>) {
506512
self.iter.size_hint()
507513
}
514+
515+
#[inline]
516+
fn last(mut self) -> Option<(usize, char)> {
517+
// No need to go through the entire string.
518+
self.next_back()
519+
}
508520
}
509521

510522
#[stable(feature = "rust1", since = "1.0.0")]

Diff for: src/librustc_data_structures/unify/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<'tcx, K, V> UnificationTable<K>
344344
}
345345

346346
pub fn probe(&mut self, a_id: K) -> Option<V> {
347-
self.get(a_id).value.clone()
347+
self.get(a_id).value
348348
}
349349

350350
pub fn unsolved_variables(&mut self) -> Vec<K> {

Diff for: src/librustc_typeck/check/mod.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -4436,19 +4436,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
44364436
let lifetime_defs = segment.map_or(&[][..], |(_, generics)| &generics.regions);
44374437
if lifetimes.len() > lifetime_defs.len() {
44384438
let span = lifetimes[lifetime_defs.len()].span;
4439-
span_err!(self.tcx.sess, span, E0088,
4440-
"too many lifetime parameters provided: \
4441-
expected {}, found {}",
4442-
count(lifetime_defs.len()),
4443-
count(lifetimes.len()));
4444-
} else if lifetimes.len() > 0 && lifetimes.len() < lifetime_defs.len() {
4445-
span_err!(self.tcx.sess, span, E0090,
4446-
"too few lifetime parameters provided: \
4447-
expected {}, found {}",
4448-
count(lifetime_defs.len()),
4449-
count(lifetimes.len()));
4439+
struct_span_err!(self.tcx.sess, span, E0088,
4440+
"too many lifetime parameters provided: \
4441+
expected {}, found {}",
4442+
count(lifetime_defs.len()),
4443+
count(lifetimes.len()))
4444+
.span_label(span, &format!("unexpected lifetime parameter{}",
4445+
match lifetimes.len() { 1 => "", _ => "s" }))
4446+
.emit();
44504447
}
44514448

4449+
// The case where there is not enough lifetime parameters is not checked,
4450+
// because this is not possible - a function never takes lifetime parameters.
4451+
// See discussion for Pull Request 36208.
4452+
44524453
// Check provided type parameters.
44534454
let type_defs = segment.map_or(&[][..], |(_, generics)| {
44544455
if generics.parent.is_none() {

Diff for: src/librustdoc/html/render.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2437,7 +2437,6 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
24372437
write!(w, "}}")?;
24382438
}
24392439
write!(w, "</pre>")?;
2440-
render_stability_since_raw(w, it.stable_since(), None)?;
24412440

24422441
document(w, cx, it)?;
24432442
if !e.variants.is_empty() {
@@ -3053,7 +3052,6 @@ fn item_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
30533052
Some("macro"),
30543053
None,
30553054
None))?;
3056-
render_stability_since_raw(w, it.stable_since(), None)?;
30573055
document(w, cx, it)
30583056
}
30593057

Diff for: src/libstd/net/addr.rs

+78-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum SocketAddr {
3131
/// An IPv4 socket address which is a (ip, port) combination.
3232
#[stable(feature = "rust1", since = "1.0.0")]
3333
V4(#[stable(feature = "rust1", since = "1.0.0")] SocketAddrV4),
34-
/// An IPv6 socket address
34+
/// An IPv6 socket address.
3535
#[stable(feature = "rust1", since = "1.0.0")]
3636
V6(#[stable(feature = "rust1", since = "1.0.0")] SocketAddrV6),
3737
}
@@ -48,6 +48,16 @@ pub struct SocketAddrV6 { inner: c::sockaddr_in6 }
4848

4949
impl SocketAddr {
5050
/// Creates a new socket address from the (ip, port) pair.
51+
///
52+
/// # Examples
53+
///
54+
/// ```
55+
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
56+
///
57+
/// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
58+
/// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
59+
/// assert_eq!(socket.port(), 8080);
60+
/// ```
5161
#[stable(feature = "ip_addr", since = "1.7.0")]
5262
pub fn new(ip: IpAddr, port: u16) -> SocketAddr {
5363
match ip {
@@ -57,6 +67,15 @@ impl SocketAddr {
5767
}
5868

5969
/// Returns the IP address associated with this socket address.
70+
///
71+
/// # Examples
72+
///
73+
/// ```
74+
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
75+
///
76+
/// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
77+
/// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
78+
/// ```
6079
#[stable(feature = "ip_addr", since = "1.7.0")]
6180
pub fn ip(&self) -> IpAddr {
6281
match *self {
@@ -66,6 +85,16 @@ impl SocketAddr {
6685
}
6786

6887
/// Change the IP address associated with this socket address.
88+
///
89+
/// # Examples
90+
///
91+
/// ```
92+
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
93+
///
94+
/// let mut socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
95+
/// socket.set_ip(IpAddr::V4(Ipv4Addr::new(10, 10, 0, 1)));
96+
/// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(10, 10, 0, 1)));
97+
/// ```
6998
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
7099
pub fn set_ip(&mut self, new_ip: IpAddr) {
71100
// `match (*self, new_ip)` would have us mutate a copy of self only to throw it away.
@@ -77,6 +106,15 @@ impl SocketAddr {
77106
}
78107

79108
/// Returns the port number associated with this socket address.
109+
///
110+
/// # Examples
111+
///
112+
/// ```
113+
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
114+
///
115+
/// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
116+
/// assert_eq!(socket.port(), 8080);
117+
/// ```
80118
#[stable(feature = "rust1", since = "1.0.0")]
81119
pub fn port(&self) -> u16 {
82120
match *self {
@@ -86,6 +124,16 @@ impl SocketAddr {
86124
}
87125

88126
/// Change the port number associated with this socket address.
127+
///
128+
/// # Examples
129+
///
130+
/// ```
131+
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
132+
///
133+
/// let mut socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
134+
/// socket.set_port(1025);
135+
/// assert_eq!(socket.port(), 1025);
136+
/// ```
89137
#[stable(feature = "sockaddr_setters", since = "1.9.0")]
90138
pub fn set_port(&mut self, new_port: u16) {
91139
match *self {
@@ -96,6 +144,20 @@ impl SocketAddr {
96144

97145
/// Returns true if the IP in this `SocketAddr` is a valid IPv4 address,
98146
/// false if it's a valid IPv6 address.
147+
///
148+
/// # Examples
149+
///
150+
/// ```
151+
/// #![feature(sockaddr_checker)]
152+
///
153+
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
154+
///
155+
/// fn main() {
156+
/// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
157+
/// assert_eq!(socket.is_ipv4(), true);
158+
/// assert_eq!(socket.is_ipv6(), false);
159+
/// }
160+
/// ```
99161
#[unstable(feature = "sockaddr_checker", issue = "36949")]
100162
pub fn is_ipv4(&self) -> bool {
101163
match *self {
@@ -106,6 +168,21 @@ impl SocketAddr {
106168

107169
/// Returns true if the IP in this `SocketAddr` is a valid IPv6 address,
108170
/// false if it's a valid IPv4 address.
171+
///
172+
/// # Examples
173+
///
174+
/// ```
175+
/// #![feature(sockaddr_checker)]
176+
///
177+
/// use std::net::{IpAddr, Ipv6Addr, SocketAddr};
178+
///
179+
/// fn main() {
180+
/// let socket = SocketAddr::new(
181+
/// IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 0, 1)), 8080);
182+
/// assert_eq!(socket.is_ipv4(), false);
183+
/// assert_eq!(socket.is_ipv6(), true);
184+
/// }
185+
/// ```
109186
#[unstable(feature = "sockaddr_checker", issue = "36949")]
110187
pub fn is_ipv6(&self) -> bool {
111188
match *self {

Diff for: src/test/compile-fail/E0088.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
// except according to those terms.
1010

1111
fn f() {}
12+
fn g<'a>() {}
1213

1314
fn main() {
1415
f::<'static>(); //~ ERROR E0088
16+
//~^ unexpected lifetime parameter
17+
18+
g::<'static, 'static>(); //~ ERROR E0088
19+
//~^ unexpected lifetime parameters
1520
}

0 commit comments

Comments
 (0)