Commit graph

435 commits

Author SHA1 Message Date
LeSeulArtichaut
ab5e296890 Document remaining undocumented From implementations for IPs 2020-01-29 17:47:05 +01:00
Mazdak Farrokhzad
5ea69781f4
Rollup merge of #67966 - popzxc:core-std-matches, r=Centril
Use matches macro in libcore and libstd

This PR replaces matches like

```rust
match var {
    value => true,
    _ => false,
}
```

with use of `matches!` macro.

r? @Centril
2020-01-09 00:22:10 +01:00
Igor Aleksanov
f720469fd0 Use matches macro in libcore and libstd 2020-01-08 07:10:28 +03:00
Strømberg
a852941829
Removed module usage. 2020-01-06 17:38:41 +01:00
Strømberg
0113cacda2
Missing module std in example. 2020-01-06 17:25:17 +01:00
Dario Gonzalez
915686d069 Implement padding for IpAddr without heap alloc 2019-12-26 08:22:59 -08:00
David Tolnay
4646a88b7a
Deprecate Error::description for real
`description` has been documented as soft-deprecated since 1.27.0 (17
months ago). There is no longer any reason to call it or implement it.

This commit:

- adds #[rustc_deprecated(since = "1.41.0")] to Error::description;

- moves description (and cause, which is also deprecated) below the
  source and backtrace methods in the Error trait;

- reduces documentation of description and cause to take up much less
  vertical real estate in rustdocs, while preserving the example that
  shows how to render errors without needing to call description;

- removes the description function of all *currently unstable* Error
  impls in the standard library;

- marks #[allow(deprecated)] the description function of all *stable*
  Error impls in the standard library;

- replaces miscellaneous uses of description in example code and the
  compiler.
2019-12-24 22:39:49 -08:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Mazdak Farrokhzad
910bb6530c
Rollup merge of #67321 - lzutao:htons, r=dtolnay
make htons const fn

This may partially help #67315.
2019-12-19 10:29:56 +01:00
Mark Rousskov
82184440ec Propagate cfg bootstrap 2019-12-18 12:16:19 -05:00
Lzu Tao
3594d8b8a1 make htons const fn 2019-12-15 13:41:32 +00:00
David Tolnay
2514cd555b
Delete flaky test net::tcp::tests::fast_rebind 2019-12-14 18:44:09 -08:00
Oliver Scherer
5e17e39881 Require stable/unstable annotations for the constness of all stable functions with a const modifier 2019-12-13 11:27:02 +01:00
Markus Reiter
79f876495b Remove boxed closures in address parser. 2019-12-06 13:28:02 +01:00
David Tolnay
4436c9d354
Format libstd with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd *that are not involved in any currently open PR* to
minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8

With the list of files from the script in outstanding_files, the
relevant commands were:

    $ find src/libstd -name '*.rs' \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ rg libstd outstanding_files | xargs git checkout --

Repeating this process several months apart should get us coverage of
most of the rest of libstd.

To confirm no funny business:

    $ git checkout $THIS_COMMIT^
    $ git show --pretty= --name-only $THIS_COMMIT \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ git diff $THIS_COMMIT  # there should be no difference
2019-11-29 18:43:27 -08:00
Benjamin Sago
c154297e6d
Fix broken links in Ipv4Addr::is_benchmarking docs 2019-11-13 15:09:40 +00:00
Yuki Okushi
f135e3312f
Rollup merge of #66058 - mjptree:patch-2, r=kennytm
Correct deprecated `is_global` IPv6 documentation

This method does currently not return false for the `site_local` unicast address space. The documentation of the `is_unicast_global` method on lines 1352 - 1382 suggests that this is intentional as the site-local prefix must no longer be supported in new implementations, thus the documentation can safely be updated to reflect that information.
If not so,  either the `is_unicast_global` method should be updated to exclude the unicast site-local address space, or the `is_global` method itself.
2019-11-10 09:27:15 +09:00
mjptree
15863a60e6
Update src/libstd/net/ip.rs
I assumed some sort of Oxford-comma case here, bit have to admit English is not my first language.

