Skip to content

Commit c12e3b1

Browse files
committed
---
yaml --- r: 272807 b: refs/heads/beta c: 064f17c h: refs/heads/master i: 272805: 3aa51ed 272803: 490dcdb 272799: 04c45ad
1 parent 8f572f2 commit c12e3b1

File tree

12 files changed

+139
-216
lines changed

12 files changed

+139
-216
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 07a1803dd3ca02c16b9820d0102a9dfc9c5ab7a5
26+
refs/heads/beta: 064f17c6a39af65982aa4bc33eb12ac531b4b32a
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/bootstrap/build/sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn check(build: &mut Build) {
7979
}
8080

8181
// Make sure musl-root is valid if specified
82-
if target.contains("musl") && target.contains("x86_64") {
82+
if target.contains("musl") {
8383
match build.config.musl_root {
8484
Some(ref root) => {
8585
if fs::metadata(root.join("lib/libc.a")).is_err() {

branches/beta/src/doc/book/vectors.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -115,36 +115,6 @@ for i in v {
115115
}
116116
```
117117

118-
Note: You cannot use the vector again once you have iterated by taking ownership of the vector.
119-
You can iterate the vector multiple times by taking a reference to the vector whilst iterating.
120-
For example, the following code does not compile.
121-
122-
```rust,ignore
123-
let mut v = vec![1, 2, 3, 4, 5];
124-
125-
for i in v {
126-
println!("Take ownership of the vector and its element {}", i);
127-
}
128-
129-
for i in v {
130-
println!("Take ownership of the vector and its element {}", i);
131-
}
132-
```
133-
134-
Whereas the following works perfectly,
135-
136-
```rust
137-
let mut v = vec![1, 2, 3, 4, 5];
138-
139-
for i in &v {
140-
println!("This is a reference to {}", i);
141-
}
142-
143-
for i in &v {
144-
println!("This is a reference to {}", i);
145-
}
146-
```
147-
148118
Vectors have many more useful methods, which you can read about in [their
149119
API documentation][vec].
150120

branches/beta/src/libcore/iter.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ pub trait Iterator {
15321532
/// An iterator adaptor that applies a function, producing a single, final value.
15331533
///
15341534
/// `fold()` takes two arguments: an initial value, and a closure with two
1535-
/// arguments: an 'accumulator', and an element. The closure returns the value that
1535+
/// arguments: an 'accumulator', and an element. It returns the value that
15361536
/// the accumulator should have for the next iteration.
15371537
///
15381538
/// The initial value is the value the accumulator will have on the first
@@ -3851,17 +3851,6 @@ impl<I> Iterator for Skip<I> where I: Iterator {
38513851
#[stable(feature = "rust1", since = "1.0.0")]
38523852
impl<I> ExactSizeIterator for Skip<I> where I: ExactSizeIterator {}
38533853

3854-
#[stable(feature = "double_ended_skip_iterator", since = "1.8.0")]
3855-
impl<I> DoubleEndedIterator for Skip<I> where I: DoubleEndedIterator + ExactSizeIterator {
3856-
fn next_back(&mut self) -> Option<Self::Item> {
3857-
if self.len() > 0 {
3858-
self.iter.next_back()
3859-
} else {
3860-
None
3861-
}
3862-
}
3863-
}
3864-
38653854
/// An iterator that only iterates over the first `n` iterations of `iter`.
38663855
///
38673856
/// This `struct` is created by the [`take()`] method on [`Iterator`]. See its

branches/beta/src/libcore/str/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,8 @@ fn eq_slice(a: &str, b: &str) -> bool {
10951095
/// faster than comparing each byte in a loop.
10961096
#[inline]
10971097
unsafe fn cmp_slice(a: &str, b: &str, len: usize) -> i32 {
1098+
// NOTE: In theory n should be libc::size_t and not usize, but libc is not available here
1099+
#[allow(improper_ctypes)]
10981100
extern { fn memcmp(s1: *const i8, s2: *const i8, n: usize) -> i32; }
10991101
memcmp(a.as_ptr() as *const i8, b.as_ptr() as *const i8, len)
11001102
}

branches/beta/src/libcoretest/iter.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -303,44 +303,6 @@ fn test_iterator_skip() {
303303
assert_eq!(it.len(), 0);
304304
}
305305

306-
#[test]
307-
fn test_iterator_skip_doubleended() {
308-
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];
309-
let mut it = xs.iter().rev().skip(5);
310-
assert_eq!(it.next(), Some(&15));
311-
assert_eq!(it.by_ref().rev().next(), Some(&0));
312-
assert_eq!(it.next(), Some(&13));
313-
assert_eq!(it.by_ref().rev().next(), Some(&1));
314-
assert_eq!(it.next(), Some(&5));
315-
assert_eq!(it.by_ref().rev().next(), Some(&2));
316-
assert_eq!(it.next(), Some(&3));
317-
assert_eq!(it.next(), None);
318-
let mut it = xs.iter().rev().skip(5).rev();
319-
assert_eq!(it.next(), Some(&0));
320-
assert_eq!(it.rev().next(), Some(&15));
321-
let mut it_base = xs.iter();
322-
{
323-
let mut it = it_base.by_ref().skip(5).rev();
324-
assert_eq!(it.next(), Some(&30));
325-
assert_eq!(it.next(), Some(&20));
326-
assert_eq!(it.next(), Some(&19));
327-
assert_eq!(it.next(), Some(&17));
328-
assert_eq!(it.next(), Some(&16));
329-
assert_eq!(it.next(), Some(&15));
330-
assert_eq!(it.next(), Some(&13));
331-
assert_eq!(it.next(), None);
332-
}
333-
// make sure the skipped parts have not been consumed
334-
assert_eq!(it_base.next(), Some(&0));
335-
assert_eq!(it_base.next(), Some(&1));
336-
assert_eq!(it_base.next(), Some(&2));
337-
assert_eq!(it_base.next(), Some(&3));
338-
assert_eq!(it_base.next(), Some(&5));
339-
assert_eq!(it_base.next(), None);
340-
let it = xs.iter().skip(5).rev();
341-
assert_eq!(it.last(), Some(&13));
342-
}
343-
344306
#[test]
345307
fn test_iterator_skip_nth() {
346308
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];

branches/beta/src/librustc_resolve/build_reduced_graph.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
207207
ResolutionError::SelfImportsOnlyAllowedWithin);
208208
}
209209

210-
let subclass = SingleImport(binding, source_name);
210+
let subclass = ImportDirectiveSubclass::single(binding, source_name);
211211
self.build_import_directive(parent,
212212
module_path,
213213
subclass,
@@ -258,9 +258,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
258258
(module_path.to_vec(), name, rename)
259259
}
260260
};
261+
let subclass = ImportDirectiveSubclass::single(rename, name);
261262
self.build_import_directive(parent,
262263
module_path,
263-
SingleImport(rename, name),
264+
subclass,
264265
source_item.span,
265266
source_item.node.id(),
266267
is_public,
@@ -683,11 +684,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
683684
id: NodeId,
684685
is_public: bool,
685686
shadowable: Shadowable) {
686-
module_.unresolved_imports
687-
.borrow_mut()
688-
.push(ImportDirective::new(module_path, subclass, span, id, is_public, shadowable));
689-
self.unresolved_imports += 1;
690-
691687
if is_public {
692688
module_.inc_pub_count();
693689
}
@@ -696,7 +692,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
696692
// the appropriate flag.
697693

698694
match subclass {
699-
SingleImport(target, _) => {
695+
SingleImport { target, .. } => {
700696
module_.increment_outstanding_references_for(target, ValueNS);
701697
module_.increment_outstanding_references_for(target, TypeNS);
702698
}
@@ -710,6 +706,11 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
710706
}
711707
}
712708
}
709+
710+
module_.unresolved_imports
711+
.borrow_mut()
712+
.push(ImportDirective::new(module_path, subclass, span, id, is_public, shadowable));
713+
self.unresolved_imports += 1;
713714
}
714715
}
715716

branches/beta/src/librustc_resolve/resolve_imports.rs

Lines changed: 77 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,31 @@ use syntax::codemap::Span;
3232
use syntax::util::lev_distance::find_best_match_for_name;
3333

3434
use std::mem::replace;
35+
use std::cell::Cell;
3536

3637
/// Contains data for specific types of import directives.
37-
#[derive(Copy, Clone,Debug)]
38+
#[derive(Clone, Debug)]
3839
pub enum ImportDirectiveSubclass {
39-
SingleImport(Name /* target */, Name /* source */),
40+
SingleImport {
41+
target: Name,
42+
source: Name,
43+
type_determined: Cell<bool>,
44+
value_determined: Cell<bool>,
45+
},
4046
GlobImport,
4147
}
4248

49+
impl ImportDirectiveSubclass {
50+
pub fn single(target: Name, source: Name) -> Self {
51+
SingleImport {
52+
target: target,
53+
source: source,
54+
type_determined: Cell::new(false),
55+
value_determined: Cell::new(false),
56+
}
57+
}
58+
}
59+
4360
/// Whether an import can be shadowed by another import.
4461
#[derive(Debug,PartialEq,Clone,Copy)]
4562
pub enum Shadowable {
@@ -218,7 +235,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
218235
fn import_resolving_error(&self, e: ImportResolvingError<'b>) {
219236
// If it's a single failed import then create a "fake" import
220237
// resolution for it so that later resolve stages won't complain.
221-
if let SingleImport(target, _) = e.import_directive.subclass {
238+
if let SingleImport { target, .. } = e.import_directive.subclass {
222239
let dummy_binding = self.resolver.new_name_binding(NameBinding {
223240
modifiers: DefModifiers::PRELUDE,
224241
kind: NameBindingKind::Def(Def::Err),
@@ -304,15 +321,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
304321
.and_then(|containing_module| {
305322
// We found the module that the target is contained
306323
// within. Attempt to resolve the import within it.
307-
if let SingleImport(target, source) = import_directive.subclass {
308-
self.resolve_single_import(module_,
309-
containing_module,
310-
target,
311-
source,
312-
import_directive)
313-
} else {
314-
self.resolve_glob_import(module_, containing_module, import_directive)
315-
}
324+
self.resolve_import(module_, containing_module, import_directive)
316325
})
317326
.and_then(|()| {
318327
// Decrement the count of unresolved imports.
@@ -332,36 +341,53 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
332341
})
333342
}
334343

335-
fn resolve_single_import(&mut self,
336-
module_: Module<'b>,
337-
target_module: Module<'b>,
338-
target: Name,
339-
source: Name,
340-
directive: &ImportDirective)
341-
-> ResolveResult<()> {
342-
debug!("(resolving single import) resolving `{}` = `{}::{}` from `{}` id {}",
343-
target,
344-
module_to_string(&target_module),
345-
source,
346-
module_to_string(module_),
347-
directive.id);
348-
349-
// If this is a circular import, we temporarily count it as determined so that
350-
// it fails (as opposed to being indeterminate) when nothing else can define it.
351-
if target_module.def_id() == module_.def_id() && source == target {
352-
module_.decrement_outstanding_references_for(target, ValueNS);
353-
module_.decrement_outstanding_references_for(target, TypeNS);
354-
}
344+
fn resolve_import(&mut self,
345+
module_: Module<'b>,
346+
target_module: Module<'b>,
347+
directive: &ImportDirective)
348+
-> ResolveResult<()> {
349+
let (source, target, value_determined, type_determined) = match directive.subclass {
350+
SingleImport { source, target, ref value_determined, ref type_determined } =>
351+
(source, target, value_determined, type_determined),
352+
GlobImport => return self.resolve_glob_import(module_, target_module, directive),
353+
};
355354

356355
// We need to resolve both namespaces for this to succeed.
357-
let value_result =
358-
self.resolver.resolve_name_in_module(target_module, source, ValueNS, false, true);
359-
let type_result =
360-
self.resolver.resolve_name_in_module(target_module, source, TypeNS, false, true);
361-
362-
if target_module.def_id() == module_.def_id() && source == target {
363-
module_.increment_outstanding_references_for(target, ValueNS);
364-
module_.increment_outstanding_references_for(target, TypeNS);
356+
let (value_result, type_result) = {
357+
let mut resolve_in_ns = |ns, determined: bool| {
358+
// Temporarily count the directive as determined so that the resolution fails
359+
// (as opposed to being indeterminate) when it can only be defined by the directive.
360+
if !determined { module_.decrement_outstanding_references_for(target, ns) }
361+
let result =
362+
self.resolver.resolve_name_in_module(target_module, source, ns, false, true);
363+
if !determined { module_.increment_outstanding_references_for(target, ns) }
364+
result
365+
};
366+
(resolve_in_ns(ValueNS, value_determined.get()),
367+
resolve_in_ns(TypeNS, type_determined.get()))
368+
};
369+
370+
for &(ns, result, determined) in &[(ValueNS, &value_result, value_determined),
371+
(TypeNS, &type_result, type_determined)] {
372+
if determined.get() { continue }
373+
if let Indeterminate = *result { continue }
374+
375+
determined.set(true);
376+
if let Success(binding) = *result {
377+
if !binding.defined_with(DefModifiers::IMPORTABLE) {
378+
let msg = format!("`{}` is not directly importable", target);
379+
span_err!(self.resolver.session, directive.span, E0253, "{}", &msg);
380+
}
381+
382+
let privacy_error = if !self.resolver.is_visible(binding, target_module) {
383+
Some(Box::new(PrivacyError(directive.span, source, binding)))
384+
} else {
385+
None
386+
};
387+
388+
self.define(module_, target, ns, directive.import(binding, privacy_error));
389+
}
390+
module_.decrement_outstanding_references_for(target, ns);
365391
}
366392

367393
match (&value_result, &type_result) {
@@ -425,37 +451,22 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
425451
_ => {}
426452
}
427453

454+
// Report a privacy error here if all successful namespaces are privacy errors.
428455
let mut privacy_error = None;
429-
let mut report_privacy_error = true;
430-
for &(ns, result) in &[(ValueNS, &value_result), (TypeNS, &type_result)] {
431-
if let Success(binding) = *result {
432-
if !binding.defined_with(DefModifiers::IMPORTABLE) {
433-
let msg = format!("`{}` is not directly importable", target);
434-
span_err!(self.resolver.session, directive.span, E0253, "{}", &msg);
435-
}
436-
437-
privacy_error = if !self.resolver.is_visible(binding, target_module) {
438-
Some(Box::new(PrivacyError(directive.span, source, binding)))
439-
} else {
440-
report_privacy_error = false;
441-
None
442-
};
443-
444-
self.define(module_, target, ns, directive.import(binding, privacy_error.clone()));
445-
}
446-
}
447-
448-
if report_privacy_error { // then all successful namespaces are privacy errors
449-
// We report here so there is an error even if the imported name is not used
450-
self.resolver.privacy_errors.push(*privacy_error.unwrap());
456+
for &ns in &[ValueNS, TypeNS] {
457+
privacy_error = match module_.resolve_name(target, ns, true) {
458+
Success(&NameBinding {
459+
kind: NameBindingKind::Import { ref privacy_error, .. }, ..
460+
}) => privacy_error.as_ref().map(|error| (**error).clone()),
461+
_ => continue,
462+
};
463+
if privacy_error.is_none() { break }
451464
}
465+
privacy_error.map(|error| self.resolver.privacy_errors.push(error));
452466

453467
// Record what this import resolves to for later uses in documentation,
454468
// this may resolve to either a value or a type, but for documentation
455469
// purposes it's good enough to just favor one over the other.
456-
module_.decrement_outstanding_references_for(target, ValueNS);
457-
module_.decrement_outstanding_references_for(target, TypeNS);
458-
459470
let def = match type_result.success().and_then(NameBinding::def) {
460471
Some(def) => def,
461472
None => value_result.success().and_then(NameBinding::def).unwrap(),
@@ -610,7 +621,7 @@ fn import_path_to_string(names: &[Name], subclass: ImportDirectiveSubclass) -> S
610621

611622
fn import_directive_subclass_to_string(subclass: ImportDirectiveSubclass) -> String {
612623
match subclass {
613-
SingleImport(_, source) => source.to_string(),
624+
SingleImport { source, .. } => source.to_string(),
614625
GlobImport => "*".to_string(),
615626
}
616627
}

0 commit comments

Comments
 (0)