1
+ use super :: errors:: {
2
+ AsyncGeneratorsNotSupported , AsyncNonMoveClosureNotSupported , AwaitOnlyInAsyncFnAndBlocks ,
3
+ BaseExpressionDoubleDot , ClosureCannotBeStatic , FunctionalRecordUpdateDestructuringAssignemnt ,
4
+ GeneratorTooManyParameters , RustcBoxAttributeError , UnderscoreExprLhsAssign ,
5
+ } ;
1
6
use super :: ResolverAstLoweringExt ;
2
7
use super :: { ImplTraitContext , LoweringContext , ParamMode , ParenthesizedGenericArgs } ;
3
8
use crate :: { FnDeclKind , ImplTraitPosition } ;
@@ -7,7 +12,6 @@ use rustc_ast::ptr::P as AstP;
7
12
use rustc_ast:: * ;
8
13
use rustc_data_structures:: stack:: ensure_sufficient_stack;
9
14
use rustc_data_structures:: thin_vec:: ThinVec ;
10
- use rustc_errors:: struct_span_err;
11
15
use rustc_hir as hir;
12
16
use rustc_hir:: def:: Res ;
13
17
use rustc_hir:: definitions:: DefPathData ;
@@ -46,13 +50,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
46
50
let hir_id = self . lower_node_id ( e. id ) ;
47
51
return hir:: Expr { hir_id, kind, span : self . lower_span ( e. span ) } ;
48
52
} else {
49
- self . tcx . sess
50
- . struct_span_err (
51
- e. span ,
52
- "#[rustc_box] requires precisely one argument \
53
- and no other attributes are allowed",
54
- )
55
- . emit ( ) ;
53
+ self . tcx . sess . emit_err ( RustcBoxAttributeError { span : e. span } ) ;
56
54
hir:: ExprKind :: Err
57
55
}
58
56
} else if let Some ( legacy_args) = self . resolver . legacy_const_generic_args ( f) {
@@ -212,13 +210,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
212
210
self . lower_expr_range ( e. span , e1. as_deref ( ) , e2. as_deref ( ) , lims)
213
211
}
214
212
ExprKind :: Underscore => {
215
- self . tcx
216
- . sess . struct_span_err (
217
- e. span ,
218
- "in expressions, `_` can only be used on the left-hand side of an assignment" ,
219
- )
220
- . span_label ( e. span , "`_` not allowed here" )
221
- . emit ( ) ;
213
+ self . tcx . sess . emit_err ( UnderscoreExprLhsAssign { span : e. span } ) ;
222
214
hir:: ExprKind :: Err
223
215
}
224
216
ExprKind :: Path ( ref qself, ref path) => {
@@ -250,11 +242,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
250
242
let rest = match & se. rest {
251
243
StructRest :: Base ( e) => Some ( self . lower_expr ( e) ) ,
252
244
StructRest :: Rest ( sp) => {
253
- self . tcx
254
- . sess
255
- . struct_span_err ( * sp, "base expression required after `..`" )
256
- . span_label ( * sp, "add a base expression here" )
257
- . emit ( ) ;
245
+ self . tcx . sess . emit_err ( BaseExpressionDoubleDot { span : * sp } ) ;
258
246
Some ( & * self . arena . alloc ( self . expr_err ( * sp) ) )
259
247
}
260
248
StructRest :: None => None ,
@@ -663,17 +651,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
663
651
match self . generator_kind {
664
652
Some ( hir:: GeneratorKind :: Async ( _) ) => { }
665
653
Some ( hir:: GeneratorKind :: Gen ) | None => {
666
- let mut err = struct_span_err ! (
667
- self . tcx. sess,
654
+ self . tcx . sess . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
668
655
dot_await_span,
669
- E0728 ,
670
- "`await` is only allowed inside `async` functions and blocks"
671
- ) ;
672
- err. span_label ( dot_await_span, "only allowed inside `async` functions and blocks" ) ;
673
- if let Some ( item_sp) = self . current_item {
674
- err. span_label ( item_sp, "this is not `async`" ) ;
675
- }
676
- err. emit ( ) ;
656
+ item_span : self . current_item ,
657
+ } ) ;
677
658
}
678
659
}
679
660
let span = self . mark_span_with_reason ( DesugaringKind :: Await , dot_await_span, None ) ;
@@ -893,13 +874,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
893
874
match generator_kind {
894
875
Some ( hir:: GeneratorKind :: Gen ) => {
895
876
if decl. inputs . len ( ) > 1 {
896
- struct_span_err ! (
897
- self . tcx. sess,
898
- fn_decl_span,
899
- E0628 ,
900
- "too many parameters for a generator (expected 0 or 1 parameters)"
901
- )
902
- . emit ( ) ;
877
+ self . tcx . sess . emit_err ( GeneratorTooManyParameters { fn_decl_span } ) ;
903
878
}
904
879
Some ( movability)
905
880
}
@@ -908,13 +883,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
908
883
}
909
884
None => {
910
885
if movability == Movability :: Static {
911
- struct_span_err ! (
912
- self . tcx. sess,
913
- fn_decl_span,
914
- E0697 ,
915
- "closures cannot be static"
916
- )
917
- . emit ( ) ;
886
+ self . tcx . sess . emit_err ( ClosureCannotBeStatic { fn_decl_span } ) ;
918
887
}
919
888
None
920
889
}
@@ -961,17 +930,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
961
930
let body = self . with_new_scopes ( |this| {
962
931
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
963
932
if capture_clause == CaptureBy :: Ref && !decl. inputs . is_empty ( ) {
964
- struct_span_err ! (
965
- this. tcx. sess,
966
- fn_decl_span,
967
- E0708 ,
968
- "`async` non-`move` closures with parameters are not currently supported" ,
969
- )
970
- . help (
971
- "consider using `let` statements to manually capture \
972
- variables by reference before entering an `async move` closure",
973
- )
974
- . emit ( ) ;
933
+ this. tcx . sess . emit_err ( AsyncNonMoveClosureNotSupported { fn_decl_span } ) ;
975
934
}
976
935
977
936
// Transform `async |x: u8| -> X { ... }` into
@@ -1211,20 +1170,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
1211
1170
) ;
1212
1171
let fields_omitted = match & se. rest {
1213
1172
StructRest :: Base ( e) => {
1214
- self . tcx
1215
- . sess
1216
- . struct_span_err (
1217
- e. span ,
1218
- "functional record updates are not allowed in destructuring \
1219
- assignments",
1220
- )
1221
- . span_suggestion (
1222
- e. span ,
1223
- "consider removing the trailing pattern" ,
1224
- "" ,
1225
- rustc_errors:: Applicability :: MachineApplicable ,
1226
- )
1227
- . emit ( ) ;
1173
+ self . tcx . sess . emit_err ( FunctionalRecordUpdateDestructuringAssignemnt {
1174
+ span : e. span ,
1175
+ } ) ;
1228
1176
true
1229
1177
}
1230
1178
StructRest :: Rest ( _) => true ,
@@ -1421,13 +1369,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1421
1369
match self . generator_kind {
1422
1370
Some ( hir:: GeneratorKind :: Gen ) => { }
1423
1371
Some ( hir:: GeneratorKind :: Async ( _) ) => {
1424
- struct_span_err ! (
1425
- self . tcx. sess,
1426
- span,
1427
- E0727 ,
1428
- "`async` generators are not yet supported"
1429
- )
1430
- . emit ( ) ;
1372
+ self . tcx . sess . emit_err ( AsyncGeneratorsNotSupported { span } ) ;
1431
1373
}
1432
1374
None => self . generator_kind = Some ( hir:: GeneratorKind :: Gen ) ,
1433
1375
}
0 commit comments