Skip to content

librustc: Ensure that proc upvars have static lifetime. #15190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libnative/io/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ fn spawn_process_os(cfg: ProcessConfig,

let dirp = cfg.cwd.map(|c| c.with_ref(|p| p)).unwrap_or(ptr::null());

let cfg = unsafe {
mem::transmute::<ProcessConfig,ProcessConfig<'static>>(cfg)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this safe? (Would it be possible to add a brief comment?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can do that.

Copy link
Member

Choose a reason for hiding this comment

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

I would personally rather this have the two procedures to using closures instead. It will involve an option dance here and there, however.

};

with_envp(cfg.env, proc(envp) {
with_argv(cfg.program, cfg.args, proc(argv) unsafe {
let (mut input, mut output) = try!(pipe());
Expand Down
10 changes: 8 additions & 2 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,14 @@ fn with_appropriate_checker(cx: &Context,
let fty = ty::node_id_to_type(cx.tcx, id);
match ty::get(fty).sty {
ty::ty_closure(box ty::ClosureTy {
store: ty::UniqTraitStore, bounds, ..
}) => b(|cx, fv| check_for_uniq(cx, fv, bounds)),
store: ty::UniqTraitStore,
bounds: mut bounds, ..
}) => {
// Procs can't close over non-static references!
bounds.add(ty::BoundStatic);

b(|cx, fv| check_for_uniq(cx, fv, bounds))
}

ty::ty_closure(box ty::ClosureTy {
store: ty::RegionTraitStore(region, _), bounds, ..
Expand Down
26 changes: 26 additions & 0 deletions src/test/compile-fail/proc-static-bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
let mut x = Some(1);
let mut p: proc(&mut Option<int>) = proc(_) {};
match x {
Some(ref y) => {
p = proc(z: &mut Option<int>) {
*z = None;
let _ = y;
//~^ ERROR cannot capture variable of type `&int`, which does not fulfill `'static`
};
}
None => {}
}
p(&mut x);
}