Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax bounds on HashMap/HashSet #67642

Merged
merged 2 commits into from
Feb 13, 2020
Merged

Conversation

Mark-Simulacrum
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum commented Dec 26, 2019

These APIs changed from the old bound listed to the new bound (possibly empty):

K: Hash + Eq -> K

  • new
  • with_capacity

K: Eq + Hash, S: BuildHasher -> K, S

  • with_hasher
  • with_capacity_and_hasher
  • hasher

K: Eq + Hash + Debug -> K: Debug
S: BuildHasher -> S
HashMap as Debug

K: Eq + Hash -> K
S: BuildHasher + Default -> S: Default
HashMap as Default

Resolves #44777.

No functional changes are made, and all APIs are moved to strictly less
restrictive bounds.

These APIs changed from the old bound listed to no trait bounds:

K: Hash + Eq
* new
* with_capacity

K: Eq + Hash, S: BuildHasher
* with_hasher
* with_capacity_and_hasher
* hasher

K: Eq + Hash + Debug -> K: Debug
S: BuildHasher -> S
<HashMap as Debug>

K: Eq + Hash -> K
S: BuildHasher + Default -> S: Default
<HashMap as Default>
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 26, 2019
@Mark-Simulacrum Mark-Simulacrum added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Dec 26, 2019
@Amanieu
Copy link
Member

Amanieu commented Dec 26, 2019

LGTM

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Dec 26, 2019

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Dec 26, 2019
@rust-highfive

This comment has been minimized.

@Mark-Simulacrum
Copy link
Member Author

Test failure appears to be because it is now possible to create a HashSet from [u8; 33] whereas it wasn't before. I will rebless shortly.

@rust-highfive

This comment has been minimized.

@sfackler
Copy link
Member

What's the rationale for allowing the creation of maps that can't be used?

@Mark-Simulacrum
Copy link
Member Author

I think the primary rationale from my perspective (I am not the one who filed the original issue, nor do I have a use case myself) is to allow wrapping HashMap/HashSet in types that don't necessarily want to constrain themselves to using those always. I am not sure that I have a concrete use case -- most things I can come up with would know the type parameters (i.e., not actually be generic).

