Closed
Description
I tried this code:
#![feature(const_btree_new)]
use std::collections::BTreeMap;
trait Proto: Ord {
const DEFAULT: Self;
}
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
struct Map<K, V>(BTreeMap<K, V>);
impl<K: Proto, V: Proto> Proto for Map<K, V> {
const DEFAULT: Map<K, V> = Map(BTreeMap::new());
}
I expected it to compile.
Instead I get the error:
Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `K: Ord` is not satisfied
--> src/lib.rs:13:36
|
13 | const DEFAULT: Map<K, V> = Map(BTreeMap::new());
| ^^^^^^^^^^^^^^^
| |
| expected an implementor of trait `Ord`
| help: consider borrowing here: `&BTreeMap::new()`
|
note: required by `BTreeMap::<K, V>::new`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error
It complains that K: Ord
is not satisfied.
But K: Proto
and Proto: Ord
therefore K: Ord
.
The code also fails if I explicitly add the K: Ord
trait bound to the impl.
Meta
I tried using the most recent nightly on macOS 11.3 (Big Sur) and on the playground.
$ rustc --version --verbose
rustc 1.56.0-nightly (d3e2578c3 2021-08-21)
binary: rustc
commit-hash: d3e2578c31688619ddc0a10ddf8543bf4ebcba5b
commit-date: 2021-08-21
host: x86_64-apple-darwin
release: 1.56.0-nightly
LLVM version: 13.0.0