librustc: minor cleanup

This commit is contained in:
Erick Tryzelaar 2013-02-16 10:36:09 -08:00
parent ae86c03af2
commit b90ccc9a38
4 changed files with 54 additions and 46 deletions

View file

@ -134,39 +134,47 @@ pub fn raw_pat(p: @pat) -> @pat {
pub fn check_exhaustive(cx: @MatchCheckCtxt, sp: span, pats: ~[@pat]) {
assert(!pats.is_empty());
let ext = match is_useful(cx, vec::map(pats, |p| ~[*p]), ~[wild()]) {
not_useful => return, // This is good, wildcard pattern isn't reachable
useful_ => None,
useful(ty, ref ctor) => {
match ty::get(ty).sty {
ty::ty_bool => {
match (*ctor) {
val(const_bool(true)) => Some(~"true"),
val(const_bool(false)) => Some(~"false"),
_ => None
}
}
ty::ty_enum(id, _) => {
let vid = match (*ctor) { variant(id) => id,
_ => fail!(~"check_exhaustive: non-variant ctor") };
match vec::find(*ty::enum_variants(cx.tcx, id),
|v| v.id == vid) {
Some(v) => Some(cx.tcx.sess.str_of(v.name)),
None => fail!(~"check_exhaustive: bad variant in ctor")
}
}
ty::ty_unboxed_vec(*) | ty::ty_evec(*) => {
match (*ctor) {
vec(n) => Some(fmt!("vectors of length %u", n)),
_ => None
}
}
_ => None
not_useful => {
// This is good, wildcard pattern isn't reachable
return;
}
useful_ => None,
useful(ty, ref ctor) => {
match ty::get(ty).sty {
ty::ty_bool => {
match (*ctor) {
val(const_bool(true)) => Some(~"true"),
val(const_bool(false)) => Some(~"false"),
_ => None
}
}
ty::ty_enum(id, _) => {
let vid = match (*ctor) {
variant(id) => id,
_ => fail!(~"check_exhaustive: non-variant ctor"),
};
let variants = ty::enum_variants(cx.tcx, id);
match variants.find(|v| v.id == vid) {
Some(v) => Some(cx.tcx.sess.str_of(v.name)),
None => {
fail!(~"check_exhaustive: bad variant in ctor")
}
}
}
ty::ty_unboxed_vec(*) | ty::ty_evec(*) => {
match (*ctor) {
vec(n) => Some(fmt!("vectors of length %u", n)),
_ => None
}
}
_ => None
}
}
}
};
let msg = ~"non-exhaustive patterns" + match ext {
Some(ref s) => ~": " + (*s) + ~" not covered",
None => ~""
Some(ref s) => ~": " + (*s) + ~" not covered",
None => ~""
};
cx.tcx.sess.span_err(sp, msg);
}

View file

@ -866,18 +866,18 @@ fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
}
match it.node {
ast::item_ty(*) | ast::item_struct(*) |
ast::item_trait(*) => {
check_case(cx, it.ident, it.id, it.id, it.span)
}
ast::item_enum(ref enum_definition, _) => {
check_case(cx, it.ident, it.id, it.id, it.span);
for enum_definition.variants.each |variant| {
check_case(cx, variant.node.name,
variant.node.id, it.id, variant.span);
ast::item_ty(*) | ast::item_struct(*) |
ast::item_trait(*) => {
check_case(cx, it.ident, it.id, it.id, it.span)
}
}
_ => ()
ast::item_enum(ref enum_definition, _) => {
check_case(cx, it.ident, it.id, it.id, it.span);
for enum_definition.variants.each |variant| {
check_case(cx, variant.node.name,
variant.node.id, it.id, variant.span);
}
}
_ => ()
}
}

View file

@ -1141,15 +1141,15 @@ pub fn C_u8(i: uint) -> ValueRef {
// This is a 'c-like' raw string, which differs from
// our boxed-and-length-annotated strings.
pub fn C_cstr(cx: @crate_ctxt, +s: ~str) -> ValueRef {
pub fn C_cstr(cx: @crate_ctxt, s: ~str) -> ValueRef {
unsafe {
match cx.const_cstr_cache.find(&s) {
Some(llval) => return llval,
None => ()
Some(llval) => return llval,
None => ()
}
let sc = do str::as_c_str(s) |buf| {
llvm::LLVMConstString(buf, str::len(s) as c_uint, False)
llvm::LLVMConstString(buf, s.len() as c_uint, False)
};
let g =
str::as_c_str(fmt!("str%u", (cx.names)(~"str").repr),

View file

@ -45,7 +45,7 @@ pub impl Reflector {
C_int(self.bcx.ccx(), i)
}
fn c_slice(&mut self, +s: ~str) -> ValueRef {
fn c_slice(&mut self, s: &str) -> ValueRef {
// We're careful to not use first class aggregates here because that
// will kick us off fast isel. (Issue #4352.)
let bcx = self.bcx;