Skip to content

Commit 630806c

Browse files
committed
---
yaml --- r: 13003 b: refs/heads/master c: 9773a22 h: refs/heads/master i: 13001: ae29db1 12999: d39c32a v: v3
1 parent d150b52 commit 630806c

12 files changed

+75
-69
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 248f8826a9287a1c98144053289aca4355785391
2+
refs/heads/master: 9773a22119bf416a1c53d0ee30f6a127c7e274e1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustc/middle/borrowck.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ enum check_loan_ctxt = @{
498498
bccx: borrowck_ctxt,
499499
req_maps: req_maps,
500500

501+
reported: hashmap<ast::node_id, ()>,
502+
501503
// Keep track of whether we're inside a ctor, so as to
502504
// allow mutating immutable fields in the same class if
503505
// we are in a ctor, we track the self id
@@ -525,6 +527,7 @@ fn check_loans(bccx: borrowck_ctxt,
525527
crate: @ast::crate) {
526528
let clcx = check_loan_ctxt(@{bccx: bccx,
527529
req_maps: req_maps,
530+
reported: int_hash(),
528531
mut in_ctor: false,
529532
mut is_pure: pc_impure});
530533
let vt = visit::mk_vt(@{visit_expr: check_loans_in_expr,
@@ -641,11 +644,9 @@ impl methods for check_loan_ctxt {
641644
/*ok*/
642645
}
643646
ast::impure_fn | ast::unsafe_fn {
644-
self.bccx.span_err(
647+
self.report_purity_error(
645648
expr.span,
646-
"access to non-pure functions \
647-
prohibited in a pure context");
648-
self.report_why_pure();
649+
"access to non-pure functions");
649650
}
650651
}
651652
}
@@ -739,11 +740,9 @@ impl methods for check_loan_ctxt {
739740
// assigned, because it is uniquely tied to this function and
740741
// is not visible from the outside
741742
if self.is_pure != pc_impure && cmt.lp.is_none() {
742-
self.bccx.span_err(
743+
self.report_purity_error(
743744
ex.span,
744-
#fmt["%s prohibited in a pure context",
745-
at.ing_form(self.bccx.cmt_to_str(cmt))]);
746-
self.report_why_pure();
745+
at.ing_form(self.bccx.cmt_to_str(cmt)));
747746
}
748747

749748
// check for a conflicting loan as well, except in the case of
@@ -776,19 +775,26 @@ impl methods for check_loan_ctxt {
776775
self.bccx.add_to_mutbl_map(cmt);
777776
}
778777

779-
fn report_why_pure() {
780-
alt self.is_pure {
778+
fn report_purity_error(sp: span, msg: str) {
779+
alt copy self.is_pure {
781780
pc_impure {
782-
self.tcx().sess.bug("report_why_pure() called when impure");
781+
self.tcx().sess.bug("report_purity_error() called when impure");
783782
}
784783
pc_declaration {
785-
// fn was declared pure; no need to report this, I think
784+
self.tcx().sess.span_err(
785+
sp,
786+
#fmt["%s prohibited in pure context", msg]);
786787
}
787788
pc_cmt(e) {
788-
self.tcx().sess.span_note(
789-
e.cmt.span,
790-
#fmt["pure context is required due to an illegal borrow: %s",
791-
self.bccx.bckerr_code_to_str(e.code)]);
789+
if self.reported.insert(e.cmt.id, ()) {
790+
self.tcx().sess.span_err(
791+
e.cmt.span,
792+
#fmt["illegal borrow unless pure: %s",
793+
self.bccx.bckerr_code_to_str(e.code)]);
794+
self.tcx().sess.span_note(
795+
sp,
796+
#fmt["impure due to %s", msg]);
797+
}
792798
}
793799
}
794800
}

trunk/src/rustc/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,15 +717,15 @@ fn follow_import(e: env, &&sc: scopes, path: [ident], sp: span) ->
717717
let mut dcur = lookup_in_scope_strict(e, sc, sp, path[0], ns_module);
718718
let mut i = 1u;
719719
loop {
720-
alt dcur {
720+
alt copy dcur {
721721
some(dcur_def) {
722722
if i == path_len { break; }
723723
dcur =
724724
lookup_in_mod_strict(e, dcur_def, sp, path[i],
725725
ns_module, outside);
726726
i += 1u;
727727
}
728-
_ { break; }
728+
none { break; }
729729
}
730730
}
731731
if i == path_len {

trunk/src/rustc/middle/typeck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt,
235235
fn check_for_main_fn(ccx: @crate_ctxt, crate: @ast::crate) {
236236
let tcx = ccx.tcx;
237237
if !tcx.sess.building_library {
238-
alt tcx.sess.main_fn {
238+
alt copy tcx.sess.main_fn {
239239
some((id, sp)) { check_main_fn_ty(ccx, id, sp); }
240240
none { tcx.sess.span_err(crate.span, "main function not found"); }
241241
}

trunk/src/test/compile-fail/borrowck-lend-args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ fn borrow_from_arg_imm_ref(&&v: ~int) {
88
}
99

1010
fn borrow_from_arg_mut_ref(&v: ~int) {
11-
borrow(v); //! ERROR access to non-pure functions prohibited in a pure context
12-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
11+
borrow(v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
12+
//!^ NOTE impure due to access to non-pure functions
1313
}
1414

1515
fn borrow_from_arg_move(-v: ~int) {

trunk/src/test/compile-fail/borrowck-pat-enum-in-box.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ fn process(_i: int) {}
3030

3131
fn match_const_box_and_do_bad_things(v: &const @const option<int>) {
3232
alt *v {
33-
@some(i) { //! NOTE pure context is required due to an illegal borrow: enum variant in aliasable, mutable location
34-
process(i) //! ERROR access to non-pure functions prohibited in a pure context
33+
@some(i) { //! ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
34+
process(i) //! NOTE impure due to access to non-pure functions
3535
}
3636
@none {}
3737
}

trunk/src/test/compile-fail/borrowck-pat-enum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ fn match_const_reg_unused(v: &const option<int>) {
3636

3737
fn match_const_reg_impure(v: &const option<int>) {
3838
alt *v {
39-
some(i) {impure(i)} //! ERROR access to non-pure functions prohibited in a pure context
40-
//!^ NOTE pure context is required due to an illegal borrow: enum variant in aliasable, mutable location
39+
some(i) {impure(i)} //! ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
40+
//!^ NOTE impure due to access to non-pure functions
4141
none {}
4242
}
4343
}

trunk/src/test/compile-fail/borrowck-unchecked-with-borrow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
fn impure(_i: int) {}
55

6+
// check that unchecked alone does not override borrowck:
67
fn foo(v: &const option<int>) {
78
alt *v {
89
some(i) {
9-
//!^ NOTE pure context is required due to an illegal borrow: enum variant in aliasable, mutable location
10-
// check that unchecked alone does not override borrowck:
10+
//!^ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
1111
unchecked {
12-
impure(i); //! ERROR access to non-pure functions prohibited in a pure context
12+
impure(i); //! NOTE impure due to access to non-pure functions
1313
}
1414
}
1515
none {

trunk/src/test/compile-fail/borrowck-uniq-via-box.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
fn borrow(_v: &int) {}
55

66
fn box_mut(v: @mut ~int) {
7-
borrow(*v); //! ERROR access to non-pure functions prohibited in a pure context
8-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
7+
borrow(*v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
8+
//!^ NOTE impure due to access to non-pure functions
99
}
1010

1111
fn box_rec_mut(v: @{mut f: ~int}) {
12-
borrow(v.f); //! ERROR access to non-pure functions prohibited in a pure context
13-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
12+
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
13+
//!^ NOTE impure due to access to non-pure functions
1414
}
1515

1616
fn box_mut_rec(v: @mut {f: ~int}) {
17-
borrow(v.f); //! ERROR access to non-pure functions prohibited in a pure context
18-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
17+
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
18+
//!^ NOTE impure due to access to non-pure functions
1919
}
2020

2121
fn box_mut_recs(v: @mut {f: {g: {h: ~int}}}) {
22-
borrow(v.f.g.h); //! ERROR access to non-pure functions prohibited in a pure context
23-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
22+
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
23+
//!^ NOTE impure due to access to non-pure functions
2424
}
2525

2626
fn box_imm(v: @~int) {
@@ -36,28 +36,28 @@ fn box_imm_recs(v: @{f: {g: {h: ~int}}}) {
3636
}
3737

3838
fn box_const(v: @const ~int) {
39-
borrow(*v); //! ERROR access to non-pure functions prohibited in a pure context
40-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
39+
borrow(*v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
40+
//!^ NOTE impure due to access to non-pure functions
4141
}
4242

4343
fn box_rec_const(v: @{const f: ~int}) {
44-
borrow(v.f); //! ERROR access to non-pure functions prohibited in a pure context
45-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
44+
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
45+
//!^ NOTE impure due to access to non-pure functions
4646
}
4747

4848
fn box_recs_const(v: @{f: {g: {const h: ~int}}}) {
49-
borrow(v.f.g.h); //! ERROR access to non-pure functions prohibited in a pure context
50-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
49+
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
50+
//!^ NOTE impure due to access to non-pure functions
5151
}
5252

5353
fn box_const_rec(v: @const {f: ~int}) {
54-
borrow(v.f); //! ERROR access to non-pure functions prohibited in a pure context
55-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
54+
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
55+
//!^ NOTE impure due to access to non-pure functions
5656
}
5757

5858
fn box_const_recs(v: @const {f: {g: {h: ~int}}}) {
59-
borrow(v.f.g.h); //! ERROR access to non-pure functions prohibited in a pure context
60-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
59+
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
60+
//!^ NOTE impure due to access to non-pure functions
6161
}
6262

6363
fn main() {

trunk/src/test/compile-fail/borrowck-uniq-via-ref.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
fn borrow(_v: &int) {}
44

55
fn box_mut(v: &mut ~int) {
6-
borrow(*v); //! ERROR access to non-pure functions prohibited in a pure context
7-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
6+
borrow(*v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
7+
//!^ NOTE impure due to access to non-pure functions
88
}
99

1010
fn box_rec_mut(v: &{mut f: ~int}) {
11-
borrow(v.f); //! ERROR access to non-pure functions prohibited in a pure context
12-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
11+
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
12+
//!^ NOTE impure due to access to non-pure functions
1313
}
1414

1515
fn box_mut_rec(v: &mut {f: ~int}) {
16-
borrow(v.f); //! ERROR access to non-pure functions prohibited in a pure context
17-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
16+
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
17+
//!^ NOTE impure due to access to non-pure functions
1818
}
1919

2020
fn box_mut_recs(v: &mut {f: {g: {h: ~int}}}) {
21-
borrow(v.f.g.h); //! ERROR access to non-pure functions prohibited in a pure context
22-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
21+
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
22+
//!^ NOTE impure due to access to non-pure functions
2323
}
2424

2525
fn box_imm(v: &~int) {
@@ -35,28 +35,28 @@ fn box_imm_recs(v: &{f: {g: {h: ~int}}}) {
3535
}
3636

3737
fn box_const(v: &const ~int) {
38-
borrow(*v); //! ERROR access to non-pure functions prohibited in a pure context
39-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
38+
borrow(*v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
39+
//!^ NOTE impure due to access to non-pure functions
4040
}
4141

4242
fn box_rec_const(v: &{const f: ~int}) {
43-
borrow(v.f); //! ERROR access to non-pure functions prohibited in a pure context
44-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
43+
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
44+
//!^ NOTE impure due to access to non-pure functions
4545
}
4646

4747
fn box_recs_const(v: &{f: {g: {const h: ~int}}}) {
48-
borrow(v.f.g.h); //! ERROR access to non-pure functions prohibited in a pure context
49-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
48+
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
49+
//!^ NOTE impure due to access to non-pure functions
5050
}
5151

5252
fn box_const_rec(v: &const {f: ~int}) {
53-
borrow(v.f); //! ERROR access to non-pure functions prohibited in a pure context
54-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
53+
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
54+
//!^ NOTE impure due to access to non-pure functions
5555
}
5656

5757
fn box_const_recs(v: &const {f: {g: {h: ~int}}}) {
58-
borrow(v.f.g.h); //! ERROR access to non-pure functions prohibited in a pure context
59-
//!^ NOTE pure context is required due to an illegal borrow: unique value in aliasable, mutable location
58+
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location
59+
//!^ NOTE impure due to access to non-pure functions
6060
}
6161

6262
fn main() {

trunk/src/test/compile-fail/impure-pred.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
fn g() { }
44

55
pure fn f(_q: int) -> bool {
6-
g(); //! ERROR access to non-pure functions prohibited in a pure context
6+
g(); //! ERROR access to non-pure functions prohibited in pure context
77
ret true;
88
}
99

trunk/src/test/compile-fail/pure-modifies-aliased.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Check that pure functions cannot modify aliased state.
22

33
pure fn modify_in_ref(&&sum: {mut f: int}) {
4-
sum.f = 3; //! ERROR assigning to mutable field prohibited in a pure context
4+
sum.f = 3; //! ERROR assigning to mutable field prohibited in pure context
55
}
66

77
pure fn modify_in_box(sum: @mut {f: int}) {
8-
sum.f = 3; //! ERROR assigning to mutable field prohibited in a pure context
8+
sum.f = 3; //! ERROR assigning to mutable field prohibited in pure context
99
}
1010

1111
impl foo for int {
1212
pure fn modify_in_box_rec(sum: @{mut f: int}) {
13-
sum.f = self; //! ERROR assigning to mutable field prohibited in a pure context
13+
sum.f = self; //! ERROR assigning to mutable field prohibited in pure context
1414
}
1515
}
1616

0 commit comments

Comments
 (0)