Skip to content

Commit 33923f4

Browse files
committed
librustc: Remove unique vector patterns from the language.
Preparatory work for removing unique vectors from the language, which is itself preparatory work for dynamically sized types.
1 parent ea00582 commit 33923f4

25 files changed

+229
-198
lines changed

src/libextra/test.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,15 @@ pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> {
315315
match maybestr {
316316
None => None,
317317
Some(s) => {
318-
match s.split('.').to_owned_vec() {
319-
[a, b] => match (from_str::<uint>(a), from_str::<uint>(b)) {
320-
(Some(a), Some(b)) => Some((a,b)),
318+
let vector = s.split('.').to_owned_vec();
319+
if vector.len() == 2 {
320+
match (from_str::<uint>(vector[0]),
321+
from_str::<uint>(vector[1])) {
322+
(Some(a), Some(b)) => Some((a, b)),
321323
_ => None
322-
},
323-
_ => None
324+
}
325+
} else {
326+
None
324327
}
325328
}
326329
}

src/libnative/io/timer_other.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,25 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
130130
}
131131

132132
'outer: loop {
133-
let timeout = match active {
133+
let timeout = if active.len() == 0 {
134134
// Empty array? no timeout (wait forever for the next request)
135-
[] => ptr::null(),
136-
137-
[~Inner { target, .. }, ..] => {
138-
let now = now();
139-
// If this request has already expired, then signal it and go
140-
// through another iteration
141-
if target <= now {
142-
signal(&mut active, &mut dead);
143-
continue;
144-
}
145-
146-
// The actual timeout listed in the requests array is an
147-
// absolute date, so here we translate the absolute time to a
148-
// relative time.
149-
let tm = target - now;
150-
timeout.tv_sec = (tm / 1000) as libc::time_t;
151-
timeout.tv_usec = ((tm % 1000) * 1000) as libc::suseconds_t;
152-
&timeout as *libc::timeval
135+
ptr::null()
136+
} else {
137+
let now = now();
138+
// If this request has already expired, then signal it and go
139+
// through another iteration
140+
if active[0].target <= now {
141+
signal(&mut active, &mut dead);
142+
continue;
153143
}
144+
145+
// The actual timeout listed in the requests array is an
146+
// absolute date, so here we translate the absolute time to a
147+
// relative time.
148+
let tm = active[0].target - now;
149+
timeout.tv_sec = (tm / 1000) as libc::time_t;
150+
timeout.tv_usec = ((tm % 1000) * 1000) as libc::suseconds_t;
151+
&timeout as *libc::timeval
154152
};
155153

156154
imp::fd_set(&mut set, input);

src/libnum/bigint.rs

+18-25
Original file line numberDiff line numberDiff line change
@@ -495,24 +495,23 @@ impl ToPrimitive for BigUint {
495495
#[cfg(target_word_size = "32")]
496496
#[inline]
497497
fn to_u64(&self) -> Option<u64> {
498-
match self.data {
499-
[] => {
500-
Some(0)
498+
match self.data.len() {
499+
0 => Some(0),
500+
1 => Some(self.data[0] as u64),
501+
2 => {
502+
Some(BigDigit::to_uint(self.data[1], self.data[0]) as u64)
501503
}
502-
[n0] => {
503-
Some(n0 as u64)
504-
}
505-
[n0, n1] => {
506-
Some(BigDigit::to_uint(n1, n0) as u64)
507-
}
508-
[n0, n1, n2] => {
509-
let n_lo = BigDigit::to_uint(n1, n0) as u64;
510-
let n_hi = n2 as u64;
504+
3 => {
505+
let n_lo = BigDigit::to_uint(self.data[1], self.data[0]) as
506+
u64;
507+
let n_hi = self.data[2] as u64;
511508
Some((n_hi << 32) + n_lo)
512509
}
513-
[n0, n1, n2, n3] => {
514-
let n_lo = BigDigit::to_uint(n1, n0) as u64;
515-
let n_hi = BigDigit::to_uint(n3, n2) as u64;
510+
4 => {
511+
let n_lo = BigDigit::to_uint(self.data[1], self.data[0])
512+
as u64;
513+
let n_hi = BigDigit::to_uint(self.data[3], self.data[2])
514+
as u64;
516515
Some((n_hi << 32) + n_lo)
517516
}
518517
_ => None
@@ -522,16 +521,10 @@ impl ToPrimitive for BigUint {
522521
#[cfg(target_word_size = "64")]
523522
#[inline]
524523
fn to_u64(&self) -> Option<u64> {
525-
match self.data {
526-
[] => {
527-
Some(0)
528-
}
529-
[n0] => {
530-
Some(n0 as u64)
531-
}
532-
[n0, n1] => {
533-
Some(BigDigit::to_uint(n1, n0) as u64)
534-
}
524+
match self.data.len() {
525+
0 => Some(0),
526+
1 => Some(self.data[0] as u64),
527+
2 => Some(BigDigit::to_uint(self.data[1], self.data[0]) as u64),
535528
_ => None
536529
}
537530
}

src/librustc/middle/lint.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1213,15 +1213,13 @@ fn check_unused_mut_pat(cx: &Context, p: &ast::Pat) {
12131213
ast::PatIdent(ast::BindByValue(ast::MutMutable),
12141214
ref path, _) if pat_util::pat_is_binding(cx.tcx.def_map, p)=> {
12151215
// `let mut _a = 1;` doesn't need a warning.
1216-
let initial_underscore = match path.segments {
1217-
[ast::PathSegment { identifier: id, .. }] => {
1218-
token::get_ident(id).get().starts_with("_")
1219-
}
1220-
_ => {
1221-
cx.tcx.sess.span_bug(p.span,
1222-
"mutable binding that doesn't \
1223-
consist of exactly one segment");
1224-
}
1216+
let initial_underscore = if path.segments.len() == 1 {
1217+
token::get_ident(path.segments[0].identifier).get()
1218+
.starts_with("_")
1219+
} else {
1220+
cx.tcx.sess.span_bug(p.span,
1221+
"mutable binding that doesn't consist \
1222+
of exactly one segment")
12251223
};
12261224

12271225
let used_mut_nodes = cx.tcx.used_mut_nodes.borrow();

src/librustc/middle/typeck/check/_match.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,17 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
603603
ty::ty_vec(mt, vstore) => {
604604
let region_var = match vstore {
605605
ty::vstore_slice(r) => r,
606-
ty::vstore_uniq | ty::vstore_fixed(_) => {
606+
ty::vstore_uniq => {
607+
fcx.type_error_message(pat.span,
608+
|_| {
609+
~"unique vector patterns are no \
610+
longer supported"
611+
},
612+
expected,
613+
None);
614+
default_region_var
615+
}
616+
ty::vstore_fixed(_) => {
607617
default_region_var
608618
}
609619
};

src/librustc/middle/typeck/check/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3894,8 +3894,11 @@ pub fn ast_expr_vstore_to_vstore(fcx: @FnCtxt,
38943894
ast::ExprVstoreUniq => ty::vstore_uniq,
38953895
ast::ExprVstoreSlice | ast::ExprVstoreMutSlice => {
38963896
match e.node {
3897-
ast::ExprLit(..) |
3898-
ast::ExprVec([], _) => {
3897+
ast::ExprLit(..) => {
3898+
// string literals and *empty slices* live in static memory
3899+
ty::vstore_slice(ty::ReStatic)
3900+
}
3901+
ast::ExprVec(ref elements, _) if elements.len() == 0 => {
38993902
// string literals and *empty slices* live in static memory
39003903
ty::vstore_slice(ty::ReStatic)
39013904
}

src/librustdoc/passes.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -311,20 +311,19 @@ pub fn unindent(s: &str) -> ~str {
311311
}
312312
});
313313

314-
match lines {
315-
[head, .. tail] => {
316-
let mut unindented = ~[ head.trim() ];
317-
unindented.push_all(tail.map(|&line| {
318-
if line.is_whitespace() {
319-
line
320-
} else {
321-
assert!(line.len() >= min_indent);
322-
line.slice_from(min_indent)
323-
}
324-
}));
325-
unindented.connect("\n")
326-
}
327-
[] => s.to_owned()
314+
if lines.len() >= 1 {
315+
let mut unindented = ~[ lines[0].trim() ];
316+
unindented.push_all(lines.tail().map(|&line| {
317+
if line.is_whitespace() {
318+
line
319+
} else {
320+
assert!(line.len() >= min_indent);
321+
line.slice_from(min_indent)
322+
}
323+
}));
324+
unindented.connect("\n")
325+
} else {
326+
s.to_owned()
328327
}
329328
}
330329

src/libsyntax/ext/deriving/clone.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,27 @@ fn cs_clone(
9797
name))
9898
}
9999

100-
match *all_fields {
101-
[FieldInfo { name: None, .. }, ..] => {
102-
// enum-like
103-
let subcalls = all_fields.map(subcall);
104-
cx.expr_call_ident(trait_span, ctor_ident, subcalls)
105-
},
106-
_ => {
107-
// struct-like
108-
let fields = all_fields.map(|field| {
109-
let ident = match field.name {
110-
Some(i) => i,
111-
None => cx.span_bug(trait_span,
112-
format!("unnamed field in normal struct in `deriving({})`",
113-
name))
114-
};
115-
cx.field_imm(field.span, ident, subcall(field))
116-
});
100+
if all_fields.len() >= 1 && all_fields[0].name.is_none() {
101+
// enum-like
102+
let subcalls = all_fields.map(subcall);
103+
cx.expr_call_ident(trait_span, ctor_ident, subcalls)
104+
} else {
105+
// struct-like
106+
let fields = all_fields.map(|field| {
107+
let ident = match field.name {
108+
Some(i) => i,
109+
None => cx.span_bug(trait_span,
110+
format!("unnamed field in normal struct in `deriving({})`",
111+
name))
112+
};
113+
cx.field_imm(field.span, ident, subcall(field))
114+
});
117115

118-
if fields.is_empty() {
119-
// no fields, so construct like `None`
120-
cx.expr_ident(trait_span, ctor_ident)
121-
} else {
122-
cx.expr_struct_ident(trait_span, ctor_ident, fields)
123-
}
116+
if fields.is_empty() {
117+
// no fields, so construct like `None`
118+
cx.expr_ident(trait_span, ctor_ident)
119+
} else {
120+
cx.expr_struct_ident(trait_span, ctor_ident, fields)
124121
}
125122
}
126123
}

src/libsyntax/ext/deriving/generic.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -663,25 +663,26 @@ impl<'a> MethodDef<'a> {
663663
}
664664

665665
// transpose raw_fields
666-
let fields = match raw_fields {
667-
[ref self_arg, .. rest] => {
668-
self_arg.iter().enumerate().map(|(i, &(span, opt_id, field))| {
669-
let other_fields = rest.map(|l| {
670-
match &l[i] {
671-
&(_, _, ex) => ex
672-
}
673-
});
674-
FieldInfo {
675-
span: span,
676-
name: opt_id,
677-
self_: field,
678-
other: other_fields
666+
let fields = if raw_fields.len() > 0 {
667+
raw_fields[0].iter()
668+
.enumerate()
669+
.map(|(i, &(span, opt_id, field))| {
670+
let other_fields = raw_fields.tail().map(|l| {
671+
match &l[i] {
672+
&(_, _, ex) => ex
679673
}
680-
}).collect()
681-
}
682-
[] => { cx.span_bug(trait_.span,
683-
"no self arguments to non-static method \
684-
in generic `deriving`") }
674+
});
675+
FieldInfo {
676+
span: span,
677+
name: opt_id,
678+
self_: field,
679+
other: other_fields
680+
}
681+
}).collect()
682+
} else {
683+
cx.span_bug(trait_.span,
684+
"no self arguments to non-static method in generic \
685+
`deriving`")
685686
};
686687

687688
// body of the inner most destructuring match

src/libsyntax/ext/deriving/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
5454
MetaNameValue(_, ref l) => {
5555
cx.span_err(l.span, "unexpected value in `deriving`");
5656
}
57-
MetaWord(_) | MetaList(_, []) => {
57+
MetaWord(_) => {
58+
cx.span_warn(mitem.span, "empty trait list in `deriving`");
59+
}
60+
MetaList(_, ref titems) if titems.len() == 0 => {
5861
cx.span_warn(mitem.span, "empty trait list in `deriving`");
5962
}
6063
MetaList(_, ref titems) => {

src/libsyntax/ext/deriving/show.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
7474
// Getting harder... making the format string:
7575
match *substr.fields {
7676
// unit struct/nullary variant: no work necessary!
77-
Struct([]) | EnumMatching(_, _, []) => {}
77+
Struct(ref fields) if fields.len() == 0 => {}
78+
EnumMatching(_, _, ref fields) if fields.len() == 0 => {}
7879

7980
Struct(ref fields) | EnumMatching(_, _, ref fields) => {
8081
if fields[0].name.is_none() {

src/libsyntax/ext/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
4040
pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
4141
-> base::MacResult {
4242
let exprs = match get_exprs_from_tts(cx, sp, tts) {
43-
Some([]) => {
43+
Some(ref exprs) if exprs.len() == 0 => {
4444
cx.span_err(sp, "env! takes 1 or 2 arguments");
4545
return MacResult::dummy_expr(sp);
4646
}

src/libsyntax/ext/expand.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -647,14 +647,10 @@ impl Visitor<()> for NewNameFinderContext {
647647
&ast::Path {
648648
global: false,
649649
span: _,
650-
segments: [
651-
ast::PathSegment {
652-
identifier: id,
653-
lifetimes: _,
654-
types: _
655-
}
656-
]
657-
} => self.ident_accumulator.push(id),
650+
segments: ref segments
651+
} if segments.len() == 1 => {
652+
self.ident_accumulator.push(segments[0].identifier)
653+
}
658654
// I believe these must be enums...
659655
_ => ()
660656
}
@@ -1187,7 +1183,12 @@ foo_module!()
11871183
let bindings = name_finder.ident_accumulator;
11881184
11891185
let cxbinds: ~[&ast::Ident] =
1190-
bindings.iter().filter(|b| "xx" == token::get_ident(**b).get()).collect();
1186+
bindings.iter().filter(|b| {
1187+
let ident = token::get_ident(**b);
1188+
let string = ident.get();
1189+
"xx" == string
1190+
}).collect();
1191+
let cxbinds: &[&ast::Ident] = cxbinds;
11911192
let cxbind = match cxbinds {
11921193
[b] => b,
11931194
_ => fail!("expected just one binding for ext_cx")

0 commit comments

Comments
 (0)