Skip to content

Commit

Permalink
Auto merge of #37896 - GuillaumeGomez:rollup, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

- Successful merges: #37835, #37840, #37841, #37848, #37876, #37880, #37881, #37882
- Failed merges:
  • Loading branch information
bors authored Nov 20, 2016
2 parents 8f8944e + b0354fe commit fb12219
Show file tree
Hide file tree
Showing 13 changed files with 1,183 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/doc/book/lifetimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ to it.
Rust supports powerful local type inference in the bodies of functions but not in their item signatures.
It's forbidden to allow reasoning about types based on the item signature alone.
However, for ergonomic reasons, a very restricted secondary inference algorithm called
“lifetime elision” does apply when judging lifetimes. Lifetime elision is concerned solely to infer
“lifetime elision” does apply when judging lifetimes. Lifetime elision is concerned solely with inferring
lifetime parameters using three easily memorizable and unambiguous rules. This means lifetime elision
acts as a shorthand for writing an item signature, while not hiding
away the actual types involved as full local inference would if applied to it.
Expand Down
17 changes: 9 additions & 8 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2474,18 +2474,19 @@ The currently implemented features of the reference compiler are:
internally without imposing on callers
(i.e. making them behave like function calls in
terms of encapsulation).
* - `default_type_parameter_fallback` - Allows type parameter defaults to
influence type inference.

* - `stmt_expr_attributes` - Allows attributes on expressions.
* `default_type_parameter_fallback` - Allows type parameter defaults to
influence type inference.

* - `type_ascription` - Allows type ascription expressions `expr: Type`.
* `stmt_expr_attributes` - Allows attributes on expressions.

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

* - `abi_sysv64` - Allows the usage of the system V AMD64 calling convention
(e.g. `extern "sysv64" func fn_();`)
* `abi_vectorcall` - Allows the usage of the vectorcall calling convention
(e.g. `extern "vectorcall" func fn_();`)

* `abi_sysv64` - Allows the usage of the system V AMD64 calling convention
(e.g. `extern "sysv64" func fn_();`)

If a feature is promoted to a language feature, then all existing programs will
start to receive compilation warnings about `#![feature]` directives which enabled
Expand Down
16 changes: 16 additions & 0 deletions src/libcollectionstest/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,14 @@ fn test_iterator_clone() {
assert!(it.clone().zip(it).all(|(x,y)| x == y));
}

#[test]
fn test_iterator_last() {
let s = "ศไทย中华Việt Nam";
let mut it = s.chars();
it.next();
assert_eq!(it.last(), Some('m'));
}

