Closed
Description
I replaced lib.rs with this code after creating an empty lib:
#![no_std]
#![feature(const_btree_new)]
#![feature(const_fn_trait_bound)]
use alloc::collections::BTreeMap;
extern crate alloc;
pub struct CustomMap<K, V>(BTreeMap<K, V>);
impl<K, V> CustomMap<K, V>
where
K: Ord,
{
pub const fn new() -> Self {
CustomMap(BTreeMap::new())
}
}
When running cargo build
, I expected to see this happen: built successfully
Instead, this happened:
Compiling failure-test v0.1.0 (/home/js2xxx/Projects/failure-test)
error[E0277]: the trait bound `K: Ord` is not satisfied
--> src/lib.rs:16:19
|
16 | CustomMap(BTreeMap::new())
| ^^^^^^^^^^^^^^^
| |
| expected an implementor of trait `Ord`
| help: consider borrowing here: `&BTreeMap::new()`
|
note: required by `BTreeMap::<K, V>::new`
--> /home/js2xxx/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/collections/btree/map.rs:512:5
|
512 | / pub const fn new() -> BTreeMap<K, V>
513 | | where
514 | | K: Ord,
| |_______________^
For more information about this error, try `rustc --explain E0277`.
error: could not compile `failure-test` due to previous error
And when I followed the suggestions it offered, it turned into a type mismatch error and wanted me to cancel the borrowing.
Meta
rustc --version --verbose
:
rustc 1.56.0-nightly (8007b506a 2021-08-14)
binary: rustc
commit-hash: 8007b506ac5da629f223b755f5a5391edd5f6d01
commit-date: 2021-08-14
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1
The output of RUST_BACKTRACE=1 cargo build
is the same as above.