Skip to content

Rollup of 11 pull requests #32496

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

Merged
merged 35 commits into from
Mar 26, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4124466
std: Fix inheriting stdin on status()
alexcrichton Mar 15, 2016
3ee841c
Don't loop forever on error recovery with EOF
nrc Mar 18, 2016
2731dc1
Error recovery in the tokeniser
nrc Mar 22, 2016
0950dc3
Remove ungrammatical dots from the error index.
nodakai Mar 23, 2016
be87650
Add augmented assignment operator impls for time types
sfackler Mar 23, 2016
80e7a1b
Mark str::split_at inline
bluss Mar 23, 2016
f621193
Accept 0 as a valid str char boundary
bluss Mar 23, 2016
180d6b5
Tests
nrc Mar 22, 2016
13877ac
make available monomorphizations shared by CGU
nikomatsakis Mar 24, 2016
8d4b1d1
Introduce name resolution fallback for primitive types
petrochenkov Mar 8, 2016
77f033b
Lift the restriction on reusing names of primitive types
petrochenkov Mar 8, 2016
b418cd2
Cleanup
petrochenkov Mar 10, 2016
78495d5
Fix unsound behaviour with null characters in thread names (issue #32…
diwic Mar 25, 2016
5bc2868
make `const_expr_to_pat` fallible (but never have it actually fail)
nikomatsakis Feb 3, 2016
99c2a6b
modify #[deriving(Eq)] to emit #[structural_match]
nikomatsakis Mar 11, 2016
05baf64
do not overwrite spans as eagerly
nikomatsakis Mar 11, 2016
f69eb8e
issue a future-compat lint for constants of invalid type
nikomatsakis Mar 11, 2016
73b4f06
suppress duplicate lints
nikomatsakis Mar 11, 2016
56ebf2b
fallout in existing tests
nikomatsakis Mar 11, 2016
7f661ec
new tests for RFC #1445
nikomatsakis Mar 11, 2016
93e4443
check for both partialeq and eq
nikomatsakis Mar 25, 2016
e539b74
use new visitor to erase regions
nikomatsakis Mar 25, 2016
944dc4a
fix cargo.toml for new dependency
nikomatsakis Mar 25, 2016
2536ae5
fix error message
nikomatsakis Mar 25, 2016
b8b17a5
Rollup merge of #32131 - petrochenkov:prim, r=eddyb
Manishearth Mar 26, 2016
128b2ad
Rollup merge of #32199 - nikomatsakis:limiting-constants-in-patterns-…
Manishearth Mar 26, 2016
a8d59e0
Rollup merge of #32257 - alexcrichton:fix-status-stdin, r=aturon
Manishearth Mar 26, 2016
b55d772
Rollup merge of #32435 - nrc:fix-err-recover, r=nikomatsakis
Manishearth Mar 26, 2016
515e87d
Rollup merge of #32447 - nodakai:dots-in-err-idx, r=Manishearth
Manishearth Mar 26, 2016
023fae6
Rollup merge of #32448 - sfackler:time-augmented-assignment, r=alexcr…
Manishearth Mar 26, 2016
6710278
Rollup merge of #32456 - bluss:str-zero, r=alexcrichton
Manishearth Mar 26, 2016
e3e5824
Rollup merge of #32469 - nikomatsakis:shared-cgu, r=eddyb
Manishearth Mar 26, 2016
d36cb22
Rollup merge of #32476 - diwic:63-null-thread-name, r=alexcrichton
Manishearth Mar 26, 2016
317acb7
Rollup merge of #32482 - nikomatsakis:erase-via-visitor, r=nagisa
Manishearth Mar 26, 2016
6c10866
Fixup #32476
Manishearth Mar 26, 2016
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
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
85 changes: 30 additions & 55 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,15 +1619,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
intravisit::walk_crate(self, krate);
}

fn check_if_primitive_type_name(&self, name: Name, span: Span) {
if let Some(_) = self.primitive_type_table.primitive_types.get(&name) {
span_err!(self.session,
span,
E0317,
"user-defined types or type parameters cannot shadow the primitive types");
}
}

fn resolve_item(&mut self, item: &Item) {
let name = item.name;

Expand All @@ -1637,8 +1628,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ItemEnum(_, ref generics) |
ItemTy(_, ref generics) |
ItemStruct(_, ref generics) => {
self.check_if_primitive_type_name(name, item.span);

self.with_type_parameter_rib(HasTypeParameters(generics, TypeSpace, ItemRibKind),
|this| intravisit::walk_item(this, item));
}
Expand All @@ -1659,8 +1648,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}

ItemTrait(_, ref generics, ref bounds, ref trait_items) => {
self.check_if_primitive_type_name(name, item.span);

// Create a new rib for the trait-wide type parameters.
self.with_type_parameter_rib(HasTypeParameters(generics,
TypeSpace,
Expand Down Expand Up @@ -1695,8 +1682,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
});
}
hir::TypeTraitItem(..) => {
this.check_if_primitive_type_name(trait_item.name,
trait_item.span);
this.with_type_parameter_rib(NoTypeParameters, |this| {
intravisit::walk_trait_item(this, trait_item)
});
Expand All @@ -1720,28 +1705,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}

