about summary refs log tree commit diff
path: root/library/std/src/net
AgeCommit message (Collapse)AuthorLines
2021-01-31Rollup merge of #81549 - est31:wording_fix, r=jonas-schievinkJonas Schievink-7/+7
Misc ip documentation fixes
2021-01-30Misc ip documentation fixesest31-7/+7
2021-01-20Dont prefix 0x when `dbg!(ipv6)`Lzu Tao-2/+5
2021-01-20Use slice::split_first instead of manuall slicingLzu Tao-2/+2
2020-12-19Auto merge of #79342 - CDirkx:ipaddr-const, r=oli-obkbors-22/+27
Stabilize all stable methods of `Ipv4Addr`, `Ipv6Addr` and `IpAddr` as const This PR stabilizes all currently stable methods of `Ipv4Addr`, `Ipv6Addr` and `IpAddr` as const. Tracking issue: #76205 `Ipv4Addr` (`const_ipv4`): - `octets` - `is_loopback` - `is_private` - `is_link_local` - `is_multicast` - `is_broadcast` - `is_docmentation` - `to_ipv6_compatible` - `to_ipv6_mapped` `Ipv6Addr` (`const_ipv6`): - `segments` - `is_unspecified` - `is_loopback` - `is_multicast` - `to_ipv4` `IpAddr` (`const_ip`): - `is_unspecified` - `is_loopback` - `is_multicast` ## Motivation The ip methods seem like prime candidates to be made const: their behavior is defined by an external spec, and based solely on the byte contents of an address. These methods have been made unstable const in the beginning of September, after the necessary const integer arithmetic was stabilized. There is currently a PR open (#78802) to change the internal representation of `IpAddr{4,6}` from `libc` types to a byte array. This does not have any impact on the constness of the methods. ## Implementation Most of the stabilizations are straightforward, with the exception of `Ipv6Addr::segments`, which uses the unstable feature `const_fn_transmute`. The code could be rewritten to equivalent stable code, but this leads to worse code generation (#75085). This is why `segments` gets marked with `#[rustc_allow_const_fn_unstable(const_fn_transmute)]`, like the already const-stable `Ipv6Addr::new`, the justification being that a const-stable alternative implementation exists https://github.com/rust-lang/rust/pull/76206#issuecomment-685044184. ## Future posibilities This PR const-stabilizes all currently stable ip methods, however there are also a number of unstable methods under the `ip` feature (#27709). These methods are already unstable const. There is a PR open (#76098) to stabilize those methods, which could include const-stabilization. However, stabilizing those methods as const is dependent on `Ipv4Addr::octets` and `Ipv6Addr::segments` (covered by this PR).
2020-11-27Stabilize all stable methods of `Ipv4Addr`, `Ipv6Addr` and `IpAddr` as constChristiaan Dirkx-22/+27
`Ipv4Addr` - `octets` - `is_loopback` - `is_private` - `is_link_local` - `is_multicast` - `is_broadcast` - `is_docmentation` - `to_ipv6_compatible` - `to_ipv6_mapped` `Ipv6Addr` - `segments` - `is_unspecified` - `is_loopback` - `is_multicast` - `to_ipv4` `IpAddr` - `is_unspecified` - `is_loopback` - `is_multicast`
2020-11-26Move const ip in ui test to unit testDaiki Ihara-0/+6
2020-11-23Auto merge of #78439 - lzutao:rm-clouldabi, r=Mark-Simulacrumbors-2/+2
Drop support for all cloudabi targets `cloudabi` is a tier-3 target, and [it is no longer being maintained upstream][no]. This PR drops supports for cloudabi targets. Those targets are: * aarch64-unknown-cloudabi * armv7-unknown-cloudabi * i686-unknown-cloudabi * x86_64-unknown-cloudabi Since this drops supports for a target, I'd like somebody to tag `relnotes` label to this PR. Some other issues: * The tidy exception for `cloudabi` crate is still remained because * `parking_lot v0.9.0` and `parking_lot v0.10.2` depends on `cloudabi v0.0.3`. * `parking_lot v0.11.0` depends on `cloudabi v0.1.0`. [no]: https://github.com/NuxiNL/cloudabi#note-this-project-is-unmaintained
2020-11-23Auto merge of #76226 - CDirkx:const-ipaddr, r=dtolnaybors-2/+4
Stabilize `IpAddr::is_ipv4` and `is_ipv6` as const Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `std::net::IpAddr` as const, in the same way as [PR#76198](https://github.com/rust-lang/rust/pull/76198). Possible because of the recent stabilization of const control flow. Part of #76225 and #76205.
2020-11-23Bump version to 1.50.0Christiaan Dirkx-2/+2
2020-11-23Stabilize `IpAddr::is_ipv4` and `is_ipv6` as constChristiaan Dirkx-2/+4
Insta-stabilize the methods `is_ipv4` and `is_ipv6` of `IpAddr`. Possible because of the recent stabilization of const control flow. Also adds a test for these methods in a const context.
2020-11-22Drop support for cloudabi targetsLzu Tao-2/+2
2020-11-19Bump bootstrap compiler versionJake Goulding-2/+1
2020-10-25Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obkYuki Okushi-1/+2
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s `#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks. While it was originally only meant to be used only on macros, its use was expanded to `const fn`s. This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s. This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540). Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'. Closes rust-lang/rust#69399 r? @oli-obk
2020-10-23Rollup merge of #77918 - wcampbell0x2a:cleanup-network-tests, r=m-ou-seYuki Okushi-10/+4
Cleanup network tests Some cleanup for network related tests
2020-10-21switch allow_internal_unstable const fns to rustc_allow_const_fn_unstableFlorian Warzecha-1/+2
2020-10-20Rollup merge of #77923 - wcampbell0x2a:cleanup-net-module, r=scottmcmYuki Okushi-8/+2
[net] apply clippy lints Applied helpful clippy lints to the network std library module.
2020-10-19Revert "[net] clippy: needless_update"wcampbell-0/+1
This reverts commit 058699d0a2fca02127761f014d0ecfce1c5541ec.
2020-10-18Remove redundant 'static from library cratesest31-1/+1
2020-10-13fmtwcampbell-1/+1
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13use matches! in library/std/src/net/ip.rs wcampbell-4/+1
Apply suggestion from review Co-authored-by: LingMan <LingMan@users.noreply.github.com>
2020-10-13[net] clippy: identity_opwcampbell-4/+4
warning: the operation is ineffective. Consider reducing it to `self.segments()[0]` --> library/std/src/net/ip.rs:1265:9 | 1265 | (self.segments()[0] & 0xffff) == 0xfe80 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(clippy::identity_op)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op warning: the operation is ineffective. Consider reducing it to `self.segments()[1]` --> library/std/src/net/ip.rs:1266:16 | 1266 | && (self.segments()[1] & 0xffff) == 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op warning: the operation is ineffective. Consider reducing it to `self.segments()[2]` --> library/std/src/net/ip.rs:1267:16 | 1267 | && (self.segments()[2] & 0xffff) == 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op warning: the operation is ineffective. Consider reducing it to `self.segments()[3]` --> library/std/src/net/ip.rs:1268:16 | 1268 | && (self.segments()[3] & 0xffff) == 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13[net] clippy: match_like_matches_macrowcampbell-4/+1
warning: match expression looks like `matches!` macro --> library/std/src/net/ip.rs:459:9 | 459 | / match self.octets() { 460 | | [169, 254, ..] => true, 461 | | _ => false, 462 | | } | |_________^ help: try this: `matches!(self.octets(), [169, 254, ..])` | = note: `#[warn(clippy::match_like_matches_macro)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13[net] clippy: needless_updatewcampbell-1/+0
warning: struct update has no effect, all the fields in the struct have already been specified --> library/std/src/net/addr.rs:367:19 | 367 | ..unsafe { mem::zeroed() } | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(clippy::needless_update)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_update
2020-10-13Use is_ok() instead of empty Ok(_)wcampbell-10/+4
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-06Parse SocketAddrV6::scope_idTamir Duberstein-4/+15
2020-10-06Avoid unused returnTamir Duberstein-9/+12
2020-10-06Rollup merge of #77528 - tamird:avoid-cast-net-parser, r=dtolnayYuki Okushi-36/+48
Avoid unchecked casts in net parser Once this and #77426 are in, I'll send another PR adding scope id parsing. r? @dtolnay
2020-10-04Inline "eof" methodsTamir Duberstein-13/+2
2020-10-04Avoid unchecked casts in net parserTamir Duberstein-23/+46
2020-10-04Include scope id in SocketAddrV6::DisplayTamir Duberstein-3/+19
2020-09-25Rollup merge of #76304 - CDirkx:const-ip, r=ecstatic-morseJonas Schievink-5/+29
Make delegation methods of `std::net::IpAddr` unstably const Make the following methods of `std::net::IpAddr` unstable const under the `const_ip` feature: - `is_unspecified` - `is_loopback` - `is_global` - `is_multicast` Also adds a test for these methods in a const context. Possible because these methods delegate to the inner `Ipv4Addr` or `Ipv6Addr`, which were made const ([PR#76205](https://github.com/rust-lang/rust/pull/76142) and [PR#76206](https://github.com/rust-lang/rust/pull/76206)), and the recent stabilization of const control flow. Part of #76205 r? @ecstatic-morse
2020-09-23Make delegation methods of `std::net::IpAddr` unstable constChristiaan Dirkx-5/+29
Make the following methods of `std::net::IpAddr` unstable const under the `const_ip` feature: - `is_unspecified` - `is_loopback` - `is_global` - `is_multicast` Also adds a test for these methods in a const context. Possible because these methods delegate to the inner `Ipv4Addr` or `Ipv6Addr`, which were made const, and the recent stabilization of const control flow. Part of #76205
2020-09-22Update library/std/src/net/addr.rsImbolc-1/+1
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2020-09-22Update library/std/src/net/addr.rsImbolc-1/+1
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2020-09-22Update addr.rsImbolc-1/+1
I little clarification
2020-09-03Make `Ipv4Addr` and `Ipv6Addr` const tests unit tests under `library`Christiaan Dirkx-0/+109
These tests are about the standard library, not the compiler itself, thus should live in `library`, see #76268.
2020-09-03Auto merge of #76235 - jyn514:std-intra-links, r=poliorceticsbors-46/+0
Convert many files to intra-doc links Helps with https://github.com/rust-lang/rust/issues/75080 r? @poliorcetics I recommend reviewing one commit at a time, but the diff is small enough you can do it all at once if you like :)
2020-09-03Rollup merge of #76142 - CDirkx:const-ip, r=ecstatic-morseDylan DPC-18/+38
Make all methods of `std::net::Ipv4Addr` const Make the following methods of `std::net::Ipv4Addr` unstable const under the `const_ipv4` feature: - `octets` - `is_loopback` - `is_private` - `is_link_local` - `is_global` (unstable) - `is_shared` (unstable) - `is_ietf_protocol_assignment` (unstable) - `is_benchmarking` (unstable) - `is_reserved` (unstable) - `is_multicast` - `is_broadcast` - `is_documentation` - `to_ipv6_compatible` - `to_ipv6_mapped` This would make all methods of `Ipv6Addr` const. Of these methods, `is_global`, `is_broadcast`, `to_ipv6_compatible`, and `to_ipv6_mapped` require a change in implementation. Part of #76205
2020-09-02Convert many files to intra-doc linksJoshua Nelson-4/+0
- Use intra-doc links for `std::io` in `std::fs` - Use intra-doc links for File::read in unix/ext/fs.rs - Remove explicit intra-doc links for `true` in `net/addr.rs` - Use intra-doc links in alloc/src/sync.rs - Use intra-doc links in src/ascii.rs - Switch to intra-doc links in alloc/rc.rs - Use intra-doc links in core/pin.rs - Use intra-doc links in std/prelude - Use shorter links in `std/fs.rs` `io` is already in scope.
2020-09-02add a note for Ipv4Addr::to_ipv6_compatible南浦月-0/+3
2020-09-01Remove explicit links to `true` and `false` in ip.rsJoshua Nelson-42/+0
2020-09-01Make all remaining methods of `std::net::Ipv4Addr` constChristiaan Dirkx-9/+20
Makes the following methods of `std::net::Ipv4Addr` unstable const under the `const_ipv4` feature: - `is_global` - `is_reserved` - `is_broadcast` - `to_ipv6_compatible` - `to_ipv6_mapped` This results in all methods of `Ipv4Addr` being const. Also adds tests for these methods in a const context.
2020-09-01Change implementation of `Ipv6Addr::is_unspecified` and `is_loopback` from ↵CDirkx-2/+2
`matches!` to `u128` comparison Done because `matches!` doesn't optimize well with array comparisons
2020-09-01Make methods unstable const under `const_ipv4`CDirkx-9/+9
2020-09-01Make all methods of `std::net::Ipv6Addr` constCDirkx-16/+30
Make the following methods of `std::net::Ipv6Addr` unstable const under the `const_ipv6` feature: - `segments` - `is_unspecified` - `is_loopback` - `is_global` (unstable) - `is_unique_local` - `is_unicast_link_local_strict` - `is_documentation` - `multicast_scope` - `is_multicast` - `to_ipv4_mapped` - `to_ipv4` Changed the implementation of `is_unspecified` and `is_loopback` to use a `match` instead of `==`. Part of #76205
2020-08-31Make more Ipv4Addr methods constCDirkx-9/+18
Constify the following methods of `std::net::Ipv4Addr`: - `octets` - `is_loopback` - `is_private` - `is_link_local` - `is_shared` - `is_ietf_protocol_assignment` - `is_benchmarking` - `is_multicast` - `is_documentation` Also insta-stabilizes these methods as const. Possible because of the stabilization of const integer arithmetic and control flow.
2020-08-31std: move "mod tests/benches" to separate filesLzu Tao-2478/+2430
Also doing fmt inplace as requested.
2020-08-19Minor changes to Ipv4AddrLzu Tao-7/+14
* Impl IntoInner rather than AsInner for Ipv4Addr * Add some comments * Add test to show endiannes of Ipv4Addr display
2020-08-16Fix a link, improve method resolutionAlexis Bourget-24/+27