Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve: Bind primitive types to items in libcore #32274

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#![feature(pattern)]
#![feature(placement_in)]
#![feature(placement_new_protocol)]
#![cfg_attr(not(stage0), feature(primitive_type))]
#![feature(shared)]
#![feature(slice_patterns)]
#![feature(staged_api)]
Expand All @@ -56,7 +57,6 @@
#![feature(unique)]
#![feature(unsafe_no_drop_flag)]
#![cfg_attr(test, feature(rand, test))]

#![no_std]

extern crate rustc_unicode;
Expand Down Expand Up @@ -99,6 +99,7 @@ pub mod fmt;
pub mod linked_list;
pub mod range;
pub mod slice;
#[cfg_attr(not(stage0), primitive_type)]
pub mod str;
pub mod string;
pub mod vec;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use num::flt2dec;
use ops::Deref;
use result;
use slice;
use str;

#[unstable(feature = "fmt_flags_align", issue = "27726")]
/// Possible alignments returned by `Formatter::align`
Expand Down
1 change: 0 additions & 1 deletion src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use prelude::v1::*;
use fmt;
use num::Zero;
use ops::{Div, Rem, Sub};
use str;
use slice;
use ptr;
use mem;
Expand Down
29 changes: 29 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![cfg_attr(not(stage0), deny(warnings))]
// This is a temporary way to use libcore's prelude in libcore
#![cfg_attr(not(stage0), feature(primitive_type, local_prelude))]
#![cfg_attr(not(stage0), local_prelude)]

#![feature(allow_internal_unstable)]
#![feature(associated_type_defaults)]
Expand Down Expand Up @@ -93,19 +96,43 @@ mod int_macros;
#[macro_use]
mod uint_macros;

/// The boolean type.
#[cfg(not(stage0))]
#[stable(feature = "core_primitive_types", since = "1.9.0")]
#[allow(non_camel_case_types)]
#[primitive_type]
pub type bool = bool;

/// The boolean type.
#[cfg(stage0)]
#[stable(feature = "core_primitive_types", since = "1.9.0")]
pub mod bool {}

#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/isize.rs"] pub mod isize;
#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/i8.rs"] pub mod i8;
#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/i16.rs"] pub mod i16;
#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/i32.rs"] pub mod i32;
#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/i64.rs"] pub mod i64;

#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/usize.rs"] pub mod usize;
#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/u8.rs"] pub mod u8;
#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/u16.rs"] pub mod u16;
#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/u32.rs"] pub mod u32;
#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/u64.rs"] pub mod u64;

#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/f32.rs"] pub mod f32;
#[cfg_attr(not(stage0), primitive_type)]
#[path = "num/f64.rs"] pub mod f64;

#[macro_use]
Expand Down Expand Up @@ -138,6 +165,7 @@ pub mod any;
pub mod array;
pub mod sync;
pub mod cell;
#[cfg_attr(not(stage0), primitive_type)]
pub mod char;
pub mod panicking;
pub mod iter;
Expand All @@ -146,6 +174,7 @@ pub mod raw;
pub mod result;

pub mod slice;
#[cfg_attr(not(stage0), primitive_type)]
pub mod str;
pub mod hash;
pub mod fmt;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/dec2flt/rawfp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
//! take the universally-correct slow path (Algorithm M) for very small and very large numbers.
//! That algorithm needs only next_float() which does handle subnormals and zeros.
use prelude::v1::*;
use u32;
use cmp::Ordering::{Less, Equal, Greater};
use ops::{Mul, Div, Neg};
use fmt::{Debug, LowerExp};
Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/flt2dec/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use prelude::v1::*;

use {f32, f64};
use num::{Float, FpCategory};

/// Decoded unsigned finite value, such that:
Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/flt2dec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ functions.
issue = "0")]

use prelude::v1::*;
use i16;
pub use self::decoder::{decode, DecodableFloat, FullDecoded, Decoded};

pub mod estimator;
Expand Down
5 changes: 5 additions & 0 deletions src/libcore/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//! same manner as the standard library's prelude.

#![stable(feature = "core_prelude", since = "1.4.0")]
#![cfg_attr(not(stage0), no_implicit_prelude)]

// Reexported core operators
#[stable(feature = "core_prelude", since = "1.4.0")]
Expand Down Expand Up @@ -51,3 +52,7 @@
#[doc(no_inline)] pub use str::StrExt;
#[stable(feature = "core_prelude", since = "1.4.0")]
#[doc(no_inline)] pub use char::CharExt;

#[stable(feature = "core_primitive_types", since = "1.9.0")]
#[doc(no_inline)] pub use {u8, u16, u32, u64, usize, i8, i16, i32, i64, isize,
f32, f64, bool, char, str};
1 change: 0 additions & 1 deletion src/libcore/str/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use prelude::v1::*;

