Closed
Description
While working on generic struct, I ran into the following error
20 | val: T::max_value(),
| ^^^^^^^^^ function or associated item not found in `T`
|
= help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `max_value`, perhaps you need to restrict type parameter `T` with it:
|
14 | impl<T: compiler_builtins::int::Int + Signed + Ord> Tree<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To reproduce this using the minimal example, I ran the code
fn test<T>(a: T) -> T {
a.max_value()
}
I expected this to fail building and not suggest me to use compiler_builtins as i'm on rustc stable,.
Instead, this happened:
2 | T::max_value()
| ^^^^^^^^^ function or associated item not found in `T`
|
= help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `max_value`, perhaps you need to restrict type parameter `T` with it:
|
1 | fn test<T: compiler_builtins::int::Int>(a: T) -> T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
However when using nightly, it wouldn't suggest me compiler_builtins.
|
2 | T::max_value()
| ^^^^^^^^^ function or associated item not found in `T`
error: aborting due to previous error
Meta
rustc --version --verbose
:
rustc 1.44.1 (c7087fe00 2020-06-17)
binary: rustc
commit-hash: c7087fe00d2ba919df1d813c040a5d47e43b0fe7
commit-date: 2020-06-17
host: x86_64-unknown-linux-gnu
release: 1.44.1
LLVM version: 9.0
rustc +nightly --version --verbose
:
rustc 1.46.0-nightly (6bb3dbfc6 2020-06-22)
binary: rustc
commit-hash: 6bb3dbfc6c6d8992d08431f320ba296a0c2f7498
commit-date: 2020-06-22
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0