Fix subtle error in caching during kind computation that could cause linear
values to be copied. Rewrite kind computation so that instead of directly computing the kind it computes what kinds of values are present in the type, and then derive kinds based on that. I find this easier to think about. Fixes #4821.
This commit is contained in:
parent
6647a3402b
commit
a380df809c
31 changed files with 612 additions and 579 deletions
|
@ -220,6 +220,16 @@ pub pure fn connect(v: &[~str], sep: &str) -> ~str {
|
|||
s
|
||||
}
|
||||
|
||||
/// Concatenate a vector of strings, placing a given separator between each
|
||||
pub pure fn connect_slices(v: &[&str], sep: &str) -> ~str {
|
||||
let mut s = ~"", first = true;
|
||||
for vec::each(v) |ss| {
|
||||
if first { first = false; } else { unsafe { push_str(&mut s, sep); } }
|
||||
unsafe { push_str(&mut s, *ss) };
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
/// Given a string, make a new string with repeated copies of it
|
||||
pub pure fn repeat(ss: &str, nn: uint) -> ~str {
|
||||
let mut acc = ~"";
|
||||
|
@ -2667,6 +2677,17 @@ mod tests {
|
|||
t(~[~"hi"], ~" ", ~"hi");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_connect_slices() {
|
||||
fn t(v: &[&str], sep: &str, s: &str) {
|
||||
assert connect_slices(v, sep) == s.to_str();
|
||||
}
|
||||
t(["you", "know", "I'm", "no", "good"],
|
||||
" ", "you know I'm no good");
|
||||
t([], " ", "");
|
||||
t(["hi"], " ", "hi");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repeat() {
|
||||
assert repeat(~"x", 4) == ~"xxxx";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue