@@ -92,22 +92,20 @@ fn check_struct_safe_for_destructor(cx: &mut Context,
9292 let struct_ty = ty:: mk_struct ( cx. tcx , struct_did,
9393 subst:: Substs :: empty ( ) ) ;
9494 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") ;
102101 }
103102 } 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") ;
111109 }
112110}
113111
@@ -124,14 +122,12 @@ fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_t
124122 let self_ty: ty:: t = ty:: node_id_to_type ( cx. tcx , it. id ) ;
125123 debug ! ( "checking impl with self type {}" , ty:: get( self_ty) . sty) ;
126124 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) ) ;
135131 } ) ;
136132
137133 // If this is a destructor, check kinds.
@@ -191,10 +187,9 @@ fn with_appropriate_checker(cx: &Context,
191187 }
192188
193189 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", "{ ... }" ) ;
198193 } // same check is done in resolve.rs, but shouldn't be done
199194
200195 let fty = ty:: node_id_to_type ( cx. tcx , id) ;
@@ -494,12 +489,11 @@ pub fn check_typaram_bounds(cx: &Context,
494489 ty,
495490 type_param_def. bounds . builtin_bounds ,
496491 |missing| {
497- cx. tcx . sess . span_err (
498- sp,
499- format ! ( "instantiating a type parameter with an incompatible type \
500- `{}`, which does not fulfill `{}`",
501- ty_to_string( cx. tcx, ty) ,
502- missing. user_string( cx. tcx) ) . as_slice ( ) ) ;
492+ span_err ! ( cx. tcx. sess, sp, E0144 ,
493+ "instantiating a type parameter with an incompatible type \
494+ `{}`, which does not fulfill `{}`",
495+ ty_to_string( cx. tcx, ty) ,
496+ missing. user_string( cx. tcx) ) ;
503497 } ) ;
504498}
505499
@@ -511,36 +505,32 @@ pub fn check_freevar_bounds(cx: &Context, sp: Span, ty: ty::t,
511505 // Emit a less mysterious error message in this case.
512506 match referenced_ty {
513507 Some ( rty) => {
514- cx. tcx . sess . span_err ( sp,
515- format ! ( "cannot implicitly borrow variable of type `{}` in a \
516- bounded stack closure (implicit reference does not \
517- fulfill `{}`)",
518- ty_to_string( cx. tcx, rty) ,
519- missing. user_string( cx. tcx) ) . as_slice ( ) )
508+ span_err ! ( cx. tcx. sess, sp, E0145 ,
509+ "cannot implicitly borrow variable of type `{}` in a \
510+ bounded stack closure (implicit reference does not fulfill `{}`)",
511+ ty_to_string( cx. tcx, rty) , missing. user_string( cx. tcx) ) ;
520512 }
521513 None => {
522- cx. tcx . sess . span_err ( sp,
523- format ! ( "cannot capture variable of type `{}`, which does \
524- not fulfill `{}`, in a bounded closure",
525- ty_to_string( cx. tcx, ty) ,
526- missing. user_string( cx. tcx) ) . as_slice ( ) )
514+ span_err ! ( cx. tcx. sess, sp, E0146 ,
515+ "cannot capture variable of type `{}`, which does \
516+ not fulfill `{}`, in a bounded closure",
517+ ty_to_string( cx. tcx, ty) , missing. user_string( cx. tcx) ) ;
527518 }
528519 }
529- cx. tcx . sess . span_note (
530- sp,
531- format ! ( "this closure's environment must satisfy `{}`" ,
532- bounds. user_string( cx. tcx) ) . as_slice ( ) ) ;
520+ span_note ! ( cx. tcx. sess, sp,
521+ "this closure's environment must satisfy `{}`" ,
522+ bounds. user_string( cx. tcx) ) ;
533523 } ) ;
534524}
535525
536526pub fn check_trait_cast_bounds ( cx : & Context , sp : Span , ty : ty:: t ,
537527 bounds : ty:: BuiltinBounds ) {
538528 check_builtin_bounds ( cx, ty, bounds, |missing| {
539- cx. tcx . sess . span_err ( sp ,
540- format ! ( "cannot pack type `{}`, which does not fulfill \
541- `{}`, as a trait bounded by {}" ,
542- ty_to_string ( cx . tcx , ty ) , missing. user_string( cx. tcx) ,
543- bounds. user_string( cx. tcx) ) . as_slice ( ) ) ;
529+ span_err ! ( cx. tcx. sess, sp , E0147 ,
530+ "cannot pack type `{}`, which does not fulfill `{}`, as a trait bounded by {}" ,
531+ ty_to_string ( cx . tcx , ty ) ,
532+ missing. user_string( cx. tcx) ,
533+ bounds. user_string( cx. tcx) ) ;
544534 } ) ;
545535}
546536
@@ -549,26 +539,26 @@ fn check_copy(cx: &Context, ty: ty::t, sp: Span, reason: &str) {
549539 ty_to_string( cx. tcx, ty) ,
550540 ty:: type_contents( cx. tcx, ty) . to_string( ) ) ;
551541 if ty:: type_moves_by_default ( cx. tcx , ty) {
552- cx. tcx . sess . span_err (
553- sp,
554- format ! ( "copying a value of non-copyable type `{}`" ,
555- ty_to_string( cx. tcx, ty) ) . as_slice ( ) ) ;
556- cx. tcx . sess . span_note ( sp, format ! ( "{}" , reason) . as_slice ( ) ) ;
542+ span_err ! ( cx. tcx. sess, sp, E0148 ,
543+ "copying a value of non-copyable type `{}`" ,
544+ ty_to_string( cx. tcx, ty) ) ;
545+ span_note ! ( cx. tcx. sess, sp, "{}" , reason. as_slice( ) ) ;
557546 }
558547}
559548
560549pub fn check_static ( tcx : & ty:: ctxt , ty : ty:: t , sp : Span ) -> bool {
561550 if !ty:: type_is_static ( tcx, ty) {
562551 match ty:: get ( ty) . sty {
563- ty:: ty_param( ..) => {
564- tcx. sess . span_err ( sp,
565- format ! ( "value may contain references; \
566- add `'static` bound to `{}`",
567- ty_to_string( tcx, ty) ) . as_slice ( ) ) ;
568- }
569- _ => {
570- tcx. sess . span_err ( sp, "value may contain references" ) ;
571- }
552+ ty:: ty_param( ..) => {
553+ span_err ! ( tcx. sess, sp, E0149 ,
554+ "value may contain references; \
555+ add `'static` bound to `{}`",
556+ ty_to_string( tcx, ty) ) ;
557+ }
558+ _ => {
559+ span_err ! ( tcx. sess, sp, E0150 ,
560+ "value may contain references" ) ;
561+ }
572562 }
573563 false
574564 } else {
@@ -685,11 +675,9 @@ pub fn check_cast_for_escaping_regions(
685675// Ensure that `ty` has a statically known size (i.e., it has the `Sized` bound).
686676fn check_sized ( tcx : & ty:: ctxt , ty : ty:: t , name : String , sp : Span ) {
687677 if !ty:: type_is_sized ( tcx, ty) {
688- tcx. sess . span_err ( sp,
689- format ! ( "variable `{}` has dynamically sized type \
690- `{}`",
691- name,
692- ty_to_string( tcx, ty) ) . as_slice ( ) ) ;
678+ span_err ! ( tcx. sess, sp, E0151 ,
679+ "variable `{}` has dynamically sized type `{}`" ,
680+ name, ty_to_string( tcx, ty) ) ;
693681 }
694682}
695683
0 commit comments