Co-Authored-By: kennytm <kennytm@gmail.com>
2019-11-09 12:27:09 +00:00
mjptree
6f79b71a69
Correct deprecated is_global IPv6 documentation
This method does currently not return false for the `site_local` unicast address space. The documentation of the `is_unicast_global` method on lines 1352 - 1382 suggests that this is intentional as the site-local prefix must no longer be supported in new implementations, thus the documentation can safely be updated to reflect that information.
If not so,  either the `is_unicast_global` method should be updated to exclude the unicast site-local address space, or the `is_global` method itself.
2019-11-03 16:16:14 +00:00
mjptree
6eddf5cb5e
Correct error in documentation for Ipv4Addr method
Correct statement in doctests on line 539 of `is_global` method of the `Ipv4Addr` object, which falsely attributed the tests to the broadcast address.
2019-11-02 18:30:10 +00:00
Mikko Rantanen
040d88dda1
Remove leading :: from paths in doc examples 2019-10-20 21:13:47 +03:00
Tyler Mandry
019b5b5f96
Rollup merge of #64728 - messense:udp-peer-addr, r=dtolnay
Stabilize UdpSocket::peer_addr

Fixes #59127
2019-10-05 21:54:49 -07:00
Lzu Tao
6c1b447f2e Remove unneeded fn main blocks from docs 2019-10-01 11:55:46 +00:00
messense
1de6f74ca4
Update src/libstd/net/udp.rs
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-09-26 09:14:45 +08:00
messense
f1835bc517 Stabilize UdpSocket::peer_addr 2019-09-24 15:10:18 +08:00
Salim Nasser
f5b1b1cdf9 VxWorks ignores the SO_SNDTIMEO socket option (this is long-standing
behavior), so skip the following tests:

net::tcp::tests::timeouts
net::udp::tests::timeouts
2019-08-22 15:26:52 -07:00
Martin Indra
48b6069eaf
Fix typo in src/libstd/net/udp.rs doc comment
Affect is usually used as a verb, effect as a verb.
2019-07-18 21:03:56 +02:00
bors
8b40a188ce Auto merge of #60145 - little-dude:ip2, r=alexcrichton
std::net: Ipv4Addr and Ipv6Addr improvements

Picking this up again from my previous PR: https://github.com/rust-lang/rust/pull/56050
Related to: https://github.com/rust-lang/rust/issues/27709
Fixes: https://github.com/rust-lang/rust/issues/57558

- add `add Ipv4Addr::is_reserved()`
  - [X] implementation
  - [X] tests
- add `Ipv6Addr::is_unicast_link_local_strict()` and update `Ipv6Addr::is_unicast_link_local()` documentation
  - [X] implementation
  - [X] test
- add `Ipv4Addr::is_benchmarking()`
  - [X] implementation
  - [X] test
- add `Ipv4Addr::is_ietf_protocol_assignment()`
  - [X] implementation
  - [X] test
- add `Ipv4Addr::is_shared()`
  - [X] implementation
  - [x] test
- fix `Ipv4Addr:is_global()`
  - [X] implementation
  - [x] test
- [X] refactor the tests for IP properties. This makes the tests more verbose, but using macros have two advantages:
    - it will now be easier to add tests for all the new methods
    - we get clear error messages when a test is failing. For instance:

```
---- net::ip::tests::ip_properties stdout ----
thread '<unnamed>' panicked at 'assertion failed: !ip!("fec0::").is_global()', src/libstd/net/ip.rs:2036:9

```

Whereas previously it was something like

```
thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
   left: `true`,
  right: `false`', libstd/net/ip.rs:1948:13
```

-----------------------

# Ongoing discussions:

## Should `Ipv4Addr::is_global()` return `true` or `false` for reserved addresses?

