Skip to content

Commit 2043aed

Browse files
committed
---
yaml --- r: 216355 b: refs/heads/stable c: 3f025fe h: refs/heads/master i: 216353: 63e8917 216351: 9ad4b06 v: v3
1 parent 7f29577 commit 2043aed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1002
-2691
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ refs/heads/tmp: 378a370ff2057afeb1eae86eb6e78c476866a4a6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: a5286998df566e736b32f6795bfc3803bdaf453d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: e14af089a47d00af85565956421200f889978c7a
32+
refs/heads/stable: 3f025fe7b2763c8715325b573b08498ec27efd1e
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375

branches/stable/src/libcore/intrinsics.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,12 @@ extern "rust-intrinsic" {
255255
/// Returns `true` if a type is managed (will be allocated on the local heap)
256256
pub fn owns_managed<T>() -> bool;
257257

258-
/// Calculates the offset from a pointer.
258+
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
259+
/// the object, or one-byte-past-the-end. An arithmetic overflow is also
260+
/// undefined behaviour.
259261
///
260262
/// This is implemented as an intrinsic to avoid converting to and from an
261263
/// integer, since the conversion would throw away aliasing information.
262-
///
263-
/// # Safety
264-
///
265-
/// Both the starting and resulting pointer must be either in bounds or one
266-
/// byte past the end of an allocated object. If either pointer is out of
267-
/// bounds or arithmetic overflow occurs then any further use of the
268-
/// returned value will result in undefined behavior.
269264
pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
270265

271266
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source

branches/stable/src/libcore/ptr.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,9 @@ impl<T: ?Sized> *const T {
284284
///
285285
/// # Safety
286286
///
287-
/// Both the starting and resulting pointer must be either in bounds or one
288-
/// byte past the end of an allocated object. If either pointer is out of
289-
/// bounds or arithmetic overflow occurs then
290-
/// any further use of the returned value will result in undefined behavior.
287+
/// The offset must be in-bounds of the object, or one-byte-past-the-end.
288+
/// Otherwise `offset` invokes Undefined Behaviour, regardless of whether
289+
/// the pointer is used.
291290
#[stable(feature = "rust1", since = "1.0.0")]
292291
#[inline]
293292
pub unsafe fn offset(self, count: isize) -> *const T where T: Sized {

branches/stable/src/librustc/diagnostics.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,25 +168,6 @@ match x {
168168
```
169169
"##,
170170

171-
E0013: r##"
172-
Static and const variables can refer to other const variables. But a const
173-
variable cannot refer to a static variable. For example, `Y` cannot refer to `X`
174-
here:
175-
176-
```
177-
static X: i32 = 42;
178-
const Y: i32 = X;
179-
```
180-
181-
To fix this, the value can be extracted as a const and then used:
182-
183-
```
184-
const A: i32 = 42;
185-
static X: i32 = A;
186-
const Y: i32 = A;
187-
```
188-
"##,
189-
190171
E0015: r##"
191172
The only function calls allowed in static or constant expressions are enum
192173
variant constructors or struct constructors (for unit or tuple structs). This
@@ -481,6 +462,7 @@ register_diagnostics! {
481462
E0010,
482463
E0011,
483464
E0012,
465+
E0013,
484466
E0014,
485467
E0016,
486468
E0017,

branches/stable/src/librustc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#![feature(path_ext)]
4040
#![feature(str_char)]
4141
#![feature(into_cow)]
42-
#![feature(fs_canonicalize)]
4342
#![feature(slice_patterns)]
4443
#![cfg_attr(test, feature(test))]
4544

@@ -139,6 +138,7 @@ pub mod plugin;
139138
pub mod lint;
140139

141140
pub mod util {
141+
pub use rustc_back::fs;
142142
pub use rustc_back::sha2;
143143

144144
pub mod common;

branches/stable/src/librustc/metadata/creader.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ use metadata::decoder;
2121
use metadata::loader;
2222
use metadata::loader::CratePaths;
2323

24-
use std::path::PathBuf;
24+
use std::path::{Path, PathBuf};
2525
use std::rc::Rc;
26-
use std::fs;
27-
2826
use syntax::ast;
2927
use syntax::abi;
3028
use syntax::attr;
@@ -34,6 +32,7 @@ use syntax::parse;
3432
use syntax::parse::token::InternedString;
3533
use syntax::parse::token;
3634
use syntax::visit;
35+
use util::fs;
3736
use log;
3837

3938
pub struct CrateReader<'a> {
@@ -323,7 +322,7 @@ impl<'a> CrateReader<'a> {
323322
let source = self.sess.cstore.get_used_crate_source(cnum).unwrap();
324323
if let Some(locs) = self.sess.opts.externs.get(name) {
325324
let found = locs.iter().any(|l| {
326-
let l = fs::canonicalize(l).ok();
325+
let l = fs::realpath(&Path::new(&l[..])).ok();
327326
source.dylib.as_ref().map(|p| &p.0) == l.as_ref() ||
328327
source.rlib.as_ref().map(|p| &p.0) == l.as_ref()
329328
});
@@ -665,7 +664,7 @@ fn import_codemap(local_codemap: &codemap::CodeMap,
665664
.into_inner()
666665
.map_in_place(|mbc|
667666
codemap::MultiByteChar {
668-
pos: mbc.pos - start_pos,
667+
pos: mbc.pos + start_pos,
669668
bytes: mbc.bytes
670669
});
671670

branches/stable/src/librustc/metadata/filesearch.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::fs;
1818
use std::io::prelude::*;
1919
use std::path::{Path, PathBuf};
2020

21+
use util::fs as myfs;
2122
use session::search_paths::{SearchPaths, PathKind};
2223

2324
#[derive(Copy, Clone)]
@@ -190,7 +191,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
190191
// Follow symlinks. If the resolved path is relative, make it absolute.
191192
fn canonicalize(path: Option<PathBuf>) -> Option<PathBuf> {
192193
path.and_then(|path| {
193-
match fs::canonicalize(&path) {
194+
match myfs::realpath(&path) {
194195
Ok(canon) => Some(canon),
195196
Err(e) => panic!("failed to get realpath: {}", e),
196197
}

branches/stable/src/librustc/metadata/loader.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ use metadata::encoder;
225225
use metadata::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
226226
use syntax::codemap::Span;
227227
use syntax::diagnostic::SpanHandler;
228+
use util::fs;
228229
use util::common;
229230
use rustc_back::target::Target;
230231

231232
use std::cmp;
232233
use std::collections::HashMap;
233-
use std::fs;
234234
use std::io::prelude::*;
235235
use std::io;
236236
use std::path::{Path, PathBuf};
@@ -430,9 +430,9 @@ impl<'a> Context<'a> {
430430
.or_insert_with(|| (HashMap::new(), HashMap::new()));
431431
let (ref mut rlibs, ref mut dylibs) = *slot;
432432
if rlib {
433-
rlibs.insert(fs::canonicalize(path).unwrap(), kind);
433+
rlibs.insert(fs::realpath(path).unwrap(), kind);
434434
} else {
435-
dylibs.insert(fs::canonicalize(path).unwrap(), kind);
435+
dylibs.insert(fs::realpath(path).unwrap(), kind);
436436
}
437437

438438
FileMatches
@@ -660,10 +660,10 @@ impl<'a> Context<'a> {
660660
// there's at most one rlib and at most one dylib.
661661
for loc in locs {
662662
if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib") {
663-
rlibs.insert(fs::canonicalize(&loc).unwrap(),
663+
rlibs.insert(fs::realpath(&loc).unwrap(),
664664
PathKind::ExternFlag);
665665
} else {
666-
dylibs.insert(fs::canonicalize(&loc).unwrap(),
666+
dylibs.insert(fs::realpath(&loc).unwrap(),
667667
PathKind::ExternFlag);
668668
}
669669
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2014 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::io;
12+
use std::path::{Path, PathBuf};
13+
14+
#[cfg(windows)]
15+
pub fn realpath(original: &Path) -> io::Result<PathBuf> {
16+
Ok(original.to_path_buf())
17+
}
18+
19+
#[cfg(unix)]
20+
pub fn realpath(original: &Path) -> io::Result<PathBuf> {
21+
use libc;
22+
use std::ffi::{OsString, CString};
23+
use std::os::unix::prelude::*;
24+
25+
extern {
26+
fn realpath(pathname: *const libc::c_char, resolved: *mut libc::c_char)
27+
-> *mut libc::c_char;
28+
}
29+
30+
let path = try!(CString::new(original.as_os_str().as_bytes()));
31+
let mut buf = vec![0u8; 16 * 1024];
32+
unsafe {
33+
let r = realpath(path.as_ptr(), buf.as_mut_ptr() as *mut _);
34+
if r.is_null() {
35+
return Err(io::Error::last_os_error())
36+
}
37+
}
38+
let p = buf.iter().position(|i| *i == 0).unwrap();
39+
buf.truncate(p);
40+
Ok(PathBuf::from(OsString::from_vec(buf)))
41+
}
42+
43+
#[cfg(all(not(windows), test))]
44+
mod tests {
45+
use tempdir::TempDir;
46+
use std::fs::{self, File};
47+
use super::realpath;
48+
49+
#[test]
50+
fn realpath_works() {
51+
let tmpdir = TempDir::new("rustc-fs").unwrap();
52+
let tmpdir = realpath(tmpdir.path()).unwrap();
53+
let file = tmpdir.join("test");
54+
let dir = tmpdir.join("test2");
55+
let link = dir.join("link");
56+
let linkdir = tmpdir.join("test3");
57+
58+
File::create(&file).unwrap();
59+
fs::create_dir(&dir).unwrap();
60+
fs::soft_link(&file, &link).unwrap();
61+
fs::soft_link(&dir, &linkdir).unwrap();
62+
63+
assert_eq!(realpath(&tmpdir).unwrap(), tmpdir);
64+
assert_eq!(realpath(&file).unwrap(), file);
65+
assert_eq!(realpath(&link).unwrap(), file);
66+
assert_eq!(realpath(&linkdir).unwrap(), dir);
67+
assert_eq!(realpath(&linkdir.join("link")).unwrap(), file);
68+
}
69+
70+
#[test]
71+
fn realpath_works_tricky() {
72+
let tmpdir = TempDir::new("rustc-fs").unwrap();
73+
let tmpdir = realpath(tmpdir.path()).unwrap();
74+
75+
let a = tmpdir.join("a");
76+
let b = a.join("b");
77+
let c = b.join("c");
78+
let d = a.join("d");
79+
let e = d.join("e");
80+
let f = a.join("f");
81+
82+
fs::create_dir_all(&b).unwrap();
83+
fs::create_dir_all(&d).unwrap();
84+
File::create(&f).unwrap();
85+
fs::soft_link("../d/e", &c).unwrap();
86+
fs::soft_link("../f", &e).unwrap();
87+
88+
assert_eq!(realpath(&c).unwrap(), f);
89+
assert_eq!(realpath(&e).unwrap(), f);
90+
}
91+
}

branches/stable/src/librustc_back/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#![feature(path_ext)]
4242
#![feature(step_by)]
4343
#![feature(libc)]
44-
#![feature(fs_canonicalize)]
4544
#![cfg_attr(test, feature(test, rand))]
4645

4746
extern crate syntax;
@@ -54,6 +53,7 @@ pub mod abi;
5453
pub mod archive;
5554
pub mod tempdir;
5655
pub mod arm;
56+
pub mod fs;
5757
pub mod mips;
5858
pub mod mipsel;
5959
pub mod rpath;

branches/stable/src/librustc_back/rpath.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
use std::collections::HashSet;
1212
use std::env;
13+
use std::io;
1314
use std::path::{Path, PathBuf};
14-
use std::fs;
1515
use syntax::ast;
1616

1717
pub struct RPathConfig<'a> {
@@ -20,6 +20,7 @@ pub struct RPathConfig<'a> {
2020
pub is_like_osx: bool,
2121
pub has_rpath: bool,
2222
pub get_install_prefix_lib_path: &'a mut FnMut() -> PathBuf,
23+
pub realpath: &'a mut FnMut(&Path) -> io::Result<PathBuf>,
2324
}
2425

2526
pub fn get_rpath_flags(config: &mut RPathConfig) -> Vec<String> {
@@ -94,11 +95,11 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig, lib: &Path) -> String
9495
};
9596

9697
let cwd = env::current_dir().unwrap();
97-
let mut lib = fs::canonicalize(&cwd.join(lib)).unwrap_or(cwd.join(lib));
98+
let mut lib = (config.realpath)(&cwd.join(lib)).unwrap();
9899
lib.pop();
99100
let mut output = cwd.join(&config.out_filename);
100101
output.pop();
101-
let output = fs::canonicalize(&output).unwrap_or(output);
102+
let output = (config.realpath)(&output).unwrap();
102103
let relative = path_relative_from(&lib, &output)
103104
.expect(&format!("couldn't create relative path from {:?} to {:?}", output, lib));
104105
// FIXME (#9639): This needs to handle non-utf8 paths
@@ -230,6 +231,7 @@ mod tests {
230231
is_like_osx: true,
231232
out_filename: PathBuf::from("bin/rustc"),
232233
get_install_prefix_lib_path: &mut || panic!(),
234+
realpath: &mut |p| Ok(p.to_path_buf()),
233235
};
234236
let res = get_rpath_relative_to_output(config,
235237
Path::new("lib/libstd.so"));
@@ -241,6 +243,7 @@ mod tests {
241243
get_install_prefix_lib_path: &mut || panic!(),
242244
has_rpath: true,
243245
is_like_osx: false,
246+
realpath: &mut |p| Ok(p.to_path_buf()),
244247
};
245248
let res = get_rpath_relative_to_output(config,
246249
Path::new("lib/libstd.so"));

0 commit comments

Comments
 (0)