Skip to content

Commit d96e47f

Browse files
committed
---
yaml --- r: 114333 b: refs/heads/master c: f30382d h: refs/heads/master i: 114331: d67b631 v: v3
1 parent 23d8876 commit d96e47f

File tree

12 files changed

+279
-81
lines changed

12 files changed

+279
-81
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ae67b74ec826cfc00467b9d4355beb307315d08b
2+
refs/heads/master: f30382d624d4a523262df05234b1c20b7de4ac0c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

trunk/src/compiletest/common.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -91,6 +91,9 @@ pub struct Config {
9191
// Only run tests that match this filter
9292
pub filter: Option<Regex>,
9393

94+
// Precompiled regex for finding expected errors in cfail
95+
pub cfail_regex: Regex,
96+
9497
// Write out a parseable log of tests that were run
9598
pub logfile: Option<Path>,
9699

@@ -144,5 +147,4 @@ pub struct Config {
144147

145148
// Explain what's going on
146149
pub verbose: bool
147-
148150
}

trunk/src/compiletest/compiletest.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -33,6 +33,7 @@ use getopts::{optopt, optflag, reqopt};
3333
use common::Config;
3434
use common::{Pretty, DebugInfoGdb, Codegen};
3535
use util::logv;
36+
use regex::Regex;
3637

3738
pub mod procsrv;
3839
pub mod util;
@@ -147,6 +148,7 @@ pub fn parse_config(args: Vec<StrBuf> ) -> Config {
147148
.as_slice()).expect("invalid mode"),
148149
run_ignored: matches.opt_present("ignored"),
149150
filter: filter,
151+
cfail_regex: Regex::new(errors::EXPECTED_PATTERN).unwrap(),
150152
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
151153
save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
152154
ratchet_metrics:

trunk/src/compiletest/errors.rs

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -9,68 +9,36 @@
99
// except according to those terms.
1010

1111
use std::io::{BufferedReader, File};
12+
use regex::Regex;
1213

1314
pub struct ExpectedError {
1415
pub line: uint,
1516
pub kind: StrBuf,
1617
pub msg: StrBuf,
1718
}
1819

19-
// Load any test directives embedded in the file
20-
pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
20+
pub static EXPECTED_PATTERN : &'static str = r"//~(?P<adjusts>\^*)\s*(?P<kind>\S*)\s*(?P<msg>.*)";
2121

22-
let mut error_patterns = Vec::new();
22+
// Load any test directives embedded in the file
23+
pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> {
2324
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
24-
let mut line_num = 1u;
25-
for ln in rdr.lines() {
26-
error_patterns.push_all_move(parse_expected(line_num,
27-
ln.unwrap().to_strbuf()));
28-
line_num += 1u;
29-
}
30-
return error_patterns;
31-
}
32-
33-
fn parse_expected(line_num: uint, line: StrBuf) -> Vec<ExpectedError> {
34-
let line = line.as_slice().trim().to_strbuf();
35-
let error_tag = "//~".to_strbuf();
36-
let mut idx;
37-
match line.as_slice().find_str(error_tag.as_slice()) {
38-
None => return Vec::new(),
39-
Some(nn) => { idx = (nn as uint) + error_tag.len(); }
40-
}
41-
42-
// "//~^^^ kind msg" denotes a message expected
43-
// three lines above current line:
44-
let mut adjust_line = 0u;
45-
let len = line.len();
46-
while idx < len && line.as_slice()[idx] == ('^' as u8) {
47-
adjust_line += 1u;
48-
idx += 1u;
49-
}
5025

51-
// Extract kind:
52-
while idx < len && line.as_slice()[idx] == (' ' as u8) {
53-
idx += 1u;
54-
}
55-
let start_kind = idx;
56-
while idx < len && line.as_slice()[idx] != (' ' as u8) {
57-
idx += 1u;
58-
}
59-
60-
let kind = line.as_slice().slice(start_kind, idx);
61-
let kind = kind.to_ascii().to_lower().into_str().to_strbuf();
62-
63-
// Extract msg:
64-
while idx < len && line.as_slice()[idx] == (' ' as u8) {
65-
idx += 1u;
66-
}
67-
let msg = line.as_slice().slice(idx, len).to_strbuf();
68-
69-
debug!("line={} kind={} msg={}", line_num - adjust_line, kind, msg);
26+
rdr.lines().enumerate().filter_map(|(line_no, ln)| {
27+
parse_expected(line_no + 1, ln.unwrap(), re)
28+
}).collect()
29+
}
7030

71-
return vec!(ExpectedError{
72-
line: line_num - adjust_line,
73-
kind: kind,
74-
msg: msg,
75-
});
31+
fn parse_expected(line_num: uint, line: &str, re: &Regex) -> Option<ExpectedError> {
32+
re.captures(line).and_then(|caps| {
33+
let adjusts = caps.name("adjusts").len();
34+
let kind = caps.name("kind").to_ascii().to_lower().into_str().to_strbuf();
35+
let msg = caps.name("msg").trim().to_strbuf();
36+
37+
debug!("line={} kind={} msg={}", line_num, kind, msg);
38+
Some(ExpectedError {
39+
line: line_num - adjusts,
40+
kind: kind,
41+
msg: msg,
42+
})
43+
})
7644
}

trunk/src/compiletest/runtest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -79,7 +79,7 @@ fn run_cfail_test(config: &Config, props: &TestProps, testfile: &Path) {
7979

8080
check_correct_failure_status(&proc_res);
8181

82-
let expected_errors = errors::load_errors(testfile);
82+
let expected_errors = errors::load_errors(&config.cfail_regex, testfile);
8383
if !expected_errors.is_empty() {
8484
if !props.error_patterns.is_empty() {
8585
fatal("both error pattern and expected errors \

trunk/src/libcore/cell.rs

Lines changed: 151 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,157 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Types that provide interior mutability.
11+
//! Sharable mutable containers.
12+
//!
13+
//! Values of the `Cell` and `RefCell` types may be mutated through
14+
//! shared references (i.e. the common `&T` type), whereas most Rust
15+
//! types can only be mutated through unique (`&mut T`) references. We
16+
//! say that `Cell` and `RefCell` provide *interior mutability*, in
17+
//! contrast with typical Rust types that exhibit *inherited
18+
//! mutability*.
19+
//!
20+
//! Cell types come in two flavors: `Cell` and `RefCell`. `Cell`
21+
//! provides `get` and `set` methods that change the
22+
//! interior value with a single method call. `Cell` though is only
23+
//! compatible with types that implement `Copy`. For other types,
24+
//! one must use the `RefCell` type, acquiring a write lock before
25+
//! mutating.
26+
//!
27+
//! `RefCell` uses Rust's lifetimes to implement *dynamic borrowing*,
28+
//! a process whereby one can claim temporary, exclusive, mutable
29+
//! access to the inner value. Borrows for `RefCell`s are tracked *at
30+
//! runtime*, unlike Rust's native reference types which are entirely
31+
//! tracked statically, at compile time. Because `RefCell` borrows are
32+
//! dynamic it is possible to attempt to borrow a value that is
33+
//! already mutably borrowed; when this happens it results in task
34+
//! failure.
35+
//!
36+
//! # When to choose interior mutability
37+
//!
38+
//! The more common inherited mutability, where one must have unique
39+
//! access to mutate a value, is one of the key language elements that
40+
//! enables Rust to reason strongly about pointer aliasing, statically
41+
//! preventing crash bugs. Because of that, inherited mutability is
42+
//! preferred, and interior mutability is something of a last
43+
//! resort. Since cell types enable mutation where it would otherwise
44+
//! be disallowed though, there are occassions when interior
45+
//! mutability might be appropriate, or even *must* be used, e.g.
46+
//!
47+
//! * Introducing inherited mutability roots to shared types.
48+
//! * Implementation details of logically-immutable methods.
49+
//! * Mutating implementations of `clone`.
50+
//!
51+
//! ## Introducing inherited mutability roots to shared types
52+
//!
53+
//! Shared smart pointer types, including `Rc` and `Arc`, provide
54+
//! containers that can be cloned and shared between multiple parties.
55+
//! Because the contained values may be multiply-aliased, they can
56+
//! only be borrowed as shared references, not mutable references.
57+
//! Without cells it would be impossible to mutate data inside of
58+
//! shared boxes at all!
59+
//!
60+
//! It's very common then to put a `RefCell` inside shared pointer
61+
//! types to reintroduce mutability:
62+
//!
63+
//! ```
64+
//! extern crate collections;
65+
//!
66+
//! use collections::HashMap;
67+
//! use std::cell::RefCell;
68+
//! use std::rc::Rc;
69+
//!
70+
//! fn main() {
71+
//! let shared_map: Rc<RefCell<_>> = Rc::new(RefCell::new(HashMap::new()));
72+
//! shared_map.borrow_mut().insert("africa", 92388);
73+
//! shared_map.borrow_mut().insert("kyoto", 11837);
74+
//! shared_map.borrow_mut().insert("piccadilly", 11826);
75+
//! shared_map.borrow_mut().insert("marbles", 38);
76+
//! }
77+
//! ```
78+
//!
79+
//! ## Implementation details of logically-immutable methods
80+
//!
81+
//! Occasionally it may be desirable not to expose in an API that
82+
//! there is mutation happening "under the hood". This may be because
83+
//! logically the operation is immutable, but e.g. caching forces the
84+
//! implementation to perform mutation; or because you must employ
85+
//! mutation to implement a trait method that was originally defined
86+
//! to take `&self`.
87+
//!
88+
//! ```
89+
//! extern crate collections;
90+
//!
91+
//! use collections::HashMap;
92+
//! use std::cell::RefCell;
93+
//!
94+
//! struct Graph {
95+
//! edges: HashMap<uint, uint>,
96+
//! span_tree_cache: RefCell<Option<Vec<(uint, uint)>>>
97+
//! }
98+
//!
99+
//! impl Graph {
100+
//! fn minimum_spanning_tree(&self) -> Vec<(uint, uint)> {
101+
//! // Create a new scope to contain the lifetime of the
102+
//! // dynamic borrow
103+
//! {
104+
//! // Take a reference to the inside of cache cell
105+
//! let mut cache = self.span_tree_cache.borrow_mut();
106+
//! if cache.is_some() {
107+
//! return cache.get_ref().clone();
108+
//! }
109+
//!
110+
//! let span_tree = self.calc_span_tree();
111+
//! *cache = Some(span_tree);
112+
//! }
113+
//!
114+
//! // Recursive call to return the just-cached value.
115+
//! // Note that if we had not let the previous borrow
116+
//! // of the cache fall out of scope then the subsequent
117+
//! // recursive borrow would cause a dynamic task failure.
118+
//! // This is the major hazard of using `RefCell`.
119+
//! self.minimum_spanning_tree()
120+
//! }
121+
//! # fn calc_span_tree(&self) -> Vec<(uint, uint)> { vec![] }
122+
//! }
123+
//! # fn main() { }
124+
//! ```
125+
//!
126+
//! ## Mutating implementations of `clone`
127+
//!
128+
//! This is simply a special - but common - case of the previous:
129+
//! hiding mutability for operations that appear to be immutable.
130+
//! The `clone` method is expected to not change the source value, and
131+
//! is declared to take `&self`, not `&mut self`. Therefore any
132+
//! mutation that happens in the `clone` method must use cell
133+
//! types. For example, `Rc` maintains its reference counts within a
134+
//! `Cell`.
135+
//!
136+
//! ```
137+
//! use std::cell::Cell;
138+
//!
139+
//! struct Rc<T> {
140+
//! ptr: *mut RcBox<T>
141+
//! }
142+
//!
143+
//! struct RcBox<T> {
144+
//! value: T,
145+
//! refcount: Cell<uint>
146+
//! }
147+
//!
148+
//! impl<T> Clone for Rc<T> {
149+
//! fn clone(&self) -> Rc<T> {
150+
//! unsafe {
151+
//! (*self.ptr).refcount.set((*self.ptr).refcount.get() + 1);
152+
//! Rc { ptr: self.ptr }
153+
//! }
154+
//! }
155+
//! }
156+
//! ```
157+
//!
158+
// FIXME: Explain difference between Cell and RefCell
159+
// FIXME: Downsides to interior mutability
160+
// FIXME: Can't be shared between threads. Dynamic borrows
161+
// FIXME: Relationship to Atomic types and RWLock
12162

13163
use clone::Clone;
14164
use cmp::Eq;

trunk/src/libcore/lib.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,28 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! The Rust core library
11+
//! The Rust Core Library
1212
//!
13-
//! This library is meant to represent the core functionality of rust that is
14-
//! maximally portable to other platforms. To that extent, this library has no
15-
//! knowledge of things like allocation, threads, I/O, etc. This library is
16-
//! built on the assumption of a few existing symbols:
13+
//! The Rust Core Library is the dependency-free foundation of [The
14+
//! Rust Standard Library](../std/index.html). It is the portable glue
15+
//! between the language and its libraries, defining the intrinsic and
16+
//! primitive building blocks of all Rust code. It links to no
17+
//! upstream libraries, no system libraries, and no libc.
18+
//!
19+
//! The core library is *minimal*: it isn't even aware of heap allocation,
20+
//! nor does it provide concurrency or I/O. These things require
21+
//! platform integration, and this library is platform-agnostic.
22+
//!
23+
//! *It is not recommended to use the core library*. The stable
24+
//! functionality of libcore is reexported from the
25+
//! [standard library](../std/index.html). The composition of this library is
26+
//! subject to change over time; only the interface exposed through libstd is
27+
//! intended to be stable.
28+
//!
29+
//! # How to use the core library
30+
//!
31+
// FIXME: Fill me in with more detail when the interface settles
32+
//! This library is built on the assumption of a few existing symbols:
1733
//!
1834
//! * `memcpy`, `memcmp`, `memset` - These are core memory routines which are
1935
//! often generated by LLVM. Additionally, this library can make explicit
@@ -23,16 +39,11 @@
2339
//! distribution.
2440
//!
2541
//! * `rust_begin_unwind` - This function takes three arguments, a
26-
//! `&fmt::Arguments`, a `&str`, and a `uint. These three arguments dictate
42+
//! `&fmt::Arguments`, a `&str`, and a `uint`. These three arguments dictate
2743
//! the failure message, the file at which failure was invoked, and the line.
2844
//! It is up to consumers of this core library to define this failure
2945
//! function; it is only required to never return.
3046
//!
31-
//! Currently, it is *not* recommended to use the core library. The stable
32-
//! functionality of libcore is exported directly into the
33-
//! [standard library](../std/index.html). The composition of this library is
34-
//! subject to change over time, only the interface exposed through libstd is
35-
//! intended to be stable.
3647
3748
#![crate_id = "core#0.11.0-pre"]
3849
#![license = "MIT/ASL2"]

trunk/src/libcore/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
/*!
1212
*
13-
* Traits representing built-in operators, useful for overloading
13+
* Overloadable operators
1414
*
1515
* Implementing these traits allows you to get an effect similar to
1616
* overloading operators.

trunk/src/librustc/middle/typeck/infer/region_inference/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ impl<'a> RegionVarBindings<'a> {
299299
sub.repr(self.tcx),
300300
sup.repr(self.tcx)));
301301
}
302+
(_, ReStatic) => {
303+
// all regions are subregions of static, so we can ignore this
304+
}
302305
(ReInfer(ReVar(sub_id)), ReInfer(ReVar(sup_id))) => {
303306
self.add_constraint(ConstrainVarSubVar(sub_id, sup_id), origin);
304307
}

0 commit comments

Comments
 (0)