Skip to content

Commit e701c72

Browse files
committed
Migrate all span_err(...) in ast_lowering to SessionDiagnostic
1 parent 5164966 commit e701c72

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

compiler/rustc_ast_lowering/src/errors.rs

+21
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,24 @@ pub struct MisplacedDoubleDot {
306306
#[primary_span]
307307
pub span: Span,
308308
}
309+
310+
#[derive(SessionDiagnostic, Clone, Copy)]
311+
#[error(ast_lowering::misplaced_relax_trait_bound)]
312+
pub struct MisplacedRelaxTraitBound {
313+
#[primary_span]
314+
pub span: Span,
315+
}
316+
317+
#[derive(SessionDiagnostic, Clone, Copy)]
318+
#[error(ast_lowering::not_supported_for_lifetime_binder_async_closure)]
319+
pub struct NotSupportedForLifetimeBinderAsyncClosure {
320+
#[primary_span]
321+
pub span: Span,
322+
}
323+
324+
#[derive(SessionDiagnostic, Clone, Copy)]
325+
#[error(ast_lowering::arbitrary_expression_in_pattern)]
326+
pub struct ArbitraryExpressionInPattern {
327+
#[primary_span]
328+
pub span: Span,
329+
}

compiler/rustc_ast_lowering/src/expr.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use super::errors::{
22
AsyncGeneratorsNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks,
33
BaseExpressionDoubleDot, ClosureCannotBeStatic, FunctionalRecordUpdateDestructuringAssignemnt,
4-
GeneratorTooManyParameters, RustcBoxAttributeError, UnderscoreExprLhsAssign,
4+
GeneratorTooManyParameters, NotSupportedForLifetimeBinderAsyncClosure, RustcBoxAttributeError,
5+
UnderscoreExprLhsAssign,
56
};
67
use super::ResolverAstLoweringExt;
78
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
@@ -915,10 +916,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
915916
fn_decl_span: Span,
916917
) -> hir::ExprKind<'hir> {
917918
if let &ClosureBinder::For { span, .. } = binder {
918-
self.tcx.sess.span_err(
919-
span,
920-
"`for<...>` binders on `async` closures are not currently supported",
921-
);
919+
self.tcx.sess.emit_err(NotSupportedForLifetimeBinderAsyncClosure { span });
922920
}
923921

924922
let (binder_clause, generic_params) = self.lower_closure_binder(binder);

compiler/rustc_ast_lowering/src/item.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::errors::InvalidAbi;
1+
use super::errors::{InvalidAbi, MisplacedRelaxTraitBound};
22
use super::ResolverAstLoweringExt;
33
use super::{AstOwner, ImplTraitContext, ImplTraitPosition};
44
use super::{FnDeclKind, LoweringContext, ParamMode};
@@ -1339,11 +1339,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13391339
}
13401340
let is_param = *is_param.get_or_insert_with(compute_is_param);
13411341
if !is_param {
1342-
self.diagnostic().span_err(
1343-
bound.span(),
1344-
"`?Trait` bounds are only permitted at the \
1345-
point where a type parameter is declared",
1346-
);
1342+
self.tcx.sess.emit_err(MisplacedRelaxTraitBound { span: bound.span() });
13471343
}
13481344
}
13491345
}

compiler/rustc_ast_lowering/src/pat.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use super::errors::{ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding};
1+
use super::errors::{
2+
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
3+
};
24
use super::ResolverAstLoweringExt;
35
use super::{ImplTraitContext, LoweringContext, ParamMode};
46
use crate::ImplTraitPosition;
@@ -330,8 +332,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
330332
ExprKind::Path(..) if allow_paths => {}
331333
ExprKind::Unary(UnOp::Neg, ref inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
332334
_ => {
333-
self.diagnostic()
334-
.span_err(expr.span, "arbitrary expressions aren't allowed in patterns");
335+
self.tcx.sess.emit_err(ArbitraryExpressionInPattern { span: expr.span });
335336
return self.arena.alloc(self.expr_err(expr.span));
336337
}
337338
}

compiler/rustc_error_messages/locales/en-US/ast_lowering.ftl

+9
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,12 @@ ast_lowering_previously_used_here = previously used here
120120
ast_lowering_misplaced_double_dot =
121121
`..` patterns are not allowed here
122122
.note = only allowed in tuple, tuple struct, and slice patterns
123+
124+
ast_lowering_misplaced_relax_trait_bound =
125+
`?Trait` bounds are only permitted at the point where a type parameter is declared
126+
127+
ast_lowering_not_supported_for_lifetime_binder_async_closure =
128+
`for<...>` binders on `async` closures are not currently supported
129+
130+
ast_lowering_arbitrary_expression_in_pattern =
131+
arbitrary expressions aren't allowed in patterns

0 commit comments

Comments
 (0)