Skip to content

Commit 09e431b

Browse files
committed
---
yaml --- r: 275194 b: refs/heads/stable c: 05485be h: refs/heads/master
1 parent bccf79b commit 09e431b

File tree

34 files changed

+279
-135
lines changed

34 files changed

+279
-135
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: c0221c8897db309a79990367476177b1230bb264
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 128283347086ff307b39c8c848d0831c6dcf576a
32+
refs/heads/stable: 05485be02f25526abeeb1e715abe532a31e0acd6
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/doc/book/iterators.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,12 @@ for i in (1..100).filter(|&x| x % 2 == 0) {
311311
```
312312

313313
This will print all of the even numbers between one and a hundred.
314-
(Note that because `filter` doesn't consume the elements that are
315-
being iterated over, it is passed a reference to each element, and
316-
thus the filter predicate uses the `&x` pattern to extract the integer
317-
itself.)
314+
(Note that, unlike `map`, the closure passed to `filter` is passed a reference
315+
to the element instead of the element itself. The filter predicate here uses
316+
the `&x` pattern to extract the integer. The filter closure is passed a
317+
reference because it returns `true` or `false` instead of the element,
318+
so the `filter` implementation must retain ownership to put the elements
319+
into the newly constructed iterator.)
318320

319321
You can chain all three things together: start with an iterator, adapt it
320322
a few times, and then consume the result. Check it out:

branches/stable/src/doc/book/ownership.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ this point of time). These two parts of the vector (the one on the stack and
157157
one on the heap) must agree with each other at all times with regards to
158158
things like the length, capacity etc.
159159

160-
When we move `v` to `v2`, rust actually does a bitwise copy of the vector
160+
When we move `v` to `v2`, Rust actually does a bitwise copy of the vector
161161
object `v` into the stack allocation represented by `v2`. This shallow copy
162162
does not create a copy of the heap allocation containing the actual data.
163163
Which means that there would be two pointers to the contents of the vector

branches/stable/src/doc/nomicon/other-reprs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ These reprs have no effect on a struct.
5757

5858
# repr(packed)
5959

60-
`repr(packed)` forces rust to strip any padding, and only align the type to a
60+
`repr(packed)` forces Rust to strip any padding, and only align the type to a
6161
byte. This may improve the memory footprint, but will likely have other negative
6262
side-effects.
6363

branches/stable/src/doc/reference.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,8 @@ extern crate std as ruststd; // linking to 'std' under another name
841841

842842
A _use declaration_ creates one or more local name bindings synonymous with
843843
some other [path](#paths). Usually a `use` declaration is used to shorten the
844-
path required to refer to a module item. These declarations may appear at the
845-
top of [modules](#modules) and [blocks](grammar.html#block-expressions).
844+
path required to refer to a module item. These declarations may appear in
845+
[modules](#modules) and [blocks](grammar.html#block-expressions), usually at the top.
846846

847847
> **Note**: Unlike in many languages,
848848
> `use` declarations in Rust do *not* declare linkage dependency with external crates.
@@ -1764,7 +1764,7 @@ pub mod submodule {
17641764
# fn main() {}
17651765
```
17661766

1767-
For a rust program to pass the privacy checking pass, all paths must be valid
1767+
For a Rust program to pass the privacy checking pass, all paths must be valid
17681768
accesses given the two rules above. This includes all use statements,
17691769
expressions, types, etc.
17701770

@@ -3564,8 +3564,9 @@ Each instance of a trait object includes:
35643564
each method of `SomeTrait` that `T` implements, a pointer to `T`'s
35653565
implementation (i.e. a function pointer).
35663566

3567-
The purpose of trait objects is to permit "late binding" of methods. A call to
3568-
a method on a trait object is only resolved to a vtable entry at compile time.
3567+
The purpose of trait objects is to permit "late binding" of methods. Calling a
3568+
method on a trait object results in virtual dispatch at runtime: that is, a
3569+
function pointer is loaded from the trait object vtable and invoked indirectly.
35693570
The actual implementation for each vtable entry can vary on an object-by-object
35703571
basis.
35713572

branches/stable/src/libcollections/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl<T> [T] {
407407
}
408408

409409
/// Returns an iterator over `size` elements of the slice at a
410-
/// time. The chunks do not overlap. If `size` does not divide the
410+
/// time. The chunks are slices and do not overlap. If `size` does not divide the
411411
/// length of the slice, then the last chunk will not have length
412412
/// `size`.
413413
///
@@ -433,7 +433,7 @@ impl<T> [T] {
433433
}
434434

435435
/// Returns an iterator over `chunk_size` elements of the slice at a time.
436-
/// The chunks are mutable and do not overlap. If `chunk_size` does
436+
/// The chunks are mutable slices, and do not overlap. If `chunk_size` does
437437
/// not divide the length of the slice, then the last chunk will not
438438
/// have length `chunk_size`.
439439
///

branches/stable/src/libcollections/vec.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,49 @@ use super::range::RangeArgument;
135135
/// }
136136
/// ```
137137
///
138+
/// # Indexing
139+
///
140+
/// The Vec type allows to access values by index, because it implements the
141+
/// `Index` trait. An example will be more explicit:
142+
///
143+
/// ```
144+
/// let v = vec!(0, 2, 4, 6);
145+
/// println!("{}", v[1]); // it will display '2'
146+
/// ```
147+
///
148+
/// However be careful: if you try to access an index which isn't in the Vec,
149+
/// your software will panic! You cannot do this:
150+
///
151+
/// ```ignore
152+
/// let v = vec!(0, 2, 4, 6);
153+
/// println!("{}", v[6]); // it will panic!
154+
/// ```
155+
///
156+
/// In conclusion: always check if the index you want to get really exists
157+
/// before doing it.
158+
///
159+
/// # Slicing
160+
///
161+
/// A Vec can be mutable. Slices, on the other hand, are read-only objects.
162+
/// To get a slice, use "&". Example:
163+
///
164+
/// ```
165+
/// fn read_slice(slice: &[usize]) {
166+
/// // ...
167+
/// }
168+
///
169+
/// let v = vec!(0, 1);
170+
/// read_slice(&v);
171+
///
172+
/// // ... and that's all!
173+
/// // you can also do it like this:
174+
/// let x : &[usize] = &v;
175+
/// ```
176+
///
177+
/// In Rust, it's more common to pass slices as arguments rather than vectors
178+
/// when you just want to provide a read access. The same goes for String and
179+
/// &str.
180+
///
138181
/// # Capacity and reallocation
139182
///
140183
/// The capacity of a vector is the amount of space allocated for any future

branches/stable/src/libgetopts/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,8 @@ impl Matches {
331331
/// Returns the string argument supplied to one of several matching options or `None`.
332332
pub fn opts_str(&self, names: &[String]) -> Option<String> {
333333
for nm in names {
334-
match self.opt_val(&nm[..]) {
335-
Some(Val(ref s)) => return Some(s.clone()),
336-
_ => (),
334+
if let Some(Val(ref s)) = self.opt_val(&nm[..]) {
335+
return Some(s.clone())
337336
}
338337
}
339338
None

branches/stable/src/librustc/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern crate getopts;
5151
extern crate graphviz;
5252
extern crate libc;
5353
extern crate rbml;
54-
extern crate rustc_llvm;
54+
pub extern crate rustc_llvm as llvm;
5555
extern crate rustc_back;
5656
extern crate rustc_front;
5757
extern crate rustc_data_structures;
@@ -66,8 +66,6 @@ extern crate serialize as rustc_serialize; // used by deriving
6666
#[cfg(test)]
6767
extern crate test;
6868

69-
pub use rustc_llvm as llvm;
70-
7169
#[macro_use]
7270
mod macros;
7371

branches/stable/src/librustc/lint/builtin.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ declare_lint! {
124124
"detect private items in public interfaces not caught by the old implementation"
125125
}
126126

127+
declare_lint! {
128+
pub INACCESSIBLE_EXTERN_CRATE,
129+
Warn,
130+
"use of inaccessible extern crate erroneously allowed"
131+
}
132+
127133
declare_lint! {
128134
pub INVALID_TYPE_PARAM_DEFAULT,
129135
Warn,
@@ -167,6 +173,7 @@ impl LintPass for HardwiredLints {
167173
TRIVIAL_CASTS,
168174
TRIVIAL_NUMERIC_CASTS,
169175
PRIVATE_IN_PUBLIC,
176+
INACCESSIBLE_EXTERN_CRATE,
170177
INVALID_TYPE_PARAM_DEFAULT,
171178
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
172179
CONST_ERR,

branches/stable/src/librustc_lint/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
158158
id: LintId::of(PRIVATE_IN_PUBLIC),
159159
reference: "the explanation for E0446 (`--explain E0446`)",
160160
},
161+
FutureIncompatibleInfo {
162+
id: LintId::of(INACCESSIBLE_EXTERN_CRATE),
163+
reference: "PR 31362 <https://github.com/rust-lang/rust/pull/31362>",
164+
},
161165
FutureIncompatibleInfo {
162166
id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
163167
reference: "PR 30742 <https://github.com/rust-lang/rust/pull/30724>",

branches/stable/src/librustc_privacy/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
743743
source_did: Option<DefId>,
744744
msg: &str)
745745
-> CheckResult {
746+
use rustc_front::hir::Item_::ItemExternCrate;
746747
debug!("ensure_public(span={:?}, to_check={:?}, source_did={:?}, msg={:?})",
747748
span, to_check, source_did, msg);
748749
let def_privacy = self.def_privacy(to_check);
@@ -763,6 +764,21 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
763764
// be local.)
764765
let def_id = source_did.unwrap_or(to_check);
765766
let node_id = self.tcx.map.as_local_node_id(def_id);
767+
768+
// Warn when using a inaccessible extern crate.
769+
if let Some(node_id) = self.tcx.map.as_local_node_id(to_check) {
770+
match self.tcx.map.get(node_id) {
771+
ast_map::Node::NodeItem(&hir::Item { node: ItemExternCrate(_), name, .. }) => {
772+
self.tcx.sess.add_lint(lint::builtin::INACCESSIBLE_EXTERN_CRATE,
773+
node_id,
774+
span,
775+
format!("extern crate `{}` is private", name));
776+
return None;
777+
}
778+
_ => {}
779+
}
780+
}
781+
766782
let (err_span, err_msg) = if Some(id) == node_id {
767783
return Some((span, format!("{} is private", msg), None));
768784
} else {

branches/stable/src/librustc_resolve/build_reduced_graph.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,19 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
293293
self.external_exports.insert(def_id);
294294
let parent_link = ModuleParentLink(parent, name);
295295
let def = Def::Mod(def_id);
296-
let external_module = self.new_extern_crate_module(parent_link, def);
296+
let local_def_id = self.ast_map.local_def_id(item.id);
297+
let external_module =
298+
self.new_extern_crate_module(parent_link, def, is_public, local_def_id);
297299
self.define(parent, name, TypeNS, (external_module, sp));
298300

301+
if is_public {
302+
let export = Export { name: name, def_id: def_id };
303+
if let Some(def_id) = parent.def_id() {
304+
let node_id = self.resolver.ast_map.as_local_node_id(def_id).unwrap();
305+
self.export_map.entry(node_id).or_insert(Vec::new()).push(export);
306+
}
307+
}
308+
299309
self.build_reduced_graph_for_external_crate(external_module);
300310
}
301311
parent

branches/stable/src/librustc_resolve/lib.rs

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,10 @@ pub struct ModuleS<'a> {
806806
parent_link: ParentLink<'a>,
807807
def: Option<Def>,
808808
is_public: bool,
809-
is_extern_crate: bool,
809+
810+
// If the module is an extern crate, `def` is root of the external crate and `extern_crate_did`
811+
// is the DefId of the local `extern crate` item (otherwise, `extern_crate_did` is None).
812+
extern_crate_did: Option<DefId>,
810813

811814
resolutions: RefCell<HashMap<(Name, Namespace), NameResolution<'a>>>,
812815
unresolved_imports: RefCell<Vec<ImportDirective>>,
@@ -853,7 +856,7 @@ impl<'a> ModuleS<'a> {
853856
parent_link: parent_link,
854857
def: def,
855858
is_public: is_public,
856-
is_extern_crate: false,
859+
extern_crate_did: None,
857860
resolutions: RefCell::new(HashMap::new()),
858861
unresolved_imports: RefCell::new(Vec::new()),
859862
module_children: RefCell::new(NodeMap()),
@@ -917,6 +920,16 @@ impl<'a> ModuleS<'a> {
917920
self.def.as_ref().map(Def::def_id)
918921
}
919922

923+
// This returns the DefId of the crate local item that controls this module's visibility.
924+
// It is only used to compute `LastPrivate` data, and it differs from `def_id` only for extern
925+
// crates, whose `def_id` is the external crate's root, not the local `extern crate` item.
926+
fn local_def_id(&self) -> Option<DefId> {
927+
match self.extern_crate_did {
928+
Some(def_id) => Some(def_id),
929+
None => self.def_id(),
930+
}
931+
}
932+
920933
fn is_normal(&self) -> bool {
921934
match self.def {
922935
Some(Def::Mod(_)) | Some(Def::ForeignMod(_)) => true,
@@ -1027,6 +1040,14 @@ impl<'a> NameBinding<'a> {
10271040
}
10281041
}
10291042

1043+
fn local_def_id(&self) -> Option<DefId> {
1044+
match self.kind {
1045+
NameBindingKind::Def(def) => Some(def.def_id()),
1046+
NameBindingKind::Module(ref module) => module.local_def_id(),
1047+
NameBindingKind::Import { binding, .. } => binding.local_def_id(),
1048+
}
1049+
}
1050+
10301051
fn defined_with(&self, modifiers: DefModifiers) -> bool {
10311052
self.modifiers.contains(modifiers)
10321053
}
@@ -1038,11 +1059,12 @@ impl<'a> NameBinding<'a> {
10381059
fn def_and_lp(&self) -> (Def, LastPrivate) {
10391060
let def = self.def().unwrap();
10401061
if let Def::Err = def { return (def, LastMod(AllPublic)) }
1041-
(def, LastMod(if self.is_public() { AllPublic } else { DependsOn(def.def_id()) }))
1062+
let lp = if self.is_public() { AllPublic } else { DependsOn(self.local_def_id().unwrap()) };
1063+
(def, LastMod(lp))
10421064
}
10431065

10441066
fn is_extern_crate(&self) -> bool {
1045-
self.module().map(|module| module.is_extern_crate).unwrap_or(false)
1067+
self.module().and_then(|module| module.extern_crate_did).is_some()
10461068
}
10471069

10481070
fn is_import(&self) -> bool {
@@ -1236,9 +1258,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12361258
self.arenas.name_bindings.alloc(name_binding)
12371259
}
12381260

1239-
fn new_extern_crate_module(&self, parent_link: ParentLink<'a>, def: Def) -> Module<'a> {
1240-
let mut module = ModuleS::new(parent_link, Some(def), false, true);
1241-
module.is_extern_crate = true;
1261+
fn new_extern_crate_module(&self,
1262+
parent_link: ParentLink<'a>,
1263+
def: Def,
1264+
is_public: bool,
1265+
local_def: DefId)
1266+
-> Module<'a> {
1267+
let mut module = ModuleS::new(parent_link, Some(def), false, is_public);
1268+
module.extern_crate_did = Some(local_def);
12421269
self.arenas.modules.alloc(module)
12431270
}
12441271

@@ -1357,7 +1384,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13571384
// Keep track of the closest private module used
13581385
// when resolving this import chain.
13591386
if !binding.is_public() {
1360-
if let Some(did) = search_module.def_id() {
1387+
if let Some(did) = search_module.local_def_id() {
13611388
closest_private = LastMod(DependsOn(did));
13621389
}
13631390
}
@@ -1462,7 +1489,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14621489
Success(PrefixFound(ref containing_module, index)) => {
14631490
search_module = containing_module;
14641491
start_index = index;
1465-
last_private = LastMod(DependsOn(containing_module.def_id()
1492+
last_private = LastMod(DependsOn(containing_module.local_def_id()
14661493
.unwrap()));
14671494
}
14681495
}
@@ -3571,7 +3598,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
35713598

35723599
if !in_module_is_extern || name_binding.is_public() {
35733600
// add the module to the lookup
3574-
let is_extern = in_module_is_extern || module.is_extern_crate;
3601+
let is_extern = in_module_is_extern || name_binding.is_extern_crate();
35753602
worklist.push((module, path_segments, is_extern));
35763603
}
35773604
}

0 commit comments

Comments
 (0)