Skip to content

Commit af30fe2

Browse files
committed
Improve the attempted dynamic environment-capture error message
1 parent d324014 commit af30fe2

File tree

9 files changed

+15
-12
lines changed

9 files changed

+15
-12
lines changed

src/librustc/middle/kind.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ fn with_appropriate_checker(cx: Context, id: node_id,
198198
fn check_for_bare(cx: Context, fv: @freevar_entry) {
199199
cx.tcx.sess.span_err(
200200
fv.span,
201-
"attempted dynamic environment capture");
202-
}
201+
"can't capture dynamic environment in a fn item; \
202+
use the || { ... } closure form instead");
203+
} // same check is done in resolve.rs, but shouldn't be done
203204

204205
let fty = ty::node_id_to_type(cx.tcx, id);
205206
match ty::get(fty).sty {

src/librustc/middle/resolve.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3382,7 +3382,8 @@ impl Resolver {
33823382

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

34053406
self.session.span_err(
34063407
span,
3407-
"attempted dynamic environment-capture");
3408+
"can't capture dynamic environment in a fn item; \
3409+
use the || { ... } closure form instead");
34083410
} else {
34093411
// This was an attempt to use a type parameter outside
34103412
// its scope.

src/test/compile-fail/bad-env-capture.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: attempted dynamic environment-capture
11+
// error-pattern: can't capture dynamic environment in a fn item;
1212
fn foo() {
1313
let x: int;
1414
fn bar() { log(debug, x); }

src/test/compile-fail/bad-env-capture2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: attempted dynamic environment-capture
11+
// error-pattern: can't capture dynamic environment in a fn item;
1212
fn foo(x: int) {
1313
fn bar() { log(debug, x); }
1414
}

src/test/compile-fail/bad-env-capture3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: attempted dynamic environment-capture
11+
// error-pattern: can't capture dynamic environment in a fn item;
1212
fn foo(x: int) {
1313
fn mth() {
1414
fn bar() { log(debug, x); }

src/test/compile-fail/capture1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// except according to those terms.
1111

1212

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

1515
fn main() {
1616
let bar: int = 5;

src/test/compile-fail/issue-3021-b.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn siphash(k0 : u64) {
1818

1919
impl siphash {
2020
pub fn reset(&mut self) {
21-
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
21+
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR can't capture dynamic environment
2222
//~^ ERROR unresolved name `k0`.
2323
}
2424
}

src/test/compile-fail/issue-3021-d.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ fn siphash(k0 : u64, k1 : u64) -> siphash {
3030

3131
impl siphash for SipState {
3232
fn reset(&self) {
33-
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
33+
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR can't capture dynamic environment
3434
//~^ ERROR unresolved name `k0`.
35-
self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR attempted dynamic environment-capture
35+
self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR can't capture dynamic environment
3636
//~^ ERROR unresolved name `k1`.
3737
}
3838
fn result(&self) -> u64 { return mk_result(self); }

src/test/compile-fail/issue-3021.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn siphash(k0 : u64) -> SipHash {
2121

2222
impl SipHash for SipState {
2323
fn reset(&self) {
24-
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
24+
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR can't capture dynamic environment
2525
//~^ ERROR unresolved name `k0`.
2626
}
2727
}

0 commit comments

Comments
 (0)