Skip to content

Commit e95e8ff

Browse files
committed
---
yaml --- r: 146406 b: refs/heads/try2 c: 556088c h: refs/heads/master v: v3
1 parent 3654618 commit e95e8ff

File tree

8 files changed

+74
-55
lines changed

8 files changed

+74
-55
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 67966fa9de062cfe05604ed7e11e9ab58bb55225
8+
refs/heads/try2: 556088cfb115b5aa39050043058eb345a55e3764
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ The currently implemented features of the compiler are:
20632063

20642064
* `once_fns` - Onceness guarantees a closure is only executed once. Defining a
20652065
closure as `once` is unlikely to be supported going forward. So
2066-
they are hidden behind this feature until they are to be removed.
2066+
they are hidden behind this feature until they are to be removed.
20672067

20682068
If a feature is promoted to a language feature, then all existing programs will
20692069
start to receive compilation warnings about #[feature] directives which enabled
@@ -2748,11 +2748,10 @@ do k(3) |j| {
27482748

27492749
~~~~ {.ebnf .gram}
27502750
for_expr : "for" pat "in" expr '{' block '}' ;
2751-
~~~~
2751+
~~~~
27522752

2753-
A `for` expression is a syntactic construct for looping
2754-
over elements provided by an implementation of
2755-
`std::iterator::Iterator`.
2753+
A `for` expression is a syntactic construct for looping over elements
2754+
provided by an implementation of `std::iter::Iterator`.
27562755

27572756
An example of a for loop over the contents of a vector:
27582757

branches/try2/doc/tutorial-container.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ heapsort.
6969
## Iteration protocol
7070

7171
The iteration protocol is defined by the `Iterator` trait in the
72-
`std::iterator` module. The minimal implementation of the trait is a `next`
72+
`std::iter` module. The minimal implementation of the trait is a `next`
7373
method, yielding the next element from an iterator object:
7474

7575
~~~

branches/try2/doc/tutorial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ different type from `Bar(1, 2)`), and tuple structs' _fields_ do not have
759759
names.
760760

761761
For example:
762+
762763
~~~~
763764
struct MyTup(int, int, f64);
764765
let mytup: MyTup = MyTup(10, 20, 30.0);

branches/try2/src/librustc/middle/trans/glue.rs

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -395,39 +395,11 @@ pub fn trans_struct_drop_flag(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did:
395395
let repr = adt::represent_type(bcx.ccx(), t);
396396
let drop_flag = adt::trans_drop_flag_ptr(bcx, repr, v0);
397397
do with_cond(bcx, IsNotNull(bcx, Load(bcx, drop_flag))) |cx| {
398-
let mut bcx = cx;
399-
400-
// Find and call the actual destructor
401-
let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did,
402-
class_did, substs.tps.clone());
403-
404-
// The second argument is the "self" argument for drop
405-
let params = unsafe {
406-
let ty = Type::from_ref(llvm::LLVMTypeOf(dtor_addr));
407-
ty.element_type().func_params()
408-
};
409-
410-
// Class dtors have no explicit args, so the params should
411-
// just consist of the environment (self)
412-
assert_eq!(params.len(), 1);
413-
414-
let self_arg = PointerCast(bcx, v0, params[0]);
415-
let args = ~[self_arg];
416-
417-
Call(bcx, dtor_addr, args, []);
418-
419-
// Drop the fields
420-
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
421-
for (i, fld) in field_tys.iter().enumerate() {
422-
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
423-
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
424-
}
425-
426-
bcx
398+
trans_struct_drop(cx, t, v0, dtor_did, class_did, substs)
427399
}
428400
}
429401

