|
1 | 1 | use rustc_errors::codes::*;
|
2 |
| -use rustc_errors::{Diag, LintDiagnostic}; |
| 2 | +use rustc_errors::{Applicability, Diag, EmissionGuarantee, LintDiagnostic, Subdiagnostic}; |
3 | 3 | use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
4 | 4 | use rustc_middle::mir::AssertKind;
|
5 | 5 | use rustc_middle::ty::TyCtxt;
|
@@ -125,6 +125,114 @@ pub(crate) struct MCDCExceedsTestVectorLimit {
|
125 | 125 | pub(crate) max_num_test_vectors: usize,
|
126 | 126 | }
|
127 | 127 |
|
| 128 | +#[derive(LintDiagnostic)] |
| 129 | +#[diag(mir_transform_unused_capture_maybe_capture_ref)] |
| 130 | +#[help] |
| 131 | +pub(crate) struct UnusedCaptureMaybeCaptureRef { |
| 132 | + pub name: String, |
| 133 | +} |
| 134 | + |
| 135 | +#[derive(LintDiagnostic)] |
| 136 | +#[diag(mir_transform_unused_var_assigned_only)] |
| 137 | +#[note] |
| 138 | +pub(crate) struct UnusedVarAssignedOnly { |
| 139 | + pub name: String, |
| 140 | +} |
| 141 | + |
| 142 | +#[derive(LintDiagnostic)] |
| 143 | +#[diag(mir_transform_unused_assign)] |
| 144 | +pub(crate) struct UnusedAssign { |
| 145 | + pub name: String, |
| 146 | + #[subdiagnostic] |
| 147 | + pub suggestion: Option<UnusedAssignSuggestion>, |
| 148 | + #[help] |
| 149 | + pub help: bool, |
| 150 | +} |
| 151 | + |
| 152 | +#[derive(Subdiagnostic)] |
| 153 | +#[multipart_suggestion(mir_transform_unused_assign_suggestion, applicability = "maybe-incorrect")] |
| 154 | +pub(crate) struct UnusedAssignSuggestion { |
| 155 | + pub pre: &'static str, |
| 156 | + #[suggestion_part(code = "{pre}mut ")] |
| 157 | + pub ty_span: Option<Span>, |
| 158 | + #[suggestion_part(code = "")] |
| 159 | + pub ty_ref_span: Span, |
| 160 | + #[suggestion_part(code = "*")] |
| 161 | + pub pre_lhs_span: Span, |
| 162 | + #[suggestion_part(code = "")] |
| 163 | + pub rhs_borrow_span: Span, |
| 164 | +} |
| 165 | + |
| 166 | +#[derive(LintDiagnostic)] |
| 167 | +#[diag(mir_transform_unused_assign_passed)] |
| 168 | +#[help] |
| 169 | +pub(crate) struct UnusedAssignPassed { |
| 170 | + pub name: String, |
| 171 | +} |
| 172 | + |
| 173 | +#[derive(LintDiagnostic)] |
| 174 | +#[diag(mir_transform_unused_variable)] |
| 175 | +pub(crate) struct UnusedVariable { |
| 176 | + pub name: String, |
| 177 | + #[subdiagnostic] |
| 178 | + pub string_interp: Vec<UnusedVariableStringInterp>, |
| 179 | + #[subdiagnostic] |
| 180 | + pub sugg: UnusedVariableSugg, |
| 181 | +} |
| 182 | + |
| 183 | +#[derive(Subdiagnostic)] |
| 184 | +pub(crate) enum UnusedVariableSugg { |
| 185 | + #[multipart_suggestion( |
| 186 | + mir_transform_unused_variable_try_ignore, |
| 187 | + applicability = "machine-applicable" |
| 188 | + )] |
| 189 | + TryIgnore { |
| 190 | + #[suggestion_part(code = "{name}: _")] |
| 191 | + shorthands: Vec<Span>, |
| 192 | + #[suggestion_part(code = "_")] |
| 193 | + non_shorthands: Vec<Span>, |
| 194 | + name: String, |
| 195 | + }, |
| 196 | + |
| 197 | + #[multipart_suggestion( |
| 198 | + mir_transform_unused_var_underscore, |
| 199 | + applicability = "machine-applicable" |
| 200 | + )] |
| 201 | + TryPrefix { |
| 202 | + #[suggestion_part(code = "_{name}")] |
| 203 | + spans: Vec<Span>, |
| 204 | + name: String, |
| 205 | + }, |
| 206 | + |
| 207 | + #[help(mir_transform_unused_variable_args_in_macro)] |
| 208 | + NoSugg { |
| 209 | + #[primary_span] |
| 210 | + span: Span, |
| 211 | + name: String, |
| 212 | + }, |
| 213 | +} |
| 214 | + |
| 215 | +pub(crate) struct UnusedVariableStringInterp { |
| 216 | + pub lit: Span, |
| 217 | +} |
| 218 | + |
| 219 | +impl Subdiagnostic for UnusedVariableStringInterp { |
| 220 | + fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) { |
| 221 | + diag.span_label( |
| 222 | + self.lit, |
| 223 | + crate::fluent_generated::mir_transform_maybe_string_interpolation, |
| 224 | + ); |
| 225 | + diag.multipart_suggestion( |
| 226 | + crate::fluent_generated::mir_transform_string_interpolation_only_works, |
| 227 | + vec![ |
| 228 | + (self.lit.shrink_to_lo(), String::from("format!(")), |
| 229 | + (self.lit.shrink_to_hi(), String::from(")")), |
| 230 | + ], |
| 231 | + Applicability::MachineApplicable, |
| 232 | + ); |
| 233 | + } |
| 234 | +} |
| 235 | + |
128 | 236 | pub(crate) struct MustNotSupend<'a, 'tcx> {
|
129 | 237 | pub tcx: TyCtxt<'tcx>,
|
130 | 238 | pub yield_sp: Span,
|
|
0 commit comments