mode: reset mode on entry to fn body.
This is an interim fix to address the "Beware!" unsoundness. I have a more comprehensive rewrite of mode.rs in the pipeline. r=pcwalton
This commit is contained in:
parent
eaa256509e
commit
737e115646
17 changed files with 69 additions and 41 deletions
10
src/test/compile-fail/access-mode-in-closures.rs
Normal file
10
src/test/compile-fail/access-mode-in-closures.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
enum sty = ~[int];
|
||||
|
||||
fn unpack(unpack: &fn(v: &sty) -> ~[int]) {}
|
||||
|
||||
fn main() {
|
||||
let foo = unpack(|s| {
|
||||
// Test that `s` is moved here.
|
||||
match *s { sty(v) => v } //~ ERROR moving out of dereference of immutable & pointer
|
||||
});
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ fn main() {
|
|||
let carrots = @~"crunchy";
|
||||
|
||||
fn@(tasties: @~str, macerate: fn(~str)) {
|
||||
macerate(*tasties);
|
||||
macerate(copy *tasties);
|
||||
} (carrots, |food| {
|
||||
let mush = food + cheese;
|
||||
let f = fn@() {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,6 @@ fn main() {
|
|||
// Verify that blocks can't interfere with each other.
|
||||
fn two_blocks(a: fn(), b: fn()) { a(); b(); a(); b(); }
|
||||
let q = ~50;
|
||||
two_blocks(|| { let a = q; assert *a == 50;},
|
||||
|| { let a = q; assert *a == 50;});
|
||||
two_blocks(|| { let a = copy q; assert *a == 50;},
|
||||
|| { let a = copy q; assert *a == 50;});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ fn transform(x: Option<int>) -> Option<~str> {
|
|||
fn main() {
|
||||
assert transform(Some(10)) == Some(~"11");
|
||||
assert transform(None) == None;
|
||||
assert (~[~"hi"]).bind(|x| ~[x, x + ~"!"] ).bind(|x| ~[x, x + ~"?"] ) ==
|
||||
assert (~[~"hi"])
|
||||
.bind(|x| ~[copy x, x + ~"!"] )
|
||||
.bind(|x| ~[copy x, x + ~"?"] ) ==
|
||||
~[~"hi", ~"hi?", ~"hi!", ~"hi!?"];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue