summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_mir_build/src/errors.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /compiler/rustc_mir_build/src/errors.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_mir_build/src/errors.rs')
-rw-r--r--compiler/rustc_mir_build/src/errors.rs130
1 files changed, 29 insertions, 101 deletions
diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs
index 418f9bb9d..c66687330 100644
--- a/compiler/rustc_mir_build/src/errors.rs
+++ b/compiler/rustc_mir_build/src/errors.rs
@@ -1,14 +1,12 @@
-use crate::{
- fluent_generated as fluent,
- thir::pattern::{deconstruct_pat::WitnessPat, MatchCheckCtxt},
-};
+use crate::fluent_generated as fluent;
+use rustc_errors::DiagnosticArgValue;
use rustc_errors::{
- error_code, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
- Handler, IntoDiagnostic, MultiSpan, SubdiagnosticMessage,
+ error_code, AddToDiagnostic, Applicability, DiagCtxt, Diagnostic, DiagnosticBuilder,
+ ErrorGuaranteed, IntoDiagnostic, MultiSpan, SubdiagnosticMessage,
};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
-use rustc_middle::thir::Pat;
use rustc_middle::ty::{self, Ty};
+use rustc_pattern_analysis::{errors::Uncovered, rustc::RustcMatchCheckCtxt};
use rustc_span::symbol::Symbol;
use rustc_span::Span;
@@ -124,11 +122,17 @@ pub struct UnsafeOpInUnsafeFnBorrowOfLayoutConstrainedFieldRequiresUnsafe {
#[derive(LintDiagnostic)]
#[diag(mir_build_unsafe_op_in_unsafe_fn_call_to_fn_with_requires_unsafe)]
-#[note]
+#[help]
pub struct UnsafeOpInUnsafeFnCallToFunctionWithRequiresUnsafe<'a> {
#[label]
pub span: Span,
pub function: &'a str,
+ pub missing_target_features: DiagnosticArgValue<'a>,
+ pub missing_target_features_count: usize,
+ #[note]
+ pub note: Option<()>,
+ pub build_target_features: DiagnosticArgValue<'a>,
+ pub build_target_features_count: usize,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedLintNote>,
}
@@ -369,24 +373,36 @@ pub struct BorrowOfLayoutConstrainedFieldRequiresUnsafeUnsafeOpInUnsafeFnAllowed
#[derive(Diagnostic)]
#[diag(mir_build_call_to_fn_with_requires_unsafe, code = "E0133")]
-#[note]
+#[help]
pub struct CallToFunctionWithRequiresUnsafe<'a> {
#[primary_span]
#[label]
pub span: Span,
pub function: &'a str,
+ pub missing_target_features: DiagnosticArgValue<'a>,
+ pub missing_target_features_count: usize,
+ #[note]
+ pub note: Option<()>,
+ pub build_target_features: DiagnosticArgValue<'a>,
+ pub build_target_features_count: usize,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
#[derive(Diagnostic)]
#[diag(mir_build_call_to_fn_with_requires_unsafe_unsafe_op_in_unsafe_fn_allowed, code = "E0133")]
-#[note]
+#[help]
pub struct CallToFunctionWithRequiresUnsafeUnsafeOpInUnsafeFnAllowed<'a> {
#[primary_span]
#[label]
pub span: Span,
pub function: &'a str,
+ pub missing_target_features: DiagnosticArgValue<'a>,
+ pub missing_target_features_count: usize,
+ #[note]
+ pub note: Option<()>,
+ pub build_target_features: DiagnosticArgValue<'a>,
+ pub build_target_features_count: usize,
#[subdiagnostic]
pub unsafe_not_inherited_note: Option<UnsafeNotInheritedNote>,
}
@@ -438,15 +454,15 @@ pub enum UnusedUnsafeEnclosing {
}
pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> {
- pub cx: &'m MatchCheckCtxt<'p, 'tcx>,
+ pub cx: &'m RustcMatchCheckCtxt<'p, 'tcx>,
pub expr_span: Span,
pub span: Span,
pub ty: Ty<'tcx>,
}
impl<'a> IntoDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> {
- fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
- let mut diag = handler.struct_span_err_with_code(
+ fn into_diagnostic(self, dcx: &'a DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
+ let mut diag = dcx.struct_span_err_with_code(
self.span,
fluent::mir_build_non_exhaustive_patterns_type_not_empty,
error_code!(E0004),
@@ -793,94 +809,6 @@ pub struct NonPartialEqMatch<'tcx> {
pub non_peq_ty: Ty<'tcx>,
}
-#[derive(LintDiagnostic)]
-#[diag(mir_build_overlapping_range_endpoints)]
-#[note]
-pub struct OverlappingRangeEndpoints<'tcx> {
- #[label(mir_build_range)]
- pub range: Span,
- #[subdiagnostic]
- pub overlap: Vec<Overlap<'tcx>>,
-}
-
-pub struct Overlap<'tcx> {
- pub span: Span,
- pub range: Pat<'tcx>,
-}
-
-impl<'tcx> AddToDiagnostic for Overlap<'tcx> {
- fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
- where
- F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
- {
- let Overlap { span, range } = self;
-
- // FIXME(mejrs) unfortunately `#[derive(LintDiagnostic)]`
- // does not support `#[subdiagnostic(eager)]`...
- let message = format!("this range overlaps on `{range}`...");
- diag.span_label(span, message);
- }
-}
-
-#[derive(LintDiagnostic)]
-#[diag(mir_build_non_exhaustive_omitted_pattern)]
-#[help]
-#[note]
-pub(crate) struct NonExhaustiveOmittedPattern<'tcx> {
- pub scrut_ty: Ty<'tcx>,
- #[subdiagnostic]
- pub uncovered: Uncovered<'tcx>,
-}
-
-#[derive(LintDiagnostic)]
-#[diag(mir_build_non_exhaustive_omitted_pattern_lint_on_arm)]
-#[help]
-pub(crate) struct NonExhaustiveOmittedPatternLintOnArm {
- #[label]
- pub lint_span: Span,
- #[suggestion(code = "#[{lint_level}({lint_name})]\n", applicability = "maybe-incorrect")]
- pub suggest_lint_on_match: Option<Span>,
- pub lint_level: &'static str,
- pub lint_name: &'static str,
-}
-
-#[derive(Subdiagnostic)]
-#[label(mir_build_uncovered)]
-pub(crate) struct Uncovered<'tcx> {
- #[primary_span]
- span: Span,
- count: usize,
- witness_1: Pat<'tcx>,
- witness_2: Pat<'tcx>,
- witness_3: Pat<'tcx>,
- remainder: usize,
-}
-
-impl<'tcx> Uncovered<'tcx> {
- pub fn new<'p>(
- span: Span,
- cx: &MatchCheckCtxt<'p, 'tcx>,
- witnesses: Vec<WitnessPat<'tcx>>,
- ) -> Self {
- let witness_1 = witnesses.get(0).unwrap().to_diagnostic_pat(cx);
- Self {
- span,
- count: witnesses.len(),
- // Substitute dummy values if witnesses is smaller than 3. These will never be read.
- witness_2: witnesses
- .get(1)
- .map(|w| w.to_diagnostic_pat(cx))
- .unwrap_or_else(|| witness_1.clone()),
- witness_3: witnesses
- .get(2)
- .map(|w| w.to_diagnostic_pat(cx))
- .unwrap_or_else(|| witness_1.clone()),
- witness_1,
- remainder: witnesses.len().saturating_sub(3),
- }
- }
-}
-
#[derive(Diagnostic)]
#[diag(mir_build_pattern_not_covered, code = "E0005")]
pub(crate) struct PatternNotCovered<'s, 'tcx> {