Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement `?` in catch expressions #40229
Conversation
rust-highfive
assigned
nikomatsakis
Mar 3, 2017
cramertj
changed the title
Break to blocks
Implement `?` in catch expressions
Mar 3, 2017
This comment has been minimized.
This comment has been minimized.
|
|
cramertj
force-pushed the
cramertj:break-to-blocks
branch
from
2513d2a
to
49f5872
Mar 3, 2017
This comment has been minimized.
This comment has been minimized.
|
at first read, this all looks good, I'll have to revisit it in more detail when it's rebased |
This comment has been minimized.
This comment has been minimized.
|
Ah, a thought. It'd be good to have some tests targeting the CFG etc. The idea would be to have initializations and moves that occur during a let x;
let _v = do catch {
x = 5;
Ok(());
};
println!("{}", x); // OKlet x;
let _v = do catch {
x = Ok(5)?;
Ok(());
};
println!("{}", x); // ERRORand similar tests for moves that may or may not occur (and perhaps a few for borrows that start in the catch and extend outside, etc). |
This comment has been minimized.
This comment has been minimized.
|
|
cramertj
force-pushed the
cramertj:break-to-blocks
branch
from
49f5872
to
f435d76
Mar 14, 2017
nikomatsakis
reviewed
Mar 14, 2017
| // option. This file may not be copied, modified, or distributed | ||
| // except according to those terms. | ||
|
|
||
| #![feature(catch_expr)] |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Mar 14, 2017
Contributor
can you add a comment on this test explaining what the test aims to demonstrate (e.g., that a borrowed valid inside the do catch will propagate out?
I also think it'd be good to possibly break this test into distinct files.
nikomatsakis
reviewed
Mar 14, 2017
| let _: Result<(), ()> = do catch { | ||
| Err(())?; | ||
| cfg_res = 5; | ||
| Ok(()) |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Mar 14, 2017
Contributor
can you modify the test to demonstrate that cfg_res is usable *within the do catch, if not outside?
Also, add a (run-pass) test like so, where cfg_res is initialized before the ?:
pub fn main() {
let cfg_res;
let _: Result<(), ()> = do catch {
cfg_res = 5;
Err(())?;
Ok(())
};
use(cfg_res); // OK
}
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Mar 14, 2017
Contributor
I think I would also like some tests around lifetimes like these:
// Test that a borrow which only conditionally occurs still freezes `i`
fn main() {
let mut i = 222;
let j;
let x = do catch {
Err(())?;
Ok(&i)
};
i = 0; // ERROR
println!("{}", i);
}// Test that a borrow which only conditionally occurs still freezes `i`
fn main() {
let mut i = 222;
let j;
let x = do catch {
Err(())?;
j = &i;
Ok(())
};
i = 0; // ERROR, I ... guess ... maybe not with NLL
println!("{}", i);
}
cramertj
force-pushed the
cramertj:break-to-blocks
branch
from
ab2b758
to
bc07fe6
Mar 15, 2017
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
cramertj
added some commits
Feb 28, 2017
cramertj
force-pushed the
cramertj:break-to-blocks
branch
from
bc07fe6
to
1f43731
Mar 18, 2017
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
cramertj commentedMar 3, 2017
Builds on #39921. Final part of #39849.
r? @nikomatsakis