My loose idea is a type that wants to construct a HashSet/Map eagerly but may not use it except for some use cases (e.g., some graph data structure that caches nodes/edges if you call some methods, but can be used without those methods in some cases).

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-12-26T22:50:33.8714030Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-12-26T22:50:33.8731087Z ##[command]git config gc.auto 0
2019-12-26T22:50:33.8733928Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-12-26T22:50:33.8736858Z ##[command]git config --get-all http.proxy
2019-12-26T22:50:33.8739306Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/67642/merge:refs/remotes/pull/67642/merge
---
2019-12-26T23:53:04.7459203Z .................................................................................................... 1600/9455
2019-12-26T23:53:09.9326183Z .................................................................................................... 1700/9455
2019-12-26T23:53:19.9258673Z .............................................................................................i...... 1800/9455
2019-12-26T23:53:28.5551899Z .................................................................................................... 1900/9455
2019-12-26T23:53:35.6423539Z ...............................................................................iiiii................ 2000/9455
2019-12-26T23:53:58.4831435Z .................................................................................................... 2200/9455
2019-12-26T23:54:00.9873085Z .................................................................................................... 2300/9455
2019-12-26T23:54:03.6722711Z .................................................................................................... 2400/9455
2019-12-26T23:54:10.3211033Z .................................................................................................... 2500/9455
---
2019-12-26T23:57:17.3139580Z ..........i...............i......................................................................... 4900/9455
2019-12-26T23:57:27.7274689Z .................................................................................................... 5000/9455
2019-12-26T23:57:32.9979015Z ......................................................i............................................. 5100/9455
2019-12-26T23:57:42.8918905Z .................................................................................................... 5200/9455
2019-12-26T23:57:49.5091380Z .....................ii.ii...........i.............................................................. 5300/9455
2019-12-26T23:57:59.0279142Z .................................................................................................... 5500/9455
2019-12-26T23:58:10.4486694Z .................................................................................................... 5600/9455
2019-12-26T23:58:18.0421934Z ...i................................................................................................ 5700/9455
2019-12-26T23:58:23.9943519Z .................................................................................................... 5800/9455
2019-12-26T23:58:23.9943519Z .................................................................................................... 5800/9455
2019-12-26T23:58:34.6370576Z ...........................................................................................ii...i..i 5900/9455
2019-12-26T23:58:47.8313982Z i...........i....................................................................................... 6000/9455
2019-12-26T23:59:06.2283898Z .................................................................................................... 6200/9455
2019-12-26T23:59:13.8599721Z .................................................................................................... 6300/9455
2019-12-26T23:59:13.8599721Z .................................................................................................... 6300/9455
2019-12-26T23:59:31.2246975Z ..................i..ii............................................................................. 6400/9455
2019-12-26T23:59:51.9843990Z ...............................................................................................i.... 6600/9455
2019-12-26T23:59:54.2539992Z .................................................................................................... 6700/9455
2019-12-26T23:59:56.6400083Z ...............................................................................................i.... 6800/9455
2019-12-26T23:59:59.4505121Z .................................................................................................... 6900/9455
---
2019-12-27T00:01:42.8250873Z .................................................................................................... 7500/9455
2019-12-27T00:01:47.9038732Z .................................................................................................... 7600/9455
2019-12-27T00:01:54.9540174Z .................................................................................................... 7700/9455
2019-12-27T00:02:06.1131880Z .................................................................................................... 7800/9455
2019-12-27T00:02:13.0664847Z ..........................iiii...................................................................... 7900/9455
2019-12-27T00:02:28.4860979Z .................................................................................................... 8100/9455
2019-12-27T00:02:38.5788464Z .................................................................................................... 8200/9455
2019-12-27T00:02:52.9164876Z .................................................................................................... 8300/9455
2019-12-27T00:03:00.5837149Z .................................................................................................... 8400/9455
---
2019-12-27T00:05:02.4815984Z 10 error[E0277]: arrays only have std trait implementations for lengths 0..=32
2019-12-27T00:05:02.4816421Z -   --> $DIR/core-traits-no-impls-length-33.rs:10:16
2019-12-27T00:05:02.4817130Z +   --> $DIR/core-traits-no-impls-length-33.rs:9:16
2019-12-27T00:05:02.4817322Z 12    |
2019-12-27T00:05:02.4817714Z 13 LL |     set.insert([0_usize; 33]);
2019-12-27T00:05:02.4817924Z 14    |                ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[usize; 33]`
2019-12-27T00:05:02.4818062Z 
2019-12-27T00:05:02.4818270Z 16    = note: required because of the requirements on the impl of `std::cmp::Eq` for `[usize; 33]`
2019-12-27T00:05:02.4818580Z 18 error[E0369]: binary operation `==` cannot be applied to type `[usize; 33]`
2019-12-27T00:05:02.4819350Z -   --> $DIR/core-traits-no-impls-length-33.rs:15:19
2019-12-27T00:05:02.4820183Z +   --> $DIR/core-traits-no-impls-length-33.rs:14:19
2019-12-27T00:05:02.4820641Z 20    |
2019-12-27T00:05:02.4820641Z 20    |
2019-12-27T00:05:02.4820798Z 21 LL |     [0_usize; 33] == [1_usize; 33]
2019-12-27T00:05:02.4821210Z 22    |     ------------- ^^ ------------- [usize; 33]
2019-12-27T00:05:02.4821578Z 26    = note: an implementation of `std::cmp::PartialEq` might be missing for `[usize; 33]`
2019-12-27T00:05:02.4821723Z 27 
2019-12-27T00:05:02.4821723Z 27 
2019-12-27T00:05:02.4821896Z 28 error[E0369]: binary operation `<` cannot be applied to type `[usize; 33]`
2019-12-27T00:05:02.4822488Z -   --> $DIR/core-traits-no-impls-length-33.rs:20:19
2019-12-27T00:05:02.4826019Z +   --> $DIR/core-traits-no-impls-length-33.rs:19:19
2019-12-27T00:05:02.4826306Z 30    |
2019-12-27T00:05:02.4826455Z 31 LL |     [0_usize; 33] < [1_usize; 33]
2019-12-27T00:05:02.4827017Z 32    |     ------------- ^ ------------- [usize; 33]
2019-12-27T00:05:02.4827414Z 
2019-12-27T00:05:02.4827738Z 36    = note: an implementation of `std::cmp::PartialOrd` might be missing for `[usize; 33]`
2019-12-27T00:05:02.4827907Z 37 
2019-12-27T00:05:02.4828059Z 38 error[E0277]: the trait bound `&[usize; 33]: std::iter::IntoIterator` is not satisfied
2019-12-27T00:05:02.4829118Z -   --> $DIR/core-traits-no-impls-length-33.rs:25:14
2019-12-27T00:05:02.4829751Z +   --> $DIR/core-traits-no-impls-length-33.rs:24:14
2019-12-27T00:05:02.4829943Z 40    |
2019-12-27T00:05:02.4830088Z 41 LL |     for _ in &[0_usize; 33] {
2019-12-27T00:05:02.4830274Z 42    |              ^^^^^^^^^^^^^^ the trait `std::iter::IntoIterator` is not implemented for `&[usize; 33]`
2019-12-27T00:05:02.4830523Z 
2019-12-27T00:05:02.4830685Z The actual stderr differed from the expected stderr.
2019-12-27T00:05:02.4830685Z The actual stderr differed from the expected stderr.
2019-12-27T00:05:02.4831194Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/array-impls/core-traits-no-impls-length-33/core-traits-no-impls-length-33.stderr
2019-12-27T00:05:02.4831626Z To update references, rerun the tests and pass the `--bless` flag
2019-12-27T00:05:02.4832145Z To only update this specific test, also pass `--test-args const-generics/array-impls/core-traits-no-impls-length-33.rs`
2019-12-27T00:05:02.4832461Z error: 1 errors occurred comparing output.
2019-12-27T00:05:02.4832924Z status: exit code: 1
2019-12-27T00:05:02.4832924Z status: exit code: 1
2019-12-27T00:05:02.4834024Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/array-impls/core-traits-no-impls-length-33" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/array-impls/core-traits-no-impls-length-33/auxiliary" "-A" "unused"
2019-12-27T00:05:02.4834847Z ------------------------------------------
2019-12-27T00:05:02.4835171Z 
2019-12-27T00:05:02.4835827Z ------------------------------------------
2019-12-27T00:05:02.4836217Z stderr:
2019-12-27T00:05:02.4836217Z stderr:
2019-12-27T00:05:02.4836933Z ------------------------------------------
2019-12-27T00:05:02.4837228Z error[E0277]: arrays only have std trait implementations for lengths 0..=32
2019-12-27T00:05:02.4837972Z   --> /checkout/src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.rs:2:22
2019-12-27T00:05:02.4841909Z    |
2019-12-27T00:05:02.4845291Z LL |     println!("{:?}", [0_usize; 33]);
2019-12-27T00:05:02.4851033Z    |                      ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[usize; 33]`
2019-12-27T00:05:02.4852368Z    = note: required because of the requirements on the impl of `std::fmt::Debug` for `[usize; 33]`
2019-12-27T00:05:02.4852583Z    = note: required by `std::fmt::Debug::fmt`
2019-12-27T00:05:02.4852713Z 
2019-12-27T00:05:02.4852974Z error[E0277]: arrays only have std trait implementations for lengths 0..=32
2019-12-27T00:05:02.4852974Z error[E0277]: arrays only have std trait implementations for lengths 0..=32
2019-12-27T00:05:02.4853587Z   --> /checkout/src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.rs:9:16
2019-12-27T00:05:02.4853819Z    |
2019-12-27T00:05:02.4854068Z LL |     set.insert([0_usize; 33]);
2019-12-27T00:05:02.4854318Z    |                ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[usize; 33]`
2019-12-27T00:05:02.4854588Z    |
2019-12-27T00:05:02.4854834Z    = note: required because of the requirements on the impl of `std::cmp::Eq` for `[usize; 33]`
2019-12-27T00:05:02.4855289Z error[E0369]: binary operation `==` cannot be applied to type `[usize; 33]`
2019-12-27T00:05:02.4855860Z   --> /checkout/src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.rs:14:19
2019-12-27T00:05:02.4856773Z    |
2019-12-27T00:05:02.4856773Z    |
2019-12-27T00:05:02.4856844Z LL |     [0_usize; 33] == [1_usize; 33]
2019-12-27T00:05:02.4857161Z    |     ------------- ^^ ------------- [usize; 33]
2019-12-27T00:05:02.4857275Z    |     [usize; 33]
2019-12-27T00:05:02.4857316Z    |
2019-12-27T00:05:02.4857378Z    = note: an implementation of `std::cmp::PartialEq` might be missing for `[usize; 33]`
2019-12-27T00:05:02.4857411Z 
2019-12-27T00:05:02.4857411Z 
2019-12-27T00:05:02.4857485Z error[E0369]: binary operation `<` cannot be applied to type `[usize; 33]`
2019-12-27T00:05:02.4857766Z   --> /checkout/src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.rs:19:19
2019-12-27T00:05:02.4857816Z    |
2019-12-27T00:05:02.4857879Z LL |     [0_usize; 33] < [1_usize; 33]
2019-12-27T00:05:02.4858103Z    |     ------------- ^ ------------- [usize; 33]
2019-12-27T00:05:02.4858213Z    |     [usize; 33]
2019-12-27T00:05:02.4858254Z    |
2019-12-27T00:05:02.4858254Z    |
2019-12-27T00:05:02.4858304Z    = note: an implementation of `std::cmp::PartialOrd` might be missing for `[usize; 33]`
2019-12-27T00:05:02.4858338Z 
2019-12-27T00:05:02.4858406Z error[E0277]: the trait bound `&[usize; 33]: std::iter::IntoIterator` is not satisfied
2019-12-27T00:05:02.4858681Z   --> /checkout/src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.rs:24:14
2019-12-27T00:05:02.4858739Z    |
2019-12-27T00:05:02.4858805Z LL |     for _ in &[0_usize; 33] {
2019-12-27T00:05:02.4858866Z    |              ^^^^^^^^^^^^^^ the trait `std::iter::IntoIterator` is not implemented for `&[usize; 33]`
2019-12-27T00:05:02.4859330Z    = help: the following implementations were found:
2019-12-27T00:05:02.4859330Z    = help: the following implementations were found:
2019-12-27T00:05:02.4859606Z              <&'a [T; _] as std::iter::IntoIterator>
2019-12-27T00:05:02.4859830Z              <&'a [T] as std::iter::IntoIterator>
2019-12-27T00:05:02.4860080Z              <&'a mut [T; _] as std::iter::IntoIterator>
2019-12-27T00:05:02.4860310Z              <&'a mut [T] as std::iter::IntoIterator>
2019-12-27T00:05:02.4860394Z 
2019-12-27T00:05:02.4860456Z error: aborting due to 5 previous errors
2019-12-27T00:05:02.4860485Z 
2019-12-27T00:05:02.4860529Z Some errors have detailed explanations: E0277, E0369.
---
2019-12-27T00:05:02.4862409Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:385:22
2019-12-27T00:05:02.4862486Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-12-27T00:05:02.4862520Z 
2019-12-27T00:05:02.4862545Z 
2019-12-27T00:05:02.4864314Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-7/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "7.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-12-27T00:05:02.4864743Z 
2019-12-27T00:05:02.4864772Z 
2019-12-27T00:05:02.4867965Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-12-27T00:05:02.4868038Z Build completed unsuccessfully in 1:07:42
2019-12-27T00:05:02.4868038Z Build completed unsuccessfully in 1:07:42
2019-12-27T00:05:02.4905930Z == clock drift check ==
2019-12-27T00:05:02.4922803Z   local time: Fri Dec 27 00:05:02 UTC 2019
2019-12-27T00:05:02.6557093Z   network time: Fri, 27 Dec 2019 00:05:02 GMT
2019-12-27T00:05:02.6564415Z == end clock drift check ==
2019-12-27T00:05:03.8093606Z 
2019-12-27T00:05:03.8241560Z ##[error]Bash exited with code '1'.
2019-12-27T00:05:03.8288174Z ##[section]Starting: Checkout
2019-12-27T00:05:03.8290895Z ==============================================================================
2019-12-27T00:05:03.8290970Z Task         : Get sources
2019-12-27T00:05:03.8291019Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

No functional changes are made, and all APIs are moved to strictly less
restrictive bounds.

These APIs changed from the old bound listed to the new bound:

T: Hash + Eq -> T
* new
* with_capacity

T: Eq + Hash, S: BuildHasher -> T
* with_hasher
* with_capacity_and_hasher
* hasher

T: Eq + Hash + Debug -> T: Debug
S: BuildHasher -> S
<HashSet as Debug>

T: Eq + Hash -> T
S: BuildHasher + Default -> S: Default
<HashSet as Default>
@Amanieu
Copy link
Member

Amanieu commented Dec 28, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Dec 28, 2019

📌 Commit 48859db has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 28, 2019
@Amanieu
Copy link
Member

Amanieu commented Dec 28, 2019

@bors r-

Oops, wrong window.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 28, 2019
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 31, 2019
@alexcrichton
Copy link
Member

IIRC this is a general guideline that we've used for libstd historically, only requiring bounds when absolutely necessary. While there's not much use in creating defunkt objects relaxing the bounds can often make generic programming much easier since you don't have to thread through so many bounds in so many places.

For example Arc::new doesn't require Send+Sync values, and while Arc<T> is more useful than HashMap<K, V, NotAHasher> I think roughly the same principle applies.

Now that being said there's also the point to be made of being conservative. I suspect these bounds were actually used at some point and refactorings have since enabled us to not need them. By removing them we're never going to be able to design a hash map where they're required for these methods. That being said the current hash table is quite good, so I suspect we won't have to worry about this too too much.

@Mark-Simulacrum
Copy link
Member Author

That being said the current hash table is quite good, so I suspect we won't have to worry about this too too much.

We already provide iter() without requiring anything (i.e., K, V, and S are boundless), so Debug is implementable atop that.

The construction methods are the only ones which are a bit up in the air -- I could see us wanting to use some property of the hasher to decide how much to allocate in the future (e.g., how many "spare bits" we need or so), but I don't think it's a huge concern as I'm not aware of cases where HashMaps specialize for the hasher being used in such a way.

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Jan 11, 2020
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Feb 7, 2020
@withoutboats
Copy link
Contributor

Since no one has brought anything up, I've checked my box, don't block on my vague concern.

@Mark-Simulacrum
Copy link
Member Author

Okay, then I believe we are ready to go ahead with this. I'm not sure if @Amanieu meant the original "LGTM" comment as a review as well, so let's do r? @Amanieu for final review

@Amanieu
Copy link
Member

Amanieu commented Feb 12, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Feb 12, 2020

📌 Commit 48859db has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 12, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Feb 13, 2020
…nieu

Relax bounds on HashMap/HashSet

These APIs changed from the old bound listed to the new bound (possibly empty):

K: Hash + Eq -> K
* new
* with_capacity

K: Eq + Hash, S: BuildHasher -> K, S
* with_hasher
* with_capacity_and_hasher
* hasher

K: Eq + Hash + Debug -> K: Debug
S: BuildHasher -> S
HashMap as Debug

K: Eq + Hash -> K
S: BuildHasher + Default -> S: Default
HashMap as Default

Resolves rust-lang#44777.
bors added a commit that referenced this pull request Feb 13, 2020
Rollup of 9 pull requests

Successful merges:

 - #67642 (Relax bounds on HashMap/HashSet)
 - #68848 (Hasten macro parsing)
 - #69008 (Properly use parent generics for opaque types)
 - #69048 (Suggestion when encountering assoc types from hrtb)
 - #69049 (Optimize image sizes)
 - #69050 (Micro-optimize the heck out of LEB128 reading and writing.)
 - #69068 (Make the SGX arg cleanup implementation a NOP)
 - #69082 (When expecting `BoxFuture` and using `async {}`, suggest `Box::pin`)
 - #69104 (bootstrap: Configure cmake when building sanitizer runtimes)

Failed merges:

r? @ghost
@bors
Copy link
Contributor

bors commented Feb 13, 2020

⌛ Testing commit 48859db with merge 2e6eace...

@matklad
Copy link
Member

matklad commented Apr 9, 2020

For posterity, one specific case where we don't want the K: Hash + Eq bound on new is the hashbrown-style raw API, like insert_with_hashing. It can be used to build this cute interner (full impl):

struct Span { lo: u32, hi: u32 }

struct Interner {
  interned: HashSet<Span>,  // equality & hash is determined by `&self.storage[span]`
  storage: String,
}

@Kixunil
Copy link
Contributor

Kixunil commented Apr 23, 2020

Damn, this ship has sailed, but I'm going to bring the argument about why this wasn't that great idea and hope to avoid such thing in the future.

Consider error messages for this program in different versions: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=38b035ac5545bc6fe2d7caa805571067

old: the trait bound Foo: std::cmp::Eq is not satisfied
new: no method named extendfound for structstd::collections::HashMap<Foo, std::string::String> in the current scope

I think the old message was much clearer than the new one. :(

@dtolnay
Copy link
Member

dtolnay commented Apr 23, 2020

That would be a diagnostics bug. The program calls extend on a HashMap<K, V>. HashMap has an extend method but it requires K: Eq. Diagnostic should say so. Please file an issue to follow up.

@Kixunil
Copy link
Contributor

Kixunil commented Apr 24, 2020

OK, I filed the bug. Just note that these kinds of things become worse when combinators are used, as the resulting type gets complicated and the code that passed a wrong type is far away from the place at which rustc found the issue. This is also the reason why error messages from futures are so difficult to understand. That's why I opened rust-lang/api-guidelines#217

I don't think that there's a general solution to such error messages. If there was, it might be a good reason to stop requiring types in (non-public) function signatures too.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request May 16, 2020
Pkgsrc changes:
 * Bump rust bootstrap version to 1.42.0, except for Darwin/i686 where the
   bootstrap is not (yet?) available.

Upstream changes:

Version 1.43.0 (2020-04-23)
==========================

Language
--------
- [Fixed using binary operations with `&{number}` (e.g. `&1.0`) not having
  the type inferred correctly.][68129]
- [Attributes such as `#[cfg()]` can now be used on `if` expressions.][69201]

