Skip to content

Commit 4450d42

Browse files
committed
---
yaml --- r: 145870 b: refs/heads/try2 c: 8015f9c h: refs/heads/master v: v3
1 parent 48e1fb5 commit 4450d42

File tree

30 files changed

+1590
-1156
lines changed

30 files changed

+1590
-1156
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: caf7b678dd2f07918b47120aa73a1bca51d12da1
8+
refs/heads/try2: 8015f9c27ec342dbf0b28c9c0c4769d8b3bcfc9f
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/compiletest/errors.rs

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

11-
use std::io;
12-
1311
pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
1412

1513
// Load any test directives embedded in the file
1614
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
15+
use std::rt::io::Open;
16+
use std::rt::io::file::FileInfo;
17+
use std::rt::io::buffered::BufferedReader;
18+
1719
let mut error_patterns = ~[];
18-
let rdr = io::file_reader(testfile).unwrap();
20+
let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
1921
let mut line_num = 1u;
20-
while !rdr.eof() {
21-
let ln = rdr.read_line();
22+
loop {
23+
let ln = match rdr.read_line() {
24+
Some(ln) => ln, None => break,
25+
};
2226
error_patterns.push_all_move(parse_expected(line_num, ln));
2327
line_num += 1u;
2428
}
2529
return error_patterns;
2630
}
2731

