Skip to content

Commit de6c08c

Browse files
committed
---
yaml --- r: 94906 b: refs/heads/try c: f499d36 h: refs/heads/master v: v3
1 parent 91eac7c commit de6c08c

File tree

15 files changed

+555
-558
lines changed

15 files changed

+555
-558
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0da105a8b7b6b1e0568e8ff20f6ff4b13cc7ecc2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d3e57dca68fde4effdda3e4ae2887aa535fcd6
5-
refs/heads/try: 2e98a93ba991e2390b0068af72c5600b659cfb66
5+
refs/heads/try: f499d365ada01a23bd046bac9b1bef7ccdb9fa8c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/ascii.rs

Lines changed: 36 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
1313
use to_str::{ToStr,IntoStr};
1414
use str;
15-
use str::Str;
1615
use str::StrSlice;
1716
use str::OwnedStr;
1817
use container::Container;
1918
use cast;
2019
use iter::Iterator;
21-
use vec::{ImmutableVector, MutableVector, Vector};
20+
use vec::{ImmutableVector, MutableVector};
2221
use to_bytes::IterBytes;
23-
use option::{Option, Some, None};
22+
use option::{Some, None};
2423

2524
/// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero.
2625
#[deriving(Clone, Eq, Ord, TotalOrd, TotalEq)]
@@ -136,22 +135,8 @@ impl ToStr for Ascii {
136135

137136
/// Trait for converting into an ascii type.
138137
pub trait AsciiCast<T> {
139-
/// Convert to an ascii type, fail on non-ASCII input.
140-
#[inline]
141-
fn to_ascii(&self) -> T {
142-
assert!(self.is_ascii());
143-
unsafe {self.to_ascii_nocheck()}
144-
}
145-
146-
/// Convert to an ascii type, return None on non-ASCII input.
147-
#[inline]
148-
fn to_ascii_opt(&self) -> Option<T> {
149-
if self.is_ascii() {
150-
Some(unsafe { self.to_ascii_nocheck() })
151-
} else {
152-
None
153-
}
154-
}
138+
/// Convert to an ascii type
139+
fn to_ascii(&self) -> T;
155140

156141
/// Convert to an ascii type, not doing any range asserts
157142
unsafe fn to_ascii_nocheck(&self) -> T;
@@ -161,6 +146,12 @@ pub trait AsciiCast<T> {
161146
}
162147

163148
impl<'a> AsciiCast<&'a[Ascii]> for &'a [u8] {
149+
#[inline]
150+
fn to_ascii(&self) -> &'a[Ascii] {
151+
assert!(self.is_ascii());
152+
unsafe {self.to_ascii_nocheck()}
153+
}
154+
164155
#[inline]
165156
unsafe fn to_ascii_nocheck(&self) -> &'a[Ascii] {
166157
cast::transmute(*self)
@@ -176,6 +167,12 @@ impl<'a> AsciiCast<&'a[Ascii]> for &'a [u8] {
176167
}
177168

178169
impl<'a> AsciiCast<&'a [Ascii]> for &'a str {
170+
#[inline]
171+
fn to_ascii(&self) -> &'a [Ascii] {
172+
assert!(self.is_ascii());
173+
unsafe { self.to_ascii_nocheck() }
174+
}
175+
179176
#[inline]
180177
unsafe fn to_ascii_nocheck(&self) -> &'a [Ascii] {
181178
cast::transmute(*self)
@@ -188,6 +185,12 @@ impl<'a> AsciiCast<&'a [Ascii]> for &'a str {
188185
}
189186

