Skip to content

Commit a540175

Browse files
committed
Auto merge of rust-lang#116782 - matthiaskrgr:rollup-t3yrgku, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#115196 (Suggest adding `return` if the for semi which can coerce to the fn return type) - rust-lang#115955 (Stabilize `{IpAddr, Ipv6Addr}::to_canonical`) - rust-lang#116776 (Enable `review-requested` feature for rustbot) r? `@ghost` `@rustbot` modify labels: rollup
2 parents be46dc8 + 0a23830 commit a540175

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

core/src/net/ip_addr.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,21 +412,24 @@ impl IpAddr {
412412
/// # Examples
413413
///
414414
/// ```
415-
/// #![feature(ip)]
416415
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
417416
///
417+
/// let localhost_v4 = Ipv4Addr::new(127, 0, 0, 1);
418+
///
419+
/// assert_eq!(IpAddr::V4(localhost_v4).to_canonical(), localhost_v4);
420+
/// assert_eq!(IpAddr::V6(localhost_v4.to_ipv6_mapped()).to_canonical(), localhost_v4);
418421
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).to_canonical().is_loopback(), true);
419422
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).is_loopback(), false);
420423
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).to_canonical().is_loopback(), true);
421424
/// ```
422425
#[inline]
423426
#[must_use = "this returns the result of the operation, \
424427
without modifying the original"]
425-
#[rustc_const_unstable(feature = "const_ip", issue = "76205")]
426-
#[unstable(feature = "ip", issue = "27709")]
428+
#[stable(feature = "ip_to_canonical", since = "CURRENT_RUSTC_VERSION")]
429+
#[rustc_const_stable(feature = "ip_to_canonical", since = "CURRENT_RUSTC_VERSION")]
427430
pub const fn to_canonical(&self) -> IpAddr {
428431
match self {
429-
&v4 @ IpAddr::V4(_) => v4,
432+
IpAddr::V4(_) => *self,
430433
IpAddr::V6(v6) => v6.to_canonical(),
431434
}
432435
}
@@ -1750,11 +1753,11 @@ impl Ipv6Addr {
17501753
/// Some(Ipv4Addr::new(192, 10, 2, 255)));
17511754
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4_mapped(), None);
17521755
/// ```
1753-
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
1754-
#[stable(feature = "ipv6_to_ipv4_mapped", since = "1.63.0")]
1756+
#[inline]
17551757
#[must_use = "this returns the result of the operation, \
17561758
without modifying the original"]
1757-
#[inline]
1759+
#[stable(feature = "ipv6_to_ipv4_mapped", since = "1.63.0")]
1760+
#[rustc_const_stable(feature = "const_ipv6_to_ipv4_mapped", since = "CURRENT_RUSTC_VERSION")]
17581761
pub const fn to_ipv4_mapped(&self) -> Option<Ipv4Addr> {
17591762
match self.octets() {
17601763
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, a, b, c, d] => {
@@ -1819,11 +1822,11 @@ impl Ipv6Addr {
18191822
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).is_loopback(), false);
18201823
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).to_canonical().is_loopback(), true);
18211824
/// ```
1822-
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
1823-
#[unstable(feature = "ip", issue = "27709")]
1825+
#[inline]
18241826
#[must_use = "this returns the result of the operation, \
18251827
without modifying the original"]
1826-
#[inline]
1828+
#[stable(feature = "ip_to_canonical", since = "CURRENT_RUSTC_VERSION")]
1829+
#[rustc_const_stable(feature = "ip_to_canonical", since = "CURRENT_RUSTC_VERSION")]
18271830
pub const fn to_canonical(&self) -> IpAddr {
18281831
if let Some(mapped) = self.to_ipv4_mapped() {
18291832
return IpAddr::V4(mapped);

0 commit comments

Comments
 (0)