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 } ;
@@ -7,7 +12,6 @@ use rustc_ast::ptr::P as AstP;
712use rustc_ast:: * ;
813use rustc_data_structures:: stack:: ensure_sufficient_stack;
914use rustc_data_structures:: thin_vec:: ThinVec ;
10- use rustc_errors:: struct_span_err;
1115use rustc_hir as hir;
1216use rustc_hir:: def:: Res ;
1317use rustc_hir:: definitions:: DefPathData ;
@@ -46,13 +50,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
4650 let hir_id = self . lower_node_id ( e. id ) ;
4751 return hir:: Expr { hir_id, kind, span : self . lower_span ( e. span ) } ;
4852 } 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 } ) ;
5654 hir:: ExprKind :: Err
5755 }
5856 } else if let Some ( legacy_args) = self . resolver . legacy_const_generic_args ( f) {
@@ -212,13 +210,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
212210 self . lower_expr_range ( e. span , e1. as_deref ( ) , e2. as_deref ( ) , lims)
213211 }
214212 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 } ) ;
222214 hir:: ExprKind :: Err
223215 }
224216 ExprKind :: Path ( ref qself, ref path) => {
@@ -250,11 +242,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
250242 let rest = match & se. rest {
251243 StructRest :: Base ( e) => Some ( self . lower_expr ( e) ) ,
252244 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 } ) ;
258246 Some ( & * self . arena . alloc ( self . expr_err ( * sp) ) )
259247 }
260248 StructRest :: None => None ,
@@ -663,17 +651,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
663651 match self . generator_kind {
664652 Some ( hir:: GeneratorKind :: Async ( _) ) => { }
665653 Some ( hir:: GeneratorKind :: Gen ) | None => {
666- let mut err = struct_span_err ! (
667- self . tcx. sess,
654+ self . tcx . sess . emit_err ( AwaitOnlyInAsyncFnAndBlocks {
668655 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+ } ) ;
677658 }
678659 }
679660 let span = self . mark_span_with_reason ( DesugaringKind :: Await , dot_await_span, None ) ;
@@ -893,13 +874,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
893874 match generator_kind {
894875 Some ( hir:: GeneratorKind :: Gen ) => {
895876 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 } ) ;
903878 }
904879 Some ( movability)
905880 }
@@ -908,13 +883,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
908883 }
909884 None => {
910885 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 } ) ;
918887 }
919888 None
920889 }
@@ -961,17 +930,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
961930 let body = self . with_new_scopes ( |this| {
962931 // FIXME(cramertj): allow `async` non-`move` closures with arguments.
963932 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 } ) ;
975934 }
976935
977936 // Transform `async |x: u8| -> X { ... }` into
@@ -1211,20 +1170,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
12111170 ) ;
12121171 let fields_omitted = match & se. rest {
12131172 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+ } ) ;
12281176 true
12291177 }
12301178 StructRest :: Rest ( _) => true ,
@@ -1421,13 +1369,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14211369 match self . generator_kind {
14221370 Some ( hir:: GeneratorKind :: Gen ) => { }
14231371 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 } ) ;
14311373 }
14321374 None => self . generator_kind = Some ( hir:: GeneratorKind :: Gen ) ,
14331375 }
0 commit comments