Skip to content

Improve the attempted dynamic environment-capture error message #7531

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
Jul 3, 2013
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
5 changes: 3 additions & 2 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ fn with_appropriate_checker(cx: Context, id: node_id,
fn check_for_bare(cx: Context, fv: @freevar_entry) {
cx.tcx.sess.span_err(
fv.span,
"attempted dynamic environment capture");
}
"can't capture dynamic environment in a fn item; \
use the || { ... } closure form instead");
} // same check is done in resolve.rs, but shouldn't be done

let fty = ty::node_id_to_type(cx.tcx, id);
match ty::get(fty).sty {
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3382,7 +3382,8 @@ impl Resolver {

self.session.span_err(
span,
"attempted dynamic environment-capture");
"can't capture dynamic environment in a fn item; \
use the || { ... } closure form instead");
} else {
// This was an attempt to use a type parameter outside
// its scope.
Expand All @@ -3404,7 +3405,8 @@ impl Resolver {

self.session.span_err(
span,
"attempted dynamic environment-capture");
"can't capture dynamic environment in a fn item; \
use the || { ... } closure form instead");
} else {
// This was an attempt to use a type parameter outside
// its scope.
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/bad-env-capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: attempted dynamic environment-capture
// error-pattern: can't capture dynamic environment in a fn item;
fn foo() {
let x: int;
fn bar() { log(debug, x); }
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/bad-env-capture2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: attempted dynamic environment-capture
// error-pattern: can't capture dynamic environment in a fn item;
fn foo(x: int) {
fn bar() { log(debug, x); }
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/bad-env-capture3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: attempted dynamic environment-capture
// error-pattern: can't capture dynamic environment in a fn item;
fn foo(x: int) {
fn mth() {
fn bar() { log(debug, x); }
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/capture1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// except according to those terms.


// error-pattern: attempted dynamic environment-capture
// error-pattern: can't capture dynamic environment in a fn item;

fn main() {
let bar: int = 5;
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-3021-b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn siphash(k0 : u64) {

impl siphash {
pub fn reset(&mut self) {
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR can't capture dynamic environment
//~^ ERROR unresolved name `k0`.
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/issue-3021-d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ fn siphash(k0 : u64, k1 : u64) -> siphash {

impl siphash for SipState {
fn reset(&self) {
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR can't capture dynamic environment
//~^ ERROR unresolved name `k0`.
self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR attempted dynamic environment-capture
self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR can't capture dynamic environment
//~^ ERROR unresolved name `k1`.
}
fn result(&self) -> u64 { return mk_result(self); }
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-3021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn siphash(k0 : u64) -> SipHash {

impl SipHash for SipState {
fn reset(&self) {
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR can't capture dynamic environment
//~^ ERROR unresolved name `k0`.
}
}
Expand Down