Skip to content

Commit b4c3e3e

Browse files
committed
---
yaml --- r: 235004 b: refs/heads/stable c: 8536152 h: refs/heads/master v: v3
1 parent bc0ae06 commit b4c3e3e

File tree

22 files changed

+426
-330
lines changed

22 files changed

+426
-330
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: e834c0348fe094da4f32594278fee6b0446cb41c
32+
refs/heads/stable: 85361528bc8f3880a2b2cffd15023c20bfe98282
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
% The (old) Rust Pointer Guide
1+
% The Rust Pointer Guide
22

3-
This content has moved into
4-
[the Rust Programming Language book](book/pointers.html).
3+
This content has been removed, with no direct replacement. Rust only
4+
has two built-in pointer types now,
5+
[references](book/references-and-borrowing.html) and [raw
6+
pointers](book/raw-pointers.html). Older Rusts had many more pointer
7+
types, they’re gone now.

branches/stable/src/doc/trpl/academic-research.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Recommended for inspiration and a better understanding of Rust's background.
1212
* [Macros that work together](https://www.cs.utah.edu/plt/publications/jfp12-draft-fcdf.pdf)
1313
* [Traits: composable units of behavior](http://scg.unibe.ch/archive/papers/Scha03aTraits.pdf)
1414
* [Alias burying](http://www.cs.uwm.edu/faculty/boyland/papers/unique-preprint.ps) - We tried something similar and abandoned it.
15-
* [External uniqueness is unique enough](http://www.computingscience.nl/research/techreps/repo/CS-2002/2002-048.pdf)
15+
* [External uniqueness is unique enough](http://www.cs.uu.nl/research/techreps/UU-CS-2002-048.html)
1616
* [Uniqueness and Reference Immutability for Safe Parallelism](https://research.microsoft.com/pubs/170528/msr-tr-2012-79.pdf)
1717
* [Region Based Memory Management](http://www.cs.ucla.edu/~palsberg/tba/papers/tofte-talpin-iandc97.pdf)
1818

@@ -26,10 +26,10 @@ Recommended for inspiration and a better understanding of Rust's background.
2626
* [Dynamic circular work stealing deque](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.170.1097&rep=rep1&type=pdf) - The Chase/Lev deque
2727
* [Work-first and help-first scheduling policies for async-finish task parallelism](http://www.cs.rice.edu/%7Eyguo/pubs/PID824943.pdf) - More general than fully-strict work stealing
2828
* [A Java fork/join calamity](http://www.coopsoft.com/ar/CalamityArticle.html) - critique of Java's fork/join library, particularly its application of work stealing to non-strict computation
29-
* [Scheduling techniques for concurrent systems](http://www.ece.rutgers.edu/%7Eparashar/Classes/ece572-papers/05/ps-ousterhout.pdf)
29+
* [Scheduling techniques for concurrent systems](http://www.stanford.edu/~ouster/cgi-bin/papers/coscheduling.pdf)
3030
* [Contention aware scheduling](http://www.blagodurov.net/files/a8-blagodurov.pdf)
3131
* [Balanced work stealing for time-sharing multicores](http://www.cse.ohio-state.edu/hpcs/WWW/HTML/publications/papers/TR-12-1.pdf)
32-
* [Three layer cake](http://www.upcrc.illinois.edu/workshops/paraplop10/papers/paraplop10_submission_8.pdf)
32+
* [Three layer cake for shared-memory programming](http://dl.acm.org/citation.cfm?id=1953616&dl=ACM&coll=DL&CFID=524387192&CFTOKEN=44362705)
3333
* [Non-blocking steal-half work queues](http://www.cs.bgu.ac.il/%7Ehendlerd/papers/p280-hendler.pdf)
3434
* [Reagents: expressing and composing fine-grained concurrency](http://www.mpi-sws.org/~turon/reagents.pdf)
3535
* [Algorithms for scalable synchronization of shared-memory multiprocessors](https://www.cs.rochester.edu/u/scott/papers/1991_TOCS_synch.pdf)

branches/stable/src/libcore/mem.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,48 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
365365

366366
/// Disposes of a value.
367367
///
368-
/// This function can be used to destroy any value by allowing `drop` to take ownership of its
369-
/// argument.
368+
/// While this does call the argument's implementation of `Drop`, it will not
369+
/// release any borrows, as borrows are based on lexical scope.
370370
///
371371
/// # Examples
372372
///
373+
/// Basic usage:
374+
///
375+
/// ```
376+
/// let v = vec![1, 2, 3];
377+
///
378+
/// drop(v); // explicitly drop the vector
379+
/// ```
380+
///
381+
/// Borrows are based on lexical scope, so this produces an error:
382+
///
383+
/// ```ignore
384+
/// let mut v = vec![1, 2, 3];
385+
/// let x = &v[0];
386+
///
387+
/// drop(x); // explicitly drop the reference, but the borrow still exists
388+
///
389+
/// v.push(4); // error: cannot borrow `v` as mutable because it is also
390+
/// // borrowed as immutable
391+
/// ```
392+
///
393+
/// An inner scope is needed to fix this:
394+
///
395+
/// ```
396+
/// let mut v = vec![1, 2, 3];
397+
///
398+
/// {
399+
/// let x = &v[0];
400+
///
401+
/// drop(x); // this is now redundant, as `x` is going out of scope anyway
402+
/// }
403+
///
404+
/// v.push(4); // no problems
405+
/// ```
406+
///
407+
/// Since `RefCell` enforces the borrow rules at runtime, `drop()` can
408+
/// seemingly release a borrow of one:
409+
///
373410
/// ```
374411
/// use std::cell::RefCell;
375412
///

branches/stable/src/librustc/middle/infer/higher_ranked/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ fn fold_regions_in<'tcx, T, F>(tcx: &ty::ctxt<'tcx>,
359359
where T: TypeFoldable<'tcx>,
360360
F: FnMut(ty::Region, ty::DebruijnIndex) -> ty::Region,
361361
{
362-
unbound_value.fold_with(&mut ty_fold::RegionFolder::new(tcx, &mut |region, current_depth| {
362+
ty_fold::fold_regions(tcx, unbound_value, &mut false, |region, current_depth| {
363363
// we should only be encountering "escaping" late-bound regions here,
364364
// because the ones at the current level should have been replaced
365365
// with fresh variables
@@ -369,7 +369,7 @@ fn fold_regions_in<'tcx, T, F>(tcx: &ty::ctxt<'tcx>,
369369
});
370370

371371
fldr(region, ty::DebruijnIndex::new(current_depth))
372-
}))
372+
})
373373
}
374374

375375
impl<'a,'tcx> InferCtxtExt for InferCtxt<'a,'tcx> {
@@ -437,11 +437,10 @@ impl<'a,'tcx> InferCtxtExt for InferCtxt<'a,'tcx> {
437437
let escaping_types =
438438
self.type_variables.borrow().types_escaping_snapshot(&snapshot.type_snapshot);
439439

440-
let escaping_region_vars: FnvHashSet<_> =
441-
escaping_types
442-
.iter()
443-
.flat_map(|&t| ty_fold::collect_regions(self.tcx, &t))
444-
.collect();
440+
let mut escaping_region_vars = FnvHashSet();
441+
for ty in &escaping_types {
442+
ty_fold::collect_regions(self.tcx, ty, &mut escaping_region_vars);
443+
}
445444

446445
region_vars.retain(|&region_vid| {
447446
let r = ty::ReInfer(ty::ReVar(region_vid));
@@ -649,7 +648,7 @@ pub fn plug_leaks<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>,
649648
// binder is that we encountered in `value`. The caller is
650649
// responsible for ensuring that (a) `value` contains at least one
651650
// binder and (b) that binder is the one we want to use.
652-
let result = ty_fold::fold_regions(infcx.tcx, &value, |r, current_depth| {
651+
let result = ty_fold::fold_regions(infcx.tcx, &value, &mut false, |r, current_depth| {
653652
match inv_skol_map.get(&r) {
654653
None => r,
655654
Some(br) => {

branches/stable/src/librustc/middle/traits/fulfill.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,16 +421,18 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
421421
// regions. If there are, we will call this obligation an
422422
// error. Eventually we should be able to support some
423423
// cases here, I imagine (e.g., `for<'a> int : 'a`).
424-
if selcx.tcx().count_late_bound_regions(binder) != 0 {
425-
errors.push(
426-
FulfillmentError::new(
427-
obligation.clone(),
428-
CodeSelectionError(Unimplemented)));
429-
} else {
430-
let ty::OutlivesPredicate(t_a, r_b) = binder.0;
431-
register_region_obligation(t_a, r_b,
432-
obligation.cause.clone(),
433-
region_obligations);
424+
match selcx.tcx().no_late_bound_regions(binder) {
425+
None => {
426+
errors.push(
427+
FulfillmentError::new(
428+
obligation.clone(),
429+
CodeSelectionError(Unimplemented)))
430+
}
431+
Some(ty::OutlivesPredicate(t_a, r_b)) => {
432+
register_region_obligation(t_a, r_b,
433+
obligation.cause.clone(),
434+
region_obligations);
435+
}
434436
}
435437
true
436438
}
@@ -501,5 +503,3 @@ impl<'tcx> FulfilledPredicates<'tcx> {
501503
!self.set.insert(p.clone())
502504
}
503505
}
504-
505-

branches/stable/src/librustc/middle/ty.rs

Lines changed: 36 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,16 @@ impl Region {
17131713
_ => false,
17141714
}
17151715
}
1716+
1717+
/// Returns the depth of `self` from the (1-based) binding level `depth`
1718+
pub fn from_depth(&self, depth: u32) -> Region {
1719+
match *self {
1720+
ty::ReLateBound(debruijn, r) => ty::ReLateBound(DebruijnIndex {
1721+
depth: debruijn.depth - (depth - 1)
1722+
}, r),
1723+
r => r
1724+
}
1725+
}
17161726
}
17171727

17181728
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash,
@@ -6783,60 +6793,6 @@ pub enum ExplicitSelfCategory {
67836793
ByBoxExplicitSelfCategory,
67846794
}
67856795

6786-
impl<'tcx> TyS<'tcx> {
6787-
/// Pushes all the lifetimes in the given type onto the given list. A
6788-
/// "lifetime in a type" is a lifetime specified by a reference or a lifetime
6789-
/// in a list of type substitutions. This does *not* traverse into nominal
6790-
/// types, nor does it resolve fictitious types.
6791-
pub fn accumulate_lifetimes_in_type(&self, accumulator: &mut Vec<ty::Region>) {
6792-
for ty in self.walk() {
6793-
match ty.sty {
6794-
TyRef(region, _) => {
6795-
accumulator.push(*region)
6796-
}
6797-
TyTrait(ref t) => {
6798-
accumulator.push_all(t.principal.0.substs.regions().as_slice());
6799-
}
6800-
TyEnum(_, substs) |
6801-
TyStruct(_, substs) => {
6802-
accum_substs(accumulator, substs);
6803-
}
6804-
TyClosure(_, substs) => {
6805-
accum_substs(accumulator, substs);
6806-
}
6807-
TyBool |
6808-
TyChar |
6809-
TyInt(_) |
6810-
TyUint(_) |
6811-
TyFloat(_) |
6812-
TyBox(_) |
6813-
TyStr |
6814-
TyArray(_, _) |
6815-
TySlice(_) |
6816-
TyRawPtr(_) |
6817-
TyBareFn(..) |
6818-
TyTuple(_) |
6819-
TyProjection(_) |
6820-
TyParam(_) |
6821-
TyInfer(_) |
6822-
TyError => {
6823-
}
6824-
}
6825-
}
6826-
6827-
fn accum_substs(accumulator: &mut Vec<Region>, substs: &Substs) {
6828-
match substs.regions {
6829-
subst::ErasedRegions => {}
6830-
subst::NonerasedRegions(ref regions) => {
6831-
for region in regions {
6832-
accumulator.push(*region)
6833-
}
6834-
}
6835-
}
6836-
}
6837-
}
6838-
}
6839-
68406796
/// A free variable referred to in a function.
68416797
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
68426798
pub struct Freevar {
@@ -6897,27 +6853,15 @@ impl<'tcx> ctxt<'tcx> {
68976853
|br| ty::ReFree(ty::FreeRegion{scope: all_outlive_scope, bound_region: br})).0
68986854
}
68996855

6900-
pub fn count_late_bound_regions<T>(&self, value: &Binder<T>) -> usize
6901-
where T : TypeFoldable<'tcx>
6902-
{
6903-
let (_, skol_map) = ty_fold::replace_late_bound_regions(self, value, |_| ty::ReStatic);
6904-
skol_map.len()
6905-
}
6906-
6907-
pub fn binds_late_bound_regions<T>(&self, value: &Binder<T>) -> bool
6908-
where T : TypeFoldable<'tcx>
6909-
{
6910-
self.count_late_bound_regions(value) > 0
6911-
}
6912-
69136856
/// Flattens two binding levels into one. So `for<'a> for<'b> Foo`
69146857
/// becomes `for<'a,'b> Foo`.
69156858
pub fn flatten_late_bound_regions<T>(&self, bound2_value: &Binder<Binder<T>>)
69166859
-> Binder<T>
69176860
where T: TypeFoldable<'tcx>
69186861
{
69196862
let bound0_value = bound2_value.skip_binder().skip_binder();
6920-
let value = ty_fold::fold_regions(self, bound0_value, |region, current_depth| {
6863+
let value = ty_fold::fold_regions(self, bound0_value, &mut false,
6864+
|region, current_depth| {
69216865
match region {
69226866
ty::ReLateBound(debruijn, br) if debruijn.depth >= current_depth => {
69236867
// should be true if no escaping regions from bound2_value
@@ -6933,9 +6877,9 @@ impl<'tcx> ctxt<'tcx> {
69336877
}
69346878

69356879
pub fn no_late_bound_regions<T>(&self, value: &Binder<T>) -> Option<T>
6936-
where T : TypeFoldable<'tcx>
6880+
where T : TypeFoldable<'tcx> + RegionEscape
69376881
{
6938-
if self.binds_late_bound_regions(value) {
6882+
if value.0.has_escaping_regions() {
69396883
None
69406884
} else {
69416885
Some(value.0.clone())
@@ -7095,6 +7039,19 @@ impl<'tcx> RegionEscape for Substs<'tcx> {
70957039
}
70967040
}
70977041

7042+
impl<T:RegionEscape> RegionEscape for Vec<T> {
7043+
fn has_regions_escaping_depth(&self, depth: u32) -> bool {
7044+
self.iter().any(|t| t.has_regions_escaping_depth(depth))
7045+
}
7046+
}
7047+
7048+
impl<'tcx> RegionEscape for FnSig<'tcx> {
7049+
fn has_regions_escaping_depth(&self, depth: u32) -> bool {
7050+
self.inputs.has_regions_escaping_depth(depth) ||
7051+
self.output.has_regions_escaping_depth(depth)
7052+
}
7053+
}
7054+
70987055
impl<'tcx,T:RegionEscape> RegionEscape for VecPerParamSpace<T> {
70997056
fn has_regions_escaping_depth(&self, depth: u32) -> bool {
71007057
self.iter_enumerated().any(|(space, _, t)| {
@@ -7167,6 +7124,15 @@ impl<'tcx,T:RegionEscape> RegionEscape for Binder<T> {
71677124
}
71687125
}
71697126

7127+
impl<'tcx> RegionEscape for FnOutput<'tcx> {
7128+
fn has_regions_escaping_depth(&self, depth: u32) -> bool {
7129+
match *self {
7130+
FnConverging(t) => t.has_regions_escaping_depth(depth),
7131+
FnDiverging => false
7132+
}
7133+
}
7134+
}
7135+
71707136
impl<'tcx> RegionEscape for EquatePredicate<'tcx> {
71717137
fn has_regions_escaping_depth(&self, depth: u32) -> bool {
71727138
self.0.has_regions_escaping_depth(depth) || self.1.has_regions_escaping_depth(depth)

0 commit comments

Comments
 (0)