@@ -92,22 +92,20 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
92
92
let struct_ty = ty:: mk_struct ( cx. tcx , struct_did,
93
93
subst:: Substs :: empty ( ) ) ;
94
94
if !ty:: type_is_sendable ( cx. tcx , struct_ty) {
95
- cx. tcx . sess . span_err ( span,
96
- "cannot implement a destructor on a \
97
- structure that does not satisfy Send") ;
98
- cx. tcx . sess . span_note ( span,
99
- "use \" #[unsafe_destructor]\" on the \
100
- implementation to force the compiler to \
101
- allow this") ;
95
+ span_err ! ( cx. tcx. sess, span, E0125 ,
96
+ "cannot implement a destructor on a \
97
+ structure that does not satisfy Send") ;
98
+ span_note ! ( cx. tcx. sess, span,
99
+ "use \" #[unsafe_destructor]\" on the implementation \
100
+ to force the compiler to allow this") ;
102
101
}
103
102
} else {
104
- cx. tcx . sess . span_err ( span,
105
- "cannot implement a destructor on a structure \
106
- with type parameters") ;
107
- cx. tcx . sess . span_note ( span,
108
- "use \" #[unsafe_destructor]\" on the \
109
- implementation to force the compiler to \
110
- allow this") ;
103
+ span_err ! ( cx. tcx. sess, span, E0141 ,
104
+ "cannot implement a destructor on a structure \
105
+ with type parameters") ;
106
+ span_note ! ( cx. tcx. sess, span,
107
+ "use \" #[unsafe_destructor]\" on the implementation \
108
+ to force the compiler to allow this") ;
111
109
}
112
110
}
113
111
@@ -124,14 +122,12 @@ fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_t
124
122
let self_ty: ty:: t = ty:: node_id_to_type ( cx. tcx , it. id ) ;
125
123
debug ! ( "checking impl with self type {}" , ty:: get( self_ty) . sty) ;
126
124
check_builtin_bounds ( cx, self_ty, trait_def. bounds , |missing| {
127
- cx. tcx . sess . span_err ( self_type. span ,
128
- format ! ( "the type `{}', which does not fulfill `{}`, cannot implement this \
129
- trait",
130
- ty_to_string( cx. tcx, self_ty) ,
131
- missing. user_string( cx. tcx) ) . as_slice ( ) ) ;
132
- cx. tcx . sess . span_note ( self_type. span ,
133
- format ! ( "types implementing this trait must fulfill `{}`" ,
134
- trait_def. bounds. user_string( cx. tcx) ) . as_slice ( ) ) ;
125
+ span_err ! ( cx. tcx. sess, self_type. span, E0142 ,
126
+ "the type `{}', which does not fulfill `{}`, cannot implement this trait" ,
127
+ ty_to_string( cx. tcx, self_ty) , missing. user_string( cx. tcx) ) ;
128
+ span_note ! ( cx. tcx. sess, self_type. span,
129
+ "types implementing this trait must fulfill `{}`" ,
130
+ trait_def. bounds. user_string( cx. tcx) ) ;
135
131
} ) ;
136
132
137
133
// If this is a destructor, check kinds.
@@ -191,10 +187,9 @@ fn with_appropriate_checker(cx: &Context,
191
187
}
192
188
193
189
fn check_for_bare ( cx : & Context , fv : & freevar_entry ) {
194
- cx. tcx . sess . span_err (
195
- fv. span ,
196
- "can't capture dynamic environment in a fn item; \
197
- use the || { ... } closure form instead") ;
190
+ span_err ! ( cx. tcx. sess, fv. span, E0143 ,
191
+ "can't capture dynamic environment in a fn item; \
192
+ use the || {} closure form instead", "{ ... }" ) ;
198
193
} // same check is done in resolve.rs, but shouldn't be done
199
194
200
195
let fty = ty:: node_id_to_type ( cx. tcx , id) ;
@@ -489,12 +484,11 @@ pub fn check_typaram_bounds(cx: &Context,
489
484
ty,
490
485
type_param_def. bounds . builtin_bounds ,
491
486
|missing| {
492
- cx. tcx . sess . span_err (
493
- sp,
494
- format ! ( "instantiating a type parameter with an incompatible type \
495
- `{}`, which does not fulfill `{}`",
496
- ty_to_string( cx. tcx, ty) ,
497
- missing. user_string( cx. tcx) ) . as_slice ( ) ) ;
487
+ span_err ! ( cx. tcx. sess, sp, E0144 ,
488
+ "instantiating a type parameter with an incompatible type \
489
+ `{}`, which does not fulfill `{}`",
490
+ ty_to_string( cx. tcx, ty) ,
491
+ missing. user_string( cx. tcx) ) ;
498
492
} ) ;
499
493
}
500
494
@@ -506,36 +500,32 @@ pub fn check_freevar_bounds(cx: &Context, sp: Span, ty: ty::t,
506
500
// Emit a less mysterious error message in this case.
507
501
match referenced_ty {
508
502
Some ( rty) => {
509
- cx. tcx . sess . span_err ( sp,
510
- format ! ( "cannot implicitly borrow variable of type `{}` in a \
511
- bounded stack closure (implicit reference does not \
512
- fulfill `{}`)",
513
- ty_to_string( cx. tcx, rty) ,
514
- missing. user_string( cx. tcx) ) . as_slice ( ) )
503
+ span_err ! ( cx. tcx. sess, sp, E0145 ,
504
+ "cannot implicitly borrow variable of type `{}` in a \
505
+ bounded stack closure (implicit reference does not fulfill `{}`)",
506
+ ty_to_string( cx. tcx, rty) , missing. user_string( cx. tcx) ) ;
515
507
}
516
508
None => {
517
- cx. tcx . sess . span_err ( sp,
518
- format ! ( "cannot capture variable of type `{}`, which does \
519
- not fulfill `{}`, in a bounded closure",
520
- ty_to_string( cx. tcx, ty) ,
521
- missing. user_string( cx. tcx) ) . as_slice ( ) )
509
+ span_err ! ( cx. tcx. sess, sp, E0146 ,
510
+ "cannot capture variable of type `{}`, which does \
511
+ not fulfill `{}`, in a bounded closure",
512
+ ty_to_string( cx. tcx, ty) , missing. user_string( cx. tcx) ) ;
522
513
}
523
514
}
524
- cx. tcx . sess . span_note (
525
- sp,
526
- format ! ( "this closure's environment must satisfy `{}`" ,
527
- bounds. user_string( cx. tcx) ) . as_slice ( ) ) ;
515
+ span_note ! ( cx. tcx. sess, sp,
516
+ "this closure's environment must satisfy `{}`" ,
517
+ bounds. user_string( cx. tcx) ) ;
528
518
} ) ;
529
519
}
530
520
531
521
pub fn check_trait_cast_bounds ( cx : & Context , sp : Span , ty : ty:: t ,
532
522
bounds : ty:: BuiltinBounds ) {
533
523
check_builtin_bounds ( cx, ty, bounds, |missing| {
534
- cx. tcx . sess . span_err ( sp ,
535
- format ! ( "cannot pack type `{}`, which does not fulfill \
536
- `{}`, as a trait bounded by {}" ,
537
- ty_to_string ( cx . tcx , ty ) , missing. user_string( cx. tcx) ,
538
- bounds. user_string( cx. tcx) ) . as_slice ( ) ) ;
524
+ span_err ! ( cx. tcx. sess, sp , E0147 ,
525
+ "cannot pack type `{}`, which does not fulfill `{}`, as a trait bounded by {}" ,
526
+ ty_to_string ( cx . tcx , ty ) ,
527
+ missing. user_string( cx. tcx) ,
528
+ bounds. user_string( cx. tcx) ) ;
539
529
} ) ;
540
530
}
541
531
@@ -544,26 +534,26 @@ fn check_copy(cx: &Context, ty: ty::t, sp: Span, reason: &str) {
544
534
ty_to_string( cx. tcx, ty) ,
545
535
ty:: type_contents( cx. tcx, ty) . to_string( ) ) ;
546
536
if ty:: type_moves_by_default ( cx. tcx , ty) {
547
- cx. tcx . sess . span_err (
548
- sp,
549
- format ! ( "copying a value of non-copyable type `{}`" ,
550
- ty_to_string( cx. tcx, ty) ) . as_slice ( ) ) ;
551
- cx. tcx . sess . span_note ( sp, format ! ( "{}" , reason) . as_slice ( ) ) ;
537
+ span_err ! ( cx. tcx. sess, sp, E0148 ,
538
+ "copying a value of non-copyable type `{}`" ,
539
+ ty_to_string( cx. tcx, ty) ) ;
540
+ span_note ! ( cx. tcx. sess, sp, "{}" , reason. as_slice( ) ) ;
552
541
}
553
542
}
554
543
555
544
pub fn check_static ( tcx : & ty:: ctxt , ty : ty:: t , sp : Span ) -> bool {
556
545
if !ty:: type_is_static ( tcx, ty) {
557
546
match ty:: get ( ty) . sty {
558
- ty:: ty_param( ..) => {
559
- tcx. sess . span_err ( sp,
560
- format ! ( "value may contain references; \
561
- add `'static` bound to `{}`",
562
- ty_to_string( tcx, ty) ) . as_slice ( ) ) ;
563
- }
564
- _ => {
565
- tcx. sess . span_err ( sp, "value may contain references" ) ;
566
- }
547
+ ty:: ty_param( ..) => {
548
+ span_err ! ( tcx. sess, sp, E0149 ,
549
+ "value may contain references; \
550
+ add `'static` bound to `{}`",
551
+ ty_to_string( tcx, ty) ) ;
552
+ }
553
+ _ => {
554
+ span_err ! ( tcx. sess, sp, E0150 ,
555
+ "value may contain references" ) ;
556
+ }
567
557
}
568
558
false
569
559
} else {
@@ -680,11 +670,9 @@ pub fn check_cast_for_escaping_regions(
680
670
// Ensure that `ty` has a statically known size (i.e., it has the `Sized` bound).
681
671
fn check_sized ( tcx : & ty:: ctxt , ty : ty:: t , name : String , sp : Span ) {
682
672
if !ty:: type_is_sized ( tcx, ty) {
683
- tcx. sess . span_err ( sp,
684
- format ! ( "variable `{}` has dynamically sized type \
685
- `{}`",
686
- name,
687
- ty_to_string( tcx, ty) ) . as_slice ( ) ) ;
673
+ span_err ! ( tcx. sess, sp, E0151 ,
674
+ "variable `{}` has dynamically sized type `{}`" ,
675
+ name, ty_to_string( tcx, ty) ) ;
688
676
}
689
677
}
690
678
0 commit comments