**Syntax only changes**
- [Allow `type Foo: Ord` syntactically.][69361]
- [Fuse associated and extern items up to defaultness.][69194]
- [Syntactically allow `self` in all `fn` contexts.][68764]
- [Merge `fn` syntax + cleanup item parsing.][68728]
- [`item` macro fragments can be interpolated into `trait`s, `impl`s,
  and `extern` blocks.][69366]
  For example, you may now write:
  ```rust
  macro_rules! mac_trait {
      ($i:item) => {
          trait T { $i }
      }
  }
  mac_trait! {
      fn foo() {}
  }
  ```
These are still rejected *semantically*, so you will likely receive an error but
these changes can be seen and parsed by macros and
conditional compilation.


Compiler
--------
- [You can now pass multiple lint flags to rustc to override the previous
  flags.][67885] For example; `rustc -D unused -A unused-variables` denies
  everything in the `unused` lint group except `unused-variables` which
  is explicitly allowed. However, passing `rustc -A unused-variables -D unused` denies
  everything in the `unused` lint group **including** `unused-variables` since
  the allow flag is specified before the deny flag (and therefore overridden).
- [rustc will now prefer your system MinGW libraries over its bundled libraries
  if they are available on `windows-gnu`.][67429]
- [rustc now buffers errors/warnings printed in JSON.][69227]

