about summary refs log tree commit diff
path: root/library/core/src/net
AgeCommit message (Collapse)AuthorLines
2025-09-26Update CURRENT_RUSTC_VERSION post-bumpMark Rousskov-6/+6
2025-09-01Constify conversion traitsltdk-15/+15
2025-08-26remove deprecated Error::description in implsMarijn Schouten-10/+5
2025-08-19Rollup merge of #141744 - GrigorenkoPV:ip_from, r=AmanieuStuart Cook-6/+6
Stabilize `ip_from` Tracking issue: rust-lang/rust#131360 Stabilizes and const-stabilizes the following APIs: ```rust // core::net impl Ipv4Addr { pub const fn from_octets(octets: [u8; 4]) -> Ipv4Addr; } impl Ipv6Addr { pub const fn from_octets(octets: [u8; 16]) -> Ipv6Addr; pub const fn from_segments(segments: [u16; 8]) -> Ipv6Addr; } ``` Closes rust-lang/rust#131360 ```@rustbot``` label +needs-fcp
2025-08-10Constify remaining operatorsltdk-17/+30
2025-08-06tidyBoxy-1/+1
2025-07-22Rollup merge of #143768 - Randl:const-try, r=oli-obk许杰友 Jieyou Xu (Joe)-15/+30
Constify Try, From, TryFrom and relevant traits
2025-07-21Constify Try, From, TryFromEvgenii Zheltonozhskii-15/+30
2025-07-08collect.rs: remove empty line after doc commentMarijn Schouten-1/+0
2025-05-29Stabilize `ip_from`Pavel Grigorenko-6/+6
2025-05-14Add `Ipv4Addr` and `Ipv6Addr` diagnostic itemsSamuel Tardieu-0/+2
They will be used in Clippy to detect runtime parsing of known-valid IP addresses.
2025-04-09replace version placeholderBoxy-8/+8
2025-03-21Recognise new IPv6 non-global range from RFC9602Bardi Harborow-0/+2
This commit adds the 5f00::/16 range defined by RFC9602 to those ranges which Ipv6Addr::is_global recognises as a non-global IP. This range is used for Segment Routing (SRv6) SIDs.
2025-03-16Rollup merge of #138082 - thaliaarchi:slice-cfg-not-test, r=thomcc许杰友 Jieyou Xu (Joe)-1/+1
Remove `#[cfg(not(test))]` gates in `core` These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-03-08Reword documentation about SocketAddr having varying layoutltdk-11/+21
2025-03-06stabilize const_sockaddr_settersRalf Jung-8/+8
2025-03-06Remove #[cfg(not(test))] gates in coreThalia Archibald-1/+1
These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-02-19core/net: IpAddr*::as_octets()Nathan Perry-0/+60
Adds `const` `Ip*Addr::as_octets` methods providing reference access to `Ip*Addr` octets contents. See https://github.com/rust-lang/libs-team/issues/535 for accepted ACP with a more detailed justification.
2025-01-20Auto merge of #134286 - Urgau:unreach_pub-std, r=ibraheemdevbors-3/+3
Enable `unreachable_pub` lint in core This PR enables the [`unreachable_pub`](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#unreachable-pub) as warn in `core`, `rtstartup` and `panic_unwind`. The motivation is similar to the compiler [MCP: Enable deny(unreachable_pub) on `rustc_*` crates](https://github.com/rust-lang/compiler-team/issues/773#issue-2467219005) : > "Where is this thing used?" is a question I ask all the time when reading unfamiliar code. Because of this, I generally find it annoying when things are marked with a more permissive visibility than necessary. "This thing marked pub, which other crates is it used in? Oh, it's not used in any other crates." Another motivation is to help to lint by utilizing it in-tree and seeing it's limitation in more complex scenarios. The diff was mostly generated with `./x.py fix --stage 1 library/core/ -- --broken-code`, as well as manual edits for code in macros, generated code and other targets. r? libs
2025-01-20core: add `#![warn(unreachable_pub)]`Urgau-3/+3
2025-01-20Recognise new IPv6 documentation range from RFC9637Bardi Harborow-4/+7
This commit adds the 3fff::/20 range defined by RFC9637 to those ranges which Ipv6Addr::is_documentation recognises as a documentation IP.
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-2/+2
2024-12-20fix typos in the example code in the doc comments of ↵hltj-3/+3
`Ipv4Addr::from_bits()`, `Ipv6Addr::from_bits()` & `Ipv6Addr::to_bits()`
2024-11-27replace placeholder versionBoxy-4/+4
2024-11-12Stabilize `Ipv6Addr::is_unique_local` and `Ipv6Addr::is_unicast_link_local`umgefahren-6/+4
2024-11-02get rid of a whole bunch of unnecessary rustc_const_unstable attributesRalf Jung-1/+0
2024-10-26Auto merge of #131715 - tgross35:add-const_sockaddr_setters, r=Amanieubors-16/+24
Add an unstable `const_sockaddr_setters` feature Unstably add `const` to the `sockaddr_setters` methods. Included API: ```rust // core::net impl SocketAddr { pub const fn set_ip(&mut self, new_ip: IpAddr); pub const fn set_port(&mut self, new_port: u16); } impl SocketAddrV4 { pub const fn set_ip(&mut self, new_ip: Ipv4Addr); pub const fn set_port(&mut self, new_port: u16); } impl SocketAddrV6 { pub const fn set_ip(&mut self, new_ip: Ipv6Addr); pub const fn set_port(&mut self, new_port: u16); } ``` Tracking issue: <https://github.com/rust-lang/rust/issues/131714>
2024-10-25Re-do recursive const stability checksRalf Jung-0/+1
Fundamentally, we have *three* disjoint categories of functions: 1. const-stable functions 2. private/unstable functions that are meant to be callable from const-stable functions 3. functions that can make use of unstable const features This PR implements the following system: - `#[rustc_const_stable]` puts functions in the first category. It may only be applied to `#[stable]` functions. - `#[rustc_const_unstable]` by default puts functions in the third category. The new attribute `#[rustc_const_stable_indirect]` can be added to such a function to move it into the second category. - `const fn` without a const stability marker are in the second category if they are still unstable. They automatically inherit the feature gate for regular calls, it can now also be used for const-calls. Also, several holes in recursive const stability checking are being closed. There's still one potential hole that is hard to avoid, which is when MIR building automatically inserts calls to a particular function in stable functions -- which happens in the panic machinery. Those need to *not* be `rustc_const_unstable` (or manually get a `rustc_const_stable_indirect`) to be sure they follow recursive const stability. But that's a fairly rare and special case so IMO it's fine. The net effect of this is that a `#[unstable]` or unmarked function can be constified simply by marking it as `const fn`, and it will then be const-callable from stable `const fn` and subject to recursive const stability requirements. If it is publicly reachable (which implies it cannot be unmarked), it will be const-unstable under the same feature gate. Only if the function ever becomes `#[stable]` does it need a `#[rustc_const_unstable]` or `#[rustc_const_stable]` marker to decide if this should also imply const-stability. Adding `#[rustc_const_unstable]` is only needed for (a) functions that need to use unstable const lang features (including intrinsics), or (b) `#[stable]` functions that are not yet intended to be const-stable. Adding `#[rustc_const_stable]` is only needed for functions that are actually meant to be directly callable from stable const code. `#[rustc_const_stable_indirect]` is used to mark intrinsics as const-callable and for `#[rustc_const_unstable]` functions that are actually called from other, exposed-on-stable `const fn`. No other attributes are required.
2024-10-24Document textual format of SocketAddrV{4,6}Nick Mathewson-0/+39
This commit adds new "Textual representation" documentation sections to SocketAddrV4 and SocketAddrV6, by analogy to the existing "textual representation" sections of Ipv4Addr and Ipv6Addr. Rationale: Without documentation about which formats are actually accepted, it's hard for a programmer to be sure that their code will actually behave as expected when implementing protocols that require support (or rejection) for particular representations. This lack of clarity can in turn can lead to ambiguities and security problems like those discussed in RFC 6942. (I've tried to describe the governing RFCs or standards where I could, but it's possible that the actual implementers had something else in mind. I could not find any standards that corresponded _exactly_ to the one implemented in SocketAddrv6, but I have linked the relevant documents that I could find.)
2024-10-14Add a `const_sockaddr_setters` featureTrevor Gross-16/+24
Unstably add `const` to the `sockaddr_setters` methods. Included API: // core::net impl SocketAddr { pub const fn set_ip(&mut self, new_ip: IpAddr); pub const fn set_port(&mut self, new_port: u16); } impl SocketAddrV4 { pub const fn set_ip(&mut self, new_ip: Ipv4Addr); pub const fn set_port(&mut self, new_port: u16); } impl SocketAddrV6 { pub const fn set_ip(&mut self, new_ip: Ipv6Addr); pub const fn set_port(&mut self, new_port: u16); } Tracking issue: <https://github.com/rust-lang/rust/issues/131714>
2024-10-14Rollup merge of #131616 - RalfJung:const_ip, r=tgross35Matthias Krüger-14/+0
merge const_ipv4 / const_ipv6 feature gate into 'ip' feature gate https://github.com/rust-lang/rust/issues/76205 has been closed a while ago, but there are still some functions that reference it. Those functions are all unstable *and* const-unstable. There's no good reason to use a separate feature gate for their const-stability, so this PR moves their const-stability under the same gate as their regular stability, and therefore removes the remaining references to https://github.com/rust-lang/rust/issues/76205.
2024-10-13core/net: use hex for ipv6 doctests for consistency.Dario Nieuwenhuis-37/+25
2024-10-13core/net: add Ipv[46]Addr::from_octets, Ipv6Addr::from_segmentsDario Nieuwenhuis-0/+77
2024-10-13merge const_ipv4 / const_ipv6 feature gate into 'ip' feature gateRalf Jung-14/+0
2024-09-01Rollup merge of #128641 - Konippi:standardize-duplicate-processes-in-parser, ↵Matthias Krüger-32/+24
r=scottmcm refactor: standardize duplicate processes in parser ## Summary This PR refactors the `read_number` function to standardize duplicate code, improve readability, and enhance efficiency. ## Changes - Merged the logic for both `max_digits` cases into a single `read_atomically` closure - Simplified control flow and reduced code duplication
2024-08-11Do not use unnecessary endian conversion.Orson Peters-6/+4
2024-08-11Fix stability annotation and expand commentOrson Peters-2/+8
2024-08-10Hash Ipv*Addr as an integerOrson Peters-2/+19
2024-08-04refactor: standardize duplicate processes in parserKonippi-32/+24
2024-07-29Reformat `use` declarations.Nicholas Nethercote-6/+3
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Fix doc nitsJohn Arundel-30/+34
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-06-30Update ip_addr.rsDaniel Huang-2/+2
2024-06-24Replace `MaybeUninit::uninit_array()` with array repeat expression.Kevin Reid-1/+1
This is possible now that inline const blocks are stable; the idea was even mentioned as an alternative when `uninit_array()` was added: <https://github.com/rust-lang/rust/pull/65580#issuecomment-544200681> > if it’s stabilized soon enough maybe it’s not worth having a > standard library method that will be replaceable with > `let buffer = [MaybeUninit::<T>::uninit(); $N];` Const array repetition and inline const blocks are now stable (in the next release), so that circumstance has come to pass, and we no longer have reason to want `uninit_array()` other than convenience. Therefore, let’s evaluate the inconvenience by not using `uninit_array()` in the standard library, before potentially deleting it entirely.
2024-06-11replace version placeholderPietro Albini-10/+10
2024-05-25Stabilise ip_bits featureltdk-18/+10
2024-04-11Avoid invalid socket address in length calculationTobias Nießen-2/+2
2024-03-25Import the 2021 prelude in the core crateDaniel Paoliello-1/+0
2024-03-04net: Add branch to Parser::read_number for parsing without checkedokaneco-21/+51
arithmetic If `max_digits.is_some()`, then we know we are parsing a `u8` or `u16` because `read_number` is only called with `Some(3)` or `Some(4)`. Both types fit well within a `u32` without risk of overflow. Thus, we can use plain arithmetic to avoid extra instructions from `checked_mul` and `checked_add`.
2024-02-16Auto merge of #116385 - kornelski:maybe-rename, r=Amanieubors-1/+1
Rename MaybeUninit::write_slice A step to push #79995 forward. https://github.com/rust-lang/libs-team/issues/122 also suggested to make them inherent methods, but they can't be — they'd conflict with slice's regular methods.
2024-02-08Bump version placeholdersMark Rousskov-1/+1