Reserved addresses are addresses that are matched by `Ipv4Addr::is_reserved()`.
@the8472 [pointed out](https://github.com/rust-lang/rust/pull/60145#issuecomment-485458319) that [RFC 4291](https://tools.ietf.org/html/rfc4291#section-2.4) says IPv6 reserved addresses should be considered global:

```
Future specifications may redefine one or more sub-ranges of the
Global Unicast space for other purposes, but unless and until that
happens, implementations must treat all addresses that do not start
with any of the above-listed prefixes as Global Unicast addresses.
```

We could extrapolate that this should also be the case for IPv4. However, it seems that [IANA considers them non global](https://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.xhtml) (see [my comment](https://github.com/rust-lang/rust/pull/60145#issuecomment-485713270))

### Final decision

There seems to be a consensus that reserved addresses have a different meaning for IPv4 and IPv6 ([comment1](https://github.com/rust-lang/rust/pull/60145#issuecomment-485963789) [comment2](https://github.com/rust-lang/rust/pull/60145#issuecomment-485944582), so we can consider that RFC4291 does not apply to IPv4, and that reserved IPv4 addresses are _not_ global.

## Should `Ipv6Addr::is_unicast_site_local()` exist?

@pusateri [noted](https://github.com/rust-lang/rust/pull/60145#issuecomment-485507515) that site-local addresses have been deprecated for a while by [RFC 3879](https://tools.ietf.org/html/rfc3879) and new implementations _must not_ support them. However, since this method is stable, removing does not seem possible. This kind of situation is covered by the RFC which stated that existing implementation _may_ continue supporting site-local addresses.

### Final decision

Let's keep this method. It is stable already, and the RFC explicitly states that existing implementation may remain.

---------

Note: I'll be AFK from April 27th to May 11th. Anyone should feel free to pick this up if the PR hasn't been merged by then. Sorry for dragging that for so long already.
2019-06-01 03:46:13 +00:00
Mazdak Farrokhzad
a34dae3587
Rollup merge of #60511 - taiki-e:libstd-intra-doc, r=Dylan-DPC
Fix intra-doc link resolution failure on re-exporting libstd

Currently, re-exporting libstd items as below will [occur a lot of failures](https://gist.github.com/taiki-e/e33e0e8631ef47f65a74a3b69f456366).
```rust
pub use std::*;
```

Until the underlying issue (#56922) fixed, we can fix that so they don't propagate to downstream crates.

Related: https://github.com/rust-lang/rust/pull/56941 (That PR fixed failures that occur when re-exporting from libcore to libstd.)

r? @QuietMisdreavus
2019-05-20 23:02:59 +02:00
Marcel Hellwig
cc314b066a Remove bitrig support from rust 2019-05-13 11:09:06 +02:00
Taiki Endo
ccb9dac5ed Fix intra-doc link resolution failure on re-exporting libstd 2019-05-04 23:48:57 +09:00
Steven Fackler
bd177f3ea3 Stabilized vectored IO
This renames `std::io::IoVec` to `std::io::IoSlice` and
`std::io::IoVecMut` to `std::io::IoSliceMut`, and stabilizes
`std::io::IoSlice`, `std::io::IoSliceMut`,
`std::io::Read::read_vectored`, and `std::io::Write::write_vectored`.

Closes #58452
2019-04-27 08:34:08 -07:00
Corentin Henry
cddb838043 std::net: tests for Ipv4addr::is_shared() 2019-04-23 12:01:41 +02:00
Corentin Henry
fe718ef07f std::net: add warning in Ipv4addr::is_reserved() documentation
See @the8472 comment's on Github:
https://github.com/rust-lang/rust/pull/60145#issuecomment-485424229

> I don't think is_reserved including ranges marked for future use is
> a good idea since those future uses may be realized at at some point
> and then old software with is_reserved filters may have false
> positives. This is not a hypothetical concern, such issues have been
> encountered before when IANA assigned previously reserved /8 address
> blocks.
2019-04-23 10:41:25 +02:00
Corentin Henry
634dcd00b4 std::net: add warning in Ipv6Addr::is_unicast_site_local() doc
site-local addresses are deprecated, so we should warn users about it.
2019-04-23 10:38:26 +02:00
Corentin Henry
66627777b5 std::net: tests for Ipv4addr::is_reserved()
Also add tests to IpAddr for make sure these addresses are not global
or multicast.
2019-04-22 17:54:27 +02:00
Corentin Henry
a2bead8761 std::net: tests for Ipv4addr::is_ietf_protocol_assignment()
Also add tests to IpAddr to make sure these addresses are not global.
2019-04-22 17:41:43 +02:00
Corentin Henry
9dcfd9f58c std::net: tests for Ipv4addr::is_benchmarking()
also add test to Ipaddr, making sure that these addresses are not
global.
2019-04-22 17:41:37 +02:00
Corentin Henry
40d0127a09 std::net: tests for Ipv6addr::is_unicast_link_local{_strict}() 2019-04-22 17:41:32 +02:00
Corentin Henry
99d9bb640f std::net: fix tests for site-local ipv6 addresses
Ipv6Addr::is_unicast_global() now returns `true` for unicast site
local addresses, since they are deprecated.
2019-04-22 16:03:39 +02:00
Corentin Henry
c302d2c78f std::net: fix Ipv4addr::is_global() tests
Ipv4addr::is_global() previously considered 0/8 was global, but has
now been fixed, so these tests needed to be fixed as well.
2019-04-22 16:03:39 +02:00
Corentin Henry
c34bcc658b std::net: use macros to test ip properties 2019-04-22 16:03:39 +02:00
Corentin Henry
8106320009 std::net: fix documentation markdown 2019-04-22 16:03:39 +02:00
Corentin Henry
9f6a747b32 std::net: fix Ipv4Addr::is_global()
As per @therealbstern's comment[0]:

The implementation of Ipv4::is_global is not complete, according to the
IANA IPv4 Special-Purpose Address Registry.

        - It compares the address to 0.0.0.0, but anything in 0.0.0.0/8
          should not be considered global.
                - 0/8 is not global and is currently forbidden because
                  some systems used to treat it as the local network.
                - The implementation of Ipv4::is_unspecified is correct.
                  0.0.0.0 is the unspecified address.
        - It does not examine 100.64.0.0/10, which is "Shared Address
          Space" and not global.
        - Ditto 192.0.0.0/24 (IETF Protocol Assignments), except for
          192.0.0.9/32 and 192.0.0.10/32, which are carved out as
          globally reachable.
        - 198.18.0.0/15 is for "Benchmarking" and should not be globally
          reachable.
        - 240.0.0.0/4 is reserved and not currently reachable
2019-04-22 16:03:39 +02:00
Corentin Henry
67291cc971 std::net: add Ipv4Addr::is_shared() 2019-04-22 16:03:39 +02:00
Corentin Henry
f87b96773b std::net: add Ipv4Addr::is_ietf_protocol_assignment() 2019-04-22 16:03:39 +02:00
Corentin Henry
de3cf0d5eb std::net: add Ipv4Addr::is_benchmarking() 2019-04-22 16:03:39 +02:00
Corentin Henry
8f679977e0 std::net: add Ipv4Addr::is_reserved() 2019-04-22 16:03:32 +02:00
Corentin Henry
aea687c314 std::net: fix doc markdown in Ipv6Addr::is_unique_local() 2019-04-20 11:19:10 +02:00
Corentin Henry
1f0aa4043b std::net: add Ipv6Addr::is_unicast_link_local_strict()
RFC 4291 is a little unclear about what is a unicast link local address.
According to section 2.4, the entire fe80::/10 range is reserved for
these addresses, but section 2.5.3 defines a stricter format for such
addresses.

After a discussion[0] is has been decided to add a different method for
each definition, so this commit:

  - renames is_unicast_link_local() into is_unicast_link_local_strict()
  - relaxed the check in is_unicast_link_local()

[0]: https://github.com/rust-lang/rust/issues/27709#issuecomment-400370706
2019-04-20 11:19:10 +02:00