ItemUse(ref view_path) => {
// check for imports shadowing primitive types
let check_rename = |this: &Self, id, name| {
match this.def_map.borrow().get(&id).map(|d| d.full_def()) {
Some(Def::Enum(..)) | Some(Def::TyAlias(..)) | Some(Def::Struct(..)) |
Some(Def::Trait(..)) | None => {
this.check_if_primitive_type_name(name, item.span);
}
_ => {}
}
};

match view_path.node {
hir::ViewPathSimple(name, _) => {
check_rename(self, item.id, name);
}
hir::ViewPathList(ref prefix, ref items) => {
for item in items {
if let Some(name) = item.node.rename() {
check_rename(self, item.node.id(), name);
}
}

// Resolve prefix of an import with empty braces (issue #28388)
if items.is_empty() && !prefix.segments.is_empty() {
match self.resolve_crate_relative_path(prefix.span,
Expand Down Expand Up @@ -1922,9 +1887,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}

fn resolve_generics(&mut self, generics: &Generics) {
for type_parameter in generics.ty_params.iter() {
self.check_if_primitive_type_name(type_parameter.name, type_parameter.span);
}
for predicate in &generics.where_clause.predicates {
match predicate {
&hir::WherePredicate::BoundPredicate(_) |
Expand Down Expand Up @@ -2658,15 +2620,37 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {

// Try to find a path to an item in a module.
let last_ident = segments.last().unwrap().identifier;
if segments.len() <= 1 {
let unqualified_def = self.resolve_identifier(last_ident, namespace, true);
return unqualified_def.and_then(|def| self.adjust_local_def(def, span))
.map(|def| {
PathResolution::new(def, path_depth)
});
}
// Resolve a single identifier with fallback to primitive types
let resolve_identifier_with_fallback = |this: &mut Self, record_used| {
let def = this.resolve_identifier(last_ident, namespace, record_used);
match def {
None | Some(LocalDef{def: Def::Mod(..), ..}) if namespace == TypeNS =>
this.primitive_type_table
.primitive_types
.get(&last_ident.unhygienic_name)
.map_or(def, |prim_ty| Some(LocalDef::from_def(Def::PrimTy(*prim_ty)))),
_ => def
}
};

let unqualified_def = self.resolve_identifier(last_ident, namespace, false);
if segments.len() == 1 {
// In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we
// don't report an error right away, but try to fallback to a primitive type.
// So, we are still able to successfully resolve something like
//
// use std::u8; // bring module u8 in scope
// fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8
// u8::max_value() // OK, resolves to associated function <u8>::max_value,
// // not to non-existent std::u8::max_value
// }
//
// Such behavior is required for backward compatibility.
// The same fallback is used when `a` resolves to nothing.
let unqualified_def = resolve_identifier_with_fallback(self, true);
return unqualified_def.and_then(|def| self.adjust_local_def(def, span)).map(mk_res);
}

let unqualified_def = resolve_identifier_with_fallback(self, false);
let def = self.resolve_module_relative_path(span, segments, namespace);
match (def, unqualified_def) {
(Some(d), Some(ref ud)) if d == ud.def => {
Expand All @@ -2692,15 +2676,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
return Some(LocalDef::from_def(Def::Err));
}

// First, check to see whether the name is a primitive type.
if namespace == TypeNS {
if let Some(&prim_ty) = self.primitive_type_table
.primitive_types
.get(&identifier.unhygienic_name) {
return Some(LocalDef::from_def(Def::PrimTy(prim_ty)));
}
}

self.resolve_identifier_in_local_ribs(identifier, namespace, record_used)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -9,17 +9,17 @@
// except according to those terms.

// aux-build:i8.rs
// ignore-pretty (#23623)

extern crate i8;
use std::string as i16;
static i32: i32 = 0;
const i64: i64 = 0;
fn u8(f32: f32) {}
fn f<f64>(f64: f64) {}
//~^ ERROR user-defined types or type parameters cannot shadow the primitive types
type u16 = u16; //~ ERROR user-defined types or type parameters cannot shadow the primitive types
enum u32 {} //~ ERROR user-defined types or type parameters cannot shadow the primitive types
struct u64; //~ ERROR user-defined types or type parameters cannot shadow the primitive types
trait bool {} //~ ERROR user-defined types or type parameters cannot shadow the primitive types
enum u32 {}
struct u64;
trait bool {}

mod char {
extern crate i8;
Expand All @@ -40,29 +40,52 @@ mod char {
use super::u8_ as u8;
use super::f_ as f64;
use super::u16_ as u16;
//~^ ERROR user-defined types or type parameters cannot shadow the primitive types
use super::u32_ as u32;
//~^ ERROR user-defined types or type parameters cannot shadow the primitive types
use super::u64_ as u64;
//~^ ERROR user-defined types or type parameters cannot shadow the primitive types
use super::bool_ as bool;
//~^ ERROR user-defined types or type parameters cannot shadow the primitive types
use super::{bool_ as str};
//~^ ERROR user-defined types or type parameters cannot shadow the primitive types
use super::char_ as char;
}
}

trait isize_ {
type isize; //~ ERROR user-defined types or type parameters cannot shadow the primitive types
type isize;
}

fn usize<'usize>(usize: &'usize usize) -> &'usize usize { usize }

mod reuse {
use std::mem::size_of;

type u8 = u64;
use std::string::String as i16;

pub fn check<u16>() {
assert_eq!(size_of::<u8>(), 8);
assert_eq!(size_of::<::u64>(), 0);
assert_eq!(size_of::<i16>(), 3 * size_of::<*const ()>());
assert_eq!(size_of::<u16>(), 0);
}
}

mod guard {
pub fn check() {
use std::u8; // bring module u8 in scope
fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8
u8::max_value() // OK, resolves to associated function <u8>::max_value,
// not to non-existent std::u8::max_value
}
assert_eq!(f(), u8::MAX); // OK, resolves to std::u8::MAX
}
}

fn main() {
let bool = true;
match bool {
let _ = match bool {
str @ true => if str { i32 as i64 } else { i64 },
false => i64,
};

reuse::check::<u64>();
guard::check();
}