diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-05-23 11:55:32 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-05-23 12:01:27 -0700 |
| commit | 9773a22119bf416a1c53d0ee30f6a127c7e274e1 (patch) | |
| tree | 2b06ac34fa37183b3e27dad396bdfb9ba123cb9f /src/rustc | |
| parent | 248f8826a9287a1c98144053289aca4355785391 (diff) | |
| download | rust-9773a22119bf416a1c53d0ee30f6a127c7e274e1.tar.gz rust-9773a22119bf416a1c53d0ee30f6a127c7e274e1.zip | |
shuffle error messages in borrowck, and prevent it from spewing too many
also, fix a few minor issues it complains about
Diffstat (limited to 'src/rustc')
| -rw-r--r-- | src/rustc/middle/borrowck.rs | 38 | ||||
| -rw-r--r-- | src/rustc/middle/resolve.rs | 4 | ||||
| -rw-r--r-- | src/rustc/middle/typeck.rs | 2 |
3 files changed, 25 insertions, 19 deletions
diff --git a/src/rustc/middle/borrowck.rs b/src/rustc/middle/borrowck.rs index bb65df934f7..ee01a0e89e2 100644 --- a/src/rustc/middle/borrowck.rs +++ b/src/rustc/middle/borrowck.rs @@ -498,6 +498,8 @@ enum check_loan_ctxt = @{ bccx: borrowck_ctxt, req_maps: req_maps, + reported: hashmap<ast::node_id, ()>, + // Keep track of whether we're inside a ctor, so as to // allow mutating immutable fields in the same class if // we are in a ctor, we track the self id @@ -525,6 +527,7 @@ fn check_loans(bccx: borrowck_ctxt, crate: @ast::crate) { let clcx = check_loan_ctxt(@{bccx: bccx, req_maps: req_maps, + reported: int_hash(), mut in_ctor: false, mut is_pure: pc_impure}); let vt = visit::mk_vt(@{visit_expr: check_loans_in_expr, @@ -641,11 +644,9 @@ impl methods for check_loan_ctxt { /*ok*/ } ast::impure_fn | ast::unsafe_fn { - self.bccx.span_err( + self.report_purity_error( expr.span, - "access to non-pure functions \ - prohibited in a pure context"); - self.report_why_pure(); + "access to non-pure functions"); } } } @@ -739,11 +740,9 @@ impl methods for check_loan_ctxt { // assigned, because it is uniquely tied to this function and // is not visible from the outside if self.is_pure != pc_impure && cmt.lp.is_none() { - self.bccx.span_err( + self.report_purity_error( ex.span, - #fmt["%s prohibited in a pure context", - at.ing_form(self.bccx.cmt_to_str(cmt))]); - self.report_why_pure(); + at.ing_form(self.bccx.cmt_to_str(cmt))); } // check for a conflicting loan as well, except in the case of @@ -776,19 +775,26 @@ impl methods for check_loan_ctxt { self.bccx.add_to_mutbl_map(cmt); } - fn report_why_pure() { - alt self.is_pure { + fn report_purity_error(sp: span, msg: str) { + alt copy self.is_pure { pc_impure { - self.tcx().sess.bug("report_why_pure() called when impure"); + self.tcx().sess.bug("report_purity_error() called when impure"); } pc_declaration { - // fn was declared pure; no need to report this, I think + self.tcx().sess.span_err( + sp, + #fmt["%s prohibited in pure context", msg]); } pc_cmt(e) { - self.tcx().sess.span_note( - e.cmt.span, - #fmt["pure context is required due to an illegal borrow: %s", - self.bccx.bckerr_code_to_str(e.code)]); + if self.reported.insert(e.cmt.id, ()) { + self.tcx().sess.span_err( + e.cmt.span, + #fmt["illegal borrow unless pure: %s", + self.bccx.bckerr_code_to_str(e.code)]); + self.tcx().sess.span_note( + sp, + #fmt["impure due to %s", msg]); + } } } } diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index 3c713329268..abce3067fdc 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -717,7 +717,7 @@ fn follow_import(e: env, &&sc: scopes, path: [ident], sp: span) -> let mut dcur = lookup_in_scope_strict(e, sc, sp, path[0], ns_module); let mut i = 1u; loop { - alt dcur { + alt copy dcur { some(dcur_def) { if i == path_len { break; } dcur = @@ -725,7 +725,7 @@ fn follow_import(e: env, &&sc: scopes, path: [ident], sp: span) -> ns_module, outside); i += 1u; } - _ { break; } + none { break; } } } if i == path_len { diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 7b97bfb7138..f9cc22a595e 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -235,7 +235,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt, fn check_for_main_fn(ccx: @crate_ctxt, crate: @ast::crate) { let tcx = ccx.tcx; if !tcx.sess.building_library { - alt tcx.sess.main_fn { + alt copy tcx.sess.main_fn { some((id, sp)) { check_main_fn_ty(ccx, id, sp); } none { tcx.sess.span_err(crate.span, "main function not found"); } } |
