Allow importing an associated constant of a type?

Currently Rust only allows importing items of a module or crate.

pub use usize::MAX;
pub use std::primitive::usize::MAX as MAX2;

pub use Foo::MAX as MAX3;

pub struct Foo;
impl Foo {
    pub const MAX: usize = 42;
}
Run the above snippet give the following error:
error[E0432]: unresolved import `usize`
 --> src/lib.rs:1:9
  |
1 | pub use usize::MAX;
  |         ^^^^^ help: a similar path exists: `std::usize`

error[E0432]: unresolved import `std::primitive::usize`
 --> src/lib.rs:2:25
  |
2 | pub use std::primitive::usize::MAX as MAX2;
  |                         ^^^^^ `usize` is a builtin type, not a module

error[E0432]: unresolved import `Foo`
 --> src/lib.rs:4:9
  |
4 | pub use Foo::MAX as MAX3;
  |         ^^^ `Foo` is a struct, not a module

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0432`.

It would allow simplifying this code in std:

Notes

1 Like
3 Likes