Skip to content

Commit

Permalink
librustc: Remove unique vector patterns from the language.
Browse files Browse the repository at this point in the history
Preparatory work for removing unique vectors from the language, which is
itself preparatory work for dynamically sized types.
  • Loading branch information
pcwalton committed Feb 20, 2014
1 parent ea00582 commit 33923f4
Show file tree
Hide file tree
Showing 25 changed files with 229 additions and 198 deletions.
13 changes: 8 additions & 5 deletions src/libextra/test.rs
Expand Up @@ -315,12 +315,15 @@ pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> {
match maybestr {
None => None,
Some(s) => {
match s.split('.').to_owned_vec() {
[a, b] => match (from_str::<uint>(a), from_str::<uint>(b)) {
(Some(a), Some(b)) => Some((a,b)),
let vector = s.split('.').to_owned_vec();
if vector.len() == 2 {
match (from_str::<uint>(vector[0]),
from_str::<uint>(vector[1])) {
(Some(a), Some(b)) => Some((a, b)),
_ => None
},
_ => None
}
} else {
None
}
}
}
Expand Down
36 changes: 17 additions & 19 deletions src/libnative/io/timer_other.rs
Expand Up @@ -130,27 +130,25 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
}

'outer: loop {
let timeout = match active {
let timeout = if active.len() == 0 {
// Empty array? no timeout (wait forever for the next request)
[] => ptr::null(),

[~Inner { target, .. }, ..] => {
let now = now();
// If this request has already expired, then signal it and go
// through another iteration
if target <= now {
signal(&mut active, &mut dead);
continue;
}

// The actual timeout listed in the requests array is an
// absolute date, so here we translate the absolute time to a
// relative time.
let tm = target - now;
timeout.tv_sec = (tm / 1000) as libc::time_t;
timeout.tv_usec = ((tm % 1000) * 1000) as libc::suseconds_t;
&timeout as *libc::timeval
ptr::null()
} else {
let now = now();
// If this request has already expired, then signal it and go
// through another iteration
if active[0].target <= now {
signal(&mut active, &mut dead);
continue;
}

// The actual timeout listed in the requests array is an
// absolute date, so here we translate the absolute time to a
// relative time.
let tm = active[0].target - now;
timeout.tv_sec = (tm / 1000) as libc::time_t;
timeout.tv_usec = ((tm % 1000) * 1000) as libc::suseconds_t;
&timeout as *libc::timeval
};

imp::fd_set(&mut set, input);
Expand Down
43 changes: 18 additions & 25 deletions src/libnum/bigint.rs
Expand Up @@ -495,24 +495,23 @@ impl ToPrimitive for BigUint {
#[cfg(target_word_size = "32")]
#[inline]
fn to_u64(&self) -> Option<u64> {
match self.data {
[] => {
Some(0)
match self.data.len() {
0 => Some(0),
1 => Some(self.data[0] as u64),
2 => {
Some(BigDigit::to_uint(self.data[1], self.data[0]) as u64)
}
[n0] => {
Some(n0 as u64)
}
[n0, n1] => {
Some(BigDigit::to_uint(n1, n0) as u64)
}
[n0, n1, n2] => {
let n_lo = BigDigit::to_uint(n1, n0) as u64;
let n_hi = n2 as u64;
3 => {
let n_lo = BigDigit::to_uint(self.data[1], self.data[0]) as
u64;
let n_hi = self.data[2] as u64;
Some((n_hi << 32) + n_lo)
}
[n0, n1, n2, n3] => {
let n_lo = BigDigit::to_uint(n1, n0) as u64;
let n_hi = BigDigit::to_uint(n3, n2) as u64;
4 => {
let n_lo = BigDigit::to_uint(self.data[1], self.data[0])
as u64;
let n_hi = BigDigit::to_uint(self.data[3], self.data[2])
as u64;
Some((n_hi << 32) + n_lo)
}
_ => None
Expand All @@ -522,16 +521,10 @@ impl ToPrimitive for BigUint {
#[cfg(target_word_size = "64")]
#[inline]
fn to_u64(&self) -> Option<u64> {
match self.data {
[] => {
Some(0)
}
[n0] => {
Some(n0 as u64)
}
[n0, n1] => {
Some(BigDigit::to_uint(n1, n0) as u64)
}
match self.data.len() {
0 => Some(0),
1 => Some(self.data[0] as u64),
2 => Some(BigDigit::to_uint(self.data[1], self.data[0]) as u64),
_ => None
}
}
Expand Down
16 changes: 7 additions & 9 deletions src/librustc/middle/lint.rs
Expand Up @@ -1213,15 +1213,13 @@ fn check_unused_mut_pat(cx: &Context, p: &ast::Pat) {
ast::PatIdent(ast::BindByValue(ast::MutMutable),
ref path, _) if pat_util::pat_is_binding(cx.tcx.def_map, p)=> {
// `let mut _a = 1;` doesn't need a warning.
let initial_underscore = match path.segments {
[ast::PathSegment { identifier: id, .. }] => {
token::get_ident(id).get().starts_with("_")
}
_ => {
cx.tcx.sess.span_bug(p.span,
"mutable binding that doesn't \
consist of exactly one segment");
}
let initial_underscore = if path.segments.len() == 1 {
token::get_ident(path.segments[0].identifier).get()
.starts_with("_")
} else {
cx.tcx.sess.span_bug(p.span,
"mutable binding that doesn't consist \
of exactly one segment")
};

let used_mut_nodes = cx.tcx.used_mut_nodes.borrow();
Expand Down
12 changes: 11 additions & 1 deletion src/librustc/middle/typeck/check/_match.rs
Expand Up @@ -603,7 +603,17 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
ty::ty_vec(mt, vstore) => {
let region_var = match vstore {
ty::vstore_slice(r) => r,
ty::vstore_uniq | ty::vstore_fixed(_) => {
ty::vstore_uniq => {
fcx.type_error_message(pat.span,
|_| {
~"unique vector patterns are no \
longer supported"
},
expected,
None);
default_region_var
}
ty::vstore_fixed(_) => {
default_region_var
}
};
Expand Down
7 changes: 5 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -3894,8 +3894,11 @@ pub fn ast_expr_vstore_to_vstore(fcx: @FnCtxt,
ast::ExprVstoreUniq => ty::vstore_uniq,
ast::ExprVstoreSlice | ast::ExprVstoreMutSlice => {
match e.node {
ast::ExprLit(..) |
ast::ExprVec([], _) => {
ast::ExprLit(..) => {
// string literals and *empty slices* live in static memory
ty::vstore_slice(ty::ReStatic)
}
ast::ExprVec(ref elements, _) if elements.len() == 0 => {
// string literals and *empty slices* live in static memory
ty::vstore_slice(ty::ReStatic)
}
Expand Down
27 changes: 13 additions & 14 deletions src/librustdoc/passes.rs
Expand Up @@ -311,20 +311,19 @@ pub fn unindent(s: &str) -> ~str {
}
});

match lines {
[head, .. tail] => {
let mut unindented = ~[ head.trim() ];
unindented.push_all(tail.map(|&line| {
if line.is_whitespace() {
line
} else {
assert!(line.len() >= min_indent);
line.slice_from(min_indent)
}
}));
unindented.connect("\n")
}
[] => s.to_owned()
if lines.len() >= 1 {
let mut unindented = ~[ lines[0].trim() ];
unindented.push_all(lines.tail().map(|&line| {
if line.is_whitespace() {
line
} else {
assert!(line.len() >= min_indent);
line.slice_from(min_indent)
}
}));
unindented.connect("\n")
} else {
s.to_owned()
}
}

Expand Down
43 changes: 20 additions & 23 deletions src/libsyntax/ext/deriving/clone.rs
Expand Up @@ -97,30 +97,27 @@ fn cs_clone(
name))
}

match *all_fields {
[FieldInfo { name: None, .. }, ..] => {
// enum-like
let subcalls = all_fields.map(subcall);
cx.expr_call_ident(trait_span, ctor_ident, subcalls)
},
_ => {
// struct-like
let fields = all_fields.map(|field| {
let ident = match field.name {
Some(i) => i,
None => cx.span_bug(trait_span,
format!("unnamed field in normal struct in `deriving({})`",
name))
};
cx.field_imm(field.span, ident, subcall(field))
});
if all_fields.len() >= 1 && all_fields[0].name.is_none() {
// enum-like
let subcalls = all_fields.map(subcall);
cx.expr_call_ident(trait_span, ctor_ident, subcalls)
} else {
// struct-like
let fields = all_fields.map(|field| {
let ident = match field.name {
Some(i) => i,
None => cx.span_bug(trait_span,
format!("unnamed field in normal struct in `deriving({})`",
name))
};
cx.field_imm(field.span, ident, subcall(field))
});

if fields.is_empty() {
// no fields, so construct like `None`
cx.expr_ident(trait_span, ctor_ident)
} else {
cx.expr_struct_ident(trait_span, ctor_ident, fields)
}
if fields.is_empty() {
// no fields, so construct like `None`
cx.expr_ident(trait_span, ctor_ident)
} else {
cx.expr_struct_ident(trait_span, ctor_ident, fields)
}
}
}
37 changes: 19 additions & 18 deletions src/libsyntax/ext/deriving/generic.rs
Expand Up @@ -663,25 +663,26 @@ impl<'a> MethodDef<'a> {
}

// transpose raw_fields
let fields = match raw_fields {
[ref self_arg, .. rest] => {
self_arg.iter().enumerate().map(|(i, &(span, opt_id, field))| {
let other_fields = rest.map(|l| {
match &l[i] {
&(_, _, ex) => ex
}
});
FieldInfo {
span: span,
name: opt_id,
self_: field,
other: other_fields
let fields = if raw_fields.len() > 0 {
raw_fields[0].iter()
.enumerate()
.map(|(i, &(span, opt_id, field))| {
let other_fields = raw_fields.tail().map(|l| {
match &l[i] {
&(_, _, ex) => ex
}
}).collect()
}
[] => { cx.span_bug(trait_.span,
"no self arguments to non-static method \
in generic `deriving`") }
});
FieldInfo {
span: span,
name: opt_id,
self_: field,
other: other_fields
}
}).collect()
} else {
cx.span_bug(trait_.span,
"no self arguments to non-static method in generic \
`deriving`")
};

// body of the inner most destructuring match
Expand Down
5 changes: 4 additions & 1 deletion src/libsyntax/ext/deriving/mod.rs
Expand Up @@ -54,7 +54,10 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt,
MetaNameValue(_, ref l) => {
cx.span_err(l.span, "unexpected value in `deriving`");
}
MetaWord(_) | MetaList(_, []) => {
MetaWord(_) => {
cx.span_warn(mitem.span, "empty trait list in `deriving`");
}
MetaList(_, ref titems) if titems.len() == 0 => {
cx.span_warn(mitem.span, "empty trait list in `deriving`");
}
MetaList(_, ref titems) => {
Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax/ext/deriving/show.rs
Expand Up @@ -74,7 +74,8 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span,
// Getting harder... making the format string:
match *substr.fields {
// unit struct/nullary variant: no work necessary!
Struct([]) | EnumMatching(_, _, []) => {}
Struct(ref fields) if fields.len() == 0 => {}
EnumMatching(_, _, ref fields) if fields.len() == 0 => {}

Struct(ref fields) | EnumMatching(_, _, ref fields) => {
if fields[0].name.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/env.rs
Expand Up @@ -40,7 +40,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> base::MacResult {
let exprs = match get_exprs_from_tts(cx, sp, tts) {
Some([]) => {
Some(ref exprs) if exprs.len() == 0 => {
cx.span_err(sp, "env! takes 1 or 2 arguments");
return MacResult::dummy_expr(sp);
}
Expand Down
19 changes: 10 additions & 9 deletions src/libsyntax/ext/expand.rs
Expand Up @@ -647,14 +647,10 @@ impl Visitor<()> for NewNameFinderContext {
&ast::Path {
global: false,
span: _,
segments: [
ast::PathSegment {
identifier: id,
lifetimes: _,
types: _
}
]
} => self.ident_accumulator.push(id),
segments: ref segments
} if segments.len() == 1 => {
self.ident_accumulator.push(segments[0].identifier)
}
// I believe these must be enums...
_ => ()
}
Expand Down Expand Up @@ -1187,7 +1183,12 @@ foo_module!()
let bindings = name_finder.ident_accumulator;
let cxbinds: ~[&ast::Ident] =
bindings.iter().filter(|b| "xx" == token::get_ident(**b).get()).collect();
bindings.iter().filter(|b| {
let ident = token::get_ident(**b);
let string = ident.get();
"xx" == string
}).collect();
let cxbinds: &[&ast::Ident] = cxbinds;
let cxbind = match cxbinds {
[b] => b,
_ => fail!("expected just one binding for ext_cx")
Expand Down

9 comments on commit 33923f4

@bors
Copy link
Contributor

@bors bors commented on 33923f4 Feb 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at pcwalton@33923f4

@bors
Copy link
Contributor

@bors bors commented on 33923f4 Feb 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pcwalton/rust/deuniquevectorpatterns = 33923f4 into auto

@bors
Copy link
Contributor

@bors bors commented on 33923f4 Feb 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pcwalton/rust/deuniquevectorpatterns = 33923f4 merged ok, testing candidate = 25aeaf1a

@bors
Copy link
Contributor

@bors bors commented on 33923f4 Feb 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at pcwalton@33923f4

@bors
Copy link
Contributor

@bors bors commented on 33923f4 Feb 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pcwalton/rust/deuniquevectorpatterns = 33923f4 into auto

@bors
Copy link
Contributor

@bors bors commented on 33923f4 Feb 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pcwalton/rust/deuniquevectorpatterns = 33923f4 merged ok, testing candidate = 0cc8ba0

@bors
Copy link
Contributor

@bors bors commented on 33923f4 Feb 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 33923f4 Feb 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 0cc8ba0

Please sign in to comment.