Skip to content

Commit a626400

Browse files
committed
Auto merge of #33049 - Manishearth:rollup, r=Manishearth
Rollup of 10 pull requests - Successful merges: #31441, #32956, #33003, #33022, #33023, #33032, #33039, #33044, #33045, #33046 - Failed merges:
2 parents f207ddb + e1db767 commit a626400

21 files changed

+542
-225
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ are:
307307
[gsearchdocs]: https://www.google.com/search?q=site:doc.rust-lang.org+your+query+here
308308
[rif]: http://internals.rust-lang.org
309309
[rr]: https://doc.rust-lang.org/book/README.html
310-
[tlgba]: http://tomlee.co/2014/04/03/a-more-detailed-tour-of-the-rust-compiler/
310+
[tlgba]: http://tomlee.co/2014/04/a-more-detailed-tour-of-the-rust-compiler/
311311
[ro]: http://www.rustaceans.org/
312312
[rctd]: ./COMPILER_TESTS.md
313313
[cheatsheet]: http://buildbot.rust-lang.org/homu/

src/doc/book/casting-between-types.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,15 @@ Rust lets us:
165165
```rust
166166
use std::mem;
167167

168-
unsafe {
169-
let a = [0u8, 0u8, 0u8, 0u8];
170-
171-
let b = mem::transmute::<[u8; 4], u32>(a);
168+
fn main() {
169+
unsafe {
170+
let a = [0u8, 1u8, 0u8, 0u8];
171+
let b = mem::transmute::<[u8; 4], u32>(a);
172+
println!("{}", b); // 256
173+
// or, more concisely:
174+
let c: u32 = mem::transmute(a);
175+
println!("{}", c); // 256
176+
}
172177
}
173178
```
174179

src/libcollections/btree/node.rs

+176-5
Large diffs are not rendered by default.

src/libcore/num/mod.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,23 @@ use slice::SliceExt;
3838
/// all standard arithmetic operations on the underlying value are
3939
/// intended to have wrapping semantics.
4040
#[stable(feature = "rust1", since = "1.0.0")]
41-
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Default)]
41+
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)]
4242
pub struct Wrapping<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
4343

44+
#[stable(feature = "rust1", since = "1.0.0")]
45+
impl<T: fmt::Debug> fmt::Debug for Wrapping<T> {
46+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47+
self.0.fmt(f)
48+
}
49+
}
50+
51+
#[stable(feature = "wrapping_display", since = "1.10.0")]
52+
impl<T: fmt::Display> fmt::Display for Wrapping<T> {
53+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54+
self.0.fmt(f)
55+
}
56+
}
57+
4458
mod wrapping;
4559

4660
// All these modules are technically private and only exposed for libcoretest:

src/libcore/ptr.rs

