|
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::query::Key;
|
@@ -158,6 +158,114 @@ pub(crate) struct FnItemRef {
|
158 | 158 | pub ident: Ident,
|
159 | 159 | }
|
160 | 160 |
|
| 161 | +#[derive(LintDiagnostic)] |
| 162 | +#[diag(mir_transform_unused_capture_maybe_capture_ref)] |
| 163 | +#[help] |
| 164 | +pub(crate) struct UnusedCaptureMaybeCaptureRef { |
| 165 | + pub name: Symbol, |
| 166 | +} |
| 167 | + |
| 168 | +#[derive(LintDiagnostic)] |
| 169 | +#[diag(mir_transform_unused_var_assigned_only)] |
| 170 | +#[note] |
| 171 | +pub(crate) struct UnusedVarAssignedOnly { |
| 172 | + pub name: Symbol, |
| 173 | +} |
| 174 | + |
| 175 | +#[derive(LintDiagnostic)] |
| 176 | +#[diag(mir_transform_unused_assign)] |
| 177 | +pub(crate) struct UnusedAssign { |
| 178 | + pub name: Symbol, |
| 179 | + #[subdiagnostic] |
| 180 | + pub suggestion: Option<UnusedAssignSuggestion>, |
| 181 | + #[help] |
| 182 | + pub help: bool, |
| 183 | +} |
| 184 | + |
| 185 | +#[derive(Subdiagnostic)] |
| 186 | +#[multipart_suggestion(mir_transform_unused_assign_suggestion, applicability = "maybe-incorrect")] |
| 187 | +pub(crate) struct UnusedAssignSuggestion { |
| 188 | + pub pre: &'static str, |
| 189 | + #[suggestion_part(code = "{pre}mut ")] |
| 190 | + pub ty_span: Option<Span>, |
| 191 | + #[suggestion_part(code = "")] |
| 192 | + pub ty_ref_span: Span, |
| 193 | + #[suggestion_part(code = "*")] |
| 194 | + pub pre_lhs_span: Span, |
| 195 | + #[suggestion_part(code = "")] |
| 196 | + pub rhs_borrow_span: Span, |
| 197 | +} |
| 198 | + |
| 199 | +#[derive(LintDiagnostic)] |
| 200 | +#[diag(mir_transform_unused_assign_passed)] |
| 201 | +#[help] |
| 202 | +pub(crate) struct UnusedAssignPassed { |
| 203 | + pub name: Symbol, |
| 204 | +} |
| 205 | + |
| 206 | +#[derive(LintDiagnostic)] |
| 207 | +#[diag(mir_transform_unused_variable)] |
| 208 | +pub(crate) struct UnusedVariable { |
| 209 | + pub name: Symbol, |
| 210 | + #[subdiagnostic] |
| 211 | + pub string_interp: Vec<UnusedVariableStringInterp>, |
| 212 | + #[subdiagnostic] |
| 213 | + pub sugg: UnusedVariableSugg, |
| 214 | +} |
| 215 | + |
| 216 | +#[derive(Subdiagnostic)] |
| 217 | +pub(crate) enum UnusedVariableSugg { |
| 218 | + #[multipart_suggestion( |
| 219 | + mir_transform_unused_variable_try_ignore, |
| 220 | + applicability = "machine-applicable" |
| 221 | + )] |
| 222 | + TryIgnore { |
| 223 | + #[suggestion_part(code = "{name}: _")] |
| 224 | + shorthands: Vec<Span>, |
| 225 | + #[suggestion_part(code = "_")] |
| 226 | + non_shorthands: Vec<Span>, |
| 227 | + name: Symbol, |
| 228 | + }, |
| 229 | + |
| 230 | + #[multipart_suggestion( |
| 231 | + mir_transform_unused_var_underscore, |
| 232 | + applicability = "machine-applicable" |
| 233 | + )] |
| 234 | + TryPrefix { |
| 235 | + #[suggestion_part(code = "_{name}")] |
| 236 | + spans: Vec<Span>, |
| 237 | + name: Symbol, |
| 238 | + }, |
| 239 | + |
| 240 | + #[help(mir_transform_unused_variable_args_in_macro)] |
| 241 | + NoSugg { |
| 242 | + #[primary_span] |
| 243 | + span: Span, |
| 244 | + name: Symbol, |
| 245 | + }, |
| 246 | +} |
| 247 | + |
| 248 | +pub(crate) struct UnusedVariableStringInterp { |
| 249 | + pub lit: Span, |
| 250 | +} |
| 251 | + |
| 252 | +impl Subdiagnostic for UnusedVariableStringInterp { |
| 253 | + fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) { |
| 254 | + diag.span_label( |
| 255 | + self.lit, |
| 256 | + crate::fluent_generated::mir_transform_maybe_string_interpolation, |
| 257 | + ); |
| 258 | + diag.multipart_suggestion( |
| 259 | + crate::fluent_generated::mir_transform_string_interpolation_only_works, |
| 260 | + vec![ |
| 261 | + (self.lit.shrink_to_lo(), String::from("format!(")), |
| 262 | + (self.lit.shrink_to_hi(), String::from(")")), |
| 263 | + ], |
| 264 | + Applicability::MachineApplicable, |
| 265 | + ); |
| 266 | + } |
| 267 | +} |
| 268 | + |
161 | 269 | pub(crate) struct MustNotSupend<'a, 'tcx> {
|
162 | 270 | pub tcx: TyCtxt<'tcx>,
|
163 | 271 | pub yield_sp: Span,
|
|
0 commit comments