rust/tests/ui/typeck/bad-index-due-to-nested.stderr

73 lines
2.3 KiB
Plaintext

error[E0277]: the trait bound `K: Hash` is not satisfied
--> $DIR/bad-index-due-to-nested.rs:20:5
|
LL | map[k]
| ^^^ the trait `Hash` is not implemented for `K`, which is required by `HashMap<_, _>: Index<&_>`
|
note: required for `HashMap<K, V>` to implement `Index<&K>`
--> $DIR/bad-index-due-to-nested.rs:7:12
|
LL | impl<K, V> Index<&K> for HashMap<K, V>
| ^^^^^^^^^ ^^^^^^^^^^^^^
LL | where
LL | K: Hash,
| ---- unsatisfied trait bound introduced here
help: consider restricting type parameter `K`
|
LL | fn index<'a, K: std::hash::Hash, V>(map: &'a HashMap<K, V>, k: K) -> &'a V {
| +++++++++++++++++
error[E0277]: the trait bound `V: Copy` is not satisfied
--> $DIR/bad-index-due-to-nested.rs:20:5
|
LL | map[k]
| ^^^ the trait `Copy` is not implemented for `V`, which is required by `HashMap<_, _>: Index<&_>`
|
note: required for `HashMap<K, V>` to implement `Index<&K>`
--> $DIR/bad-index-due-to-nested.rs:7:12
|
LL | impl<K, V> Index<&K> for HashMap<K, V>
| ^^^^^^^^^ ^^^^^^^^^^^^^
...
LL | V: Copy,
| ---- unsatisfied trait bound introduced here
help: consider restricting type parameter `V`
|
LL | fn index<'a, K, V: std::marker::Copy>(map: &'a HashMap<K, V>, k: K) -> &'a V {
| +++++++++++++++++++
error[E0308]: mismatched types
--> $DIR/bad-index-due-to-nested.rs:20:9
|
LL | fn index<'a, K, V>(map: &'a HashMap<K, V>, k: K) -> &'a V {
| - found this type parameter
LL | map[k]
| ^ expected `&K`, found type parameter `K`
|
= note: expected reference `&_`
found type parameter `_`
help: consider borrowing here
|
LL | map[&k]
| +
error[E0308]: mismatched types
--> $DIR/bad-index-due-to-nested.rs:20:5
|
LL | fn index<'a, K, V>(map: &'a HashMap<K, V>, k: K) -> &'a V {
| - found this type parameter ----- expected `&'a V` because of return type
LL | map[k]
| ^^^^^^ expected `&V`, found type parameter `V`
|
= note: expected reference `&'a _`
found type parameter `_`
help: consider borrowing here
|
LL | &map[k]
| +
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.