#[test]
fn test_bytesator() {
let s = "ศไทย中华Việt Nam";
Expand Down Expand Up @@ -911,6 +919,14 @@ fn test_char_indices_revator() {
assert_eq!(pos, p.len());
}

#[test]
fn test_char_indices_last() {
let s = "ศไทย中华Việt Nam";
let mut it = s.char_indices();
it.next();
assert_eq!(it.last(), Some((27, 'm')));
}

#[test]
fn test_splitn_char_iterator() {
let data = "\nMäry häd ä little lämb\nLittle lämb\n";
Expand Down
12 changes: 12 additions & 0 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ impl<'a> Iterator for Chars<'a> {
// `isize::MAX` (that's well below `usize::MAX`).
((len + 3) / 4, Some(len))
}

#[inline]
fn last(mut self) -> Option<char> {
// No need to go through the entire string.
self.next_back()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -505,6 +511,12 @@ impl<'a> Iterator for CharIndices<'a> {
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}

#[inline]
fn last(mut self) -> Option<(usize, char)> {
// No need to go through the entire string.
self.next_back()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/unify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl<'tcx, K, V> UnificationTable<K>
}

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

pub fn unsolved_variables(&mut self) -> Vec<K> {
Expand Down
23 changes: 12 additions & 11 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4436,19 +4436,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let lifetime_defs = segment.map_or(&[][..], |(_, generics)| &generics.regions);
if lifetimes.len() > lifetime_defs.len() {
let span = lifetimes[lifetime_defs.len()].span;
span_err!(self.tcx.sess, span, E0088,
"too many lifetime parameters provided: \
expected {}, found {}",
count(lifetime_defs.len()),
count(lifetimes.len()));
} else if lifetimes.len() > 0 && lifetimes.len() < lifetime_defs.len() {
span_err!(self.tcx.sess, span, E0090,
"too few lifetime parameters provided: \
expected {}, found {}",
count(lifetime_defs.len()),
count(lifetimes.len()));
struct_span_err!(self.tcx.sess, span, E0088,
"too many lifetime parameters provided: \
expected {}, found {}",
count(lifetime_defs.len()),
count(lifetimes.len()))
.span_label(span, &format!("unexpected lifetime parameter{}",
match lifetimes.len() { 1 => "", _ => "s" }))
.emit();
}

// The case where there is not enough lifetime parameters is not checked,
// because this is not possible - a function never takes lifetime parameters.
// See discussion for Pull Request 36208.

// Check provided type parameters.
let type_defs = segment.map_or(&[][..], |(_, generics)| {
if generics.parent.is_none() {
Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2437,7 +2437,6 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "}}")?;
}
write!(w, "</pre>")?;
render_stability_since_raw(w, it.stable_since(), None)?;

document(w, cx, it)?;
if !e.variants.is_empty() {
Expand Down Expand Up @@ -3053,7 +3052,6 @@ fn item_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
Some("macro"),
None,
None))?;
render_stability_since_raw(w, it.stable_since(), None)?;
document(w, cx, it)
}

Expand Down
79 changes: 78 additions & 1 deletion src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum SocketAddr {
/// An IPv4 socket address which is a (ip, port) combination.
#[stable(feature = "rust1", since = "1.0.0")]
V4(#[stable(feature = "rust1", since = "1.0.0")] SocketAddrV4),
/// An IPv6 socket address
/// An IPv6 socket address.
#[stable(feature = "rust1", since = "1.0.0")]
V6(#[stable(feature = "rust1", since = "1.0.0")] SocketAddrV6),
}
Expand All @@ -48,6 +48,16 @@ pub struct SocketAddrV6 { inner: c::sockaddr_in6 }

impl SocketAddr {
/// Creates a new socket address from the (ip, port) pair.
///
/// # Examples
///
/// ```
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
///
/// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
/// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
/// assert_eq!(socket.port(), 8080);
/// ```
#[stable(feature = "ip_addr", since = "1.7.0")]
pub fn new(ip: IpAddr, port: u16) -> SocketAddr {
match ip {
Expand All @@ -57,6 +67,15 @@ impl SocketAddr {
}

/// Returns the IP address associated with this socket address.
///
/// # Examples
///
/// ```
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
///
/// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
/// assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
/// ```
#[stable(feature = "ip_addr", since = "1.7.0")]
pub fn ip(&self) -> IpAddr {
match *self {
Expand All @@ -66,6 +85,16 @@ impl SocketAddr {
}

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

/// Returns the port number associated with this socket address.
///
/// # Examples
///
/// ```
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
///
/// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
/// assert_eq!(socket.port(), 8080);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn port(&self) -> u16 {
match *self {
Expand All @@ -86,6 +124,16 @@ impl SocketAddr {
}

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

/// Returns true if the IP in this `SocketAddr` is a valid IPv4 address,
/// false if it's a valid IPv6 address.
///
/// # Examples
///
/// ```
/// #![feature(sockaddr_checker)]
///
/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
///
/// fn main() {
/// let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
/// assert_eq!(socket.is_ipv4(), true);
/// assert_eq!(socket.is_ipv6(), false);
/// }
/// ```
#[unstable(feature = "sockaddr_checker", issue = "36949")]
pub fn is_ipv4(&self) -> bool {
match *self {
Expand All @@ -106,6 +168,21 @@ impl SocketAddr {

/// Returns true if the IP in this `SocketAddr` is a valid IPv6 address,
/// false if it's a valid IPv4 address.
///
/// # Examples
///
/// ```
/// #![feature(sockaddr_checker)]
///
/// use std::net::{IpAddr, Ipv6Addr, SocketAddr};
///
/// fn main() {
/// let socket = SocketAddr::new(
/// IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 0, 1)), 8080);
/// assert_eq!(socket.is_ipv4(), false);
/// assert_eq!(socket.is_ipv6(), true);
/// }
/// ```
#[unstable(feature = "sockaddr_checker", issue = "36949")]
pub fn is_ipv6(&self) -> bool {
match *self {
Expand Down
5 changes: 5 additions & 0 deletions src/test/compile-fail/E0088.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
// except according to those terms.

fn f() {}
fn g<'a>() {}

fn main() {
f::<'static>(); //~ ERROR E0088
//~^ unexpected lifetime parameter

g::<'static, 'static>(); //~ ERROR E0088
//~^ unexpected lifetime parameters
}
Loading

0 comments on commit fb12219

Please sign in to comment.