Libraries
---------
- [`Arc<[T; N]>`, `Box<[T; N]>`, and `Rc<[T; N]>`, now implement
  `TryFrom<Arc<[T]>>`,`TryFrom<Box<[T]>>`, and `TryFrom<Rc<[T]>>`
  respectively.][69538] **Note** These conversions are only available when `N`
  is `0..=32`.
- [You can now use associated constants on floats and integers directly, rather
  than having to import the module.][68952] e.g. You can now write `u32::MAX` or
  `f32::NAN` with no imports.
- [`u8::is_ascii` is now `const`.][68984]
- [`String` now implements `AsMut<str>`.][68742]
- [Added the `primitive` module to `std` and `core`.][67637] This module
  reexports Rust's primitive types. This is mainly useful in macros
  where you want avoid these types being shadowed.
- [Relaxed some of the trait bounds on `HashMap` and `HashSet`.][67642]
- [`string::FromUtf8Error` now implements `Clone + Eq`.][68738]

Stabilized APIs
---------------
- [`Once::is_completed`]
- [`f32::LOG10_2`]
- [`f32::LOG2_10`]
- [`f64::LOG10_2`]
- [`f64::LOG2_10`]
- [`iter::once_with`]

Cargo
-----
- [You can now set config `[profile]`s in your `.cargo/config`, or through
  your environment.][cargo/7823]
