]> git.lizzy.rs Git - rust.git/commitdiff
Migrate all span_err(...) in ast_lowering to SessionDiagnostic
authorJean CASPAR <55629512+JeanCASPAR@users.noreply.github.com>
Thu, 18 Aug 2022 17:30:56 +0000 (19:30 +0200)
committerJean CASPAR <55629512+JeanCASPAR@users.noreply.github.com>
Mon, 22 Aug 2022 17:21:41 +0000 (19:21 +0200)
compiler/rustc_ast_lowering/src/errors.rs
compiler/rustc_ast_lowering/src/expr.rs
compiler/rustc_ast_lowering/src/item.rs
compiler/rustc_ast_lowering/src/pat.rs
compiler/rustc_error_messages/locales/en-US/ast_lowering.ftl

index 3644e664cebf2cfc5bf4cf287f68635893030aee..2da42c96ec0cf02bbef9adf786d463f299b25544 100644 (file)
@@ -306,3 +306,24 @@ pub struct MisplacedDoubleDot {
     #[primary_span]
     pub span: Span,
 }
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[error(ast_lowering::misplaced_relax_trait_bound)]
+pub struct MisplacedRelaxTraitBound {
+    #[primary_span]
+    pub span: Span,
+}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[error(ast_lowering::not_supported_for_lifetime_binder_async_closure)]
+pub struct NotSupportedForLifetimeBinderAsyncClosure {
+    #[primary_span]
+    pub span: Span,
+}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[error(ast_lowering::arbitrary_expression_in_pattern)]
+pub struct ArbitraryExpressionInPattern {
+    #[primary_span]
+    pub span: Span,
+}
index e470df122b6d3a1a93c3a42ef0608d6ededfc1a8..61f8c0216f1cf91c2f6d7ef65e4c6667bbde5a0e 100644 (file)
@@ -1,7 +1,8 @@
 use super::errors::{
     AsyncGeneratorsNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks,
     BaseExpressionDoubleDot, ClosureCannotBeStatic, FunctionalRecordUpdateDestructuringAssignemnt,
-    GeneratorTooManyParameters, RustcBoxAttributeError, UnderscoreExprLhsAssign,
+    GeneratorTooManyParameters, NotSupportedForLifetimeBinderAsyncClosure, RustcBoxAttributeError,
+    UnderscoreExprLhsAssign,
 };
 use super::ResolverAstLoweringExt;
 use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
@@ -915,10 +916,7 @@ fn lower_expr_async_closure(
         fn_decl_span: Span,
     ) -> hir::ExprKind<'hir> {
         if let &ClosureBinder::For { span, .. } = binder {
-            self.tcx.sess.span_err(
-                span,
-                "`for<...>` binders on `async` closures are not currently supported",
-            );
+            self.tcx.sess.emit_err(NotSupportedForLifetimeBinderAsyncClosure { span });
         }
 
         let (binder_clause, generic_params) = self.lower_closure_binder(binder);
index a789268dfdaff5a901558d5da14425b78c25e346..fd338ffc0c5e8b64c9ca0469cc25cb766070e671 100644 (file)
@@ -1,4 +1,4 @@
-use super::errors::InvalidAbi;
+use super::errors::{InvalidAbi, MisplacedRelaxTraitBound};
 use super::ResolverAstLoweringExt;
 use super::{AstOwner, ImplTraitContext, ImplTraitPosition};
 use super::{FnDeclKind, LoweringContext, ParamMode};
@@ -1339,11 +1339,7 @@ fn lower_generics<T>(
                 }
                 let is_param = *is_param.get_or_insert_with(compute_is_param);
                 if !is_param {
-                    self.diagnostic().span_err(
-                        bound.span(),
-                        "`?Trait` bounds are only permitted at the \
-                        point where a type parameter is declared",
-                    );
+                    self.tcx.sess.emit_err(MisplacedRelaxTraitBound { span: bound.span() });
                 }
             }
         }
index abe9b354252ac0492cba5df98fdfffadc6c8af3a..1efa19a3a828655d22f7721cb4357d3cb5a308ff 100644 (file)
@@ -1,4 +1,6 @@
-use super::errors::{ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding};
+use super::errors::{
+    ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
+};
 use super::ResolverAstLoweringExt;
 use super::{ImplTraitContext, LoweringContext, ParamMode};
 use crate::ImplTraitPosition;
@@ -330,8 +332,7 @@ fn lower_expr_within_pat(&mut self, expr: &Expr, allow_paths: bool) -> &'hir hir
             ExprKind::Path(..) if allow_paths => {}
             ExprKind::Unary(UnOp::Neg, ref inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
             _ => {
-                self.diagnostic()
-                    .span_err(expr.span, "arbitrary expressions aren't allowed in patterns");
+                self.tcx.sess.emit_err(ArbitraryExpressionInPattern { span: expr.span });
                 return self.arena.alloc(self.expr_err(expr.span));
             }
         }
index 438fbd8e57ba0997ef22515b1062d2e86a629236..8effd9ca75017d559896c0b7c9be913e5a598788 100644 (file)
@@ -120,3 +120,12 @@ ast_lowering_previously_used_here = previously used here
 ast_lowering_misplaced_double_dot =
     `..` patterns are not allowed here
     .note = only allowed in tuple, tuple struct, and slice patterns
+
+ast_lowering_misplaced_relax_trait_bound =
+    `?Trait` bounds are only permitted at the point where a type parameter is declared
+
+ast_lowering_not_supported_for_lifetime_binder_async_closure =
+    `for<...>` binders on `async` closures are not currently supported
+
+ast_lowering_arbitrary_expression_in_pattern =
+    arbitrary expressions aren't allowed in patterns