mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
Convert to inline diagnostics in rustc_pattern_analysis
This commit is contained in:
@@ -3796,7 +3796,6 @@ dependencies = [
|
||||
"rustc_mir_transform",
|
||||
"rustc_parse",
|
||||
"rustc_passes",
|
||||
"rustc_pattern_analysis",
|
||||
"rustc_public",
|
||||
"rustc_resolve",
|
||||
"rustc_session",
|
||||
@@ -4451,7 +4450,6 @@ dependencies = [
|
||||
"rustc_arena",
|
||||
"rustc_data_structures",
|
||||
"rustc_errors",
|
||||
"rustc_fluent_macro",
|
||||
"rustc_hir",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
|
||||
@@ -33,7 +33,6 @@ rustc_mir_build = { path = "../rustc_mir_build" }
|
||||
rustc_mir_transform = { path = "../rustc_mir_transform" }
|
||||
rustc_parse = { path = "../rustc_parse" }
|
||||
rustc_passes = { path = "../rustc_passes" }
|
||||
rustc_pattern_analysis = { path = "../rustc_pattern_analysis" }
|
||||
rustc_public = { path = "../rustc_public", features = ["rustc_internal"] }
|
||||
rustc_resolve = { path = "../rustc_resolve" }
|
||||
rustc_session = { path = "../rustc_session" }
|
||||
|
||||
@@ -125,7 +125,6 @@ pub fn default_translator() -> Translator {
|
||||
rustc_mir_build::DEFAULT_LOCALE_RESOURCE,
|
||||
rustc_parse::DEFAULT_LOCALE_RESOURCE,
|
||||
rustc_passes::DEFAULT_LOCALE_RESOURCE,
|
||||
rustc_pattern_analysis::DEFAULT_LOCALE_RESOURCE,
|
||||
rustc_trait_selection::DEFAULT_LOCALE_RESOURCE,
|
||||
// tidy-alphabetical-end
|
||||
];
|
||||
|
||||
@@ -11,7 +11,6 @@ rustc_apfloat = "0.2.0"
|
||||
rustc_arena = { path = "../rustc_arena", optional = true }
|
||||
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
|
||||
rustc_errors = { path = "../rustc_errors", optional = true }
|
||||
rustc_fluent_macro = { path = "../rustc_fluent_macro", optional = true }
|
||||
rustc_hir = { path = "../rustc_hir", optional = true }
|
||||
rustc_index = { path = "../rustc_index", default-features = false }
|
||||
rustc_macros = { path = "../rustc_macros", optional = true }
|
||||
@@ -36,7 +35,6 @@ rustc = [
|
||||
"dep:rustc_arena",
|
||||
"dep:rustc_data_structures",
|
||||
"dep:rustc_errors",
|
||||
"dep:rustc_fluent_macro",
|
||||
"dep:rustc_hir",
|
||||
"dep:rustc_macros",
|
||||
"dep:rustc_middle",
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
pattern_analysis_excluside_range_missing_gap = multiple ranges are one apart
|
||||
.label = this range doesn't match `{$gap}` because `..` is an exclusive range
|
||||
.suggestion = use an inclusive range instead
|
||||
|
||||
pattern_analysis_excluside_range_missing_max = exclusive range missing `{$max}`
|
||||
.label = this range doesn't match `{$max}` because `..` is an exclusive range
|
||||
.suggestion = use an inclusive range instead
|
||||
|
||||
pattern_analysis_mixed_deref_pattern_constructors = mix of deref patterns and normal constructors
|
||||
.deref_pattern_label = matches on the result of dereferencing `{$smart_pointer_ty}`
|
||||
.normal_constructor_label = matches directly on `{$smart_pointer_ty}`
|
||||
|
||||
pattern_analysis_non_exhaustive_omitted_pattern = some variants are not matched explicitly
|
||||
.help = ensure that all variants are matched explicitly by adding the suggested match arms
|
||||
.note = the matched value is of type `{$scrut_ty}` and the `non_exhaustive_omitted_patterns` attribute was found
|
||||
|
||||
pattern_analysis_non_exhaustive_omitted_pattern_lint_on_arm = the lint level must be set on the whole match
|
||||
.help = it no longer has any effect to set the lint level on an individual match arm
|
||||
.label = remove this attribute
|
||||
.suggestion = set the lint level on the whole match
|
||||
|
||||
pattern_analysis_overlapping_range_endpoints = multiple patterns overlap on their endpoints
|
||||
.label = ... with this range
|
||||
.note = you likely meant to write mutually exclusive ranges
|
||||
|
||||
pattern_analysis_uncovered = {$count ->
|
||||
[1] pattern `{$witness_1}`
|
||||
[2] patterns `{$witness_1}` and `{$witness_2}`
|
||||
[3] patterns `{$witness_1}`, `{$witness_2}` and `{$witness_3}`
|
||||
*[other] patterns `{$witness_1}`, `{$witness_2}`, `{$witness_3}` and {$remainder} more
|
||||
} not covered
|
||||
@@ -6,7 +6,14 @@
|
||||
use crate::rustc::{RustcPatCtxt, WitnessPat};
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[label(pattern_analysis_uncovered)]
|
||||
#[label(
|
||||
"{$count ->
|
||||
[1] pattern `{$witness_1}`
|
||||
[2] patterns `{$witness_1}` and `{$witness_2}`
|
||||
[3] patterns `{$witness_1}`, `{$witness_2}` and `{$witness_3}`
|
||||
*[other] patterns `{$witness_1}`, `{$witness_2}`, `{$witness_3}` and {$remainder} more
|
||||
} not covered"
|
||||
)]
|
||||
pub struct Uncovered {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
@@ -40,10 +47,10 @@ pub fn new<'p, 'tcx>(
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(pattern_analysis_overlapping_range_endpoints)]
|
||||
#[note]
|
||||
#[diag("multiple patterns overlap on their endpoints")]
|
||||
#[note("you likely meant to write mutually exclusive ranges")]
|
||||
pub struct OverlappingRangeEndpoints {
|
||||
#[label]
|
||||
#[label("... with this range")]
|
||||
pub range: Span,
|
||||
#[subdiagnostic]
|
||||
pub overlap: Vec<Overlap>,
|
||||
@@ -66,10 +73,14 @@ fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(pattern_analysis_excluside_range_missing_max)]
|
||||
#[diag("exclusive range missing `{$max}`")]
|
||||
pub struct ExclusiveRangeMissingMax {
|
||||
#[label]
|
||||
#[suggestion(code = "{suggestion}", applicability = "maybe-incorrect")]
|
||||
#[label("this range doesn't match `{$max}` because `..` is an exclusive range")]
|
||||
#[suggestion(
|
||||
"use an inclusive range instead",
|
||||
code = "{suggestion}",
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
/// This is an exclusive range that looks like `lo..max` (i.e. doesn't match `max`).
|
||||
pub first_range: Span,
|
||||
/// Suggest `lo..=max` instead.
|
||||
@@ -78,10 +89,14 @@ pub struct ExclusiveRangeMissingMax {
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(pattern_analysis_excluside_range_missing_gap)]
|
||||
#[diag("multiple ranges are one apart")]
|
||||
pub struct ExclusiveRangeMissingGap {
|
||||
#[label]
|
||||
#[suggestion(code = "{suggestion}", applicability = "maybe-incorrect")]
|
||||
#[label("this range doesn't match `{$gap}` because `..` is an exclusive range")]
|
||||
#[suggestion(
|
||||
"use an inclusive range instead",
|
||||
code = "{suggestion}",
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
/// This is an exclusive range that looks like `lo..gap` (i.e. doesn't match `gap`).
|
||||
pub first_range: Span,
|
||||
pub gap: String, // a printed pattern
|
||||
@@ -113,9 +128,11 @@ fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(pattern_analysis_non_exhaustive_omitted_pattern)]
|
||||
#[help]
|
||||
#[note]
|
||||
#[diag("some variants are not matched explicitly")]
|
||||
#[help("ensure that all variants are matched explicitly by adding the suggested match arms")]
|
||||
#[note(
|
||||
"the matched value is of type `{$scrut_ty}` and the `non_exhaustive_omitted_patterns` attribute was found"
|
||||
)]
|
||||
pub(crate) struct NonExhaustiveOmittedPattern<'tcx> {
|
||||
pub scrut_ty: Ty<'tcx>,
|
||||
#[subdiagnostic]
|
||||
@@ -123,25 +140,29 @@ pub(crate) struct NonExhaustiveOmittedPattern<'tcx> {
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(pattern_analysis_non_exhaustive_omitted_pattern_lint_on_arm)]
|
||||
#[help]
|
||||
#[diag("the lint level must be set on the whole match")]
|
||||
#[help("it no longer has any effect to set the lint level on an individual match arm")]
|
||||
pub(crate) struct NonExhaustiveOmittedPatternLintOnArm {
|
||||
#[label]
|
||||
#[label("remove this attribute")]
|
||||
pub lint_span: Span,
|
||||
#[suggestion(code = "#[{lint_level}({lint_name})]\n", applicability = "maybe-incorrect")]
|
||||
#[suggestion(
|
||||
"set the lint level on the whole match",
|
||||
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(Diagnostic)]
|
||||
#[diag(pattern_analysis_mixed_deref_pattern_constructors)]
|
||||
#[diag("mix of deref patterns and normal constructors")]
|
||||
pub(crate) struct MixedDerefPatternConstructors<'tcx> {
|
||||
#[primary_span]
|
||||
pub spans: Vec<Span>,
|
||||
pub smart_pointer_ty: Ty<'tcx>,
|
||||
#[label(pattern_analysis_deref_pattern_label)]
|
||||
#[label("matches on the result of dereferencing `{$smart_pointer_ty}`")]
|
||||
pub deref_pattern_label: Span,
|
||||
#[label(pattern_analysis_normal_constructor_label)]
|
||||
#[label("matches directly on `{$smart_pointer_ty}`")]
|
||||
pub normal_constructor_label: Span,
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
pub mod rustc;
|
||||
pub mod usefulness;
|
||||
|
||||
#[cfg(feature = "rustc")]
|
||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
||||
|
||||
use std::fmt;
|
||||
|
||||
pub use rustc_index::{Idx, IndexVec}; // re-exported to avoid rustc_index version issues
|
||||
|
||||
Reference in New Issue
Block a user