430-
pub fn trans_struct_drop(mut bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did: ast::DefId,
402+
pub fn trans_struct_drop(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did: ast::DefId,
431403
class_did: ast::DefId, substs: &ty::substs) -> @mut Block {
432404
let repr = adt::represent_type(bcx.ccx(), t);
433405

@@ -445,19 +417,24 @@ pub fn trans_struct_drop(mut bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did:
445417
// just consist of the environment (self)
446418
assert_eq!(params.len(), 1);
447419

448-
let self_arg = PointerCast(bcx, v0, params[0]);
449-
let args = ~[self_arg];
420+
// Be sure to put all of the fields into a scope so we can use an invoke
421+
// instruction to call the user destructor but still call the field
422+
// destructors if the user destructor fails.
423+
do with_scope(bcx, None, "field drops") |bcx| {
424+
let self_arg = PointerCast(bcx, v0, params[0]);
425+
let args = ~[self_arg];
450426

451-
Call(bcx, dtor_addr, args, []);
427+
// Add all the fields as a value which needs to be cleaned at the end of
428+
// this scope.
429+
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
430+
for (i, fld) in field_tys.iter().enumerate() {
431+
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
432+
add_clean(bcx, llfld_a, fld.mt.ty);
433+
}
452434

453-
// Drop the fields
454-
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
455-
for (i, fld) in field_tys.iter().enumerate() {
456-
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
457-
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
435+
let (_, bcx) = invoke(bcx, dtor_addr, args, []);
436+
bcx
458437
}
459-
460-
bcx
461438
}
462439

463440
pub fn make_drop_glue(bcx: @mut Block, v0: ValueRef, t: ty::t) -> @mut Block {

branches/try2/src/libstd/c_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ fn check_for_null(v: &[u8], buf: *mut libc::c_char) {
330330

331331
/// External iterator for a CString's bytes.
332332
///
333-
/// Use with the `std::iterator` module.
333+
/// Use with the `std::iter` module.
334334
pub struct CStringIterator<'self> {
335335
priv ptr: *libc::c_char,
336336
priv lifetime: &'self libc::c_char, // FIXME: #5922

branches/try2/src/libstd/str.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ Section: Iterators
352352
*/
353353

354354
/// External iterator for a string's characters.
355-
/// Use with the `std::iterator` module.
355+
/// Use with the `std::iter` module.
356356
#[deriving(Clone)]
357357
pub struct CharIterator<'self> {
358358
/// The slice remaining to be iterated
@@ -397,7 +397,7 @@ impl<'self> DoubleEndedIterator<char> for CharIterator<'self> {
397397
}
398398

399399
/// External iterator for a string's characters and their byte offsets.
400-
/// Use with the `std::iterator` module.
400+
/// Use with the `std::iter` module.
401401
#[deriving(Clone)]
402402
pub struct CharOffsetIterator<'self> {
403403
/// The original string to be iterated
@@ -439,20 +439,20 @@ impl<'self> DoubleEndedIterator<(uint, char)> for CharOffsetIterator<'self> {
439439
}
440440

441441
/// External iterator for a string's characters in reverse order.
442-
/// Use with the `std::iterator` module.
442+
/// Use with the `std::iter` module.
443443
pub type CharRevIterator<'self> = Invert<CharIterator<'self>>;
444444

445445
/// External iterator for a string's characters and their byte offsets in reverse order.
446-
/// Use with the `std::iterator` module.
446+
/// Use with the `std::iter` module.
447447
pub type CharOffsetRevIterator<'self> = Invert<CharOffsetIterator<'self>>;
448448

449449
/// External iterator for a string's bytes.
450-
/// Use with the `std::iterator` module.
450+
/// Use with the `std::iter` module.
451451
pub type ByteIterator<'self> =
452452
Map<'self, &'self u8, u8, vec::VecIterator<'self, u8>>;
453453

454454
/// External iterator for a string's bytes in reverse order.
455-
/// Use with the `std::iterator` module.
455+
/// Use with the `std::iter` module.
456456
pub type ByteRevIterator<'self> = Invert<ByteIterator<'self>>;
457457

458458
/// An iterator over the substrings of a string, separated by `sep`.
@@ -682,7 +682,7 @@ enum NormalizationForm {
682682
}
683683

684684
/// External iterator for a string's normalization's characters.
685-
/// Use with the `std::iterator` module.
685+
/// Use with the `std::iter` module.
686686
#[deriving(Clone)]
687687
struct NormalizationIterator<'self> {
688688
priv kind: NormalizationForm,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::task;
12+
13+
static mut dropped: bool = false;
14+
15+
struct A {
16+
b: B,
17+
}
18+
19+
struct B {
20+
foo: int,
21+
}
22+
23+
impl Drop for A {
24+
fn drop(&mut self) {
25+
fail!()
26+
}
27+
}
28+
29+
impl Drop for B {
30+
fn drop(&mut self) {
31+
unsafe { dropped = true; }
32+
}
33+
}
34+
35+
pub fn main() {
36+
let ret = do task::try {
37+
let _a = A { b: B { foo: 3 } };
38+
};
39+
assert!(ret.is_err());
40+
unsafe { assert!(dropped); }
41+
}
42+

0 commit comments

Comments
 (0)