Skip to content

Commit 7ff9634

Browse files
committed
---
yaml --- r: 68570 b: refs/heads/auto c: 313dd37 h: refs/heads/master v: v3
1 parent 181659b commit 7ff9634

File tree

13 files changed

+79
-26
lines changed

13 files changed

+79
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: af30fe25a58c5eb1ac088f824b22621ed3652976
17+
refs/heads/auto: 313dd37acb78b9fba701e9aebb0a01cb70b98db1
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/librustc/back/link.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,10 @@ pub fn sanitize(s: &str) -> ~str {
660660
| '_' => result.push_char(c),
661661

662662
_ => {
663-
if c > 'z' && char::is_XID_continue(c) {
664-
result.push_char(c);
665-
}
663+
let mut tstr = ~"";
664+
do char::escape_unicode(c) |c| { tstr.push_char(c); }
665+
result.push_char('$');
666+
result.push_str(tstr.slice_from(1));
666667
}
667668
}
668669
}

branches/auto/src/librustc/middle/borrowck/mod.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,13 @@ impl BorrowckCtxt {
538538

539539
move_data::MoveExpr(expr) => {
540540
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
541+
let suggestion = move_suggestion(self.tcx, expr_ty,
542+
"moved by default (use `copy` to override)");
541543
self.tcx.sess.span_note(
542544
expr.span,
543-
fmt!("`%s` moved here because it has type `%s`, \
544-
which is moved by default (use `copy` to override)",
545+
fmt!("`%s` moved here because it has type `%s`, which is %s",
545546
self.loan_path_to_str(moved_lp),
546-
expr_ty.user_string(self.tcx)));
547+
expr_ty.user_string(self.tcx), suggestion));
547548
}
548549

549550
move_data::MovePat(pat) => {
@@ -557,12 +558,28 @@ impl BorrowckCtxt {
557558
}
558559

559560
move_data::Captured(expr) => {
561+
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
562+
let suggestion = move_suggestion(self.tcx, expr_ty,
563+
"moved by default (make a copy and \
564+
capture that instead to override)");
560565
self.tcx.sess.span_note(
561566
expr.span,
562-
fmt!("`%s` moved into closure environment here \
563-
because its type is moved by default \
564-
(make a copy and capture that instead to override)",
565-
self.loan_path_to_str(moved_lp)));
567+
fmt!("`%s` moved into closure environment here because it \
568+
has type `%s`, which is %s",
569+
self.loan_path_to_str(moved_lp),
570+
expr_ty.user_string(self.tcx), suggestion));
571+
}
572+
}
573+
574+
fn move_suggestion(tcx: ty::ctxt, ty: ty::t, default_msg: &'static str)
575+
-> &'static str {
576+
match ty::get(ty).sty {
577+
ty::ty_closure(ref cty) if cty.sigil == ast::BorrowedSigil =>
578+
"a non-copyable stack closure (capture it in a new closure, \
579+
e.g. `|x| f(x)`, to override)",
580+
_ if !ty::type_is_copyable(tcx, ty) =>
581+
"non-copyable (perhaps you meant to use clone()?)",
582+
_ => default_msg,
566583
}
567584
}
568585
}

branches/auto/src/librustc/middle/kind.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ 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-
"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
201+
"attempted dynamic environment capture");
202+
}
204203

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

branches/auto/src/librustc/middle/resolve.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,8 +3382,7 @@ impl Resolver {
33823382

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

34063405
self.session.span_err(
34073406
span,
3408-
"can't capture dynamic environment in a fn item; \
3409-
use the || { ... } closure form instead");
3407+
"attempted dynamic environment-capture");
34103408
} else {
34113409
// This was an attempt to use a type parameter outside
34123410
// its scope.
@@ -3848,6 +3846,27 @@ impl Resolver {
38483846
generics: &Generics,
38493847
fields: &[@struct_field],
38503848
visitor: ResolveVisitor) {
3849+
let mut ident_map = HashMap::new::<ast::ident, @struct_field>();
3850+
for fields.iter().advance |&field| {
3851+
match field.node.kind {
3852+
named_field(ident, _) => {
3853+
match ident_map.find(&ident) {
3854+
Some(&prev_field) => {
3855+
let ident_str = self.session.str_of(ident);
3856+
self.session.span_err(field.span,
3857+
fmt!("field `%s` is already declared", ident_str));
3858+
self.session.span_note(prev_field.span,
3859+
"Previously declared here");
3860+
},
3861+
None => {
3862+
ident_map.insert(ident, field);
3863+
}
3864+
}
3865+
}
3866+
_ => ()
3867+
}
3868+
}
3869+
38513870
// If applicable, create a rib for the type parameters.
38523871
do self.with_type_parameter_rib(HasTypeParameters
38533872
(generics, id, 0,

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

Lines changed: 1 addition & 1 deletion
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: can't capture dynamic environment in a fn item;
11+
// error-pattern: attempted dynamic environment-capture
1212
fn foo() {
1313
let x: int;
1414
fn bar() { log(debug, x); }

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

Lines changed: 1 addition & 1 deletion
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: can't capture dynamic environment in a fn item;
11+
// error-pattern: attempted dynamic environment-capture
1212
fn foo(x: int) {
1313
fn bar() { log(debug, x); }
1414
}

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

Lines changed: 1 addition & 1 deletion
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: can't capture dynamic environment in a fn item;
11+
// error-pattern: attempted dynamic environment-capture
1212
fn foo(x: int) {
1313
fn mth() {
1414
fn bar() { log(debug, x); }

branches/auto/src/test/compile-fail/capture1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// except according to those terms.
1111

1212

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

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

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

Lines changed: 1 addition & 1 deletion
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 can't capture dynamic environment
21+
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
2222
//~^ ERROR unresolved name `k0`.
2323
}
2424
}

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

Lines changed: 2 additions & 2 deletions
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 can't capture dynamic environment
33+
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
3434
//~^ ERROR unresolved name `k0`.
35-
self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR can't capture dynamic environment
35+
self.v1 = k1 ^ 0x646f72616e646f6d; //~ ERROR attempted dynamic environment-capture
3636
//~^ ERROR unresolved name `k1`.
3737
}
3838
fn result(&self) -> u64 { return mk_result(self); }

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

Lines changed: 1 addition & 1 deletion
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 can't capture dynamic environment
24+
self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture
2525
//~^ ERROR unresolved name `k0`.
2626
}
2727
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct BuildData {
12+
foo: int,
13+
foo: int, //~ ERROR field `foo` is already declared
14+
}
15+
16+
fn main() {
17+
}

0 commit comments

Comments
 (0)