Migrate all span_err(...) in ast_lowering to SessionDiagnostic

This commit is contained in:
Jean CASPAR 2022-08-18 19:30:56 +02:00
parent 5164966591
commit e701c72a63
5 changed files with 39 additions and 14 deletions

View File

@ -306,3 +306,24 @@ pub struct MisplacedDoubleDot {
#[primary_span] #[primary_span]
pub span: 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,
}

View File

@ -1,7 +1,8 @@
use super::errors::{ use super::errors::{
AsyncGeneratorsNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks, AsyncGeneratorsNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks,
BaseExpressionDoubleDot, ClosureCannotBeStatic, FunctionalRecordUpdateDestructuringAssignemnt, BaseExpressionDoubleDot, ClosureCannotBeStatic, FunctionalRecordUpdateDestructuringAssignemnt,
GeneratorTooManyParameters, RustcBoxAttributeError, UnderscoreExprLhsAssign, GeneratorTooManyParameters, NotSupportedForLifetimeBinderAsyncClosure, RustcBoxAttributeError,
UnderscoreExprLhsAssign,
}; };
use super::ResolverAstLoweringExt; use super::ResolverAstLoweringExt;
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs}; use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
@ -915,10 +916,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn_decl_span: Span, fn_decl_span: Span,
) -> hir::ExprKind<'hir> { ) -> hir::ExprKind<'hir> {
if let &ClosureBinder::For { span, .. } = binder { if let &ClosureBinder::For { span, .. } = binder {
self.tcx.sess.span_err( self.tcx.sess.emit_err(NotSupportedForLifetimeBinderAsyncClosure { span });
span,
"`for<...>` binders on `async` closures are not currently supported",
);
} }
let (binder_clause, generic_params) = self.lower_closure_binder(binder); let (binder_clause, generic_params) = self.lower_closure_binder(binder);

View File

@ -1,4 +1,4 @@
use super::errors::InvalidAbi; use super::errors::{InvalidAbi, MisplacedRelaxTraitBound};
use super::ResolverAstLoweringExt; use super::ResolverAstLoweringExt;
use super::{AstOwner, ImplTraitContext, ImplTraitPosition}; use super::{AstOwner, ImplTraitContext, ImplTraitPosition};
use super::{FnDeclKind, LoweringContext, ParamMode}; use super::{FnDeclKind, LoweringContext, ParamMode};
@ -1339,11 +1339,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
let is_param = *is_param.get_or_insert_with(compute_is_param); let is_param = *is_param.get_or_insert_with(compute_is_param);
if !is_param { if !is_param {
self.diagnostic().span_err( self.tcx.sess.emit_err(MisplacedRelaxTraitBound { span: bound.span() });
bound.span(),
"`?Trait` bounds are only permitted at the \
point where a type parameter is declared",
);
} }
} }
} }

View File

@ -1,4 +1,6 @@
use super::errors::{ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding}; use super::errors::{
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
};
use super::ResolverAstLoweringExt; use super::ResolverAstLoweringExt;
use super::{ImplTraitContext, LoweringContext, ParamMode}; use super::{ImplTraitContext, LoweringContext, ParamMode};
use crate::ImplTraitPosition; use crate::ImplTraitPosition;
@ -330,8 +332,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ExprKind::Path(..) if allow_paths => {} ExprKind::Path(..) if allow_paths => {}
ExprKind::Unary(UnOp::Neg, ref inner) if matches!(inner.kind, ExprKind::Lit(_)) => {} ExprKind::Unary(UnOp::Neg, ref inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
_ => { _ => {
self.diagnostic() self.tcx.sess.emit_err(ArbitraryExpressionInPattern { span: expr.span });
.span_err(expr.span, "arbitrary expressions aren't allowed in patterns");
return self.arena.alloc(self.expr_err(expr.span)); return self.arena.alloc(self.expr_err(expr.span));
} }
} }

View File

@ -120,3 +120,12 @@ ast_lowering_previously_used_here = previously used here
ast_lowering_misplaced_double_dot = ast_lowering_misplaced_double_dot =
`..` patterns are not allowed here `..` patterns are not allowed here
.note = only allowed in tuple, tuple struct, and slice patterns .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