use rustc_span::{Span, Symbol};
#[derive(SessionDiagnostic, Clone, Copy)]
-#[error(ast_lowering::generic_type_with_parentheses, code = "E0214")]
+#[diag(ast_lowering::generic_type_with_parentheses, code = "E0214")]
pub struct GenericTypeWithParentheses {
#[primary_span]
#[label]
#[derive(SessionDiagnostic)]
#[help]
-#[error(ast_lowering::invalid_abi, code = "E0703")]
+#[diag(ast_lowering::invalid_abi, code = "E0703")]
pub struct InvalidAbi {
#[primary_span]
#[label]
}
#[derive(SessionDiagnostic, Clone, Copy)]
-#[error(ast_lowering::assoc_ty_parentheses)]
+#[diag(ast_lowering::assoc_ty_parentheses)]
pub struct AssocTyParentheses {
#[primary_span]
pub span: Span,
}
#[derive(SessionDiagnostic)]
-#[error(ast_lowering::misplaced_impl_trait, code = "E0562")]
+#[diag(ast_lowering::misplaced_impl_trait, code = "E0562")]
pub struct MisplacedImplTrait {
#[primary_span]
pub span: Span,
pub position: String,
}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[diag(ast_lowering::rustc_box_attribute_error)]
+pub struct RustcBoxAttributeError {
+ #[primary_span]
+ pub span: Span,
+}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[diag(ast_lowering::underscore_expr_lhs_assign)]
+pub struct UnderscoreExprLhsAssign {
+ #[primary_span]
+ #[label]
+ pub span: Span,
+}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[diag(ast_lowering::base_expression_double_dot)]
+pub struct BaseExpressionDoubleDot {
+ #[primary_span]
+ #[label]
+ pub span: Span,
+}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[diag(ast_lowering::await_only_in_async_fn_and_blocks, code = "E0728")]
+pub struct AwaitOnlyInAsyncFnAndBlocks {
+ #[primary_span]
+ #[label]
+ pub dot_await_span: Span,
+ #[label(ast_lowering::this_not_async)]
+ pub item_span: Option<Span>,
+}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[diag(ast_lowering::generator_too_many_parameters, code = "E0628")]
+pub struct GeneratorTooManyParameters {
+ #[primary_span]
+ pub fn_decl_span: Span,
+}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[diag(ast_lowering::closure_cannot_be_static, code = "E0697")]
+pub struct ClosureCannotBeStatic {
+ #[primary_span]
+ pub fn_decl_span: Span,
+}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[help]
+#[diag(ast_lowering::async_non_move_closure_not_supported, code = "E0708")]
+pub struct AsyncNonMoveClosureNotSupported {
+ #[primary_span]
+ pub fn_decl_span: Span,
+}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[diag(ast_lowering::functional_record_update_destructuring_assignment)]
+pub struct FunctionalRecordUpdateDestructuringAssignemnt {
+ #[primary_span]
+ #[suggestion(code = "", applicability = "machine-applicable")]
+ pub span: Span,
+}
+
+#[derive(SessionDiagnostic, Clone, Copy)]
+#[diag(ast_lowering::async_generators_not_supported, code = "E0727")]
+pub struct AsyncGeneratorsNotSupported {
+ #[primary_span]
+ pub span: Span,
+}
+use super::errors::{
+ AsyncGeneratorsNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks,
+ BaseExpressionDoubleDot, ClosureCannotBeStatic, FunctionalRecordUpdateDestructuringAssignemnt,
+ GeneratorTooManyParameters, RustcBoxAttributeError, UnderscoreExprLhsAssign,
+};
use super::ResolverAstLoweringExt;
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
use crate::{FnDeclKind, ImplTraitPosition};
use rustc_ast::ptr::P as AstP;
use rustc_ast::*;
use rustc_data_structures::stack::ensure_sufficient_stack;
-use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::Res;
use rustc_hir::definitions::DefPathData;
let hir_id = self.lower_node_id(e.id);
return hir::Expr { hir_id, kind, span: self.lower_span(e.span) };
} else {
- self.tcx.sess
- .struct_span_err(
- e.span,
- "#[rustc_box] requires precisely one argument \
- and no other attributes are allowed",
- )
- .emit();
+ self.tcx.sess.emit_err(RustcBoxAttributeError { span: e.span });
hir::ExprKind::Err
}
} else if let Some(legacy_args) = self.resolver.legacy_const_generic_args(f) {
self.lower_expr_range(e.span, e1.as_deref(), e2.as_deref(), lims)
}
ExprKind::Underscore => {
- self.tcx
- .sess.struct_span_err(
- e.span,
- "in expressions, `_` can only be used on the left-hand side of an assignment",
- )
- .span_label(e.span, "`_` not allowed here")
- .emit();
+ self.tcx.sess.emit_err(UnderscoreExprLhsAssign { span: e.span });
hir::ExprKind::Err
}
ExprKind::Path(ref qself, ref path) => {
let rest = match &se.rest {
StructRest::Base(e) => Some(self.lower_expr(e)),
StructRest::Rest(sp) => {
- self.tcx
- .sess
- .struct_span_err(*sp, "base expression required after `..`")
- .span_label(*sp, "add a base expression here")
- .emit();
+ self.tcx.sess.emit_err(BaseExpressionDoubleDot { span: *sp });
Some(&*self.arena.alloc(self.expr_err(*sp)))
}
StructRest::None => None,
match self.generator_kind {
Some(hir::GeneratorKind::Async(_)) => {}
Some(hir::GeneratorKind::Gen) | None => {
- let mut err = struct_span_err!(
- self.tcx.sess,
+ self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
dot_await_span,
- E0728,
- "`await` is only allowed inside `async` functions and blocks"
- );
- err.span_label(dot_await_span, "only allowed inside `async` functions and blocks");
- if let Some(item_sp) = self.current_item {
- err.span_label(item_sp, "this is not `async`");
- }
- err.emit();
+ item_span: self.current_item,
+ });
}
}
let span = self.mark_span_with_reason(DesugaringKind::Await, dot_await_span, None);
match generator_kind {
Some(hir::GeneratorKind::Gen) => {
if decl.inputs.len() > 1 {
- struct_span_err!(
- self.tcx.sess,
- fn_decl_span,
- E0628,
- "too many parameters for a generator (expected 0 or 1 parameters)"
- )
- .emit();
+ self.tcx.sess.emit_err(GeneratorTooManyParameters { fn_decl_span });
}
Some(movability)
}
}
None => {
if movability == Movability::Static {
- struct_span_err!(
- self.tcx.sess,
- fn_decl_span,
- E0697,
- "closures cannot be static"
- )
- .emit();
+ self.tcx.sess.emit_err(ClosureCannotBeStatic { fn_decl_span });
}
None
}
let body = self.with_new_scopes(|this| {
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
if capture_clause == CaptureBy::Ref && !decl.inputs.is_empty() {
- struct_span_err!(
- this.tcx.sess,
- fn_decl_span,
- E0708,
- "`async` non-`move` closures with parameters are not currently supported",
- )
- .help(
- "consider using `let` statements to manually capture \
- variables by reference before entering an `async move` closure",
- )
- .emit();
+ this.tcx.sess.emit_err(AsyncNonMoveClosureNotSupported { fn_decl_span });
}
// Transform `async |x: u8| -> X { ... }` into
);
let fields_omitted = match &se.rest {
StructRest::Base(e) => {
- self.tcx
- .sess
- .struct_span_err(
- e.span,
- "functional record updates are not allowed in destructuring \
- assignments",
- )
- .span_suggestion(
- e.span,
- "consider removing the trailing pattern",
- "",
- rustc_errors::Applicability::MachineApplicable,
- )
- .emit();
+ self.tcx.sess.emit_err(FunctionalRecordUpdateDestructuringAssignemnt {
+ span: e.span,
+ });
true
}
StructRest::Rest(_) => true,
match self.generator_kind {
Some(hir::GeneratorKind::Gen) => {}
Some(hir::GeneratorKind::Async(_)) => {
- struct_span_err!(
- self.tcx.sess,
- span,
- E0727,
- "`async` generators are not yet supported"
- )
- .emit();
+ self.tcx.sess.emit_err(AsyncGeneratorsNotSupported { span });
}
None => self.generator_kind = Some(hir::GeneratorKind::Gen),
}
ast_lowering_misplaced_impl_trait =
`impl Trait` only allowed in function and inherent method return types, not in {$position}
+
+ast_lowering_rustc_box_attribute_error =
+ #[rustc_box] requires precisely one argument and no other attributes are allowed
+
+ast_lowering_underscore_expr_lhs_assign =
+ in expressions, `_` can only be used on the left-hand side of an assignment
+ .label = `_` not allowed here
+
+ast_lowering_base_expression_double_dot =
+ base expression required after `..`
+ .label = add a base expression here
+
+ast_lowering_await_only_in_async_fn_and_blocks =
+ `await` is only allowed inside `async` functions and blocks
+ .label = only allowed inside `async` functions and blocks
+
+ast_lowering_this_not_async = this is not `async`
+
+ast_lowering_generator_too_many_parameters =
+ too many parameters for a generator (expected 0 or 1 parameters)
+
+ast_lowering_closure_cannot_be_static = closures cannot be static
+
+ast_lowering_async_non_move_closure_not_supported =
+ `async` non-`move` closures with parameters are not currently supported
+ .help = consider using `let` statements to manually capture variables by reference before entering an `async move` closure
+
+ast_lowering_functional_record_update_destructuring_assignment =
+ functional record updates are not allowed in destructuring assignments
+ .suggestion = consider removing the trailing pattern
+
+ast_lowering_async_generators_not_supported =
+ `async` generators are not yet supported