Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require #[must_use] on Diagnostic structs to prevent future bugs #119180

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_span::{symbol::Ident, Span, Symbol};

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_generic_type_with_parentheses, code = "E0214")]
#[must_use]
pub struct GenericTypeWithParentheses {
#[primary_span]
#[label]
Expand All @@ -24,6 +25,7 @@ pub struct UseAngleBrackets {
#[derive(Diagnostic)]
#[diag(ast_lowering_invalid_abi, code = "E0703")]
#[note]
#[must_use]
pub struct InvalidAbi {
#[primary_span]
#[label]
Expand Down Expand Up @@ -65,6 +67,7 @@ pub struct InvalidAbiSuggestion {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_assoc_ty_parentheses)]
#[must_use]
pub struct AssocTyParentheses {
#[primary_span]
pub span: Span,
Expand All @@ -90,6 +93,7 @@ pub enum AssocTyParenthesesSub {

#[derive(Diagnostic)]
#[diag(ast_lowering_misplaced_impl_trait, code = "E0562")]
#[must_use]
pub struct MisplacedImplTrait<'a> {
#[primary_span]
pub span: Span,
Expand All @@ -98,6 +102,7 @@ pub struct MisplacedImplTrait<'a> {

#[derive(Diagnostic)]
#[diag(ast_lowering_misplaced_assoc_ty_binding)]
#[must_use]
pub struct MisplacedAssocTyBinding<'a> {
#[primary_span]
pub span: Span,
Expand All @@ -106,6 +111,7 @@ pub struct MisplacedAssocTyBinding<'a> {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_underscore_expr_lhs_assign)]
#[must_use]
pub struct UnderscoreExprLhsAssign {
#[primary_span]
#[label]
Expand All @@ -114,6 +120,7 @@ pub struct UnderscoreExprLhsAssign {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_base_expression_double_dot)]
#[must_use]
pub struct BaseExpressionDoubleDot {
#[primary_span]
#[label]
Expand All @@ -122,6 +129,7 @@ pub struct BaseExpressionDoubleDot {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_await_only_in_async_fn_and_blocks, code = "E0728")]
#[must_use]
pub struct AwaitOnlyInAsyncFnAndBlocks {
#[primary_span]
#[label]
Expand All @@ -132,13 +140,15 @@ pub struct AwaitOnlyInAsyncFnAndBlocks {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_coroutine_too_many_parameters, code = "E0628")]
#[must_use]
pub struct CoroutineTooManyParameters {
#[primary_span]
pub fn_decl_span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_closure_cannot_be_static, code = "E0697")]
#[must_use]
pub struct ClosureCannotBeStatic {
#[primary_span]
pub fn_decl_span: Span,
Expand All @@ -147,13 +157,15 @@ pub struct ClosureCannotBeStatic {
#[derive(Diagnostic, Clone, Copy)]
#[help]
#[diag(ast_lowering_async_non_move_closure_not_supported, code = "E0708")]
#[must_use]
pub struct AsyncNonMoveClosureNotSupported {
#[primary_span]
pub fn_decl_span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_functional_record_update_destructuring_assignment)]
#[must_use]
pub struct FunctionalRecordUpdateDestructuringAssignment {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
Expand All @@ -162,27 +174,31 @@ pub struct FunctionalRecordUpdateDestructuringAssignment {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_async_coroutines_not_supported, code = "E0727")]
#[must_use]
pub struct AsyncCoroutinesNotSupported {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_inline_asm_unsupported_target, code = "E0472")]
#[must_use]
pub struct InlineAsmUnsupportedTarget {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_att_syntax_only_x86)]
#[must_use]
pub struct AttSyntaxOnlyX86 {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_abi_specified_multiple_times)]
#[must_use]
pub struct AbiSpecifiedMultipleTimes {
#[primary_span]
pub abi_span: Span,
Expand All @@ -195,6 +211,7 @@ pub struct AbiSpecifiedMultipleTimes {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_clobber_abi_not_supported)]
#[must_use]
pub struct ClobberAbiNotSupported {
#[primary_span]
pub abi_span: Span,
Expand All @@ -203,6 +220,7 @@ pub struct ClobberAbiNotSupported {
#[derive(Diagnostic)]
#[note]
#[diag(ast_lowering_invalid_abi_clobber_abi)]
#[must_use]
pub struct InvalidAbiClobberAbi {
#[primary_span]
pub abi_span: Span,
Expand All @@ -211,6 +229,7 @@ pub struct InvalidAbiClobberAbi {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_invalid_register)]
#[must_use]
pub struct InvalidRegister<'a> {
#[primary_span]
pub op_span: Span,
Expand All @@ -220,6 +239,7 @@ pub struct InvalidRegister<'a> {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_invalid_register_class)]
#[must_use]
pub struct InvalidRegisterClass<'a> {
#[primary_span]
pub op_span: Span,
Expand All @@ -229,6 +249,7 @@ pub struct InvalidRegisterClass<'a> {

#[derive(Diagnostic)]
#[diag(ast_lowering_invalid_asm_template_modifier_reg_class)]
#[must_use]
pub struct InvalidAsmTemplateModifierRegClass {
#[primary_span]
#[label(ast_lowering_template_modifier)]
Expand All @@ -249,6 +270,7 @@ pub enum InvalidAsmTemplateModifierRegClassSub {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_invalid_asm_template_modifier_const)]
#[must_use]
pub struct InvalidAsmTemplateModifierConst {
#[primary_span]
#[label(ast_lowering_template_modifier)]
Expand All @@ -259,6 +281,7 @@ pub struct InvalidAsmTemplateModifierConst {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_invalid_asm_template_modifier_sym)]
#[must_use]
pub struct InvalidAsmTemplateModifierSym {
#[primary_span]
#[label(ast_lowering_template_modifier)]
Expand All @@ -269,6 +292,7 @@ pub struct InvalidAsmTemplateModifierSym {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_register_class_only_clobber)]
#[must_use]
pub struct RegisterClassOnlyClobber {
#[primary_span]
pub op_span: Span,
Expand All @@ -277,6 +301,7 @@ pub struct RegisterClassOnlyClobber {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_register_conflict)]
#[must_use]
pub struct RegisterConflict<'a> {
#[primary_span]
#[label(ast_lowering_register1)]
Expand All @@ -292,6 +317,7 @@ pub struct RegisterConflict<'a> {
#[derive(Diagnostic, Clone, Copy)]
#[help]
#[diag(ast_lowering_sub_tuple_binding)]
#[must_use]
pub struct SubTupleBinding<'a> {
#[primary_span]
#[label]
Expand All @@ -309,6 +335,7 @@ pub struct SubTupleBinding<'a> {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_extra_double_dot)]
#[must_use]
pub struct ExtraDoubleDot<'a> {
#[primary_span]
#[label]
Expand All @@ -321,27 +348,31 @@ pub struct ExtraDoubleDot<'a> {
#[derive(Diagnostic, Clone, Copy)]
#[note]
#[diag(ast_lowering_misplaced_double_dot)]
#[must_use]
pub struct MisplacedDoubleDot {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_misplaced_relax_trait_bound)]
#[must_use]
pub struct MisplacedRelaxTraitBound {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_not_supported_for_lifetime_binder_async_closure)]
#[must_use]
pub struct NotSupportedForLifetimeBinderAsyncClosure {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_lowering_match_arm_with_no_body)]
#[must_use]
pub struct MatchArmWithNoBody {
#[primary_span]
pub span: Span,
Expand All @@ -351,6 +382,7 @@ pub struct MatchArmWithNoBody {

#[derive(Diagnostic)]
#[diag(ast_lowering_never_pattern_with_body)]
#[must_use]
pub struct NeverPatternWithBody {
#[primary_span]
#[label]
Expand All @@ -360,6 +392,7 @@ pub struct NeverPatternWithBody {

#[derive(Diagnostic)]
#[diag(ast_lowering_never_pattern_with_guard)]
#[must_use]
pub struct NeverPatternWithGuard {
#[primary_span]
#[suggestion(code = "", applicability = "maybe-incorrect")]
Expand All @@ -368,13 +401,15 @@ pub struct NeverPatternWithGuard {

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_arbitrary_expression_in_pattern)]
#[must_use]
pub struct ArbitraryExpressionInPattern {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic, Clone, Copy)]
#[diag(ast_lowering_inclusive_range_with_no_end)]
#[must_use]
pub struct InclusiveRangeWithNoEnd {
#[primary_span]
pub span: Span,
Expand Down
Loading
Loading