1+ use super :: errors:: {
2+ AsyncGeneratorsNotSupported , AsyncNonMoveClosureNotSupported , AwaitOnlyInAsyncFnAndBlocks ,
3+ BaseExpressionDoubleDot , ClosureCannotBeStatic , FunctionalRecordUpdateDestructuringAssignemnt ,
4+ GeneratorTooManyParameters , RustcBoxAttributeError , UnderscoreExprLhsAssign ,
5+ } ;
16use super :: ResolverAstLoweringExt ;
27use super :: { ImplTraitContext , LoweringContext , ParamMode , ParenthesizedGenericArgs } ;
38use crate :: { FnDeclKind , ImplTraitPosition } ;
@@ -6,7 +11,6 @@ use rustc_ast::attr;
611use rustc_ast:: ptr:: P as AstP ;
712use rustc_ast:: * ;
813use rustc_data_structures:: stack:: ensure_sufficient_stack;
9- use rustc_errors:: struct_span_err;
1014use rustc_hir as hir;
1115use rustc_hir:: def:: Res ;
1216use rustc_hir:: definitions:: DefPathData ;
@@ -45,13 +49,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
4549 let hir_id = self . lower_node_id ( e. id ) ;
4650 return hir:: Expr { hir_id, kind, span : self . lower_span ( e. span ) } ;
4751 } 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 } ) ;
5553 hir:: ExprKind :: Err
5654 }
5755 } else if let Some ( legacy_args) = self . resolver . legacy_const_generic_args ( f) {
@@ -211,13 +209,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
211209 self . lower_expr_range ( e. span , e1. as_deref ( ) , e2. as_deref ( ) , lims)
212210 }
213211 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 } ) ;
221213 hir:: ExprKind :: Err
222214 }
223215 ExprKind :: Path ( ref qself, ref path) => {
@@ -249,11 +241,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
249241 let rest = match & se. rest {
250242 StructRest :: Base ( e) => Some ( self . lower_expr ( e) ) ,
251243 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 } ) ;
257245 Some ( & * self . arena . alloc ( self . expr_err ( * sp) ) )
258246 }
259247 StructRest :: None => None ,
@@ -662,17 +650,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
662650 match self . generator_kind {
663651 Some ( hir:: GeneratorKind :: Async ( _) ) => { }
664652 Some ( hir:: GeneratorKind :: Gen ) | None => {
665- let mut err = struct_span_err ! (
666- self . tcx. sess,
653+ self . tcx . sess . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
667654 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+ } ) ;
676657 }
677658 }
678659 let span = self . mark_span_with_reason ( DesugaringKind :: Await , dot_await_span, None ) ;
@@ -892,13 +873,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
892873 match generator_kind {
893874 Some ( hir:: GeneratorKind :: Gen ) => {
894875 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 } ) ;
902877 }
903878 Some ( movability)
904879 }
@@ -907,13 +882,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
907882 }
908883 None => {
909884 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 } ) ;
917886 }
918887 None
919888 }
@@ -960,17 +929,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
960929 let body = self . with_new_scopes ( |this| {
961930 // FIXME(cramertj): allow `async` non-`move` closures with arguments.
962931 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 } ) ;
974933 }
975934
976935 // Transform `async |x: u8| -> X { ... }` into
@@ -1210,20 +1169,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
12101169 ) ;
12111170 let fields_omitted = match & se. rest {
12121171 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+ } ) ;
12271175 true
12281176 }
12291177 StructRest :: Rest ( _) => true ,
@@ -1420,13 +1368,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14201368 match self . generator_kind {
14211369 Some ( hir:: GeneratorKind :: Gen ) => { }
14221370 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 } ) ;
14301372 }
14311373 None => self . generator_kind = Some ( hir:: GeneratorKind :: Gen ) ,
14321374 }
0 commit comments