Skip to content

Commit 10e27db

Browse files
committed
---
yaml --- r: 225534 b: refs/heads/stable c: e12d386 h: refs/heads/master v: v3
1 parent 17987bb commit 10e27db

File tree

13 files changed

+183
-65
lines changed

13 files changed

+183
-65
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ refs/heads/tmp: e5d90d98402475b6e154ce216f9efcb80da1a747
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: 1fe32ca12c51afcd761d9962f51a74ff0d07a591
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: e0ca6b1a314f949827fda499ee29dcbf6ef18acd
32+
refs/heads/stable: e12d3869e3c5f7ee3e49fbccb668edabd9cdb643
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b

branches/stable/src/libcollections/linked_list.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,13 @@ impl<T> LinkedList<T> {
609609
length: len - at
610610
};
611611

612+
// Swap split_node.next with list_head (which is None), nulling out split_node.next,
613+
// as it is the new tail.
612614
mem::swap(&mut split_node.resolve().unwrap().next, &mut splitted_list.list_head);
615+
// Null out list_head.prev. Note this `unwrap` won't fail because if at == len
616+
// we already branched out at the top of the fn to return the empty list.
617+
splitted_list.list_head.as_mut().unwrap().prev = Rawlink::none();
618+
// Fix the tail ptr
613619
self.list_tail = split_node;
614620
self.length = at;
615621

@@ -1075,6 +1081,26 @@ mod tests {
10751081
}
10761082
}
10771083

1084+
#[test]
1085+
fn test_26021() {
1086+
use std::iter::ExactSizeIterator;
1087+
// There was a bug in split_off that failed to null out the RHS's head's prev ptr.
1088+
// This caused the RHS's dtor to walk up into the LHS at drop and delete all of
1089+
// its nodes.
1090+
//
1091+
// https://github.com/rust-lang/rust/issues/26021
1092+
let mut v1 = LinkedList::new();
1093+
v1.push_front(1u8);
1094+
v1.push_front(1u8);
1095+
v1.push_front(1u8);
1096+
v1.push_front(1u8);
1097+
let _ = v1.split_off(3); // Dropping this now should not cause laundry consumption
1098+
assert_eq!(v1.len(), 3);
1099+
1100+
assert_eq!(v1.iter().len(), 3);
1101+
assert_eq!(v1.iter().collect::<Vec<_>>().len(), 3);
1102+
}
1103+
10781104
#[cfg(test)]
10791105
fn fuzz_test(sz: i32) {
10801106
let mut m: LinkedList<_> = LinkedList::new();

branches/stable/src/liblibc/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6308,8 +6308,8 @@ pub mod funcs {
63086308
lpOverlapped: LPOVERLAPPED) -> BOOL;
63096309
pub fn WriteFile(hFile: HANDLE,
63106310
lpBuffer: LPVOID,
6311-
nNumberOfBytesToWrite: DWORD,
6312-
lpNumberOfBytesWritten: LPDWORD,
6311+
nNumberOfBytesToRead: DWORD,
6312+
lpNumberOfBytesRead: LPDWORD,
63136313
lpOverlapped: LPOVERLAPPED) -> BOOL;
63146314
pub fn SetFilePointerEx(hFile: HANDLE,
63156315
liDistanceToMove: LARGE_INTEGER,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,20 @@ impl<T> VecPerParamSpace<T> {
448448
self.self_limit)
449449
}
450450

451+
pub fn map_move<U, F>(self, mut pred: F) -> VecPerParamSpace<U> where
452+
F: FnMut(T) -> U,
453+
{
454+
let SeparateVecsPerParamSpace {
455+
types: t,
456+
selfs: s,
457+
fns: f
458+
} = self.split();
459+
460+
VecPerParamSpace::new(t.into_iter().map(|p| pred(p)).collect(),
461+
s.into_iter().map(|p| pred(p)).collect(),
462+
f.into_iter().map(|p| pred(p)).collect())
463+
}
464+
451465
pub fn split(self) -> SeparateVecsPerParamSpace<T> {
452466
let VecPerParamSpace { type_limit, self_limit, content } = self;
453467

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ fn process_predicate<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
329329
false
330330
}
331331
Ok(Some(s)) => {
332-
new_obligations.append(&mut s.nested_obligations());
332+
s.map_move_nested(|p| new_obligations.push(p));
333333
true
334334
}
335335
Err(selection_err) => {

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

Lines changed: 109 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use middle::subst;
2020
use middle::ty::{self, HasProjectionTypes, Ty};
2121
use middle::ty_fold::TypeFoldable;
2222
use middle::infer::{self, fixup_err_to_string, InferCtxt};
23+
use std::slice::Iter;
2324
use std::rc::Rc;
2425
use syntax::ast;
2526
use syntax::codemap::{Span, DUMMY_SP};
@@ -145,9 +146,9 @@ pub struct DerivedObligationCause<'tcx> {
145146
parent_code: Rc<ObligationCauseCode<'tcx>>
146147
}
147148

148-
pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>;
149-
pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>;
150-
pub type TraitObligations<'tcx> = Vec<TraitObligation<'tcx>>;
149+
pub type Obligations<'tcx, O> = subst::VecPerParamSpace<Obligation<'tcx, O>>;
150+
pub type PredicateObligations<'tcx> = subst::VecPerParamSpace<PredicateObligation<'tcx>>;
151+
pub type TraitObligations<'tcx> = subst::VecPerParamSpace<TraitObligation<'tcx>>;
151152

152153
pub type Selection<'tcx> = Vtable<'tcx, PredicateObligation<'tcx>>;
153154

@@ -265,7 +266,7 @@ pub enum Vtable<'tcx, N> {
265266
pub struct VtableImplData<'tcx, N> {
266267
pub impl_def_id: ast::DefId,
267268
pub substs: subst::Substs<'tcx>,
268-
pub nested: Vec<N>
269+
pub nested: subst::VecPerParamSpace<N>
269270
}
270271