+52
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
119119
/// `src` is not used before the data is overwritten again (e.g. with `write`,
120120
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
121121
/// because it will attempt to drop the value previously at `*src`.
122+
///
123+
/// # Examples
124+
///
125+
/// Basic usage:
126+
///
127+
/// ```
128+
/// let x = 12;
129+
/// let y = &x as *const i32;
130+
///
131+
/// unsafe { println!("{}", std::ptr::read(y)); }
132+
/// ```
122133
#[inline(always)]
123134
#[stable(feature = "rust1", since = "1.0.0")]
124135
pub unsafe fn read<T>(src: *const T) -> T {
@@ -155,6 +166,21 @@ pub unsafe fn read_and_drop<T>(dest: *mut T) -> T {
155166
///
156167
/// This is appropriate for initializing uninitialized memory, or overwriting
157168
/// memory that has previously been `read` from.
169+
///
170+
/// # Examples
171+
///
172+
/// Basic usage:
173+
///
174+
/// ```
175+
/// let mut x = 0;
176+
/// let y = &mut x as *mut i32;
177+
/// let z = 12;
178+
///
179+
/// unsafe {
180+
/// std::ptr::write(y, z);
181+
/// println!("{}", std::ptr::read(y));
182+
/// }
183+
/// ```
158184
#[inline]
159185
#[stable(feature = "rust1", since = "1.0.0")]
160186
pub unsafe fn write<T>(dst: *mut T, src: T) {
@@ -185,6 +211,17 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
185211
/// `src` is not used before the data is overwritten again (e.g. with `write`,
186212
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
187213
/// because it will attempt to drop the value previously at `*src`.
214+
///
215+
/// # Examples
216+
///
217+
/// Basic usage:
218+
///
219+
/// ```
220+
/// let x = 12;
221+
/// let y = &x as *const i32;
222+
///
223+
/// unsafe { println!("{}", std::ptr::read_volatile(y)); }
224+
/// ```
188225
#[inline]
189226
#[stable(feature = "volatile", since = "1.9.0")]
190227
pub unsafe fn read_volatile<T>(src: *const T) -> T {
@@ -217,6 +254,21 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
217254
///
218255
/// This is appropriate for initializing uninitialized memory, or overwriting
219256
/// memory that has previously been `read` from.
257+
///
258+
/// # Examples
259+
///
260+
/// Basic usage:
261+
///
262+
/// ```
263+
/// let mut x = 0;
264+
/// let y = &mut x as *mut i32;
265+
/// let z = 12;
266+
///
267+
/// unsafe {
268+
/// std::ptr::write_volatile(y, z);
269+
/// println!("{}", std::ptr::read_volatile(y));
270+
/// }
271+
/// ```
220272
#[inline]
221273
#[stable(feature = "volatile", since = "1.9.0")]
222274
pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {

src/librustc_resolve/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ crate-type = ["dylib"]
1212
log = { path = "../liblog" }
1313
syntax = { path = "../libsyntax" }
1414
rustc = { path = "../librustc" }
15-
rustc_bitflags = { path = "../librustc_bitflags" }
1615
arena = { path = "../libarena" }

src/librustc_resolve/build_reduced_graph.rs

+53-49
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//! Here we build the "reduced graph": the graph of the module tree without
1414
//! any imports resolved.
1515
16-
use DefModifiers;
1716
use resolve_imports::ImportDirectiveSubclass::{self, GlobImport};
1817
use Module;
1918
use Namespace::{self, TypeNS, ValueNS};
@@ -28,9 +27,9 @@ use rustc::hir::def::*;
2827
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
2928
use rustc::ty::{self, VariantKind};
3029

31-
use syntax::ast::Name;
30+
use syntax::ast::{Name, NodeId};
3231
use syntax::attr::AttrMetaMethods;
33-
use syntax::parse::token::{special_idents, SELF_KEYWORD_NAME, SUPER_KEYWORD_NAME};
32+
use syntax::parse::token::keywords;
3433
use syntax::codemap::{Span, DUMMY_SP};
3534

3635
use rustc::hir;
@@ -53,10 +52,9 @@ impl<'a> ToNameBinding<'a> for (Module<'a>, Span) {
5352
}
5453
}
5554

56-
impl<'a> ToNameBinding<'a> for (Def, Span, DefModifiers, ty::Visibility) {
55+
impl<'a> ToNameBinding<'a> for (Def, Span, ty::Visibility) {
5756
fn to_name_binding(self) -> NameBinding<'a> {
58-
let kind = NameBindingKind::Def(self.0);
59-
NameBinding { modifiers: self.2, kind: kind, span: Some(self.1), vis: self.3 }
57+
NameBinding { kind: NameBindingKind::Def(self.0), span: Some(self.1), vis: self.2 }
6058
}
6159
}
6260

@@ -100,12 +98,42 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
10098
block.stmts.iter().any(is_item)
10199
}
102100

101+
fn sanity_check_import(&self, view_path: &hir::ViewPath, id: NodeId) {
102+
let path = match view_path.node {
103+
ViewPathSimple(_, ref path) |
104+
ViewPathGlob (ref path) |
105+
ViewPathList(ref path, _) => path
106+
};
107+
108+
// Check for type parameters
109+
let found_param = path.segments.iter().any(|segment| {
110+
!segment.parameters.types().is_empty() ||
111+
!segment.parameters.lifetimes().is_empty() ||
112+
!segment.parameters.bindings().is_empty()
113+
});
114+
if found_param {
115+
self.session.span_err(path.span,
116+
"type or lifetime parameter is found in import path");
117+
}
118+
119+
// Checking for special identifiers in path
120+
// prevent `self` or `super` at beginning of global path
121+
if path.global && path.segments.len() > 0 {
122+
let first = path.segments[0].identifier.name;
123+
if first == keywords::Super.to_name() || first == keywords::SelfValue.to_name() {
124+
self.session.add_lint(
125+
lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span,
126+
format!("expected identifier, found keyword `{}`", first)
127+
);
128+
}
129+
}
130+
}
131+
103132
/// Constructs the reduced graph for one item.
104133
fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<'b>) {
105134
let parent = *parent_ref;
106135
let name = item.name;
107136
let sp = item.span;
108-
let modifiers = DefModifiers::IMPORTABLE;
109137
self.current_module = parent;
110138
let vis = self.resolve_visibility(&item.vis);
111139

@@ -114,10 +142,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
114142
// Extract and intern the module part of the path. For
115143
// globs and lists, the path is found directly in the AST;
116144
// for simple paths we have to munge the path a little.
117-
let is_global;
118145
let module_path: Vec<Name> = match view_path.node {
119146
ViewPathSimple(_, ref full_path) => {
120-
is_global = full_path.global;
121147
full_path.segments
122148
.split_last()
123149
.unwrap()
@@ -129,30 +155,17 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
129155

130156
ViewPathGlob(ref module_ident_path) |
131157
ViewPathList(ref module_ident_path, _) => {
132-
is_global = module_ident_path.global;
133158
module_ident_path.segments
134159
.iter()
135160
.map(|seg| seg.identifier.name)
136161
.collect()
137162
}
138163
};
139164

140-
// Checking for special identifiers in path
141-
// prevent `self` or `super` at beginning of global path
142-
if is_global && (module_path.first() == Some(&SELF_KEYWORD_NAME) ||
143-
module_path.first() == Some(&SUPER_KEYWORD_NAME)) {
144-
self.session.add_lint(
145-
lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH,
146-
item.id,
147-
item.span,
148-
format!("expected identifier, found keyword `{}`",
149-
module_path.first().unwrap().as_str()));
150-
}
165+
self.sanity_check_import(view_path, item.id);
151166

152167
// Build up the import directives.
153-
let is_prelude = item.attrs.iter().any(|attr| {
154-
attr.name() == special_idents::prelude_import.name.as_str()
155-
});
168+
let is_prelude = item.attrs.iter().any(|attr| attr.name() == "prelude_import");
156169

157170
match view_path.node {
158171
ViewPathSimple(binding, ref full_path) => {
@@ -268,21 +281,21 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
268281
ItemStatic(_, m, _) => {
269282
let mutbl = m == hir::MutMutable;
270283
let def = Def::Static(self.ast_map.local_def_id(item.id), mutbl);
271-
self.define(parent, name, ValueNS, (def, sp, modifiers, vis));
284+
self.define(parent, name, ValueNS, (def, sp, vis));
272285
}
273286
ItemConst(_, _) => {
274287
let def = Def::Const(self.ast_map.local_def_id(item.id));
275-
self.define(parent, name, ValueNS, (def, sp, modifiers, vis));
288+
self.define(parent, name, ValueNS, (def, sp, vis));
276289
}
277290
ItemFn(_, _, _, _, _, _) => {
278291
let def = Def::Fn(self.ast_map.local_def_id(item.id));
279-
self.define(parent, name, ValueNS, (def, sp, modifiers, vis));
292+
self.define(parent, name, ValueNS, (def, sp, vis));
280293
}
281294

282295
// These items live in the type namespace.
283296
ItemTy(..) => {
284297
let def = Def::TyAlias(self.ast_map.local_def_id(item.id));
285-
self.define(parent, name, TypeNS, (def, sp, modifiers, vis));
298+
self.define(parent, name, TypeNS, (def, sp, vis));
286299
}
287300

288301
ItemEnum(ref enum_definition, _) => {
@@ -301,13 +314,13 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
301314
ItemStruct(ref struct_def, _) => {
302315
// Define a name in the type namespace.
303316
let def = Def::Struct(self.ast_map.local_def_id(item.id));
304-
self.define(parent, name, TypeNS, (def, sp, modifiers, vis));
317+
self.define(parent, name, TypeNS, (def, sp, vis));
305318

306319
// If this is a newtype or unit-like struct, define a name
307320
// in the value namespace as well
308321
if !struct_def.is_struct() {
309322
let def = Def::Struct(self.ast_map.local_def_id(struct_def.id()));
310-
self.define(parent, name, ValueNS, (def, sp, modifiers, vis));
323+
self.define(parent, name, ValueNS, (def, sp, vis));
311324
}
312325

313326
// Record the def ID and fields of this struct.
@@ -339,8 +352,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
339352
hir::TypeTraitItem(..) => (Def::AssociatedTy(def_id, item_def_id), TypeNS),
340353
};
341354

342-
let modifiers = DefModifiers::empty(); // NB: not DefModifiers::IMPORTABLE
343-
self.define(module_parent, item.name, ns, (def, item.span, modifiers, vis));
355+
self.define(module_parent, item.name, ns, (def, item.span, vis));
344356

345357
self.trait_item_map.insert((item.name, def_id), item_def_id);
346358
}
@@ -363,19 +375,16 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
363375

364376
// Variants are always treated as importable to allow them to be glob used.
365377
// All variants are defined in both type and value namespaces as future-proofing.
366-
let modifiers = DefModifiers::IMPORTABLE;
367378
let def = Def::Variant(item_id, self.ast_map.local_def_id(variant.node.data.id()));
368-
369-
self.define(parent, name, ValueNS, (def, variant.span, modifiers, parent.vis));
370-
self.define(parent, name, TypeNS, (def, variant.span, modifiers, parent.vis));
379+
self.define(parent, name, ValueNS, (def, variant.span, parent.vis));
380+
self.define(parent, name, TypeNS, (def, variant.span, parent.vis));
371381
}
372382

373383
/// Constructs the reduced graph for one foreign item.
374384
fn build_reduced_graph_for_foreign_item(&mut self,
375385
foreign_item: &ForeignItem,
376386
parent: Module<'b>) {
377387
let name = foreign_item.name;
378-
let modifiers = DefModifiers::IMPORTABLE;
379388

380389
let def = match foreign_item.node {
381390
ForeignItemFn(..) => {
@@ -387,7 +396,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
387396
};
388397
self.current_module = parent;
389398
let vis = self.resolve_visibility(&foreign_item.vis);
390-
self.define(parent, name, ValueNS, (def, foreign_item.span, modifiers, vis));
399+
self.define(parent, name, ValueNS, (def, foreign_item.span, vis));
391400
}
392401

393402
fn build_reduced_graph_for_block(&mut self, block: &Block, parent: &mut Module<'b>) {
@@ -422,10 +431,6 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
422431

423432
let name = xcdef.name;
424433
let vis = if parent.is_trait() { ty::Visibility::Public } else { xcdef.vis };
425-
let modifiers = match parent.is_normal() {
426-
true => DefModifiers::IMPORTABLE,
427-
false => DefModifiers::empty(),
428-
};
429434

430435
match def {
431436
Def::Mod(_) | Def::ForeignMod(_) | Def::Enum(..) => {
@@ -439,9 +444,8 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
439444
debug!("(building reduced graph for external crate) building variant {}", name);
440445
// Variants are always treated as importable to allow them to be glob used.
441446
// All variants are defined in both type and value namespaces as future-proofing.
442-
let modifiers = DefModifiers::IMPORTABLE;
443-
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, modifiers, vis));
444-
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, modifiers, vis));
447+
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, vis));
448+
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, vis));
445449
if self.session.cstore.variant_kind(variant_id) == Some(VariantKind::Struct) {
446450
// Not adding fields for variants as they are not accessed with a self receiver
447451
self.structs.insert(variant_id, Vec::new());
@@ -454,7 +458,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
454458
Def::Method(..) => {
455459
debug!("(building reduced graph for external crate) building value (fn/static) {}",
456460
name);
457-
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, modifiers, vis));
461+
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, vis));
458462
}
459463
Def::Trait(def_id) => {
460464
debug!("(building reduced graph for external crate) building type {}", name);
@@ -480,16 +484,16 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
480484
}
481485
Def::TyAlias(..) | Def::AssociatedTy(..) => {
482486
debug!("(building reduced graph for external crate) building type {}", name);
483-
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, modifiers, vis));
487+
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, vis));
484488
}
485489
Def::Struct(def_id)
486490
if self.session.cstore.tuple_struct_definition_if_ctor(def_id).is_none() => {
487491
debug!("(building reduced graph for external crate) building type and value for {}",
488492
name);
489-
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, modifiers, vis));
493+
self.try_define(parent, name, TypeNS, (def, DUMMY_SP, vis));
490494
if let Some(ctor_def_id) = self.session.cstore.struct_ctor_def_id(def_id) {
491495
let def = Def::Struct(ctor_def_id);
492-
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, modifiers, vis));
496+
self.try_define(parent, name, ValueNS, (def, DUMMY_SP, vis));
493497
}
494498

495499
// Record the def ID and fields of this struct.

0 commit comments

Comments
 (0)