|
1 |
| -use rustc_errors::{codes::*, Diag, DiagMessage, LintDiagnostic}; |
| 1 | +use rustc_errors::{ |
| 2 | + codes::*, Applicability, Diag, DiagMessage, EmissionGuarantee, LintDiagnostic, |
| 3 | + SubdiagMessageOp, Subdiagnostic, |
| 4 | +}; |
2 | 5 | use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
3 | 6 | use rustc_middle::mir::AssertKind;
|
4 | 7 | use rustc_middle::ty::TyCtxt;
|
@@ -91,6 +94,101 @@ pub(crate) struct FnItemRef {
|
91 | 94 | pub ident: String,
|
92 | 95 | }
|
93 | 96 |
|
| 97 | +#[derive(LintDiagnostic)] |
| 98 | +#[diag(mir_transform_unused_capture_maybe_capture_ref)] |
| 99 | +#[help] |
| 100 | +pub(crate) struct UnusedCaptureMaybeCaptureRef { |
| 101 | + pub name: String, |
| 102 | +} |
| 103 | + |
| 104 | +#[derive(LintDiagnostic)] |
| 105 | +#[diag(mir_transform_unused_var_assigned_only)] |
| 106 | +#[note] |
| 107 | +pub(crate) struct UnusedVarAssignedOnly { |
| 108 | + pub name: String, |
| 109 | +} |
| 110 | + |
| 111 | +#[derive(LintDiagnostic)] |
| 112 | +#[diag(mir_transform_unused_assign)] |
| 113 | +#[help] |
| 114 | +pub(crate) struct UnusedAssign { |
| 115 | + pub name: String, |
| 116 | +} |
| 117 | + |
| 118 | +#[derive(LintDiagnostic)] |
| 119 | +#[diag(mir_transform_unused_assign_passed)] |
| 120 | +#[help] |
| 121 | +pub(crate) struct UnusedAssignPassed { |
| 122 | + pub name: String, |
| 123 | +} |
| 124 | + |
| 125 | +#[derive(LintDiagnostic)] |
| 126 | +#[diag(mir_transform_unused_variable)] |
| 127 | +pub(crate) struct UnusedVariable { |
| 128 | + pub name: String, |
| 129 | + #[subdiagnostic] |
| 130 | + pub string_interp: Vec<UnusedVariableStringInterp>, |
| 131 | + #[subdiagnostic] |
| 132 | + pub sugg: UnusedVariableSugg, |
| 133 | +} |
| 134 | + |
| 135 | +#[derive(Subdiagnostic)] |
| 136 | +pub(crate) enum UnusedVariableSugg { |
| 137 | + #[multipart_suggestion( |
| 138 | + mir_transform_unused_variable_try_ignore, |
| 139 | + applicability = "machine-applicable" |
| 140 | + )] |
| 141 | + TryIgnore { |
| 142 | + #[suggestion_part(code = "{name}: _")] |
| 143 | + shorthands: Vec<Span>, |
| 144 | + #[suggestion_part(code = "_")] |
| 145 | + non_shorthands: Vec<Span>, |
| 146 | + name: String, |
| 147 | + }, |
| 148 | + |
| 149 | + #[multipart_suggestion( |
| 150 | + mir_transform_unused_var_underscore, |
| 151 | + applicability = "machine-applicable" |
| 152 | + )] |
| 153 | + TryPrefix { |
| 154 | + #[suggestion_part(code = "_{name}")] |
| 155 | + spans: Vec<Span>, |
| 156 | + name: String, |
| 157 | + }, |
| 158 | + |
| 159 | + #[help(mir_transform_unused_variable_args_in_macro)] |
| 160 | + NoSugg { |
| 161 | + #[primary_span] |
| 162 | + span: Span, |
| 163 | + name: String, |
| 164 | + }, |
| 165 | +} |
| 166 | + |
| 167 | +pub(crate) struct UnusedVariableStringInterp { |
| 168 | + pub lit: Span, |
| 169 | +} |
| 170 | + |
| 171 | +impl Subdiagnostic for UnusedVariableStringInterp { |
| 172 | + fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>( |
| 173 | + self, |
| 174 | + diag: &mut Diag<'_, G>, |
| 175 | + _: F, |
| 176 | + ) { |
| 177 | + diag.span_label( |
| 178 | + self.lit, |
| 179 | + crate::fluent_generated::mir_transform_maybe_string_interpolation, |
| 180 | + ); |
| 181 | + diag.multipart_suggestion( |
| 182 | + crate::fluent_generated::mir_transform_string_interpolation_only_works, |
| 183 | + vec![ |
| 184 | + (self.lit.shrink_to_lo(), String::from("format!(")), |
| 185 | + (self.lit.shrink_to_hi(), String::from(")")), |
| 186 | + ], |
| 187 | + Applicability::MachineApplicable, |
| 188 | + ); |
| 189 | + } |
| 190 | +} |
| 191 | + |
94 | 192 | pub(crate) struct MustNotSupend<'tcx, 'a> {
|
95 | 193 | pub tcx: TyCtxt<'tcx>,
|
96 | 194 | pub yield_sp: Span,
|
|
0 commit comments