Skip to content

rustc recommends a compiler_builtin on stable, and not on nightly.  #73666

Closed
@b4skyx

Description

@b4skyx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions