Change:
I got a bug report on Diesel from someone who has a database column called . This lead to us attempting to generate the following code: which causes a type mismatch because their struct is shadowing the primitive. I'd like to change the generated code to be , which is the path that the rustdoc for libstd indicates it should be, but the type doesn't exist there, or anywhere else I can find. I would assume the same issue exists for , , and all the numeric types.
Since the module already exists, the type cannot be called . But it can be aliased as I guess.
would make sense as well
Related: The reason these primitives are not put into prelude was because but I think this is no longer a problem? (cc
Tagging this as a library issue. The solution (if it happens on our side) is to add a module or (and reexport it from as well) as described in In the meantime Diesel can privately define such a module itself and use it when unintended shadowing can happen. It doesn't make much sense to put primitive types into the std prelude because they are already in a prelude actually, it's just not the std prelude, but an additional language prelude one level below (as it was decided in and ).
I agree that primitives should be exposed at some absolute path. sounds reasonable.
I'd be happy to work on this. What's needed besides the implementation? I'm not entirely sure what a test for this should look like. Just a run-pass test that shadows and references ? Do we need one for every type?
I would start with a PR that has: Implementation, Module-level documentation for std::primitive with a helpful example that communicates why you may want to use this, One run-pass test for a shadowed bool as you suggested.
Sounds good. I'll try to get that PR done this week.
Does this need a feature gate?
Yes I believe so.
Triage: not aware of anything happening here.

Discussion:
mod tuple; mod unit; <ins> #[stable(feature = "core_primitive", since = "1.43.0")] pub mod primitive; </ins> // Pull in the `core_arch` crate directly into libcore. The contents of // `core_arch` are in a different repository: rust-lang/stdarch. //

<ins> //! This module reexports the primitive types to allow usage that is not //! possibly shadowed by other declared types. //! //! This is normally only useful in macro generated code. //! //! An example of this is when generating a new struct and an impl for it: //! //! ```rust,compile_fail //! pub struct bool; //! //! impl QueryId for bool { //!     const SOME_PROPERTY: bool = true; //! } //! //! # trait QueryId { const SOME_PROPERTY: core::primitive::bool; } //! ``` //! //! Note that the `SOME_PROPERTY` associated constant would not compile, as its //! type `bool` refers to the struct, rather than to the primitive bool type. //! //! A correct implementation could look like: //! //! ```rust //! # #[allow(non_camel_case_types)] //! pub struct bool; //! //! impl QueryId for bool { //!     const SOME_PROPERTY: core::primitive::bool = true; //! } //! //! # trait QueryId { const SOME_PROPERTY: core::primitive::bool; } //! ``` #[stable(feature = "core_primitive", since = "1.43.0")] pub use bool; #[stable(feature = "core_primitive", since = "1.43.0")] pub use char; #[stable(feature = "core_primitive", since = "1.43.0")] pub use f32; #[stable(feature = "core_primitive", since = "1.43.0")] pub use f64; #[stable(feature = "core_primitive", since = "1.43.0")] pub use i128; #[stable(feature = "core_primitive", since = "1.43.0")] pub use i16; #[stable(feature = "core_primitive", since = "1.43.0")] pub use i32; #[stable(feature = "core_primitive", since = "1.43.0")] pub use i64; #[stable(feature = "core_primitive", since = "1.43.0")] pub use i8; #[stable(feature = "core_primitive", since = "1.43.0")] pub use isize; #[stable(feature = "core_primitive", since = "1.43.0")] pub use str; #[stable(feature = "core_primitive", since = "1.43.0")] pub use u128; #[stable(feature = "core_primitive", since = "1.43.0")] pub use u16; #[stable(feature = "core_primitive", since = "1.43.0")] pub use u32; #[stable(feature = "core_primitive", since = "1.43.0")] pub use u64; #[stable(feature = "core_primitive", since = "1.43.0")] pub use u8; #[stable(feature = "core_primitive", since = "1.43.0")] pub use usize; </ins>

#![feature(allocator_internals)] #![feature(allow_internal_unsafe)] #![feature(allow_internal_unstable)] <del> #![feature(atomic_mut_ptr)] </del> #![feature(arbitrary_self_types)] #![feature(array_error_internals)] #![feature(asm)] #![feature(assoc_int_consts)] #![feature(associated_type_bounds)] <ins> #![feature(atomic_mut_ptr)] </ins> #![feature(box_syntax)] #![feature(c_variadic)] #![feature(cfg_target_has_atomic)]

trace_macros, }; <ins> #[stable(feature = "core_primitive", since = "1.43.0")] pub use core::primitive; </ins> // Include a number of private modules that exist solely to provide // the rustdoc documentation for primitive types. Using `include!` // because rustdoc only looks for these modules at the crate level.

| LL |     let _: ::u8; |              ^^ not found in the crate root <ins> | help: possible candidate is found in another module, you can import it into scope | LL | use std::primitive::u8; | </ins> error[E0061]: this function takes 0 parameters but 1 parameter was supplied --> $DIR/resolve-primitive-fallback.rs:3:5

<ins> // check-pass mod bar { pub trait QueryId { const SOME_PROPERTY: bool; } } use bar::QueryId; #[allow(non_camel_case_types)] pub struct bool; impl QueryId for bool { const SOME_PROPERTY: core::primitive::bool = true; } fn main() {} </ins>