|  | 
| 1 |  | -use rustc_data_structures::fx::FxIndexMap; | 
| 2 | 1 | use rustc_errors::codes::*; | 
| 3 | 2 | use rustc_errors::{ | 
| 4 | 3 |     Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, | 
| 5 |  | -    MultiSpan, Subdiagnostic, pluralize, | 
|  | 4 | +    MultiSpan, Subdiagnostic, | 
| 6 | 5 | }; | 
| 7 | 6 | use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; | 
| 8 | 7 | use rustc_middle::ty::{self, Ty}; | 
| @@ -1087,69 +1086,6 @@ pub(crate) enum MiscPatternSuggestion { | 
| 1087 | 1086 |     }, | 
| 1088 | 1087 | } | 
| 1089 | 1088 | 
 | 
| 1090 |  | -#[derive(LintDiagnostic)] | 
| 1091 |  | -#[diag(mir_build_rust_2024_incompatible_pat)] | 
| 1092 |  | -pub(crate) struct Rust2024IncompatiblePat { | 
| 1093 |  | -    #[subdiagnostic] | 
| 1094 |  | -    pub(crate) sugg: Rust2024IncompatiblePatSugg, | 
| 1095 |  | -    pub(crate) bad_modifiers: bool, | 
| 1096 |  | -    pub(crate) bad_ref_pats: bool, | 
| 1097 |  | -    pub(crate) is_hard_error: bool, | 
| 1098 |  | -} | 
| 1099 |  | - | 
| 1100 |  | -pub(crate) struct Rust2024IncompatiblePatSugg { | 
| 1101 |  | -    /// If true, our suggestion is to elide explicit binding modifiers. | 
| 1102 |  | -    /// If false, our suggestion is to make the pattern fully explicit. | 
| 1103 |  | -    pub(crate) suggest_eliding_modes: bool, | 
| 1104 |  | -    pub(crate) suggestion: Vec<(Span, String)>, | 
| 1105 |  | -    pub(crate) ref_pattern_count: usize, | 
| 1106 |  | -    pub(crate) binding_mode_count: usize, | 
| 1107 |  | -    /// Labels for where incompatibility-causing by-ref default binding modes were introduced. | 
| 1108 |  | -    pub(crate) default_mode_labels: FxIndexMap<Span, ty::Mutability>, | 
| 1109 |  | -} | 
| 1110 |  | - | 
| 1111 |  | -impl Subdiagnostic for Rust2024IncompatiblePatSugg { | 
| 1112 |  | -    fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) { | 
| 1113 |  | -        // Format and emit explanatory notes about default binding modes. Reversing the spans' order | 
| 1114 |  | -        // means if we have nested spans, the innermost ones will be visited first. | 
| 1115 |  | -        for (span, def_br_mutbl) in self.default_mode_labels.into_iter().rev() { | 
| 1116 |  | -            // Don't point to a macro call site. | 
| 1117 |  | -            if !span.from_expansion() { | 
| 1118 |  | -                let note_msg = "matching on a reference type with a non-reference pattern changes the default binding mode"; | 
| 1119 |  | -                let label_msg = | 
| 1120 |  | -                    format!("this matches on type `{}_`", def_br_mutbl.ref_prefix_str()); | 
| 1121 |  | -                let mut label = MultiSpan::from(span); | 
| 1122 |  | -                label.push_span_label(span, label_msg); | 
| 1123 |  | -                diag.span_note(label, note_msg); | 
| 1124 |  | -            } | 
| 1125 |  | -        } | 
| 1126 |  | - | 
| 1127 |  | -        // Format and emit the suggestion. | 
| 1128 |  | -        let applicability = | 
| 1129 |  | -            if self.suggestion.iter().all(|(span, _)| span.can_be_used_for_suggestions()) { | 
| 1130 |  | -                Applicability::MachineApplicable | 
| 1131 |  | -            } else { | 
| 1132 |  | -                Applicability::MaybeIncorrect | 
| 1133 |  | -            }; | 
| 1134 |  | -        let msg = if self.suggest_eliding_modes { | 
| 1135 |  | -            let plural_modes = pluralize!(self.binding_mode_count); | 
| 1136 |  | -            format!("remove the unnecessary binding modifier{plural_modes}") | 
| 1137 |  | -        } else { | 
| 1138 |  | -            let plural_derefs = pluralize!(self.ref_pattern_count); | 
| 1139 |  | -            let and_modes = if self.binding_mode_count > 0 { | 
| 1140 |  | -                format!(" and variable binding mode{}", pluralize!(self.binding_mode_count)) | 
| 1141 |  | -            } else { | 
| 1142 |  | -                String::new() | 
| 1143 |  | -            }; | 
| 1144 |  | -            format!("make the implied reference pattern{plural_derefs}{and_modes} explicit") | 
| 1145 |  | -        }; | 
| 1146 |  | -        // FIXME(dianne): for peace of mind, don't risk emitting a 0-part suggestion (that panics!) | 
| 1147 |  | -        if !self.suggestion.is_empty() { | 
| 1148 |  | -            diag.multipart_suggestion_verbose(msg, self.suggestion, applicability); | 
| 1149 |  | -        } | 
| 1150 |  | -    } | 
| 1151 |  | -} | 
| 1152 |  | - | 
| 1153 | 1089 | #[derive(Diagnostic)] | 
| 1154 | 1090 | #[diag(mir_build_loop_match_invalid_update)] | 
| 1155 | 1091 | pub(crate) struct LoopMatchInvalidUpdate { | 
|  | 
0 commit comments