use cmp;
use fmt;
use usize;

// Pattern

Expand Down
1 change: 1 addition & 0 deletions src/libcoretest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#![feature(libc)]
#![feature(nonzero)]
#![feature(peekable_is_empty)]
#![feature(primitive_type)]
#![feature(ptr_as_ref)]
#![feature(rand)]
#![feature(raw)]
Expand Down
2 changes: 1 addition & 1 deletion src/libcoretest/num/flt2dec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use std::prelude::v1::*;
use std::{str, mem, i16, f32, f64, fmt};
use std::{mem, fmt};
use std::__rand as rand;
use rand::{Rand, XorShiftRng};
use rand::distributions::{IndependentSample, Range};
Expand Down
1 change: 0 additions & 1 deletion src/libcoretest/num/flt2dec/strategy/dragon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

use std::prelude::v1::*;
use std::{i16, f64};
use super::super::*;
use core::num::flt2dec::*;
use core::num::bignum::Big32x40 as Big;
Expand Down
1 change: 1 addition & 0 deletions src/libcoretest/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod uint_macros;

mod u8;
mod u16;
#[primitive_type]
mod u32;
mod u64;

Expand Down
10 changes: 7 additions & 3 deletions src/librustc/middle/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,29 @@ impl Def {
}
}

pub fn def_id(&self) -> DefId {
pub fn opt_def_id(&self) -> Option<DefId> {
match *self {
Def::Fn(id) | Def::Mod(id) | Def::ForeignMod(id) | Def::Static(id, _) |
Def::Variant(_, id) | Def::Enum(id) | Def::TyAlias(id) | Def::AssociatedTy(_, id) |
Def::TyParam(_, _, id, _) | Def::Struct(id) | Def::Trait(id) |
Def::Method(id) | Def::Const(id) | Def::AssociatedConst(id) |
Def::Local(id, _) | Def::Upvar(id, _, _, _) => {
id
Some(id)
}

Def::Label(..) |
Def::PrimTy(..) |
Def::SelfTy(..) |
Def::Err => {
panic!("attempted .def_id() on invalid def: {:?}", self)
None
}
}
}

pub fn def_id(&self) -> DefId {
self.opt_def_id().expect(&format!("attempted .def_id() on invalid def: {:?}", self))
}

pub fn variant_def_ids(&self) -> Option<(DefId, DefId)> {
match *self {
Def::Variant(enum_id, var_id) => {
Expand Down
9 changes: 9 additions & 0 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
} else {
DefModifiers::empty()
} | DefModifiers::IMPORTABLE;
if item.attrs.iter().any(|attr| attr.name() == "primitive_type") {
if let Some(def_id) = self.ast_map.opt_local_def_id(item.id) {
self.resolver.primitive_type_items.insert(def_id);
}
}

match item.node {
ItemUse(ref view_path) => {
Expand Down Expand Up @@ -463,6 +468,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
if new_parent.is_normal() {
modifiers = modifiers | DefModifiers::IMPORTABLE;
}
if self.session.cstore.item_attrs(def.def_id()).
iter().any(|attr| attr.name() == "primitive_type") {
self.resolver.primitive_type_items.insert(def.def_id());
}

match def {
Def::Mod(_) | Def::ForeignMod(_) | Def::Enum(..) => {
Expand Down
45 changes: 0 additions & 45 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,51 +205,6 @@ about what constitutes an Item declaration and what does not:
https://doc.rust-lang.org/reference.html#statements
"##,

E0317: r##"
User-defined types or type parameters cannot shadow the primitive types.
This error indicates you tried to define a type, struct or enum with the same
name as an existing primitive type:

```compile_fail
struct u8 {
// ...
}
```

To fix this, simply name it something else.

Such an error may also occur if you define a type parameter which shadows a
primitive type. An example would be something like:

```compile_fail
impl<u8> MyTrait for Option<u8> {
// ...
}
```

In such a case, if you meant for `u8` to be a generic type parameter (i.e. any
type can be used in its place), use something like `T` instead:

```ignore
impl<T> MyTrait for Option<T> {
// ...
}
```

On the other hand, if you wished to refer to the specific type `u8`, remove it
from the type parameter list:

```ignore
impl MyTrait for Option<u8> {
// ...
}

See the Types section of the reference for more information about the primitive
types:

https://doc.rust-lang.org/reference.html#types
"##,

E0364: r##"
Private items cannot be publicly re-exported. This error indicates that you
attempted to `pub use` a type or value that was not itself public.
Expand Down
Loading