271272
#[derive(Debug,Clone)]
@@ -276,7 +277,7 @@ pub struct VtableDefaultImplData<N> {
276277

277278
#[derive(Debug,Clone)]
278279
pub struct VtableBuiltinData<N> {
279-
pub nested: Vec<N>
280+
pub nested: subst::VecPerParamSpace<N>
280281
}
281282

282283
/// A vtable for some object-safe trait `Foo` automatically derived
@@ -524,35 +525,114 @@ impl<'tcx> ObligationCause<'tcx> {
524525
}
525526

526527
impl<'tcx, N> Vtable<'tcx, N> {
527-
pub fn nested_obligations(self) -> Vec<N> {
528-
match self {
529-
VtableImpl(i) => i.nested,
530-
VtableParam(n) => n,
531-
VtableBuiltin(i) => i.nested,
532-
VtableDefaultImpl(d) => d.nested,
533-
VtableObject(_) | VtableFnPointer(..) |
534-
VtableClosure(..) => vec![]
528+
pub fn iter_nested(&self) -> Iter<N> {
529+
match *self {
530+
VtableImpl(ref i) => i.iter_nested(),
531+
VtableParam(ref n) => n.iter(),
532+
VtableBuiltin(ref i) => i.iter_nested(),
533+
VtableObject(_) |
534+
VtableDefaultImpl(..) | VtableFnPointer(..) |
535+
VtableClosure(..) => (&[]).iter(),
536+
}
537+
}
538+
539+
pub fn map_nested<M, F>(&self, op: F) -> Vtable<'tcx, M> where
540+
F: FnMut(&N) -> M,
541+
{
542+
match *self {
543+
VtableImpl(ref i) => VtableImpl(i.map_nested(op)),
544+
VtableDefaultImpl(ref t) => VtableDefaultImpl(t.map_nested(op)),
545+
VtableFnPointer(ref sig) => VtableFnPointer((*sig).clone()),
546+
VtableClosure(d, ref s) => VtableClosure(d, s.clone()),
547+
VtableParam(ref n) => VtableParam(n.iter().map(op).collect()),
548+
VtableObject(ref p) => VtableObject(p.clone()),
549+
VtableBuiltin(ref b) => VtableBuiltin(b.map_nested(op)),
535550
}
536551
}
537552

538-
pub fn map<M, F>(self, f: F) -> Vtable<'tcx, M> where F: FnMut(N) -> M {
553+
pub fn map_move_nested<M, F>(self, op: F) -> Vtable<'tcx, M> where
554+
F: FnMut(N) -> M,
555+
{
539556
match self {
540-
VtableImpl(i) => VtableImpl(VtableImplData {
541-
impl_def_id: i.impl_def_id,
542-
substs: i.substs,
543-
nested: i.nested.into_iter().map(f).collect()
544-
}),
545-
VtableParam(n) => VtableParam(n.into_iter().map(f).collect()),
546-
VtableBuiltin(i) => VtableBuiltin(VtableBuiltinData {
547-
nested: i.nested.into_iter().map(f).collect()
548-
}),
549-
VtableObject(o) => VtableObject(o),
550-
VtableDefaultImpl(d) => VtableDefaultImpl(VtableDefaultImplData {
551-
trait_def_id: d.trait_def_id,
552-
nested: d.nested.into_iter().map(f).collect()
553-
}),
554-
VtableFnPointer(f) => VtableFnPointer(f),
557+
VtableImpl(i) => VtableImpl(i.map_move_nested(op)),
558+
VtableFnPointer(sig) => VtableFnPointer(sig),
555559
VtableClosure(d, s) => VtableClosure(d, s),
560+
VtableDefaultImpl(t) => VtableDefaultImpl(t.map_move_nested(op)),
561+
VtableParam(n) => VtableParam(n.into_iter().map(op).collect()),
562+
VtableObject(p) => VtableObject(p),
563+
VtableBuiltin(no) => VtableBuiltin(no.map_move_nested(op)),
564+
}
565+
}
566+
}
567+
568+
impl<'tcx, N> VtableImplData<'tcx, N> {
569+
pub fn iter_nested(&self) -> Iter<N> {
570+
self.nested.iter()
571+
}
572+
573+
pub fn map_nested<M, F>(&self, op: F) -> VtableImplData<'tcx, M> where
574+
F: FnMut(&N) -> M,
575+
{
576+
VtableImplData {
577+
impl_def_id: self.impl_def_id,
578+
substs: self.substs.clone(),
579+
nested: self.nested.map(op)
580+
}
581+
}
582+
583+
pub fn map_move_nested<M, F>(self, op: F) -> VtableImplData<'tcx, M> where
584+
F: FnMut(N) -> M,
585+
{
586+
let VtableImplData { impl_def_id, substs, nested } = self;
587+
VtableImplData {
588+
impl_def_id: impl_def_id,
589+
substs: substs,
590+
nested: nested.map_move(op)
591+
}
592+
}
593+
}
594+
595+
impl<N> VtableDefaultImplData<N> {
596+
pub fn iter_nested(&self) -> Iter<N> {
597+
self.nested.iter()
598+
}
599+
600+
pub fn map_nested<M, F>(&self, op: F) -> VtableDefaultImplData<M> where
601+
F: FnMut(&N) -> M,
602+
{
603+
VtableDefaultImplData {
604+
trait_def_id: self.trait_def_id,
605+
nested: self.nested.iter().map(op).collect()
606+
}
607+
}
608+
609+
pub fn map_move_nested<M, F>(self, op: F) -> VtableDefaultImplData<M> where
610+
F: FnMut(N) -> M,
611+
{
612+
let VtableDefaultImplData { trait_def_id, nested } = self;
613+
VtableDefaultImplData {
614+
trait_def_id: trait_def_id,
615+
nested: nested.into_iter().map(op).collect()
616+
}
617+
}
618+
}
619+
620+
impl<N> VtableBuiltinData<N> {
621+
pub fn iter_nested(&self) -> Iter<N> {
622+
self.nested.iter()
623+
}
624+
625+
pub fn map_nested<M, F>(&self, op: F) -> VtableBuiltinData<M> where F: FnMut(&N) -> M {
626+
VtableBuiltinData {
627+
nested: self.nested.map(op)
628+
}
629+
}
630+
631+
pub fn map_move_nested<M, F>(self, op: F) -> VtableBuiltinData<M> where
632+
F: FnMut(N) -> M,
633+
{
634+
VtableBuiltinData {
635+
nested: self.nested.map_move(op)
556636
}
557637
}
558638
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ pub fn normalize_with_depth<'a,'b,'tcx,T>(selcx: &'a mut SelectionContext<'b,'tc
203203
{
204204
let mut normalizer = AssociatedTypeNormalizer::new(selcx, cause, depth);
205205
let result = normalizer.fold(value);
206-
207206
Normalized {
208207
value: result,
209208
obligations: normalizer.obligations,
@@ -865,7 +864,7 @@ fn confirm_impl_candidate<'cx,'tcx>(
865864
if let ty::TypeTraitItem(ref assoc_ty) = impl_or_trait_items_map[&impl_item.def_id()] {
866865
if assoc_ty.name == obligation.predicate.item_name {
867866
return (assoc_ty.ty.unwrap().subst(selcx.tcx(), &impl_vtable.substs),
868-
impl_vtable.nested);
867+
impl_vtable.nested.into_vec());
869868
}
870869
}
871870
}
@@ -877,7 +876,7 @@ fn confirm_impl_candidate<'cx,'tcx>(
877876
if assoc_ty.name == obligation.predicate.item_name {
878877
if let Some(ty) = assoc_ty.ty {
879878
return (ty.subst(selcx.tcx(), trait_ref.substs),
880-
impl_vtable.nested);
879+
impl_vtable.nested.into_vec());
881880
} else {
882881
// This means that the impl is missing a
883882
// definition for the associated type. This error

0 commit comments

Comments
 (0)