190187
impl AsciiCast<Ascii> for u8 {
188+
#[inline]
189+
fn to_ascii(&self) -> Ascii {
190+
assert!(self.is_ascii());
191+
unsafe {self.to_ascii_nocheck()}
192+
}
193+
191194
#[inline]
192195
unsafe fn to_ascii_nocheck(&self) -> Ascii {
193196
Ascii{ chr: *self }
@@ -200,6 +203,12 @@ impl AsciiCast<Ascii> for u8 {
200203
}
201204

202205
impl AsciiCast<Ascii> for char {
206+
#[inline]
207+
fn to_ascii(&self) -> Ascii {
208+
assert!(self.is_ascii());
209+
unsafe {self.to_ascii_nocheck()}
210+
}
211+
203212
#[inline]
204213
unsafe fn to_ascii_nocheck(&self) -> Ascii {
205214
Ascii{ chr: *self as u8 }
@@ -213,25 +222,8 @@ impl AsciiCast<Ascii> for char {
213222

214223
/// Trait for copyless casting to an ascii vector.
215224
pub trait OwnedAsciiCast {
216-
/// Check if convertible to ascii
217-
fn is_ascii(&self) -> bool;
218-
219-
/// Take ownership and cast to an ascii vector. Fail on non-ASCII input.
220-
#[inline]
221-
fn into_ascii(self) -> ~[Ascii] {
222-
assert!(self.is_ascii());
223-
unsafe {self.into_ascii_nocheck()}
224-
}
225-
226-
/// Take ownership and cast to an ascii vector. Return None on non-ASCII input.
227-
#[inline]
228-
fn into_ascii_opt(self) -> Option<~[Ascii]> {
229-
if self.is_ascii() {
230-
Some(unsafe { self.into_ascii_nocheck() })
231-
} else {
232-
None
233-
}
234-
}
225+
/// Take ownership and cast to an ascii vector.
226+
fn into_ascii(self) -> ~[Ascii];
235227

236228
/// Take ownership and cast to an ascii vector.
237229
/// Does not perform validation checks.
@@ -240,8 +232,9 @@ pub trait OwnedAsciiCast {
240232

241233
impl OwnedAsciiCast for ~[u8] {
242234
#[inline]
243-
fn is_ascii(&self) -> bool {
244-
self.as_slice().is_ascii()
235+
fn into_ascii(self) -> ~[Ascii] {
236+
assert!(self.is_ascii());
237+
unsafe {self.into_ascii_nocheck()}
245238
}
246239

247240
#[inline]
@@ -252,8 +245,9 @@ impl OwnedAsciiCast for ~[u8] {
252245

253246
impl OwnedAsciiCast for ~str {
254247
#[inline]
255-
fn is_ascii(&self) -> bool {
256-
self.as_slice().is_ascii()
248+
fn into_ascii(self) -> ~[Ascii] {
249+
assert!(self.is_ascii());
250+
unsafe {self.into_ascii_nocheck()}
257251
}
258252

259253
#[inline]
@@ -481,11 +475,9 @@ mod tests {
481475
use super::*;
482476
use str::from_char;
483477
use char::from_u32;
484-
use option::{Some, None};
485478

486479
macro_rules! v2ascii (
487480
( [$($e:expr),*]) => ( [$(Ascii{chr:$e}),*]);
488-
(&[$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);
489481
(~[$($e:expr),*]) => (~[$(Ascii{chr:$e}),*]);
490482
)
491483

@@ -577,32 +569,6 @@ mod tests {
577569
#[test] #[should_fail]
578570
fn test_ascii_fail_char_slice() { 'λ'.to_ascii(); }
579571
580-
fn test_opt() {
581-
assert_eq!(65u8.to_ascii_opt(), Some(Ascii { chr: 65u8 }));
582-
assert_eq!(255u8.to_ascii_opt(), None);
583-
584-
assert_eq!('A'.to_ascii_opt(), Some(Ascii { chr: 65u8 }));
585-
assert_eq!('λ'.to_ascii_opt(), None);
586-
587-
assert_eq!("zoä华".to_ascii_opt(), None);
588-
589-
assert_eq!((&[127u8, 128u8, 255u8]).to_ascii_opt(), None);
590-
591-
let v = [40u8, 32u8, 59u8];
592-
assert_eq!(v.to_ascii_opt(), Some(v2ascii!(&[40, 32, 59])));
593-
let v = [127u8, 128u8, 255u8];
594-
assert_eq!(v.to_ascii_opt(), None);
595-
596-
assert_eq!("( ;".to_ascii_opt(), Some(v2ascii!(&[40, 32, 59])));
597-
assert_eq!("zoä华".to_ascii_opt(), None);
598-
599-
assert_eq!((~[40u8, 32u8, 59u8]).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59])));
600-
assert_eq!((~[127u8, 128u8, 255u8]).into_ascii_opt(), None);
601-
602-
assert_eq!((~"( ;").into_ascii_opt(), Some(v2ascii!(~[40, 32, 59])));
603-
assert_eq!((~"zoä华").into_ascii_opt(), None);
604-
}
605-
606572
#[test]
607573
fn test_to_ascii_upper() {
608574
assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), ~"URL()URL()URL()üRL");

branches/try/src/libsyntax/ext/asm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ fn next_state(s: State) -> Option<State> {
3939

4040
pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
4141
-> base::MacResult {
42-
let p = parse::new_parser_from_tts(cx.parse_sess(),
43-
cx.cfg(),
44-
tts.to_owned());
42+
let mut p = parse::new_parser_from_tts(cx.parse_sess(),
43+
cx.cfg(),
44+
tts.to_owned());
4545

4646
let mut asm = @"";
4747
let mut asm_str_style = None;

branches/try/src/libsyntax/ext/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ pub fn get_single_str_from_tts(cx: &ExtCtxt,
442442
pub fn get_exprs_from_tts(cx: &ExtCtxt,
443443
sp: Span,
444444
tts: &[ast::token_tree]) -> ~[@ast::Expr] {
445-
let p = parse::new_parser_from_tts(cx.parse_sess(),
446-
cx.cfg(),
447-
tts.to_owned());
445+
let mut p = parse::new_parser_from_tts(cx.parse_sess(),
446+
cx.cfg(),
447+
tts.to_owned());
448448
let mut es = ~[];
449449
while *p.token != token::EOF {
450450
if es.len() != 0 && !p.eat(&token::COMMA) {

branches/try/src/libsyntax/ext/cfg.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ use parse::token;
2626
use parse::attr::parser_attr;
2727

2828
pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult {
29-
let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.to_owned());
29+
let mut p = parse::new_parser_from_tts(cx.parse_sess(),
30+
cx.cfg(),
31+
tts.to_owned());
3032

3133
let mut cfgs = ~[];
3234
// parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)`

branches/try/src/libsyntax/ext/format.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ struct Context<'a> {
5353
impl<'a> Context<'a> {
5454
/// Parses the arguments from the given list of tokens, returning None if
5555
/// there's a parse error so we can continue parsing other format! expressions.
56-
fn parse_args(&mut self, sp: Span,
57-
tts: &[ast::token_tree]) -> (@ast::Expr, Option<@ast::Expr>) {
58-
let p = rsparse::new_parser_from_tts(self.ecx.parse_sess(),
59-
self.ecx.cfg(),
60-
tts.to_owned());
56+
fn parse_args(&mut self, sp: Span, tts: &[ast::token_tree])
57+
-> (@ast::Expr, Option<@ast::Expr>) {
58+
let mut p = rsparse::new_parser_from_tts(self.ecx.parse_sess(),
59+
self.ecx.cfg(),
60+
tts.to_owned());
6161
// Parse the leading function expression (maybe a block, maybe a path)
6262
let extra = p.parse_expr();
6363
if !p.eat(&token::COMMA) {

branches/try/src/libsyntax/ext/quote.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -579,21 +579,17 @@ fn mk_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
579579
ss
580580
}
581581

582-
fn expand_tts(cx: &ExtCtxt,
583-
sp: Span,
584-
tts: &[ast::token_tree]) -> (@ast::Expr, @ast::Expr) {
585-
582+
fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::token_tree])
583+
-> (@ast::Expr, @ast::Expr) {
586584
// NB: It appears that the main parser loses its mind if we consider
587585
// $foo as a tt_nonterminal during the main parse, so we have to re-parse
588586
// under quote_depth > 0. This is silly and should go away; the _guess_ is
589587
// it has to do with transition away from supporting old-style macros, so
590588
// try removing it when enough of them are gone.
591589

592-
let p = parse::new_parser_from_tts(
593-
cx.parse_sess(),
594-
cx.cfg(),
595-
tts.to_owned()
596-
);
590+
let mut p = parse::new_parser_from_tts(cx.parse_sess(),
591+
cx.cfg(),
592+
tts.to_owned());
597593
*p.quote_depth += 1u;
598594

599595
let cx_expr = p.parse_expr();

branches/try/src/libsyntax/ext/source_util.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
8181
-> base::MacResult {
8282
let file = get_single_str_from_tts(cx, sp, tts, "include!");
8383
// The file will be added to the code map by the parser
84-
let p = parse::new_sub_parser_from_file(
85-
cx.parse_sess(), cx.cfg(),
86-
&res_rel_file(cx, sp, &Path::new(file)), sp);
84+
let mut p =
85+
parse::new_sub_parser_from_file(cx.parse_sess(),
86+
cx.cfg(),
87+
&res_rel_file(cx,
88+
sp,
89+
&Path::new(file)),
90+
sp);
8791
base::MRExpr(p.parse_expr())
8892
}
8993

branches/try/src/libsyntax/ext/trace_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt,
2626
None,
2727
tt.to_owned());
2828
let rdr = tt_rdr as @mut reader;
29-
let rust_parser = Parser(sess, cfg.clone(), rdr.dup());
29+
let mut rust_parser = Parser(sess, cfg.clone(), rdr.dup());
3030

3131
if rust_parser.is_keyword(keywords::True) {
3232
cx.set_trace_macros(true);
@@ -38,7 +38,7 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt,
3838

3939
rust_parser.bump();
4040

41-
let rust_parser = Parser(sess, cfg, rdr.dup());
41+
let mut rust_parser = Parser(sess, cfg, rdr.dup());
4242
let result = rust_parser.parse_expr();
4343
base::MRExpr(result)
4444
}

branches/try/src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,13 @@ pub fn parse(
403403
}
404404
rdr.next_token();
405405
} else /* bb_eis.len() == 1 */ {
406-
let rust_parser = Parser(sess, cfg.clone(), rdr.dup());
406+
let mut rust_parser = Parser(sess, cfg.clone(), rdr.dup());
407407
408408
let mut ei = bb_eis.pop();
409409
match ei.elts[ei.idx].node {
410410
match_nonterminal(_, ref name, idx) => {
411411
ei.matches[idx].push(@matched_nonterminal(
412-
parse_nt(&rust_parser, ident_to_str(name))));
412+
parse_nt(&mut rust_parser, ident_to_str(name))));
413413
ei.idx += 1u;
414414
}
415415
_ => fail!()
@@ -426,7 +426,7 @@ pub fn parse(
426426
}
427427
}
428428
429-
pub fn parse_nt(p: &Parser, name: &str) -> nonterminal {
429+
pub fn parse_nt(p: &mut Parser, name: &str) -> nonterminal {
430430
match name {
431431
"item" => match p.parse_item(~[]) {
432432
Some(i) => token::nt_item(i),

0 commit comments

Comments
 (0)