- [Cargo will now set `CARGO_BIN_EXE_<name>` pointing to a binary's
  executable path when running integration tests or benchmarks.][cargo/7697]
  `<name>` is the name of your binary as-is e.g. If you wanted the executable
  path for a binary named `my-program`you would use
  `env!("CARGO_BIN_EXE_my-program")`.

Misc
----
- [Certain checks in the `const_err` lint were deemed unrelated to const
  evaluation][69185], and have been moved to the `unconditional_panic` and
  `arithmetic_overflow` lints.

Compatibility Notes
-------------------

- [Having trailing syntax in the `assert!` macro is now a hard error.][69548]
  This has been a warning since 1.36.0.
- [Fixed `Self` not having the correctly inferred type.][69340] This incorrectly
  led to some instances being accepted, and now correctly emits a hard error.

[69340]: rust-lang/rust#69340

Internal Only
-------------
These changes provide no direct user facing benefits, but represent significant
improvements to the internals and overall performance of `rustc` and
related tools.

- [All components are now built with `opt-level=3` instead of `2`.][67878]
- [Improved how rustc generates drop code.][67332]
- [Improved performance from `#[inline]`-ing certain hot functions.][69256]
- [traits: preallocate 2 Vecs of known initial size][69022]
- [Avoid exponential behaviour when relating types][68772]
- [Skip `Drop` terminators for enum variants without drop glue][68943]
- [Improve performance of coherence checks][68966]
- [Deduplicate types in the generator witness][68672]
- [Invert control in struct_lint_level.][68725]