2832
fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] {
33+
let line = line.trim();
2934
let error_tag = ~"//~";
3035
let mut idx;
3136
match line.find_str(error_tag) {

branches/try2/src/compiletest/header.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use common::config;
1212
use common;
1313
use util;
1414

15-
use std::io;
16-
1715
pub struct TestProps {
1816
// Lines that should be expected, in order, on standard out
1917
error_patterns: ~[~str],
@@ -104,17 +102,23 @@ pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
104102
!val
105103
}
106104

107-
fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
108-
let rdr = io::file_reader(testfile).unwrap();
109-
while !rdr.eof() {
110-
let ln = rdr.read_line();
105+
fn iter_header(testfile: &Path, it: &fn(&str) -> bool) -> bool {
106+
use std::rt::io::Open;
107+
use std::rt::io::file::FileInfo;
108+
use std::rt::io::buffered::BufferedReader;
109+
110+
let mut rdr = BufferedReader::new(testfile.open_reader(Open).unwrap());
111+
loop {
112+
let ln = match rdr.read_line() {
113+
Some(ln) => ln, None => break
114+
};
111115

112116
// Assume that any directives will be found before the first
113117
// module or function. This doesn't seem to be an optimization
114118
// with a warm page cache. Maybe with a cold one.
115119
if ln.starts_with("fn") || ln.starts_with("mod") {
116120
return true;
117-
} else { if !(it(ln)) { return false; } }
121+
} else { if !(it(ln.trim())) { return false; } }
118122
}
119123
return true;
120124
}

branches/try2/src/compiletest/procsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn run(lib_path: &str,
5757
});
5858

5959
for input in input.iter() {
60-
proc.input().write_str(*input);
60+
proc.input().write(input.as_bytes());
6161
}
6262
let output = proc.finish_with_output();
6363

branches/try2/src/libextra/base64.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ impl<'self> ToBase64 for &'self [u8] {
6464
*
6565
* ```rust
6666
* extern mod extra;
67-
* use extra::base64::{ToBase64, standard};
67+
* use extra::base64::{ToBase64, STANDARD};
6868
*
6969
* fn main () {
70-
* let str = [52,32].to_base64(standard);
71-
* println!("{}", str);
70+
* let str = [52,32].to_base64(STANDARD);
71+
* println!("base 64 output: {}", str);
7272
* }
7373
* ```
7474
*/
@@ -172,16 +172,19 @@ impl<'self> FromBase64 for &'self str {
172172
*
173173
* ```rust
174174
* extern mod extra;
175-
* use extra::base64::{ToBase64, FromBase64, standard};
175+
* use extra::base64::{ToBase64, FromBase64, STANDARD};
176176
* use std::str;
177177
*
178178
* fn main () {
179-
* let hello_str = "Hello, World".to_base64(standard);
180-
* println!("{}", hello_str);
181-
* let bytes = hello_str.from_base64();
182-
* println!("{:?}", bytes);
183-
* let result_str = str::from_utf8(bytes);
184-
* println!("{}", result_str);
179+
* let hello_str = bytes!("Hello, World").to_base64(STANDARD);
180+
* println!("base64 output: {}", hello_str);
181+
* let res = hello_str.from_base64();
182+
* if res.is_ok() {
183+
* let optBytes = str::from_utf8_opt(res.unwrap());
184+
* if optBytes.is_some() {
185+
* println!("decoded from base64: {}", optBytes.unwrap());
186+
* }
187+
* }
185188
* }
186189
* ```
187190
*/

branches/try2/src/librustc/middle/effect.rs

Lines changed: 100 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,14 @@
1111
//! Enforces the Rust effect system. Currently there is just one effect,
1212
/// `unsafe`.
1313
14-
use middle::ty::{ty_bare_fn, ty_closure, ty_ptr};
1514
use middle::ty;
1615
use middle::typeck::method_map;
1716
use util::ppaux;
1817

19-
use syntax::ast::{UnDeref, ExprCall, ExprInlineAsm, ExprMethodCall};
20-
use syntax::ast::{ExprUnary, unsafe_fn, ExprPath};
2118
use syntax::ast;
2219
use syntax::codemap::Span;
23-
use syntax::visit::{fk_item_fn, fk_method};
2420
use syntax::visit;
25-
use syntax::visit::{Visitor,fn_kind};
26-
use syntax::ast::{fn_decl,Block,NodeId,Expr};
21+
use syntax::visit::Visitor;
2722

2823
#[deriving(Eq)]
2924
enum UnsafeContext {
@@ -32,29 +27,26 @@ enum UnsafeContext {
3227
UnsafeBlock(ast::NodeId),
3328
}
3429

35-
struct Context {
36-
/// The method map.
37-
method_map: method_map,
38-
/// Whether we're in an unsafe context.
39-
unsafe_context: UnsafeContext,
40-
}
41-
4230
fn type_is_unsafe_function(ty: ty::t) -> bool {
4331
match ty::get(ty).sty {
44-
ty_bare_fn(ref f) => f.purity == unsafe_fn,
45-
ty_closure(ref f) => f.purity == unsafe_fn,
32+
ty::ty_bare_fn(ref f) => f.purity == ast::unsafe_fn,
33+
ty::ty_closure(ref f) => f.purity == ast::unsafe_fn,
4634
_ => false,
4735
}
4836
}
4937

5038
struct EffectCheckVisitor {
5139
tcx: ty::ctxt,
52-
context: @mut Context,
40+
41+
/// The method map.
42+
method_map: method_map,
43+
/// Whether we're in an unsafe context.
44+
unsafe_context: UnsafeContext,
5345
}
5446

5547
impl EffectCheckVisitor {
5648
fn require_unsafe(&mut self, span: Span, description: &str) {
57-
match self.context.unsafe_context {
49+
match self.unsafe_context {
5850
SafeContext => {
5951
// Report an error.
6052
self.tcx.sess.span_err(span,
@@ -69,112 +61,124 @@ impl EffectCheckVisitor {
6961
UnsafeFn => {}
7062
}
7163
}
64+
65+
fn check_str_index(&mut self, e: @ast::Expr) {
66+
let base_type = match e.node {
67+
ast::ExprIndex(_, base, _) => ty::node_id_to_type(self.tcx, base.id),
68+
_ => return
69+
};
70+
debug2!("effect: checking index with base type {}",
71+
ppaux::ty_to_str(self.tcx, base_type));
72+
match ty::get(base_type).sty {
73+
ty::ty_estr(*) => {
74+
self.tcx.sess.span_err(e.span,
75+
"modification of string types is not allowed");
76+
}
77+
_ => {}
78+
}
79+
}
7280
}
7381

7482
impl Visitor<()> for EffectCheckVisitor {
75-
fn visit_fn(&mut self, fn_kind:&fn_kind, fn_decl:&fn_decl,
76-
block:&Block, span:Span, node_id:NodeId, _:()) {
77-
78-
let (is_item_fn, is_unsafe_fn) = match *fn_kind {
79-
fk_item_fn(_, _, purity, _) => (true, purity == unsafe_fn),
80-
fk_method(_, _, method) => (true, method.purity == unsafe_fn),
81-
_ => (false, false),
82-
};
83-
84-
let old_unsafe_context = self.context.unsafe_context;
85-
if is_unsafe_fn {
86-
self.context.unsafe_context = UnsafeFn
87-
} else if is_item_fn {
88-
self.context.unsafe_context = SafeContext
89-
}
83+
fn visit_fn(&mut self, fn_kind: &visit::fn_kind, fn_decl: &ast::fn_decl,
84+
block: &ast::Block, span: Span, node_id: ast::NodeId, _:()) {
85+
86+
let (is_item_fn, is_unsafe_fn) = match *fn_kind {
87+
visit::fk_item_fn(_, _, purity, _) =>
88+
(true, purity == ast::unsafe_fn),
89+
visit::fk_method(_, _, method) =>
90+
(true, method.purity == ast::unsafe_fn),
91+
_ => (false, false),
92+
};
93+
94+
let old_unsafe_context = self.unsafe_context;
95+
if is_unsafe_fn {
96+
self.unsafe_context = UnsafeFn
97+
} else if is_item_fn {
98+
self.unsafe_context = SafeContext
99+
}
90100

91-
visit::walk_fn(self,
92-
fn_kind,
93-
fn_decl,
94-
block,
95-
span,
96-
node_id,
97-
());
101+
visit::walk_fn(self, fn_kind, fn_decl, block, span, node_id, ());
98102

99-
self.context.unsafe_context = old_unsafe_context
103+
self.unsafe_context = old_unsafe_context
100104
}
101105

102-
fn visit_block(&mut self, block:&Block, _:()) {
103-
104-
let old_unsafe_context = self.context.unsafe_context;
105-
let is_unsafe = match block.rules {
106-
ast::UnsafeBlock(*) => true, ast::DefaultBlock => false
107-
};
108-
if is_unsafe && self.context.unsafe_context == SafeContext {
109-
self.context.unsafe_context = UnsafeBlock(block.id)
110-
}
106+
fn visit_block(&mut self, block: &ast::Block, _:()) {
107+
let old_unsafe_context = self.unsafe_context;
108+
let is_unsafe = match block.rules {
109+
ast::UnsafeBlock(*) => true, ast::DefaultBlock => false
110+
};
111+
if is_unsafe && self.unsafe_context == SafeContext {
112+
self.unsafe_context = UnsafeBlock(block.id)
113+
}
111114

112-
visit::walk_block(self, block, ());
115+
visit::walk_block(self, block, ());
113116

114-
self.context.unsafe_context = old_unsafe_context
117+
self.unsafe_context = old_unsafe_context
115118
}
116119

117-
fn visit_expr(&mut self, expr:@Expr, _:()) {
118-
119-
match expr.node {
120-
ExprMethodCall(callee_id, _, _, _, _, _) => {
121-
let base_type = ty::node_id_to_type(self.tcx, callee_id);
122-
debug2!("effect: method call case, base type is {}",
123-
ppaux::ty_to_str(self.tcx, base_type));
124-
if type_is_unsafe_function(base_type) {
125-
self.require_unsafe(expr.span,
126-
"invocation of unsafe method")
127-
}
120+
fn visit_expr(&mut self, expr: @ast::Expr, _:()) {
121+
match expr.node {
122+
ast::ExprMethodCall(callee_id, _, _, _, _, _) => {
123+
let base_type = ty::node_id_to_type(self.tcx, callee_id);
124+
debug2!("effect: method call case, base type is {}",
125+
ppaux::ty_to_str(self.tcx, base_type));
126+
if type_is_unsafe_function(base_type) {
127+
self.require_unsafe(expr.span,
128+
"invocation of unsafe method")
128129
}
129-
ExprCall(base, _, _) => {
130-
let base_type = ty::node_id_to_type(self.tcx, base.id);
131-
debug2!("effect: call case, base type is {}",
132-
ppaux::ty_to_str(self.tcx, base_type));
133-
if type_is_unsafe_function(base_type) {
134-
self.require_unsafe(expr.span, "call to unsafe function")
135-
}
130+
}
131+
ast::ExprCall(base, _, _) => {
132+
let base_type = ty::node_id_to_type(self.tcx, base.id);
133+
debug2!("effect: call case, base type is {}",
134+
ppaux::ty_to_str(self.tcx, base_type));
135+
if type_is_unsafe_function(base_type) {
136+
self.require_unsafe(expr.span, "call to unsafe function")
136137
}
137-
ExprUnary(_, UnDeref, base) => {
138-
let base_type = ty::node_id_to_type(self.tcx, base.id);
139-
debug2!("effect: unary case, base type is {}",
140-
ppaux::ty_to_str(self.tcx, base_type));
141-
match ty::get(base_type).sty {
142-
ty_ptr(_) => {
143-
self.require_unsafe(expr.span,
144-
"dereference of unsafe pointer")
145-
}
146-
_ => {}
138+
}
139+
ast::ExprUnary(_, ast::UnDeref, base) => {
140+
let base_type = ty::node_id_to_type(self.tcx, base.id);
141+
debug2!("effect: unary case, base type is {}",
142+
ppaux::ty_to_str(self.tcx, base_type));
143+
match ty::get(base_type).sty {
144+
ty::ty_ptr(_) => {
145+
self.require_unsafe(expr.span,
146+
"dereference of unsafe pointer")
147147
}
148+
_ => {}
148149
}
149-
ExprInlineAsm(*) => {
150-
self.require_unsafe(expr.span, "use of inline assembly")
151-
}
152-
ExprPath(*) => {
153-
match ty::resolve_expr(self.tcx, expr) {
154-
ast::DefStatic(_, true) => {
155-
self.require_unsafe(expr.span, "use of mutable static")
156-
}
157-
_ => {}
150+
}
151+
ast::ExprAssign(base, _) | ast::ExprAssignOp(_, _, base, _) => {
152+
self.check_str_index(base);
153+
}
154+
ast::ExprAddrOf(ast::MutMutable, base) => {
155+
self.check_str_index(base);
156+
}
157+
ast::ExprInlineAsm(*) => {
158+
self.require_unsafe(expr.span, "use of inline assembly")
159+
}
160+
ast::ExprPath(*) => {
161+
match ty::resolve_expr(self.tcx, expr) {
162+
ast::DefStatic(_, true) => {
163+
self.require_unsafe(expr.span, "use of mutable static")
158164
}
165+
_ => {}
159166
}
160-
_ => {}
161167
}
168+
_ => {}
169+
}
162170

163-
visit::walk_expr(self, expr, ());
171+
visit::walk_expr(self, expr, ());
164172
}
165173
}
166174

167175
pub fn check_crate(tcx: ty::ctxt,
168176
method_map: method_map,
169177
crate: &ast::Crate) {
170-
let context = @mut Context {
171-
method_map: method_map,
172-
unsafe_context: SafeContext,
173-
};
174-
175178
let mut visitor = EffectCheckVisitor {
176179
tcx: tcx,
177-
context: context,
180+
method_map: method_map,
181+
unsafe_context: SafeContext,
178182
};
179183

180184
visit::walk_crate(&mut visitor, crate, ());

0 commit comments

Comments
 (0)