Skip to content

Constify std::net::IpAddr, Ipv4Addr, and Ipv6Addr #76205

@CDirkx

Description

@CDirkx
Contributor

Due to recent stabilizations of const integer arithmetic and const control flow, all methods of types std::net::IpAddr, Ipv4Addr, and Ipv6Addr can be made const. This issue provides an overview of all methods and steps that need to be taken:

Ipv4Addr

Methods already stable const:

  • new
  • is_unspecified

Methods unstable const by PR#76142 (const_ipv4):

  • octets
  • is_loopback
  • is_private
  • is_link_local
  • is_shared (unstable)
  • is_ietf_protocol_assignment (unstable)
  • is_benchmarking (unstable)
  • is_multicast
  • is_documentation
  • is_global (unstable)
  • is_reserved (unstable)
  • is_broadcast
  • to_ipv6_compatible (deprecated?)
  • to_ipv6_mapped

None of these methods depends on an unstable feature, and could all thus be made stable const.

Ipv6Addr

Methods already stable const:

  • new (uses #[allow_internal_unstable(const_fn_transmute)])
  • octets

Ipv6Addr::segments has been made unstable const in PR#76206 (const_ipv6), together with all dependent methods:

  • segments
  • is_unspecified
  • is_loopback
  • is_global (unstable)
  • is_unique_local (unstable)
  • is_unicast_link_local_strict (unstable)
  • is_documentation (unstable)
  • multicast_scope (unstable)
  • is_multicast
  • to_ipv4_mapped (unstable)
  • to_ipv4

All of these methods depend on segments, and thus upon the unstable feature const_fn_transmute, however the transmute is only used for better code generation, the operations could be rewritten equivalently using stable const code.

IpAddr

The following methods are stable const:

  • is_ip4
  • is_ipv6

Implemented in PR#76226.

With the relevant methods of Ipv4Addr and Ipv6Addr made const, the following were also made unstable const in PR#76304:

  • is_documentation (unstable)
  • is_global (unstable)
  • is_loopback
  • is_multicast
  • is_unspecified

Activity

added
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Sep 1, 2020
added a commit that references this issue on Sep 2, 2020
11ff32f
added a commit that references this issue on Sep 3, 2020
9605f94
added a commit that references this issue on Sep 24, 2020
4893b4f

12 remaining items

Dylan-DPC

Dylan-DPC commented on Jan 3, 2024

@Dylan-DPC
Member

Closing this as it these have been stabilised by #79342. If any are missing it is better to add them in a new tracking issue for visibility sake.

RalfJung

RalfJung commented on Oct 12, 2024

@RalfJung
Member

This should not have been closed, there's still a bunch of functions referencing this as their tracking issue.

#131616 fixes that.

added 5 commits that reference this issue on Oct 12, 2024
1b941a7
c0b6c59
06462e1
e01eae7
5d63a3d
added
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
on Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @RalfJung@jonas-schievink@CDirkx@Jirubizu@Dylan-DPC

        Issue actions

          Constify `std::net::IpAddr`, `Ipv4Addr`, and `Ipv6Addr` · Issue #76205 · rust-lang/rust