@@ -220,7 +220,8 @@ use syntax::visit;
220
220
use syntax:: ast_util;
221
221
use syntax:: ast_map;
222
222
use syntax:: codemap:: span;
223
- use util:: ppaux:: { ty_to_str, region_to_str, explain_region} ;
223
+ use util:: ppaux:: { ty_to_str, region_to_str, explain_region,
224
+ note_and_explain_region} ;
224
225
use std:: map:: { int_hash, hashmap, set} ;
225
226
use std:: list;
226
227
use std:: list:: { List , Cons , Nil } ;
@@ -464,6 +465,7 @@ impl borrowck_ctxt {
464
465
err. cmt . span ,
465
466
fmt ! ( "illegal borrow: %s" ,
466
467
self . bckerr_code_to_str( err. code) ) ) ;
468
+ self . note_and_explain_bckerr ( err. code ) ;
467
469
}
468
470
469
471
fn span_err ( s : span , m : ~str ) {
@@ -488,37 +490,65 @@ impl borrowck_ctxt {
488
490
489
491
fn bckerr_code_to_str ( code : bckerr_code ) -> ~str {
490
492
match code {
491
- err_mutbl( req, act) => {
492
- fmt ! ( "creating %s alias to aliasable, %s memory" ,
493
- self . mut_to_str( req) , self . mut_to_str( act) )
494
- }
495
- err_mut_uniq => {
496
- ~"unique value in aliasable, mutable location"
497
- }
498
- err_mut_variant => {
499
- ~"enum variant in aliasable, mutable location"
500
- }
501
- err_root_not_permitted => {
502
- // note: I don't expect users to ever see this error
503
- // message, reasons are discussed in attempt_root() in
504
- // preserve.rs.
505
- ~"rooting is not permitted"
506
- }
507
- err_out_of_root_scope( super_scope, sub_scope) => {
508
- fmt ! ( "managed value would have to be rooted for %s, \
509
- but can only be rooted for %s",
510
- explain_region( self . tcx, sub_scope) ,
511
- explain_region( self . tcx, super_scope) )
512
- }
513
- err_out_of_scope( super_scope, sub_scope) => {
514
- fmt ! ( "borrowed pointer must be valid for %s, \
515
- but the borrowed value is only valid for %s",
516
- explain_region( self . tcx, sub_scope) ,
517
- explain_region( self . tcx, super_scope) )
493
+ err_mutbl( req, act) => {
494
+ fmt ! ( "creating %s alias to aliasable, %s memory" ,
495
+ self . mut_to_str( req) , self . mut_to_str( act) )
496
+ }
497
+ err_mut_uniq => {
498
+ ~"unique value in aliasable, mutable location"
499
+ }
500
+ err_mut_variant => {
501
+ ~"enum variant in aliasable, mutable location"
502
+ }
503
+ err_root_not_permitted => {
504
+ // note: I don't expect users to ever see this error
505
+ // message, reasons are discussed in attempt_root() in
506
+ // preserve.rs.
507
+ ~"rooting is not permitted"
508
+ }
509
+ err_out_of_root_scope( * ) => {
510
+ ~"cannot root managed value long enough"
511
+ }
512
+ err_out_of_scope( * ) => {
513
+ ~"borrowed value does not live long enough"
514
+ }
515
+ }
516
+ }
517
+
518
+ fn note_and_explain_bckerr( code : bckerr_code ) {
519
+ match code {
520
+ err_mutbl( * ) | err_mut_uniq | err_mut_variant |
521
+ err_root_not_permitted => { }
522
+
523
+ err_out_of_root_scope( super_scope, sub_scope) => {
524
+ note_and_explain_region (
525
+ self . tcx ,
526
+ ~"managed value would have to be rooted for ",
527
+ sub_scope,
528
+ ~" ...");
529
+ note_and_explain_region(
530
+ self.tcx,
531
+ ~" ...but can only be rooted for ",
532
+ super_scope,
533
+ ~" ") ;
534
+ }
535
+
536
+ err_out_of_scope( super_scope, sub_scope) => {
537
+ note_and_explain_region (
538
+ self . tcx ,
539
+ ~"borrowed pointer must be valid for ",
540
+ sub_scope,
541
+ ~" ...");
542
+ note_and_explain_region(
543
+ self.tcx,
544
+ ~" ...but borrowed value is only valid for ",
545
+ super_scope,
546
+ ~" ") ;
518
547
}
519
548
}
520
549
}
521
550
551
+
522
552
fn cmt_to_str( cmt: cmt) -> ~str {
523
553
let mc = & mem_categorization_ctxt { tcx : self . tcx ,
524
554
method_map : self . method_map } ;
0 commit comments