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