@@ -14,8 +14,13 @@ use crate::check::Expectation::{self, ExpectCastableToType, ExpectHasType, NoExp
14
14
use crate :: check:: FnCtxt ;
15
15
use crate :: check:: Needs ;
16
16
use crate :: check:: TupleArgumentsFlag :: DontTupleArguments ;
17
+ use crate :: errors:: {
18
+ FieldMultiplySpecifiedInInitializer , FunctionalRecordUpdateOnNonStruct ,
19
+ YieldExprOutsideOfGenerator ,
20
+ } ;
17
21
use crate :: type_error_struct;
18
22
23
+ use crate :: errors:: { AddressOfTemporaryTaken , ReturnStmtOutsideOfFnBody , StructExprNonExhaustive } ;
19
24
use rustc_ast as ast;
20
25
use rustc_ast:: util:: lev_distance:: find_best_match_for_name;
21
26
use rustc_data_structures:: fx:: FxHashMap ;
@@ -439,14 +444,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
439
444
} )
440
445
} ) ;
441
446
if !is_named {
442
- struct_span_err ! (
443
- self . tcx. sess,
444
- oprnd. span,
445
- E0745 ,
446
- "cannot take address of a temporary"
447
- )
448
- . span_label ( oprnd. span , "temporary value" )
449
- . emit ( ) ;
447
+ self . tcx . sess . emit_err ( AddressOfTemporaryTaken { span : oprnd. span } )
450
448
}
451
449
}
452
450
@@ -665,13 +663,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
665
663
expr : & ' tcx hir:: Expr < ' tcx > ,
666
664
) -> Ty < ' tcx > {
667
665
if self . ret_coercion . is_none ( ) {
668
- struct_span_err ! (
669
- self . tcx. sess,
670
- expr. span,
671
- E0572 ,
672
- "return statement outside of function body" ,
673
- )
674
- . emit ( ) ;
666
+ self . tcx . sess . emit_err ( ReturnStmtOutsideOfFnBody { span : expr. span } ) ;
675
667
} else if let Some ( ref e) = expr_opt {
676
668
if self . ret_coercion_span . borrow ( ) . is_none ( ) {
677
669
* self . ret_coercion_span . borrow_mut ( ) = Some ( e. span ) ;
@@ -740,6 +732,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
740
732
expr_span : & Span ,
741
733
) {
742
734
if !lhs. is_syntactic_place_expr ( ) {
735
+ // FIXME: Make this use SessionDiagnostic once error codes can be dynamically set.
743
736
let mut err = self . tcx . sess . struct_span_err_with_code (
744
737
* expr_span,
745
738
"invalid left-hand side of assignment" ,
@@ -1120,14 +1113,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1120
1113
// Prohibit struct expressions when non-exhaustive flag is set.
1121
1114
let adt = adt_ty. ty_adt_def ( ) . expect ( "`check_struct_path` returned non-ADT type" ) ;
1122
1115
if !adt. did . is_local ( ) && variant. is_field_list_non_exhaustive ( ) {
1123
- struct_span_err ! (
1124
- self . tcx. sess,
1125
- expr. span,
1126
- E0639 ,
1127
- "cannot create non-exhaustive {} using struct expression" ,
1128
- adt. variant_descr( )
1129
- )
1130
- . emit ( ) ;
1116
+ self . tcx
1117
+ . sess
1118
+ . emit_err ( StructExprNonExhaustive { span : expr. span , what : adt. variant_descr ( ) } ) ;
1131
1119
}
1132
1120
1133
1121
let error_happened = self . check_expr_struct_fields (
@@ -1165,13 +1153,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1165
1153
. insert ( expr. hir_id , fru_field_types) ;
1166
1154
}
1167
1155
_ => {
1168
- struct_span_err ! (
1169
- self . tcx. sess,
1170
- base_expr. span,
1171
- E0436 ,
1172
- "functional record update syntax requires a struct"
1173
- )
1174
- . emit ( ) ;
1156
+ self . tcx
1157
+ . sess
1158
+ . emit_err ( FunctionalRecordUpdateOnNonStruct { span : base_expr. span } ) ;
1175
1159
}
1176
1160
}
1177
1161
}
@@ -1234,18 +1218,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1234
1218
} else {
1235
1219
error_happened = true ;
1236
1220
if let Some ( prev_span) = seen_fields. get ( & ident) {
1237
- let mut err = struct_span_err ! (
1238
- self . tcx. sess,
1239
- field. ident. span,
1240
- E0062 ,
1241
- "field `{}` specified more than once" ,
1242
- ident
1243
- ) ;
1244
-
1245
- err. span_label ( field. ident . span , "used more than once" ) ;
1246
- err. span_label ( * prev_span, format ! ( "first use of `{}`" , ident) ) ;
1247
-
1248
- err. emit ( ) ;
1221
+ tcx. sess . emit_err ( FieldMultiplySpecifiedInInitializer {
1222
+ span : field. ident . span ,
1223
+ prev_span : * prev_span,
1224
+ ident,
1225
+ } ) ;
1249
1226
} else {
1250
1227
self . report_unknown_field ( adt_ty, variant, field, ast_fields, kind_name, span) ;
1251
1228
}
@@ -1876,13 +1853,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1876
1853
self . tcx . mk_unit ( )
1877
1854
}
1878
1855
_ => {
1879
- struct_span_err ! (
1880
- self . tcx. sess,
1881
- expr. span,
1882
- E0627 ,
1883
- "yield expression outside of generator literal"
1884
- )
1885
- . emit ( ) ;
1856
+ self . tcx . sess . emit_err ( YieldExprOutsideOfGenerator { span : expr. span } ) ;
1886
1857
self . tcx . mk_unit ( )
1887
1858
}
1888
1859
}
0 commit comments