rust/compiler/rustc_mir_build/src/errors.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1003 lines
28 KiB
Rust
Raw Normal View History

use rustc_errors::codes::*;
2022-11-26 20:22:49 +00:00
use rustc_errors::{
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level,
MultiSpan, SubdiagMessageOp, Subdiagnostic,
2022-11-26 20:22:49 +00:00
};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::{self, Ty};
use rustc_pattern_analysis::errors::Uncovered;
use rustc_pattern_analysis::rustc::RustcPatCtxt;
2023-02-27 17:43:39 +00:00
use rustc_span::symbol::Symbol;
use rustc_span::Span;
use crate::fluent_generated as fluent;
#[derive(LintDiagnostic)]
2022-11-26 20:22:49 +00:00
#[diag(mir_build_unconditional_recursion)]
#[help]
pub(crate) struct UnconditionalRecursion {
#[label]
pub(crate) span: Span,
2022-11-26 20:22:49 +00:00
#[label(mir_build_unconditional_recursion_call_site_label)]
pub(crate) call_sites: Vec<Span>,
}
2022-08-20 20:54:58 +00:00
#[derive(LintDiagnostic)]
#[diag(mir_build_call_to_deprecated_safe_fn_requires_unsafe)]
pub(crate) struct CallToDeprecatedSafeFnRequiresUnsafe {
#[label]
pub(crate) span: Span,
pub(crate) function: String,
pub(crate) guarantee: String,
#[subdiagnostic]
pub(crate) sub: CallToDeprecatedSafeFnRequiresUnsafeSub,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(mir_build_suggestion, applicability = "machine-applicable")]
pub(crate) struct CallToDeprecatedSafeFnRequiresUnsafeSub {
pub(crate) start_of_line_suggestion: String,
#[suggestion_part(code = "{start_of_line_suggestion}")]
pub(crate) start_of_line: Span,
#[suggestion_part(code = "unsafe {{ ")]
pub(crate) left: Span,
#[suggestion_part(code = " }}")]
pub(crate) right: Span,
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_unsafe_fn_requires_unsafe, code = E0133)]
2022-08-20 20:54:58 +00:00
#[note]
pub(crate) struct UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafe {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
pub(crate) function: String,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_unsafe_fn_requires_unsafe_nameless, code = E0133)]
2022-08-20 20:54:58 +00:00
#[note]
pub(crate) struct UnsafeOpInUnsafeFnCallToUnsafeFunctionRequiresUnsafeNameless {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(mir_build_unsafe_op_in_unsafe_fn_inline_assembly_requires_unsafe, code = E0133)]
2022-08-20 20:54:58 +00:00
#[note]
pub(crate) struct UnsafeOpInUnsafeFnUseOfInlineAssemblyRequiresUnsafe {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(mir_build_unsafe_op_in_unsafe_fn_initializing_type_with_requires_unsafe, code = E0133)]
2022-08-20 20:54:58 +00:00
#[note]
pub(crate) struct UnsafeOpInUnsafeFnInitializingTypeWithRequiresUnsafe {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(mir_build_unsafe_op_in_unsafe_fn_mutable_static_requires_unsafe, code = E0133)]
2022-08-20 20:54:58 +00:00
#[note]
pub(crate) struct UnsafeOpInUnsafeFnUseOfMutableStaticRequiresUnsafe {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(mir_build_unsafe_op_in_unsafe_fn_extern_static_requires_unsafe, code = E0133)]
2022-08-20 20:54:58 +00:00
#[note]
pub(crate) struct UnsafeOpInUnsafeFnUseOfExternStaticRequiresUnsafe {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(mir_build_unsafe_op_in_unsafe_fn_deref_raw_pointer_requires_unsafe, code = E0133)]
2022-08-20 20:54:58 +00:00
#[note]
pub(crate) struct UnsafeOpInUnsafeFnDerefOfRawPointerRequiresUnsafe {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(mir_build_unsafe_op_in_unsafe_fn_union_field_requires_unsafe, code = E0133)]
2022-08-20 20:54:58 +00:00
#[note]
pub(crate) struct UnsafeOpInUnsafeFnAccessToUnionFieldRequiresUnsafe {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(
mir_build_unsafe_op_in_unsafe_fn_mutation_of_layout_constrained_field_requires_unsafe,
code = E0133
)]
2022-08-20 20:54:58 +00:00
#[note]
pub(crate) struct UnsafeOpInUnsafeFnMutationOfLayoutConstrainedFieldRequiresUnsafe {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(
mir_build_unsafe_op_in_unsafe_fn_borrow_of_layout_constrained_field_requires_unsafe,
code = E0133,
)]
pub(crate) struct UnsafeOpInUnsafeFnBorrowOfLayoutConstrainedFieldRequiresUnsafe {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
#[derive(LintDiagnostic)]
2024-05-17 12:43:59 +00:00
#[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_fn_with_requires_unsafe, code = E0133)]
#[help]
pub(crate) struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe {
2022-08-20 20:54:58 +00:00
#[label]
pub(crate) span: Span,
pub(crate) function: String,
pub(crate) missing_target_features: DiagArgValue,
pub(crate) missing_target_features_count: usize,
#[note]
pub(crate) note: Option<()>,
pub(crate) build_target_features: DiagArgValue,
pub(crate) build_target_features_count: usize,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
2022-08-20 20:54:58 +00:00
}
2022-08-24 08:01:53 +00:00
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_call_to_unsafe_fn_requires_unsafe, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct CallToUnsafeFunctionRequiresUnsafe {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
pub(crate) function: String,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_call_to_unsafe_fn_requires_unsafe_nameless, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct CallToUnsafeFunctionRequiresUnsafeNameless {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_call_to_unsafe_fn_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct CallToUnsafeFunctionRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
pub(crate) function: String,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
2022-08-24 08:01:53 +00:00
#[diag(
2022-11-26 20:22:49 +00:00
mir_build_call_to_unsafe_fn_requires_unsafe_nameless_unsafe_op_in_unsafe_fn_allowed,
code = E0133
2022-08-24 08:01:53 +00:00
)]
#[note]
pub(crate) struct CallToUnsafeFunctionRequiresUnsafeNamelessUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_inline_assembly_requires_unsafe, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct UseOfInlineAssemblyRequiresUnsafe {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_inline_assembly_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct UseOfInlineAssemblyRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_initializing_type_with_requires_unsafe, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct InitializingTypeWithRequiresUnsafe {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
2022-08-24 08:01:53 +00:00
#[diag(
2022-11-26 20:22:49 +00:00
mir_build_initializing_type_with_requires_unsafe_unsafe_op_in_unsafe_fn_allowed,
code = E0133
2022-08-24 08:01:53 +00:00
)]
#[note]
pub(crate) struct InitializingTypeWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_mutable_static_requires_unsafe, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct UseOfMutableStaticRequiresUnsafe {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_mutable_static_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct UseOfMutableStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_extern_static_requires_unsafe, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct UseOfExternStaticRequiresUnsafe {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_extern_static_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct UseOfExternStaticRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_deref_raw_pointer_requires_unsafe, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct DerefOfRawPointerRequiresUnsafe {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_deref_raw_pointer_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct DerefOfRawPointerRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_union_field_requires_unsafe, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct AccessToUnionFieldRequiresUnsafe {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_union_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct AccessToUnionFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_mutation_of_layout_constrained_field_requires_unsafe, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct MutationOfLayoutConstrainedFieldRequiresUnsafe {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
2022-08-24 08:01:53 +00:00
#[diag(
2022-11-26 20:22:49 +00:00
mir_build_mutation_of_layout_constrained_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed,
code = E0133
2022-08-24 08:01:53 +00:00
)]
#[note]
pub(crate) struct MutationOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_borrow_of_layout_constrained_field_requires_unsafe, code = E0133)]
2022-08-24 08:01:53 +00:00
#[note]
pub(crate) struct BorrowOfLayoutConstrainedFieldRequiresUnsafe {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
2022-08-24 08:01:53 +00:00
#[diag(
2022-11-26 20:22:49 +00:00
mir_build_borrow_of_layout_constrained_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed,
code = E0133
2022-08-24 08:01:53 +00:00
)]
#[note]
pub(crate) struct BorrowOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_call_to_fn_with_requires_unsafe, code = E0133)]
#[help]
pub(crate) struct CallToFunctionWithRequiresUnsafe {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
pub(crate) function: String,
pub(crate) missing_target_features: DiagArgValue,
pub(crate) missing_target_features_count: usize,
#[note]
pub(crate) note: Option<()>,
pub(crate) build_target_features: DiagArgValue,
pub(crate) build_target_features_count: usize,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
2022-08-24 08:01:53 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_call_to_fn_with_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = E0133)]
#[help]
pub(crate) struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed {
2022-08-24 08:01:53 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
pub(crate) function: String,
pub(crate) missing_target_features: DiagArgValue,
pub(crate) missing_target_features_count: usize,
#[note]
pub(crate) note: Option<()>,
pub(crate) build_target_features: DiagArgValue,
pub(crate) build_target_features_count: usize,
#[subdiagnostic]
pub(crate) unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Subdiagnostic)]
#[label(mir_build_unsafe_not_inherited)]
pub(crate) struct UnsafeNotInheritedNote {
#[primary_span]
pub(crate) span: Span,
2022-08-24 08:01:53 +00:00
}
2022-08-24 17:16:50 +00:00
pub(crate) struct UnsafeNotInheritedLintNote {
pub(crate) signature_span: Span,
pub(crate) body_span: Span,
}
impl Subdiagnostic for UnsafeNotInheritedLintNote {
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
Reduce capabilities of `Diagnostic`. Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-06 05:44:30 +00:00
self,
diag: &mut Diag<'_, G>,
_f: &F,
Reduce capabilities of `Diagnostic`. Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-06 05:44:30 +00:00
) {
diag.span_note(self.signature_span, fluent::mir_build_unsafe_fn_safe_body);
let body_start = self.body_span.shrink_to_lo();
let body_end = self.body_span.shrink_to_hi();
diag.tool_only_multipart_suggestion(
fluent::mir_build_wrap_suggestion,
vec![(body_start, "{ unsafe ".into()), (body_end, "}".into())],
Applicability::MachineApplicable,
);
}
}
2022-08-24 17:16:50 +00:00
#[derive(LintDiagnostic)]
2022-11-26 20:22:49 +00:00
#[diag(mir_build_unused_unsafe)]
pub(crate) struct UnusedUnsafe {
2022-08-24 17:16:50 +00:00
#[label]
pub(crate) span: Span,
2022-08-24 17:16:50 +00:00
#[subdiagnostic]
pub(crate) enclosing: Option<UnusedUnsafeEnclosing>,
2022-08-24 17:16:50 +00:00
}
2022-11-26 20:22:49 +00:00
#[derive(Subdiagnostic)]
pub(crate) enum UnusedUnsafeEnclosing {
2022-11-26 20:22:49 +00:00
#[label(mir_build_unused_unsafe_enclosing_block_label)]
2022-08-24 17:16:50 +00:00
Block {
#[primary_span]
span: Span,
},
}
pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> {
pub(crate) cx: &'m RustcPatCtxt<'p, 'tcx>,
pub(crate) scrut_span: Span,
pub(crate) braces_span: Option<Span>,
pub(crate) ty: Ty<'tcx>,
}
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> {
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'_, G> {
let mut diag =
Diag::new(dcx, level, fluent::mir_build_non_exhaustive_patterns_type_not_empty);
diag.span(self.scrut_span);
diag.code(E0004);
let peeled_ty = self.ty.peel_refs();
diag.arg("ty", self.ty);
diag.arg("peeled_ty", peeled_ty);
if let ty::Adt(def, _) = peeled_ty.kind() {
let def_span = self
.cx
.tcx
.hir()
.get_if_local(def.did())
.and_then(|node| node.ident())
.map(|ident| ident.span)
.unwrap_or_else(|| self.cx.tcx.def_span(def.did()));
// workaround to make test pass
let mut span: MultiSpan = def_span.into();
span.push_span_label(def_span, "");
diag.span_note(span, fluent::mir_build_def_note);
}
2023-04-15 18:49:54 +00:00
let is_variant_list_non_exhaustive = matches!(self.ty.kind(),
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local());
if is_variant_list_non_exhaustive {
diag.note(fluent::mir_build_non_exhaustive_type_note);
} else {
diag.note(fluent::mir_build_type_note);
}
if let ty::Ref(_, sub_ty, _) = self.ty.kind() {
2022-11-26 20:22:49 +00:00
if !sub_ty.is_inhabited_from(self.cx.tcx, self.cx.module, self.cx.param_env) {
diag.note(fluent::mir_build_reference_note);
}
}
let sm = self.cx.tcx.sess.source_map();
if let Some(braces_span) = self.braces_span {
// Get the span for the empty match body `{}`.
let (indentation, more) = if let Some(snippet) = sm.indentation_before(self.scrut_span)
{
(format!("\n{snippet}"), " ")
} else {
(" ".to_string(), "")
};
diag.span_suggestion_verbose(
braces_span,
fluent::mir_build_suggestion,
format!(" {{{indentation}{more}_ => todo!(),{indentation}}}"),
Applicability::HasPlaceholders,
);
} else {
diag.help(fluent::mir_build_help);
}
diag
}
}
2023-06-28 05:49:21 +00:00
#[derive(Subdiagnostic)]
#[note(mir_build_non_exhaustive_match_all_arms_guarded)]
pub(crate) struct NonExhaustiveMatchAllArmsGuarded;
2023-06-28 05:49:21 +00:00
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_static_in_pattern, code = E0158)]
pub(crate) struct StaticInPattern {
#[primary_span]
pub(crate) span: Span,
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_const_param_in_pattern, code = E0158)]
pub(crate) struct ConstParamInPattern {
#[primary_span]
pub(crate) span: Span,
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_non_const_path, code = E0080)]
pub(crate) struct NonConstPath {
#[primary_span]
pub(crate) span: Span,
}
2022-08-27 19:06:06 +00:00
#[derive(LintDiagnostic)]
2022-11-26 20:22:49 +00:00
#[diag(mir_build_unreachable_pattern)]
pub(crate) struct UnreachablePattern<'tcx> {
2022-08-27 19:06:06 +00:00
#[label]
pub(crate) span: Option<Span>,
#[subdiagnostic]
pub(crate) matches_no_values: Option<UnreachableMatchesNoValues<'tcx>>,
#[label(mir_build_unreachable_covered_by_catchall)]
pub(crate) covered_by_catchall: Option<Span>,
#[label(mir_build_unreachable_covered_by_one)]
pub(crate) covered_by_one: Option<Span>,
2024-07-24 06:40:04 +00:00
#[note(mir_build_unreachable_covered_by_many)]
pub(crate) covered_by_many: Option<MultiSpan>,
}
#[derive(Subdiagnostic)]
#[note(mir_build_unreachable_matches_no_values)]
pub(crate) struct UnreachableMatchesNoValues<'tcx> {
pub(crate) ty: Ty<'tcx>,
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_const_pattern_depends_on_generic_parameter, code = E0158)]
pub(crate) struct ConstPatternDependsOnGenericParameter {
#[primary_span]
pub(crate) span: Span,
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_could_not_eval_const_pattern)]
pub(crate) struct CouldNotEvalConstPattern {
#[primary_span]
pub(crate) span: Span,
}
2022-08-27 19:48:18 +00:00
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_lower_range_bound_must_be_less_than_or_equal_to_upper, code = E0030)]
pub(crate) struct LowerRangeBoundMustBeLessThanOrEqualToUpper {
2022-08-27 19:48:18 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
#[note(mir_build_teach_note)]
pub(crate) teach: Option<()>,
2022-08-27 19:48:18 +00:00
}
#[derive(Diagnostic)]
#[diag(mir_build_literal_in_range_out_of_bounds)]
pub(crate) struct LiteralOutOfRange<'tcx> {
#[primary_span]
#[label]
pub(crate) span: Span,
pub(crate) ty: Ty<'tcx>,
pub(crate) min: i128,
pub(crate) max: u128,
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_lower_range_bound_must_be_less_than_upper, code = E0579)]
pub(crate) struct LowerRangeBoundMustBeLessThanUpper {
2022-08-27 19:48:18 +00:00
#[primary_span]
pub(crate) span: Span,
2022-08-27 19:48:18 +00:00
}
#[derive(LintDiagnostic)]
2022-11-26 20:22:49 +00:00
#[diag(mir_build_leading_irrefutable_let_patterns)]
#[note]
#[help]
pub(crate) struct LeadingIrrefutableLetPatterns {
pub(crate) count: usize,
}
#[derive(LintDiagnostic)]
2022-11-26 20:22:49 +00:00
#[diag(mir_build_trailing_irrefutable_let_patterns)]
#[note]
#[help]
pub(crate) struct TrailingIrrefutableLetPatterns {
pub(crate) count: usize,
}
#[derive(LintDiagnostic)]
#[diag(mir_build_bindings_with_variant_name, code = E0170)]
pub(crate) struct BindingsWithVariantName {
2023-02-27 17:43:39 +00:00
#[suggestion(code = "{ty_path}::{name}", applicability = "machine-applicable")]
pub(crate) suggestion: Option<Span>,
pub(crate) ty_path: String,
pub(crate) name: Symbol,
}
#[derive(LintDiagnostic)]
2022-11-26 20:22:49 +00:00
#[diag(mir_build_irrefutable_let_patterns_if_let)]
#[note]
#[help]
pub(crate) struct IrrefutableLetPatternsIfLet {
pub(crate) count: usize,
}
#[derive(LintDiagnostic)]
2022-11-26 20:22:49 +00:00
#[diag(mir_build_irrefutable_let_patterns_if_let_guard)]
#[note]
#[help]
pub(crate) struct IrrefutableLetPatternsIfLetGuard {
pub(crate) count: usize,
}
#[derive(LintDiagnostic)]
2022-11-26 20:22:49 +00:00
#[diag(mir_build_irrefutable_let_patterns_let_else)]
#[note]
#[help]
pub(crate) struct IrrefutableLetPatternsLetElse {
pub(crate) count: usize,
}
#[derive(LintDiagnostic)]
2022-11-26 20:22:49 +00:00
#[diag(mir_build_irrefutable_let_patterns_while_let)]
#[note]
#[help]
pub(crate) struct IrrefutableLetPatternsWhileLet {
pub(crate) count: usize,
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_borrow_of_moved_value)]
pub(crate) struct BorrowOfMovedValue<'tcx> {
#[primary_span]
#[label]
#[label(mir_build_occurs_because_label)]
pub(crate) binding_span: Span,
#[label(mir_build_value_borrowed_label)]
pub(crate) conflicts_ref: Vec<Span>,
pub(crate) name: Symbol,
pub(crate) ty: Ty<'tcx>,
#[suggestion(code = "ref ", applicability = "machine-applicable")]
pub(crate) suggest_borrowing: Option<Span>,
}
2022-11-26 20:22:49 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_multiple_mut_borrows)]
pub(crate) struct MultipleMutBorrows {
#[primary_span]
pub(crate) span: Span,
2022-12-17 18:20:44 +00:00
#[subdiagnostic]
pub(crate) occurrences: Vec<Conflict>,
2023-01-17 12:48:43 +00:00
}
#[derive(Diagnostic)]
#[diag(mir_build_already_borrowed)]
pub(crate) struct AlreadyBorrowed {
2023-01-17 12:48:43 +00:00
#[primary_span]
pub(crate) span: Span,
2023-01-17 12:48:43 +00:00
#[subdiagnostic]
pub(crate) occurrences: Vec<Conflict>,
2023-01-17 12:48:43 +00:00
}
#[derive(Diagnostic)]
#[diag(mir_build_already_mut_borrowed)]
pub(crate) struct AlreadyMutBorrowed {
2023-01-17 12:48:43 +00:00
#[primary_span]
pub(crate) span: Span,
2023-01-17 12:48:43 +00:00
#[subdiagnostic]
pub(crate) occurrences: Vec<Conflict>,
2023-01-17 12:48:43 +00:00
}
#[derive(Diagnostic)]
#[diag(mir_build_moved_while_borrowed)]
pub(crate) struct MovedWhileBorrowed {
2023-01-17 12:48:43 +00:00
#[primary_span]
pub(crate) span: Span,
2023-01-17 12:48:43 +00:00
#[subdiagnostic]
pub(crate) occurrences: Vec<Conflict>,
}
2022-11-26 20:22:49 +00:00
#[derive(Subdiagnostic)]
pub(crate) enum Conflict {
2023-01-17 12:48:43 +00:00
#[label(mir_build_mutable_borrow)]
Mut {
#[primary_span]
span: Span,
2023-02-27 17:43:39 +00:00
name: Symbol,
},
2023-01-17 12:48:43 +00:00
#[label(mir_build_borrow)]
Ref {
#[primary_span]
span: Span,
2023-02-27 17:43:39 +00:00
name: Symbol,
},
2023-01-17 12:48:43 +00:00
#[label(mir_build_moved)]
Moved {
#[primary_span]
span: Span,
2023-02-27 17:43:39 +00:00
name: Symbol,
},
}
2022-12-19 23:28:33 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_union_pattern)]
pub(crate) struct UnionPattern {
2022-12-19 23:28:33 +00:00
#[primary_span]
pub(crate) span: Span,
2022-12-19 23:28:33 +00:00
}
#[derive(Diagnostic)]
#[diag(mir_build_type_not_structural)]
#[note(mir_build_type_not_structural_tip)]
#[note(mir_build_type_not_structural_more_info)]
pub(crate) struct TypeNotStructural<'tcx> {
2022-12-19 23:28:33 +00:00
#[primary_span]
pub(crate) span: Span,
pub(crate) non_sm_ty: Ty<'tcx>,
2022-12-19 23:28:33 +00:00
}
#[derive(Diagnostic)]
#[diag(mir_build_non_partial_eq_match)]
pub(crate) struct TypeNotPartialEq<'tcx> {
#[primary_span]
pub(crate) span: Span,
pub(crate) non_peq_ty: Ty<'tcx>,
}
2022-12-19 23:28:33 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_invalid_pattern)]
pub(crate) struct InvalidPattern<'tcx> {
2022-12-19 23:28:33 +00:00
#[primary_span]
pub(crate) span: Span,
pub(crate) non_sm_ty: Ty<'tcx>,
2022-12-19 23:28:33 +00:00
}
#[derive(Diagnostic)]
#[diag(mir_build_unsized_pattern)]
pub(crate) struct UnsizedPattern<'tcx> {
2022-12-19 23:28:33 +00:00
#[primary_span]
pub(crate) span: Span,
pub(crate) non_sm_ty: Ty<'tcx>,
2022-12-19 23:28:33 +00:00
}
2023-09-30 06:15:34 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_nan_pattern)]
#[note]
#[help]
pub(crate) struct NaNPattern {
2023-09-30 06:15:34 +00:00
#[primary_span]
pub(crate) span: Span,
2023-09-30 06:15:34 +00:00
}
2022-12-19 23:28:33 +00:00
#[derive(Diagnostic)]
2022-12-19 23:28:33 +00:00
#[diag(mir_build_pointer_pattern)]
pub(crate) struct PointerPattern {
#[primary_span]
pub(crate) span: Span,
}
2022-12-19 23:28:33 +00:00
2024-01-05 16:21:09 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_non_empty_never_pattern)]
#[note]
pub(crate) struct NonEmptyNeverPattern<'tcx> {
2024-01-05 16:21:09 +00:00
#[primary_span]
#[label]
pub(crate) span: Span,
pub(crate) ty: Ty<'tcx>,
2024-01-05 16:21:09 +00:00
}
2022-12-23 20:02:23 +00:00
#[derive(Diagnostic)]
#[diag(mir_build_exceeds_mcdc_condition_limit)]
pub(crate) struct MCDCExceedsConditionLimit {
#[primary_span]
pub(crate) span: Span,
pub(crate) num_conditions: usize,
pub(crate) max_conditions: usize,
}
#[derive(Diagnostic)]
#[diag(mir_build_pattern_not_covered, code = E0005)]
2022-12-23 20:02:23 +00:00
pub(crate) struct PatternNotCovered<'s, 'tcx> {
#[primary_span]
pub(crate) span: Span,
pub(crate) origin: &'s str,
2022-12-23 20:02:23 +00:00
#[subdiagnostic]
pub(crate) uncovered: Uncovered,
2022-12-23 20:02:23 +00:00
#[subdiagnostic]
pub(crate) inform: Option<Inform>,
2022-12-23 20:02:23 +00:00
#[subdiagnostic]
pub(crate) interpreted_as_const: Option<InterpretedAsConst>,
2022-12-23 20:02:23 +00:00
#[subdiagnostic]
pub(crate) adt_defined_here: Option<AdtDefinedHere<'tcx>>,
#[note(mir_build_privately_uninhabited)]
pub(crate) witness_1_is_privately_uninhabited: Option<()>,
#[note(mir_build_pattern_ty)]
pub(crate) _p: (),
pub(crate) pattern_ty: Ty<'tcx>,
2022-12-23 20:02:23 +00:00
#[subdiagnostic]
pub(crate) let_suggestion: Option<SuggestLet>,
2022-12-23 20:02:23 +00:00
#[subdiagnostic]
pub(crate) misc_suggestion: Option<MiscPatternSuggestion>,
2022-12-23 20:02:23 +00:00
}
#[derive(Subdiagnostic)]
#[note(mir_build_inform_irrefutable)]
#[note(mir_build_more_information)]
pub(crate) struct Inform;
2022-12-23 20:02:23 +00:00
pub(crate) struct AdtDefinedHere<'tcx> {
pub(crate) adt_def_span: Span,
pub(crate) ty: Ty<'tcx>,
pub(crate) variants: Vec<Variant>,
2022-12-23 20:02:23 +00:00
}
pub(crate) struct Variant {
pub(crate) span: Span,
2022-12-23 20:02:23 +00:00
}
impl<'tcx> Subdiagnostic for AdtDefinedHere<'tcx> {
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
Reduce capabilities of `Diagnostic`. Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-06 05:44:30 +00:00
self,
diag: &mut Diag<'_, G>,
_f: &F,
Reduce capabilities of `Diagnostic`. Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-06 05:44:30 +00:00
) {
diag.arg("ty", self.ty);
2022-12-23 20:02:23 +00:00
let mut spans = MultiSpan::from(self.adt_def_span);
for Variant { span } in self.variants {
spans.push_span_label(span, fluent::mir_build_variant_defined_here);
2022-12-23 20:02:23 +00:00
}
diag.span_note(spans, fluent::mir_build_adt_defined_here);
2022-12-23 20:02:23 +00:00
}
}
#[derive(Subdiagnostic)]
#[suggestion(
mir_build_interpreted_as_const,
code = "{variable}_var",
applicability = "maybe-incorrect"
)]
#[label(mir_build_confused)]
pub(crate) struct InterpretedAsConst {
2022-12-23 20:02:23 +00:00
#[primary_span]
pub(crate) span: Span,
pub(crate) variable: String,
2022-12-23 20:02:23 +00:00
}
#[derive(Subdiagnostic)]
pub(crate) enum SuggestLet {
2022-12-23 20:02:23 +00:00
#[multipart_suggestion(mir_build_suggest_if_let, applicability = "has-placeholders")]
If {
2022-12-23 20:02:23 +00:00
#[suggestion_part(code = "if ")]
start_span: Span,
#[suggestion_part(code = " {{ todo!() }}")]
semi_span: Span,
count: usize,
},
#[suggestion(
mir_build_suggest_let_else,
code = " else {{ todo!() }}",
applicability = "has-placeholders"
)]
Else {
#[primary_span]
2022-12-23 20:02:23 +00:00
end_span: Span,
count: usize,
},
}
#[derive(Subdiagnostic)]
pub(crate) enum MiscPatternSuggestion {
#[suggestion(
mir_build_suggest_attempted_int_lit,
code = "_",
applicability = "maybe-incorrect"
)]
AttemptedIntegerLiteral {
#[primary_span]
start_span: Span,
},
}
#[derive(Diagnostic)]
#[diag(mir_build_rustc_box_attribute_error)]
pub(crate) struct RustcBoxAttributeError {
#[primary_span]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) reason: RustcBoxAttrReason,
}
#[derive(Subdiagnostic)]
pub(crate) enum RustcBoxAttrReason {
#[note(mir_build_attributes)]
Attributes,
#[note(mir_build_not_box)]
NotBoxNew,
#[note(mir_build_missing_box)]
MissingBox,
}
#[derive(LintDiagnostic)]
#[diag(mir_build_rust_2024_incompatible_pat)]
pub(crate) struct Rust2024IncompatiblePat {
#[subdiagnostic]
pub(crate) sugg: Rust2024IncompatiblePatSugg,
}
pub(crate) struct Rust2024IncompatiblePatSugg {
pub(crate) suggestion: Vec<(Span, String)>,
}
impl Subdiagnostic for Rust2024IncompatiblePatSugg {
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self,
diag: &mut Diag<'_, G>,
_f: &F,
) {
let applicability =
if self.suggestion.iter().all(|(span, _)| span.can_be_used_for_suggestions()) {
Applicability::MachineApplicable
} else {
Applicability::MaybeIncorrect
};
diag.multipart_suggestion("desugar the match ergonomics", self.suggestion, applicability);
}
}