[67332]: rust-lang/rust#67332
[67429]: rust-lang/rust#67429
[67637]: rust-lang/rust#67637
[67642]: rust-lang/rust#67642
[67878]: rust-lang/rust#67878
[67885]: rust-lang/rust#67885
[68129]: rust-lang/rust#68129
[68672]: rust-lang/rust#68672
[68725]: rust-lang/rust#68725
[68728]: rust-lang/rust#68728
[68738]: rust-lang/rust#68738
[68742]: rust-lang/rust#68742
[68764]: rust-lang/rust#68764
[68772]: rust-lang/rust#68772
[68943]: rust-lang/rust#68943
[68952]: rust-lang/rust#68952
[68966]: rust-lang/rust#68966
[68984]: rust-lang/rust#68984
[69022]: rust-lang/rust#69022
[69185]: rust-lang/rust#69185
[69194]: rust-lang/rust#69194
[69201]: rust-lang/rust#69201
[69227]: rust-lang/rust#69227
[69548]: rust-lang/rust#69548
[69256]: rust-lang/rust#69256
[69361]: rust-lang/rust#69361
[69366]: rust-lang/rust#69366
[69538]: rust-lang/rust#69538
[cargo/7823]: rust-lang/cargo#7823
[cargo/7697]: rust-lang/cargo#7697
[`Once::is_completed`]: https://doc.rust-lang.org/std/sync/struct.Once.html#method.is_completed
[`f32::LOG10_2`]: https://doc.rust-lang.org/std/f32/consts/constant.LOG10_2.html
[`f32::LOG2_10`]: https://doc.rust-lang.org/std/f32/consts/constant.LOG2_10.html
[`f64::LOG10_2`]: https://doc.rust-lang.org/std/f64/consts/constant.LOG10_2.html
[`f64::LOG2_10`]: https://doc.rust-lang.org/std/f64/consts/constant.LOG2_10.html
[`iter::once_with`]: https://doc.rust-lang.org/std/iter/fn.once_with.html
bors added a commit to rust-lang/hashbrown that referenced this pull request Aug 10, 2020
Relax bounds on HashSet constructors

Relax bounds on `HashSet::with_hasher` and `with_capacity_and_hasher` to match the bounds on `HashMap` and on `std::collections::HashSet`.

This will allow `std::collections::HashSet` to be based on `hashbrown::HashSet`.

See also rust-lang/rust#67642
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unnecessary trait bounds in HashMap (and BTreeMap)