Skip to content

Commit a8346fb

Browse files
committed
---
yaml --- r: 55117 b: refs/heads/snap-stage3 c: e4ca2da h: refs/heads/master i: 55115: f8ef441 v: v3
1 parent fb305c5 commit a8346fb

File tree

5 files changed

+60
-140
lines changed

5 files changed

+60
-140
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: d045ce7b87af0fb0730ccf5291c11d28a5382254
4+
refs/heads/snap-stage3: e4ca2da42072fccd16aefdc4f2090b0489e8293c
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/os.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -643,22 +643,20 @@ pub fn make_dir(p: &Path, mode: c_int) -> bool {
643643
/// Returns true iff creation
644644
/// succeeded. Also creates all intermediate subdirectories
645645
/// if they don't already exist, giving all of them the same mode.
646-
647-
// tjc: if directory exists but with different permissions,
648-
// should we return false?
649646
pub fn mkdir_recursive(p: &Path, mode: c_int) -> bool {
650647
if path_is_dir(p) {
651648
return true;
652649
}
653-
else if p.components.is_empty() {
654-
return false;
655-
}
656-
else if p.components.len() == 1 {
650+
let parent = p.dir_path();
651+
debug!("mkdir_recursive: parent = %s",
652+
parent.to_str());
653+
if parent.to_str() == ~"."
654+
|| parent.to_str() == ~"/" { // !!!
657655
// No parent directories to create
658-
path_is_dir(p) || make_dir(p, mode)
656+
path_is_dir(&parent) && make_dir(p, mode)
659657
}
660658
else {
661-
mkdir_recursive(&p.pop(), mode) && make_dir(p, mode)
659+
mkdir_recursive(&parent, mode) && make_dir(p, mode)
662660
}
663661
}
664662

@@ -1269,8 +1267,6 @@ mod tests {
12691267
use run;
12701268
use str;
12711269
use vec;
1272-
use libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
1273-
12741270
12751271
#[test]
12761272
pub fn last_os_error() {
@@ -1494,16 +1490,16 @@ mod tests {
14941490
}
14951491
14961492
#[test]
1497-
fn recursive_mkdir_slash() {
1498-
let path = Path("/");
1499-
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
1500-
}
1493+
fn recursive_mkdir_ok() {
1494+
use libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
15011495
1502-
#[test]
1503-
fn recursive_mkdir_empty() {
1504-
let path = Path("");
1505-
assert!(!os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
1496+
let root = os::tmpdir();
1497+
let path = "xy/z/zy";
1498+
let nested = root.push(path);
1499+
assert!(os::mkdir_recursive(&nested, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
1500+
assert!(os::path_is_dir(&root.push("xy")));
1501+
assert!(os::path_is_dir(&root.push("xy/z")));
1502+
assert!(os::path_is_dir(&nested));
15061503
}
15071504

1508-
// More recursive_mkdir tests are in std::tempfile
15091505
}

branches/snap-stage3/src/libcore/path.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,71 +44,31 @@ pub fn PosixPath(s: &str) -> PosixPath {
4444
}
4545

4646
pub trait GenericPath {
47-
/// Converts a string to a Path
4847
fn from_str(&str) -> Self;
4948

50-
/// Returns the directory component of `self`, as a string
5149
fn dirname(&self) -> ~str;
52-
/// Returns the file component of `self`, as a string option.
53-
/// Returns None if `self` names a directory.
5450
fn filename(&self) -> Option<~str>;
55-
/// Returns the stem of the file component of `self`, as a string option.
56-
/// The stem is the slice of a filename starting at 0 and ending just before
57-
/// the last '.' in the name.
58-
/// Returns None if `self` names a directory.
5951
fn filestem(&self) -> Option<~str>;
60-
/// Returns the type of the file component of `self`, as a string option.
61-
/// The file type is the slice of a filename starting just after the last
62-
/// '.' in the name and ending at the last index in the filename.
63-
/// Returns None if `self` names a directory.
6452
fn filetype(&self) -> Option<~str>;
6553

66-
/// Returns a new path consisting of `self` with the parent directory component replaced
67-
/// with the given string.
6854
fn with_dirname(&self, (&str)) -> Self;
69-
/// Returns a new path consisting of `self` with the file component replaced
70-
/// with the given string.
7155
fn with_filename(&self, (&str)) -> Self;
72-
/// Returns a new path consisting of `self` with the file stem replaced
73-
/// with the given string.
7456
fn with_filestem(&self, (&str)) -> Self;
75-
/// Returns a new path consisting of `self` with the file type replaced
76-
/// with the given string.
7757
fn with_filetype(&self, (&str)) -> Self;
7858

79-
/// Returns the directory component of `self`, as a new path.
80-
/// If `self` has no parent, returns `self`.
8159
fn dir_path(&self) -> Self;
82-
/// Returns the file component of `self`, as a new path.
83-
/// If `self` names a directory, returns the empty path.
8460
fn file_path(&self) -> Self;
8561

86-
/// Returns a new Path whose parent directory is `self` and whose
87-
/// file component is the given string.
8862
fn push(&self, (&str)) -> Self;
89-
/// Returns a new Path consisting of the given path, made relative to `self`.
9063
fn push_rel(&self, (&Self)) -> Self;
91-
/// Returns a new Path consisting of the path given by the given vector
92-
/// of strings, relative to `self`.
9364
fn push_many(&self, (&[~str])) -> Self;
94-
/// Identical to `dir_path` except in the case where `self` has only one
95-
/// component. In this case, `pop` returns the empty path.
9665
fn pop(&self) -> Self;
9766

98-
/// The same as `push_rel`, except that the directory argument must not
99-
/// contain directory separators in any of its components.
10067
fn unsafe_join(&self, (&Self)) -> Self;
101-
/// On Unix, always returns false. On Windows, returns true iff `self`'s
102-
/// file stem is one of: `con` `aux` `com1` `com2` `com3` `com4`
103-
/// `lpt1` `lpt2` `lpt3` `prn` `nul`
10468
fn is_restricted(&self) -> bool;
10569

106-
/// Returns a new path that names the same file as `self`, without containing
107-
/// any '.', '..', or empty components. On Windows, uppercases the drive letter
108-
/// as well.
10970
fn normalize(&self) -> Self;
11071

111-
/// Returns `true` if `self` is an absolute path.
11272
fn is_absolute(&self) -> bool;
11373
}
11474

branches/snap-stage3/src/libstd/num/bigint.rs

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ A BigUint is represented as an array of BigDigits.
1616
A BigInt is a combination of BigUint and Sign.
1717
*/
1818

19+
#[deny(vecs_implicitly_copyable)];
20+
#[deny(deprecated_mutable_fields)];
21+
1922
use core::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
2023
use core::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix};
2124
use core::*;
@@ -355,16 +358,24 @@ impl Integer for BigUint {
355358
let mut (d0, d_unit, b_unit) = div_estimate(&m, &b, n);
356359
let mut prod = b * d0;
357360
while prod > m {
358-
d0 -= d_unit;
359-
prod -= b_unit;
361+
// FIXME(#6050): overloaded operators force moves with generic types
362+
// d0 -= d_unit
363+
d0 = d0 - d_unit;
364+
// FIXME(#6050): overloaded operators force moves with generic types
365+
// prod = prod - b_unit;
366+
prod = prod - b_unit
360367
}
361368
if d0.is_zero() {
362369
n = 2;
363370
loop;
364371
}
365372
n = 1;
366-
d += d0;
367-
m -= prod;
373+
// FIXME(#6102): Assignment operator for BigInt causes ICE
374+
// d += d0;
375+
d = d + d0;
376+
// FIXME(#6102): Assignment operator for BigInt causes ICE
377+
// m -= prod;
378+
m = m - prod;
368379
}
369380
return (d, m);
370381
}
@@ -411,7 +422,7 @@ impl Integer for BigUint {
411422
#[inline(always)]
412423
fn gcd(&self, other: &BigUint) -> BigUint {
413424
// Use Euclid's algorithm
414-
let mut m = *self, n = *other;
425+
let mut m = copy *self, n = copy *other;
415426
while !m.is_zero() {
416427
let temp = m;
417428
m = n % temp;
@@ -547,14 +558,18 @@ impl BigUint {
547558
loop {
548559
let start = uint::max(end, unit_len) - unit_len;
549560
match uint::parse_bytes(vec::slice(buf, start, end), radix) {
550-
Some(d) => n += BigUint::from_uint(d) * power,
561+
// FIXME(#6102): Assignment operator for BigInt causes ICE
562+
// Some(d) => n += BigUint::from_uint(d) * power,
563+
Some(d) => n = n + BigUint::from_uint(d) * power,
551564
None => return None
552565
}
553566
if end <= unit_len {
554567
return Some(n);
555568
}
556569
end -= unit_len;
557-
power *= base_num;
570+
// FIXME(#6050): overloaded operators force moves with generic types
571+
// power *= base_num;
572+
power = power * base_num;
558573
}
559574
}
560575

@@ -569,15 +584,15 @@ impl BigUint {
569584
}
570585

571586
#[inline(always)]
572-
priv fn shl_unit(self, n_unit: uint) -> BigUint {
573-
if n_unit == 0 || self.is_zero() { return self; }
587+
priv fn shl_unit(&self, n_unit: uint) -> BigUint {
588+
if n_unit == 0 || self.is_zero() { return copy *self; }
574589

575590
return BigUint::new(vec::from_elem(n_unit, 0) + self.data);
576591
}
577592

578593
#[inline(always)]
579-
priv fn shl_bits(self, n_bits: uint) -> BigUint {
580-
if n_bits == 0 || self.is_zero() { return self; }
594+
priv fn shl_bits(&self, n_bits: uint) -> BigUint {
595+
if n_bits == 0 || self.is_zero() { return copy *self; }
581596

582597
let mut carry = 0;
583598
let shifted = do vec::map(self.data) |elem| {
@@ -592,17 +607,17 @@ impl BigUint {
592607
}
593608

594609
#[inline(always)]
595-
priv fn shr_unit(self, n_unit: uint) -> BigUint {
596-
if n_unit == 0 { return self; }
610+
priv fn shr_unit(&self, n_unit: uint) -> BigUint {
611+
if n_unit == 0 { return copy *self; }
597612
if self.data.len() < n_unit { return Zero::zero(); }
598613
return BigUint::from_slice(
599614
vec::slice(self.data, n_unit, self.data.len())
600615
);
601616
}
602617

603618
#[inline(always)]
604-
priv fn shr_bits(self, n_bits: uint) -> BigUint {
605-
if n_bits == 0 || self.data.is_empty() { return self; }
619+
priv fn shr_bits(&self, n_bits: uint) -> BigUint {
620+
if n_bits == 0 || self.data.is_empty() { return copy *self; }
606621

607622
let mut borrow = 0;
608623
let mut shifted = ~[];
@@ -1070,7 +1085,7 @@ pub impl BigInt {
10701085
start = 1;
10711086
}
10721087
return BigUint::parse_bytes(vec::slice(buf, start, buf.len()), radix)
1073-
.map(|bu| BigInt::from_biguint(sign, *bu));
1088+
.map_consume(|bu| BigInt::from_biguint(sign, bu));
10741089
}
10751090
10761091
#[inline(always)]
@@ -1376,10 +1391,10 @@ mod biguint_tests {
13761391
let c = BigUint::from_slice(cVec);
13771392

13781393
if !a.is_zero() {
1379-
assert!(c.quot_rem(&a) == (b, Zero::zero()));
1394+
assert!(c.quot_rem(&a) == (copy b, Zero::zero()));
13801395
}
13811396
if !b.is_zero() {
1382-
assert!(c.quot_rem(&b) == (a, Zero::zero()));
1397+
assert!(c.quot_rem(&b) == (copy a, Zero::zero()));
13831398
}
13841399
}
13851400

@@ -1503,7 +1518,7 @@ mod biguint_tests {
15031518
let &(n, rs) = num_pair;
15041519
for rs.each |str_pair| {
15051520
let &(radix, str) = str_pair;
1506-
assert_eq!(Some(n), FromStrRadix::from_str_radix(str, radix));
1521+
assert_eq!(&n, &FromStrRadix::from_str_radix(str, radix).get());
15071522
}
15081523
}
15091524

@@ -1517,7 +1532,9 @@ mod biguint_tests {
15171532
fn factor(n: uint) -> BigUint {
15181533
let mut f= One::one::<BigUint>();
15191534
for uint::range(2, n + 1) |i| {
1520-
f *= BigUint::from_uint(i);
1535+
// FIXME(#6102): Assignment operator for BigInt causes ICE
1536+
// f *= BigUint::from_uint(i);
1537+
f = f * BigUint::from_uint(i);
15211538
}
15221539
return f;
15231540
}

branches/snap-stage3/src/libstd/tempfile.rs

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -23,62 +23,9 @@ pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> {
2323
None
2424
}
2525

26-
#[cfg(test)]
27-
mod tests {
28-
use tempfile::mkdtemp;
29-
use tempfile;
30-
31-
#[test]
32-
fn test_mkdtemp() {
33-
let p = mkdtemp(&Path("."), "foobar").unwrap();
34-
os::remove_dir(&p);
35-
assert!(str::ends_with(p.to_str(), "foobar"));
36-
}
37-
38-
// Ideally these would be in core::os but then core would need
39-
// to depend on std
40-
#[test]
41-
fn recursive_mkdir_rel() {
42-
use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
43-
use core::os;
44-
45-
let root = mkdtemp(&os::tmpdir(), "temp").expect("recursive_mkdir_rel");
46-
os::change_dir(&root);
47-
let path = Path("frob");
48-
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
49-
assert!(os::path_is_dir(&path));
50-
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
51-
assert!(os::path_is_dir(&path));
52-
}
53-
54-
#[test]
55-
fn recursive_mkdir_dot() {
56-
use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
57-
use core::os;
58-
59-
let dot = Path(".");
60-
assert!(os::mkdir_recursive(&dot, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
61-
let dotdot = Path("..");
62-
assert!(os::mkdir_recursive(&dotdot, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
63-
}
64-
65-
#[test]
66-
fn recursive_mkdir_rel_2() {
67-
use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
68-
use core::os;
69-
70-
let root = mkdtemp(&os::tmpdir(), "temp").expect("recursive_mkdir_rel_2");
71-
os::change_dir(&root);
72-
let path = Path("./frob/baz");
73-
debug!("...Making: %s in cwd %s", path.to_str(), os::getcwd().to_str());
74-
assert!(os::mkdir_recursive(&path, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
75-
assert!(os::path_is_dir(&path));
76-
assert!(os::path_is_dir(&path.pop()));
77-
let path2 = Path("quux/blat");
78-
debug!("Making: %s in cwd %s", path2.to_str(), os::getcwd().to_str());
79-
assert!(os::mkdir_recursive(&path2, (S_IRUSR | S_IWUSR | S_IXUSR) as i32));
80-
assert!(os::path_is_dir(&path2));
81-
assert!(os::path_is_dir(&path2.pop()));
82-
}
83-
84-
}
26+
#[test]
27+
fn test_mkdtemp() {
28+
let p = mkdtemp(&Path("."), "foobar").unwrap();
29+
os::remove_dir(&p);
30+
assert!(str::ends_with(p.to_str(), "foobar"));
31+
}

0 commit comments

Comments
 (0)