]>
Commit | Line | Data |
---|---|---|
9c376795 FG |
1 | #![allow(rustc::untranslatable_diagnostic)] |
2 | #![allow(rustc::diagnostic_outside_of_impl)] | |
3 | use std::num::NonZeroU32; | |
4 | ||
9ffffee4 | 5 | use crate::fluent_generated as fluent; |
9c376795 | 6 | use rustc_errors::{ |
9ffffee4 FG |
7 | AddToDiagnostic, Applicability, DecorateLint, DiagnosticMessage, DiagnosticStyledString, |
8 | SuggestionStyle, | |
9c376795 FG |
9 | }; |
10 | use rustc_hir::def_id::DefId; | |
11 | use rustc_macros::{LintDiagnostic, Subdiagnostic}; | |
9ffffee4 FG |
12 | use rustc_middle::ty::{ |
13 | inhabitedness::InhabitedPredicate, PolyExistentialTraitRef, Predicate, Ty, TyCtxt, | |
14 | }; | |
9c376795 FG |
15 | use rustc_session::parse::ParseSess; |
16 | use rustc_span::{edition::Edition, sym, symbol::Ident, Span, Symbol}; | |
17 | ||
18 | use crate::{ | |
19 | builtin::InitError, builtin::TypeAliasBounds, errors::OverruledAttributeSub, LateContext, | |
20 | }; | |
21 | ||
22 | // array_into_iter.rs | |
23 | #[derive(LintDiagnostic)] | |
24 | #[diag(lint_array_into_iter)] | |
25 | pub struct ArrayIntoIterDiag<'a> { | |
26 | pub target: &'a str, | |
9ffffee4 | 27 | #[suggestion(lint_use_iter_suggestion, code = "iter", applicability = "machine-applicable")] |
9c376795 FG |
28 | pub suggestion: Span, |
29 | #[subdiagnostic] | |
30 | pub sub: Option<ArrayIntoIterDiagSub>, | |
31 | } | |
32 | ||
33 | #[derive(Subdiagnostic)] | |
34 | pub enum ArrayIntoIterDiagSub { | |
9ffffee4 | 35 | #[suggestion(lint_remove_into_iter_suggestion, code = "", applicability = "maybe-incorrect")] |
9c376795 FG |
36 | RemoveIntoIter { |
37 | #[primary_span] | |
38 | span: Span, | |
39 | }, | |
9ffffee4 FG |
40 | #[multipart_suggestion( |
41 | lint_use_explicit_into_iter_suggestion, | |
42 | applicability = "maybe-incorrect" | |
43 | )] | |
9c376795 FG |
44 | UseExplicitIntoIter { |
45 | #[suggestion_part(code = "IntoIterator::into_iter(")] | |
46 | start_span: Span, | |
47 | #[suggestion_part(code = ")")] | |
48 | end_span: Span, | |
49 | }, | |
50 | } | |
51 | ||
52 | // builtin.rs | |
53 | #[derive(LintDiagnostic)] | |
54 | #[diag(lint_builtin_while_true)] | |
55 | pub struct BuiltinWhileTrue { | |
56 | #[suggestion(style = "short", code = "{replace}", applicability = "machine-applicable")] | |
57 | pub suggestion: Span, | |
58 | pub replace: String, | |
59 | } | |
60 | ||
61 | #[derive(LintDiagnostic)] | |
62 | #[diag(lint_builtin_box_pointers)] | |
63 | pub struct BuiltinBoxPointers<'a> { | |
64 | pub ty: Ty<'a>, | |
65 | } | |
66 | ||
67 | #[derive(LintDiagnostic)] | |
68 | #[diag(lint_builtin_non_shorthand_field_patterns)] | |
69 | pub struct BuiltinNonShorthandFieldPatterns { | |
70 | pub ident: Ident, | |
71 | #[suggestion(code = "{prefix}{ident}", applicability = "machine-applicable")] | |
72 | pub suggestion: Span, | |
73 | pub prefix: &'static str, | |
74 | } | |
75 | ||
76 | #[derive(LintDiagnostic)] | |
77 | pub enum BuiltinUnsafe { | |
78 | #[diag(lint_builtin_allow_internal_unsafe)] | |
79 | AllowInternalUnsafe, | |
80 | #[diag(lint_builtin_unsafe_block)] | |
81 | UnsafeBlock, | |
82 | #[diag(lint_builtin_unsafe_trait)] | |
83 | UnsafeTrait, | |
84 | #[diag(lint_builtin_unsafe_impl)] | |
85 | UnsafeImpl, | |
86 | #[diag(lint_builtin_no_mangle_fn)] | |
87 | #[note(lint_builtin_overridden_symbol_name)] | |
88 | NoMangleFn, | |
89 | #[diag(lint_builtin_export_name_fn)] | |
90 | #[note(lint_builtin_overridden_symbol_name)] | |
91 | ExportNameFn, | |
92 | #[diag(lint_builtin_link_section_fn)] | |
93 | #[note(lint_builtin_overridden_symbol_section)] | |
94 | LinkSectionFn, | |
95 | #[diag(lint_builtin_no_mangle_static)] | |
96 | #[note(lint_builtin_overridden_symbol_name)] | |
97 | NoMangleStatic, | |
98 | #[diag(lint_builtin_export_name_static)] | |
99 | #[note(lint_builtin_overridden_symbol_name)] | |
100 | ExportNameStatic, | |
101 | #[diag(lint_builtin_link_section_static)] | |
102 | #[note(lint_builtin_overridden_symbol_section)] | |
103 | LinkSectionStatic, | |
104 | #[diag(lint_builtin_no_mangle_method)] | |
105 | #[note(lint_builtin_overridden_symbol_name)] | |
106 | NoMangleMethod, | |
107 | #[diag(lint_builtin_export_name_method)] | |
108 | #[note(lint_builtin_overridden_symbol_name)] | |
109 | ExportNameMethod, | |
110 | #[diag(lint_builtin_decl_unsafe_fn)] | |
111 | DeclUnsafeFn, | |
112 | #[diag(lint_builtin_decl_unsafe_method)] | |
113 | DeclUnsafeMethod, | |
114 | #[diag(lint_builtin_impl_unsafe_method)] | |
115 | ImplUnsafeMethod, | |
116 | } | |
117 | ||
118 | #[derive(LintDiagnostic)] | |
119 | #[diag(lint_builtin_missing_doc)] | |
120 | pub struct BuiltinMissingDoc<'a> { | |
121 | pub article: &'a str, | |
122 | pub desc: &'a str, | |
123 | } | |
124 | ||
125 | #[derive(LintDiagnostic)] | |
126 | #[diag(lint_builtin_missing_copy_impl)] | |
127 | pub struct BuiltinMissingCopyImpl; | |
128 | ||
129 | pub struct BuiltinMissingDebugImpl<'a> { | |
130 | pub tcx: TyCtxt<'a>, | |
131 | pub def_id: DefId, | |
132 | } | |
133 | ||
134 | // Needed for def_path_str | |
135 | impl<'a> DecorateLint<'a, ()> for BuiltinMissingDebugImpl<'_> { | |
136 | fn decorate_lint<'b>( | |
137 | self, | |
138 | diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, | |
139 | ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { | |
140 | diag.set_arg("debug", self.tcx.def_path_str(self.def_id)); | |
141 | diag | |
142 | } | |
143 | ||
144 | fn msg(&self) -> DiagnosticMessage { | |
145 | fluent::lint_builtin_missing_debug_impl | |
146 | } | |
147 | } | |
148 | ||
149 | #[derive(LintDiagnostic)] | |
150 | #[diag(lint_builtin_anonymous_params)] | |
151 | pub struct BuiltinAnonymousParams<'a> { | |
152 | #[suggestion(code = "_: {ty_snip}")] | |
153 | pub suggestion: (Span, Applicability), | |
154 | pub ty_snip: &'a str, | |
155 | } | |
156 | ||
157 | // FIXME(davidtwco) translatable deprecated attr | |
158 | #[derive(LintDiagnostic)] | |
159 | #[diag(lint_builtin_deprecated_attr_link)] | |
160 | pub struct BuiltinDeprecatedAttrLink<'a> { | |
161 | pub name: Symbol, | |
162 | pub reason: &'a str, | |
163 | pub link: &'a str, | |
164 | #[subdiagnostic] | |
165 | pub suggestion: BuiltinDeprecatedAttrLinkSuggestion<'a>, | |
166 | } | |
167 | ||
168 | #[derive(Subdiagnostic)] | |
169 | pub enum BuiltinDeprecatedAttrLinkSuggestion<'a> { | |
9ffffee4 | 170 | #[suggestion(lint_msg_suggestion, code = "", applicability = "machine-applicable")] |
9c376795 FG |
171 | Msg { |
172 | #[primary_span] | |
173 | suggestion: Span, | |
174 | msg: &'a str, | |
175 | }, | |
9ffffee4 | 176 | #[suggestion(lint_default_suggestion, code = "", applicability = "machine-applicable")] |
9c376795 FG |
177 | Default { |
178 | #[primary_span] | |
179 | suggestion: Span, | |
180 | }, | |
181 | } | |
182 | ||
183 | #[derive(LintDiagnostic)] | |
184 | #[diag(lint_builtin_deprecated_attr_used)] | |
185 | pub struct BuiltinDeprecatedAttrUsed { | |
186 | pub name: String, | |
187 | #[suggestion( | |
188 | lint_builtin_deprecated_attr_default_suggestion, | |
189 | style = "short", | |
190 | code = "", | |
191 | applicability = "machine-applicable" | |
192 | )] | |
193 | pub suggestion: Span, | |
194 | } | |
195 | ||
196 | #[derive(LintDiagnostic)] | |
197 | #[diag(lint_builtin_unused_doc_comment)] | |
198 | pub struct BuiltinUnusedDocComment<'a> { | |
199 | pub kind: &'a str, | |
200 | #[label] | |
201 | pub label: Span, | |
202 | #[subdiagnostic] | |
203 | pub sub: BuiltinUnusedDocCommentSub, | |
204 | } | |
205 | ||
206 | #[derive(Subdiagnostic)] | |
207 | pub enum BuiltinUnusedDocCommentSub { | |
9ffffee4 | 208 | #[help(lint_plain_help)] |
9c376795 | 209 | PlainHelp, |
9ffffee4 | 210 | #[help(lint_block_help)] |
9c376795 FG |
211 | BlockHelp, |
212 | } | |
213 | ||
214 | #[derive(LintDiagnostic)] | |
215 | #[diag(lint_builtin_no_mangle_generic)] | |
216 | pub struct BuiltinNoMangleGeneric { | |
217 | // Use of `#[no_mangle]` suggests FFI intent; correct | |
218 | // fix may be to monomorphize source by hand | |
219 | #[suggestion(style = "short", code = "", applicability = "maybe-incorrect")] | |
220 | pub suggestion: Span, | |
221 | } | |
222 | ||
223 | #[derive(LintDiagnostic)] | |
224 | #[diag(lint_builtin_const_no_mangle)] | |
225 | pub struct BuiltinConstNoMangle { | |
226 | #[suggestion(code = "pub static", applicability = "machine-applicable")] | |
227 | pub suggestion: Span, | |
228 | } | |
229 | ||
230 | #[derive(LintDiagnostic)] | |
231 | #[diag(lint_builtin_mutable_transmutes)] | |
232 | pub struct BuiltinMutablesTransmutes; | |
233 | ||
234 | #[derive(LintDiagnostic)] | |
235 | #[diag(lint_builtin_unstable_features)] | |
236 | pub struct BuiltinUnstableFeatures; | |
237 | ||
238 | // lint_ungated_async_fn_track_caller | |
239 | pub struct BuiltinUngatedAsyncFnTrackCaller<'a> { | |
240 | pub label: Span, | |
241 | pub parse_sess: &'a ParseSess, | |
242 | } | |
243 | ||
244 | impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> { | |
245 | fn decorate_lint<'b>( | |
246 | self, | |
247 | diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, | |
248 | ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { | |
9ffffee4 | 249 | diag.span_label(self.label, fluent::lint_label); |
9c376795 FG |
250 | rustc_session::parse::add_feature_diagnostics( |
251 | diag, | |
252 | &self.parse_sess, | |
253 | sym::closure_track_caller, | |
254 | ); | |
255 | diag | |
256 | } | |
257 | ||
258 | fn msg(&self) -> DiagnosticMessage { | |
259 | fluent::lint_ungated_async_fn_track_caller | |
260 | } | |
261 | } | |
262 | ||
263 | #[derive(LintDiagnostic)] | |
264 | #[diag(lint_builtin_unreachable_pub)] | |
265 | pub struct BuiltinUnreachablePub<'a> { | |
266 | pub what: &'a str, | |
267 | #[suggestion(code = "pub(crate)")] | |
268 | pub suggestion: (Span, Applicability), | |
269 | #[help] | |
270 | pub help: Option<()>, | |
271 | } | |
272 | ||
273 | pub struct SuggestChangingAssocTypes<'a, 'b> { | |
274 | pub ty: &'a rustc_hir::Ty<'b>, | |
275 | } | |
276 | ||
277 | impl AddToDiagnostic for SuggestChangingAssocTypes<'_, '_> { | |
278 | fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F) | |
279 | where | |
280 | F: Fn( | |
281 | &mut rustc_errors::Diagnostic, | |
282 | rustc_errors::SubdiagnosticMessage, | |
283 | ) -> rustc_errors::SubdiagnosticMessage, | |
284 | { | |
285 | // Access to associates types should use `<T as Bound>::Assoc`, which does not need a | |
286 | // bound. Let's see if this type does that. | |
287 | ||
288 | // We use a HIR visitor to walk the type. | |
289 | use rustc_hir::intravisit::{self, Visitor}; | |
290 | struct WalkAssocTypes<'a> { | |
291 | err: &'a mut rustc_errors::Diagnostic, | |
292 | } | |
293 | impl Visitor<'_> for WalkAssocTypes<'_> { | |
294 | fn visit_qpath( | |
295 | &mut self, | |
296 | qpath: &rustc_hir::QPath<'_>, | |
297 | id: rustc_hir::HirId, | |
298 | span: Span, | |
299 | ) { | |
300 | if TypeAliasBounds::is_type_variable_assoc(qpath) { | |
301 | self.err.span_help(span, fluent::lint_builtin_type_alias_bounds_help); | |
302 | } | |
303 | intravisit::walk_qpath(self, qpath, id) | |
304 | } | |
305 | } | |
306 | ||
307 | // Let's go for a walk! | |
308 | let mut visitor = WalkAssocTypes { err: diag }; | |
309 | visitor.visit_ty(self.ty); | |
310 | } | |
311 | } | |
312 | ||
313 | #[derive(LintDiagnostic)] | |
314 | #[diag(lint_builtin_type_alias_where_clause)] | |
315 | pub struct BuiltinTypeAliasWhereClause<'a, 'b> { | |
316 | #[suggestion(code = "", applicability = "machine-applicable")] | |
317 | pub suggestion: Span, | |
318 | #[subdiagnostic] | |
319 | pub sub: Option<SuggestChangingAssocTypes<'a, 'b>>, | |
320 | } | |
321 | ||
322 | #[derive(LintDiagnostic)] | |
323 | #[diag(lint_builtin_type_alias_generic_bounds)] | |
324 | pub struct BuiltinTypeAliasGenericBounds<'a, 'b> { | |
325 | #[subdiagnostic] | |
326 | pub suggestion: BuiltinTypeAliasGenericBoundsSuggestion, | |
327 | #[subdiagnostic] | |
328 | pub sub: Option<SuggestChangingAssocTypes<'a, 'b>>, | |
329 | } | |
330 | ||
331 | pub struct BuiltinTypeAliasGenericBoundsSuggestion { | |
332 | pub suggestions: Vec<(Span, String)>, | |
333 | } | |
334 | ||
335 | impl AddToDiagnostic for BuiltinTypeAliasGenericBoundsSuggestion { | |
336 | fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F) | |
337 | where | |
338 | F: Fn( | |
339 | &mut rustc_errors::Diagnostic, | |
340 | rustc_errors::SubdiagnosticMessage, | |
341 | ) -> rustc_errors::SubdiagnosticMessage, | |
342 | { | |
343 | diag.multipart_suggestion( | |
9ffffee4 | 344 | fluent::lint_suggestion, |
9c376795 FG |
345 | self.suggestions, |
346 | Applicability::MachineApplicable, | |
347 | ); | |
348 | } | |
349 | } | |
350 | ||
351 | #[derive(LintDiagnostic)] | |
352 | #[diag(lint_builtin_trivial_bounds)] | |
353 | pub struct BuiltinTrivialBounds<'a> { | |
354 | pub predicate_kind_name: &'a str, | |
355 | pub predicate: Predicate<'a>, | |
356 | } | |
357 | ||
358 | #[derive(LintDiagnostic)] | |
359 | pub enum BuiltinEllipsisInclusiveRangePatternsLint { | |
360 | #[diag(lint_builtin_ellipsis_inclusive_range_patterns)] | |
361 | Parenthesise { | |
362 | #[suggestion(code = "{replace}", applicability = "machine-applicable")] | |
363 | suggestion: Span, | |
364 | replace: String, | |
365 | }, | |
366 | #[diag(lint_builtin_ellipsis_inclusive_range_patterns)] | |
367 | NonParenthesise { | |
368 | #[suggestion(style = "short", code = "..=", applicability = "machine-applicable")] | |
369 | suggestion: Span, | |
370 | }, | |
371 | } | |
372 | ||
373 | #[derive(LintDiagnostic)] | |
374 | #[diag(lint_builtin_unnameable_test_items)] | |
375 | pub struct BuiltinUnnameableTestItems; | |
376 | ||
377 | #[derive(LintDiagnostic)] | |
378 | #[diag(lint_builtin_keyword_idents)] | |
379 | pub struct BuiltinKeywordIdents { | |
380 | pub kw: Ident, | |
381 | pub next: Edition, | |
382 | #[suggestion(code = "r#{kw}", applicability = "machine-applicable")] | |
383 | pub suggestion: Span, | |
384 | } | |
385 | ||
386 | #[derive(LintDiagnostic)] | |
387 | #[diag(lint_builtin_explicit_outlives)] | |
388 | pub struct BuiltinExplicitOutlives { | |
389 | pub count: usize, | |
390 | #[subdiagnostic] | |
391 | pub suggestion: BuiltinExplicitOutlivesSuggestion, | |
392 | } | |
393 | ||
394 | #[derive(Subdiagnostic)] | |
9ffffee4 | 395 | #[multipart_suggestion(lint_suggestion)] |
9c376795 FG |
396 | pub struct BuiltinExplicitOutlivesSuggestion { |
397 | #[suggestion_part(code = "")] | |
398 | pub spans: Vec<Span>, | |
399 | #[applicability] | |
400 | pub applicability: Applicability, | |
401 | } | |
402 | ||
403 | #[derive(LintDiagnostic)] | |
404 | #[diag(lint_builtin_incomplete_features)] | |
405 | pub struct BuiltinIncompleteFeatures { | |
406 | pub name: Symbol, | |
407 | #[subdiagnostic] | |
408 | pub note: Option<BuiltinIncompleteFeaturesNote>, | |
409 | #[subdiagnostic] | |
410 | pub help: Option<BuiltinIncompleteFeaturesHelp>, | |
411 | } | |
412 | ||
413 | #[derive(Subdiagnostic)] | |
9ffffee4 | 414 | #[help(lint_help)] |
9c376795 FG |
415 | pub struct BuiltinIncompleteFeaturesHelp; |
416 | ||
417 | #[derive(Subdiagnostic)] | |
9ffffee4 | 418 | #[note(lint_note)] |
9c376795 FG |
419 | pub struct BuiltinIncompleteFeaturesNote { |
420 | pub n: NonZeroU32, | |
421 | } | |
422 | ||
423 | pub struct BuiltinUnpermittedTypeInit<'a> { | |
424 | pub msg: DiagnosticMessage, | |
425 | pub ty: Ty<'a>, | |
426 | pub label: Span, | |
427 | pub sub: BuiltinUnpermittedTypeInitSub, | |
9ffffee4 | 428 | pub tcx: TyCtxt<'a>, |
9c376795 FG |
429 | } |
430 | ||
431 | impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> { | |
432 | fn decorate_lint<'b>( | |
433 | self, | |
434 | diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, | |
435 | ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { | |
436 | diag.set_arg("ty", self.ty); | |
437 | diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label); | |
9ffffee4 FG |
438 | if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) { |
439 | // Only suggest late `MaybeUninit::assume_init` initialization if the type is inhabited. | |
440 | diag.span_label( | |
441 | self.label, | |
442 | fluent::lint_builtin_unpermitted_type_init_label_suggestion, | |
443 | ); | |
444 | } | |
9c376795 FG |
445 | self.sub.add_to_diagnostic(diag); |
446 | diag | |
447 | } | |
448 | ||
449 | fn msg(&self) -> rustc_errors::DiagnosticMessage { | |
450 | self.msg.clone() | |
451 | } | |
452 | } | |
453 | ||
454 | // FIXME(davidtwco): make translatable | |
455 | pub struct BuiltinUnpermittedTypeInitSub { | |
456 | pub err: InitError, | |
457 | } | |
458 | ||
459 | impl AddToDiagnostic for BuiltinUnpermittedTypeInitSub { | |
460 | fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F) | |
461 | where | |
462 | F: Fn( | |
463 | &mut rustc_errors::Diagnostic, | |
464 | rustc_errors::SubdiagnosticMessage, | |
465 | ) -> rustc_errors::SubdiagnosticMessage, | |
466 | { | |
467 | let mut err = self.err; | |
468 | loop { | |
469 | if let Some(span) = err.span { | |
470 | diag.span_note(span, err.message); | |
471 | } else { | |
472 | diag.note(err.message); | |
473 | } | |
474 | if let Some(e) = err.nested { | |
475 | err = *e; | |
476 | } else { | |
477 | break; | |
478 | } | |
479 | } | |
480 | } | |
481 | } | |
482 | ||
483 | #[derive(LintDiagnostic)] | |
484 | pub enum BuiltinClashingExtern<'a> { | |
485 | #[diag(lint_builtin_clashing_extern_same_name)] | |
486 | SameName { | |
487 | this: Symbol, | |
488 | orig: Symbol, | |
9ffffee4 | 489 | #[label(lint_previous_decl_label)] |
9c376795 | 490 | previous_decl_label: Span, |
9ffffee4 | 491 | #[label(lint_mismatch_label)] |
9c376795 FG |
492 | mismatch_label: Span, |
493 | #[subdiagnostic] | |
494 | sub: BuiltinClashingExternSub<'a>, | |
495 | }, | |
496 | #[diag(lint_builtin_clashing_extern_diff_name)] | |
497 | DiffName { | |
498 | this: Symbol, | |
499 | orig: Symbol, | |
9ffffee4 | 500 | #[label(lint_previous_decl_label)] |
9c376795 | 501 | previous_decl_label: Span, |
9ffffee4 | 502 | #[label(lint_mismatch_label)] |
9c376795 FG |
503 | mismatch_label: Span, |
504 | #[subdiagnostic] | |
505 | sub: BuiltinClashingExternSub<'a>, | |
506 | }, | |
507 | } | |
508 | ||
509 | // FIXME(davidtwco): translatable expected/found | |
510 | pub struct BuiltinClashingExternSub<'a> { | |
511 | pub tcx: TyCtxt<'a>, | |
512 | pub expected: Ty<'a>, | |
513 | pub found: Ty<'a>, | |
514 | } | |
515 | ||
516 | impl AddToDiagnostic for BuiltinClashingExternSub<'_> { | |
517 | fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F) | |
518 | where | |
519 | F: Fn( | |
520 | &mut rustc_errors::Diagnostic, | |
521 | rustc_errors::SubdiagnosticMessage, | |
522 | ) -> rustc_errors::SubdiagnosticMessage, | |
523 | { | |
524 | let mut expected_str = DiagnosticStyledString::new(); | |
525 | expected_str.push(self.expected.fn_sig(self.tcx).to_string(), false); | |
526 | let mut found_str = DiagnosticStyledString::new(); | |
527 | found_str.push(self.found.fn_sig(self.tcx).to_string(), true); | |
528 | diag.note_expected_found(&"", expected_str, &"", found_str); | |
529 | } | |
530 | } | |
531 | ||
532 | #[derive(LintDiagnostic)] | |
533 | #[diag(lint_builtin_deref_nullptr)] | |
534 | pub struct BuiltinDerefNullptr { | |
535 | #[label] | |
536 | pub label: Span, | |
537 | } | |
538 | ||
539 | // FIXME: migrate fluent::lint::builtin_asm_labels | |
540 | ||
541 | #[derive(LintDiagnostic)] | |
542 | pub enum BuiltinSpecialModuleNameUsed { | |
543 | #[diag(lint_builtin_special_module_name_used_lib)] | |
544 | #[note] | |
545 | #[help] | |
546 | Lib, | |
547 | #[diag(lint_builtin_special_module_name_used_main)] | |
548 | #[note] | |
549 | Main, | |
550 | } | |
551 | ||
552 | #[derive(LintDiagnostic)] | |
553 | #[diag(lint_builtin_unexpected_cli_config_name)] | |
554 | #[help] | |
555 | pub struct BuiltinUnexpectedCliConfigName { | |
556 | pub name: Symbol, | |
557 | } | |
558 | ||
559 | #[derive(LintDiagnostic)] | |
560 | #[diag(lint_builtin_unexpected_cli_config_value)] | |
561 | #[help] | |
562 | pub struct BuiltinUnexpectedCliConfigValue { | |
563 | pub name: Symbol, | |
564 | pub value: Symbol, | |
565 | } | |
566 | ||
567 | // deref_into_dyn_supertrait.rs | |
568 | #[derive(LintDiagnostic)] | |
569 | #[diag(lint_supertrait_as_deref_target)] | |
570 | pub struct SupertraitAsDerefTarget<'a> { | |
571 | pub t: Ty<'a>, | |
572 | pub target_principal: PolyExistentialTraitRef<'a>, | |
573 | #[subdiagnostic] | |
574 | pub label: Option<SupertraitAsDerefTargetLabel>, | |
575 | } | |
576 | ||
577 | #[derive(Subdiagnostic)] | |
9ffffee4 | 578 | #[label(lint_label)] |
9c376795 FG |
579 | pub struct SupertraitAsDerefTargetLabel { |
580 | #[primary_span] | |
581 | pub label: Span, | |
582 | } | |
583 | ||
584 | // enum_intrinsics_non_enums.rs | |
585 | #[derive(LintDiagnostic)] | |
586 | #[diag(lint_enum_intrinsics_mem_discriminant)] | |
587 | pub struct EnumIntrinsicsMemDiscriminate<'a> { | |
588 | pub ty_param: Ty<'a>, | |
589 | #[note] | |
590 | pub note: Span, | |
591 | } | |
592 | ||
593 | #[derive(LintDiagnostic)] | |
594 | #[diag(lint_enum_intrinsics_mem_variant)] | |
595 | #[note] | |
596 | pub struct EnumIntrinsicsMemVariant<'a> { | |
597 | pub ty_param: Ty<'a>, | |
598 | } | |
599 | ||
600 | // expect.rs | |
601 | #[derive(LintDiagnostic)] | |
602 | #[diag(lint_expectation)] | |
603 | pub struct Expectation { | |
604 | #[subdiagnostic] | |
605 | pub rationale: Option<ExpectationNote>, | |
606 | #[note] | |
607 | pub note: Option<()>, | |
608 | } | |
609 | ||
610 | #[derive(Subdiagnostic)] | |
9ffffee4 | 611 | #[note(lint_rationale)] |
9c376795 FG |
612 | pub struct ExpectationNote { |
613 | pub rationale: Symbol, | |
614 | } | |
615 | ||
616 | // for_loops_over_fallibles.rs | |
617 | #[derive(LintDiagnostic)] | |
618 | #[diag(lint_for_loops_over_fallibles)] | |
619 | pub struct ForLoopsOverFalliblesDiag<'a> { | |
620 | pub article: &'static str, | |
621 | pub ty: &'static str, | |
622 | #[subdiagnostic] | |
623 | pub sub: ForLoopsOverFalliblesLoopSub<'a>, | |
624 | #[subdiagnostic] | |
625 | pub question_mark: Option<ForLoopsOverFalliblesQuestionMark>, | |
626 | #[subdiagnostic] | |
627 | pub suggestion: ForLoopsOverFalliblesSuggestion<'a>, | |
628 | } | |
629 | ||
630 | #[derive(Subdiagnostic)] | |
631 | pub enum ForLoopsOverFalliblesLoopSub<'a> { | |
9ffffee4 | 632 | #[suggestion(lint_remove_next, code = ".by_ref()", applicability = "maybe-incorrect")] |
9c376795 FG |
633 | RemoveNext { |
634 | #[primary_span] | |
635 | suggestion: Span, | |
636 | recv_snip: String, | |
637 | }, | |
9ffffee4 | 638 | #[multipart_suggestion(lint_use_while_let, applicability = "maybe-incorrect")] |
9c376795 FG |
639 | UseWhileLet { |
640 | #[suggestion_part(code = "while let {var}(")] | |
641 | start_span: Span, | |
642 | #[suggestion_part(code = ") = ")] | |
643 | end_span: Span, | |
644 | var: &'a str, | |
645 | }, | |
646 | } | |
647 | ||
648 | #[derive(Subdiagnostic)] | |
9ffffee4 | 649 | #[suggestion(lint_use_question_mark, code = "?", applicability = "maybe-incorrect")] |
9c376795 FG |
650 | pub struct ForLoopsOverFalliblesQuestionMark { |
651 | #[primary_span] | |
652 | pub suggestion: Span, | |
653 | } | |
654 | ||
655 | #[derive(Subdiagnostic)] | |
9ffffee4 | 656 | #[multipart_suggestion(lint_suggestion, applicability = "maybe-incorrect")] |
9c376795 FG |
657 | pub struct ForLoopsOverFalliblesSuggestion<'a> { |
658 | pub var: &'a str, | |
659 | #[suggestion_part(code = "if let {var}(")] | |
660 | pub start_span: Span, | |
661 | #[suggestion_part(code = ") = ")] | |
662 | pub end_span: Span, | |
663 | } | |
664 | ||
665 | // hidden_unicode_codepoints.rs | |
666 | #[derive(LintDiagnostic)] | |
667 | #[diag(lint_hidden_unicode_codepoints)] | |
668 | #[note] | |
669 | pub struct HiddenUnicodeCodepointsDiag<'a> { | |
670 | pub label: &'a str, | |
671 | pub count: usize, | |
672 | #[label] | |
673 | pub span_label: Span, | |
674 | #[subdiagnostic] | |
675 | pub labels: Option<HiddenUnicodeCodepointsDiagLabels>, | |
676 | #[subdiagnostic] | |
677 | pub sub: HiddenUnicodeCodepointsDiagSub, | |
678 | } | |
679 | ||
680 | pub struct HiddenUnicodeCodepointsDiagLabels { | |
681 | pub spans: Vec<(char, Span)>, | |
682 | } | |
683 | ||
684 | impl AddToDiagnostic for HiddenUnicodeCodepointsDiagLabels { | |
685 | fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F) | |
686 | where | |
687 | F: Fn( | |
688 | &mut rustc_errors::Diagnostic, | |
689 | rustc_errors::SubdiagnosticMessage, | |
690 | ) -> rustc_errors::SubdiagnosticMessage, | |
691 | { | |
692 | for (c, span) in self.spans { | |
693 | diag.span_label(span, format!("{:?}", c)); | |
694 | } | |
695 | } | |
696 | } | |
697 | ||
698 | pub enum HiddenUnicodeCodepointsDiagSub { | |
699 | Escape { spans: Vec<(char, Span)> }, | |
700 | NoEscape { spans: Vec<(char, Span)> }, | |
701 | } | |
702 | ||
703 | // Used because of multiple multipart_suggestion and note | |
704 | impl AddToDiagnostic for HiddenUnicodeCodepointsDiagSub { | |
705 | fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F) | |
706 | where | |
707 | F: Fn( | |
708 | &mut rustc_errors::Diagnostic, | |
709 | rustc_errors::SubdiagnosticMessage, | |
710 | ) -> rustc_errors::SubdiagnosticMessage, | |
711 | { | |
712 | match self { | |
713 | HiddenUnicodeCodepointsDiagSub::Escape { spans } => { | |
714 | diag.multipart_suggestion_with_style( | |
9ffffee4 | 715 | fluent::lint_suggestion_remove, |
9c376795 FG |
716 | spans.iter().map(|(_, span)| (*span, "".to_string())).collect(), |
717 | Applicability::MachineApplicable, | |
718 | SuggestionStyle::HideCodeAlways, | |
719 | ); | |
720 | diag.multipart_suggestion( | |
9ffffee4 | 721 | fluent::lint_suggestion_escape, |
9c376795 FG |
722 | spans |
723 | .into_iter() | |
724 | .map(|(c, span)| { | |
725 | let c = format!("{:?}", c); | |
726 | (span, c[1..c.len() - 1].to_string()) | |
727 | }) | |
728 | .collect(), | |
729 | Applicability::MachineApplicable, | |
730 | ); | |
731 | } | |
732 | HiddenUnicodeCodepointsDiagSub::NoEscape { spans } => { | |
733 | // FIXME: in other suggestions we've reversed the inner spans of doc comments. We | |
734 | // should do the same here to provide the same good suggestions as we do for | |
735 | // literals above. | |
736 | diag.set_arg( | |
737 | "escaped", | |
738 | spans | |
739 | .into_iter() | |
740 | .map(|(c, _)| format!("{:?}", c)) | |
741 | .collect::<Vec<String>>() | |
742 | .join(", "), | |
743 | ); | |
9ffffee4 FG |
744 | diag.note(fluent::lint_suggestion_remove); |
745 | diag.note(fluent::lint_no_suggestion_note_escape); | |
9c376795 FG |
746 | } |
747 | } | |
748 | } | |
749 | } | |
750 | ||
9ffffee4 FG |
751 | // map_unit_fn.rs |
752 | #[derive(LintDiagnostic)] | |
753 | #[diag(lint_map_unit_fn)] | |
754 | #[note] | |
755 | pub struct MappingToUnit { | |
756 | #[label(lint_function_label)] | |
757 | pub function_label: Span, | |
758 | #[label(lint_argument_label)] | |
759 | pub argument_label: Span, | |
760 | #[label(lint_map_label)] | |
761 | pub map_label: Span, | |
762 | #[suggestion(style = "verbose", code = "{replace}", applicability = "maybe-incorrect")] | |
763 | pub suggestion: Span, | |
764 | pub replace: String, | |
765 | } | |
766 | ||
9c376795 FG |
767 | // internal.rs |
768 | #[derive(LintDiagnostic)] | |
769 | #[diag(lint_default_hash_types)] | |
770 | #[note] | |
771 | pub struct DefaultHashTypesDiag<'a> { | |
772 | pub preferred: &'a str, | |
773 | pub used: Symbol, | |
774 | } | |
775 | ||
776 | #[derive(LintDiagnostic)] | |
777 | #[diag(lint_query_instability)] | |
778 | #[note] | |
779 | pub struct QueryInstability { | |
780 | pub query: Symbol, | |
781 | } | |
782 | ||
783 | #[derive(LintDiagnostic)] | |
784 | #[diag(lint_tykind_kind)] | |
785 | pub struct TykindKind { | |
786 | #[suggestion(code = "ty", applicability = "maybe-incorrect")] | |
787 | pub suggestion: Span, | |
788 | } | |
789 | ||
790 | #[derive(LintDiagnostic)] | |
791 | #[diag(lint_tykind)] | |
792 | #[help] | |
793 | pub struct TykindDiag; | |
794 | ||
795 | #[derive(LintDiagnostic)] | |
796 | #[diag(lint_ty_qualified)] | |
797 | pub struct TyQualified { | |
798 | pub ty: String, | |
799 | #[suggestion(code = "{ty}", applicability = "maybe-incorrect")] | |
800 | pub suggestion: Span, | |
801 | } | |
802 | ||
803 | #[derive(LintDiagnostic)] | |
804 | #[diag(lint_lintpass_by_hand)] | |
805 | #[help] | |
806 | pub struct LintPassByHand; | |
807 | ||
808 | #[derive(LintDiagnostic)] | |
809 | #[diag(lint_non_existant_doc_keyword)] | |
810 | #[help] | |
811 | pub struct NonExistantDocKeyword { | |
812 | pub keyword: Symbol, | |
813 | } | |
814 | ||
815 | #[derive(LintDiagnostic)] | |
816 | #[diag(lint_diag_out_of_impl)] | |
817 | pub struct DiagOutOfImpl; | |
818 | ||
819 | #[derive(LintDiagnostic)] | |
820 | #[diag(lint_untranslatable_diag)] | |
821 | pub struct UntranslatableDiag; | |
822 | ||
823 | #[derive(LintDiagnostic)] | |
824 | #[diag(lint_bad_opt_access)] | |
825 | pub struct BadOptAccessDiag<'a> { | |
826 | pub msg: &'a str, | |
827 | } | |
828 | ||
829 | // let_underscore.rs | |
830 | #[derive(LintDiagnostic)] | |
831 | pub enum NonBindingLet { | |
832 | #[diag(lint_non_binding_let_on_sync_lock)] | |
833 | SyncLock { | |
834 | #[subdiagnostic] | |
835 | sub: NonBindingLetSub, | |
836 | }, | |
837 | #[diag(lint_non_binding_let_on_drop_type)] | |
838 | DropType { | |
839 | #[subdiagnostic] | |
840 | sub: NonBindingLetSub, | |
841 | }, | |
842 | } | |
843 | ||
844 | pub struct NonBindingLetSub { | |
845 | pub suggestion: Span, | |
846 | pub multi_suggestion_start: Span, | |
847 | pub multi_suggestion_end: Span, | |
848 | } | |
849 | ||
850 | impl AddToDiagnostic for NonBindingLetSub { | |
851 | fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F) | |
852 | where | |
853 | F: Fn( | |
854 | &mut rustc_errors::Diagnostic, | |
855 | rustc_errors::SubdiagnosticMessage, | |
856 | ) -> rustc_errors::SubdiagnosticMessage, | |
857 | { | |
858 | diag.span_suggestion_verbose( | |
859 | self.suggestion, | |
860 | fluent::lint_non_binding_let_suggestion, | |
861 | "_unused", | |
862 | Applicability::MachineApplicable, | |
863 | ); | |
864 | diag.multipart_suggestion( | |
865 | fluent::lint_non_binding_let_multi_suggestion, | |
866 | vec![ | |
867 | (self.multi_suggestion_start, "drop(".to_string()), | |
868 | (self.multi_suggestion_end, ")".to_string()), | |
869 | ], | |
870 | Applicability::MachineApplicable, | |
871 | ); | |
872 | } | |
873 | } | |
874 | ||
875 | // levels.rs | |
876 | #[derive(LintDiagnostic)] | |
877 | #[diag(lint_overruled_attribute)] | |
878 | pub struct OverruledAtributeLint<'a> { | |
879 | #[label] | |
880 | pub overruled: Span, | |
881 | pub lint_level: &'a str, | |
882 | pub lint_source: Symbol, | |
883 | #[subdiagnostic] | |
884 | pub sub: OverruledAttributeSub, | |
885 | } | |
886 | ||
887 | #[derive(LintDiagnostic)] | |
888 | #[diag(lint_deprecated_lint_name)] | |
889 | pub struct DeprecatedLintName<'a> { | |
890 | pub name: String, | |
891 | #[suggestion(code = "{replace}", applicability = "machine-applicable")] | |
892 | pub suggestion: Span, | |
893 | pub replace: &'a str, | |
894 | } | |
895 | ||
896 | // FIXME: Non-translatable msg | |
897 | #[derive(LintDiagnostic)] | |
898 | #[diag(lint_renamed_or_removed_lint)] | |
899 | pub struct RenamedOrRemovedLint<'a> { | |
900 | pub msg: &'a str, | |
901 | #[subdiagnostic] | |
902 | pub suggestion: Option<RenamedOrRemovedLintSuggestion<'a>>, | |
903 | } | |
904 | ||
905 | #[derive(Subdiagnostic)] | |
9ffffee4 | 906 | #[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")] |
9c376795 FG |
907 | pub struct RenamedOrRemovedLintSuggestion<'a> { |
908 | #[primary_span] | |
909 | pub suggestion: Span, | |
910 | pub replace: &'a str, | |
911 | } | |
912 | ||
913 | #[derive(LintDiagnostic)] | |
914 | #[diag(lint_unknown_lint)] | |
915 | pub struct UnknownLint { | |
916 | pub name: String, | |
917 | #[subdiagnostic] | |
918 | pub suggestion: Option<UnknownLintSuggestion>, | |
919 | } | |
920 | ||
921 | #[derive(Subdiagnostic)] | |
9ffffee4 | 922 | #[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")] |
9c376795 FG |
923 | pub struct UnknownLintSuggestion { |
924 | #[primary_span] | |
925 | pub suggestion: Span, | |
926 | pub replace: Symbol, | |
927 | } | |
928 | ||
929 | #[derive(LintDiagnostic)] | |
930 | #[diag(lint_ignored_unless_crate_specified)] | |
931 | pub struct IgnoredUnlessCrateSpecified<'a> { | |
932 | pub level: &'a str, | |
933 | pub name: Symbol, | |
934 | } | |
935 | ||
936 | // methods.rs | |
937 | #[derive(LintDiagnostic)] | |
938 | #[diag(lint_cstring_ptr)] | |
939 | #[note] | |
940 | #[help] | |
941 | pub struct CStringPtr { | |
9ffffee4 | 942 | #[label(lint_as_ptr_label)] |
9c376795 | 943 | pub as_ptr: Span, |
9ffffee4 | 944 | #[label(lint_unwrap_label)] |
9c376795 FG |
945 | pub unwrap: Span, |
946 | } | |
947 | ||
9ffffee4 FG |
948 | // multiple_supertrait_upcastable.rs |
949 | #[derive(LintDiagnostic)] | |
950 | #[diag(lint_multple_supertrait_upcastable)] | |
951 | pub struct MultipleSupertraitUpcastable { | |
952 | pub ident: Ident, | |
953 | } | |
954 | ||
9c376795 FG |
955 | // non_ascii_idents.rs |
956 | #[derive(LintDiagnostic)] | |
957 | #[diag(lint_identifier_non_ascii_char)] | |
958 | pub struct IdentifierNonAsciiChar; | |
959 | ||
960 | #[derive(LintDiagnostic)] | |
961 | #[diag(lint_identifier_uncommon_codepoints)] | |
962 | pub struct IdentifierUncommonCodepoints; | |
963 | ||
964 | #[derive(LintDiagnostic)] | |
965 | #[diag(lint_confusable_identifier_pair)] | |
966 | pub struct ConfusableIdentifierPair { | |
967 | pub existing_sym: Symbol, | |
968 | pub sym: Symbol, | |
969 | #[label] | |
970 | pub label: Span, | |
971 | } | |
972 | ||
973 | #[derive(LintDiagnostic)] | |
974 | #[diag(lint_mixed_script_confusables)] | |
9ffffee4 | 975 | #[note(lint_includes_note)] |
9c376795 FG |
976 | #[note] |
977 | pub struct MixedScriptConfusables { | |
978 | pub set: String, | |
979 | pub includes: String, | |
980 | } | |
981 | ||
982 | // non_fmt_panic.rs | |
983 | pub struct NonFmtPanicUnused { | |
984 | pub count: usize, | |
985 | pub suggestion: Option<Span>, | |
986 | } | |
987 | ||
988 | // Used because of two suggestions based on one Option<Span> | |
989 | impl<'a> DecorateLint<'a, ()> for NonFmtPanicUnused { | |
990 | fn decorate_lint<'b>( | |
991 | self, | |
992 | diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, | |
993 | ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { | |
994 | diag.set_arg("count", self.count); | |
9ffffee4 | 995 | diag.note(fluent::lint_note); |
9c376795 FG |
996 | if let Some(span) = self.suggestion { |
997 | diag.span_suggestion( | |
998 | span.shrink_to_hi(), | |
9ffffee4 | 999 | fluent::lint_add_args_suggestion, |
9c376795 FG |
1000 | ", ...", |
1001 | Applicability::HasPlaceholders, | |
1002 | ); | |
1003 | diag.span_suggestion( | |
1004 | span.shrink_to_lo(), | |
9ffffee4 | 1005 | fluent::lint_add_fmt_suggestion, |
9c376795 FG |
1006 | "\"{}\", ", |
1007 | Applicability::MachineApplicable, | |
1008 | ); | |
1009 | } | |
1010 | diag | |
1011 | } | |
1012 | ||
1013 | fn msg(&self) -> rustc_errors::DiagnosticMessage { | |
1014 | fluent::lint_non_fmt_panic_unused | |
1015 | } | |
1016 | } | |
1017 | ||
1018 | #[derive(LintDiagnostic)] | |
1019 | #[diag(lint_non_fmt_panic_braces)] | |
1020 | #[note] | |
1021 | pub struct NonFmtPanicBraces { | |
1022 | pub count: usize, | |
1023 | #[suggestion(code = "\"{{}}\", ", applicability = "machine-applicable")] | |
1024 | pub suggestion: Option<Span>, | |
1025 | } | |
1026 | ||
1027 | // nonstandard_style.rs | |
1028 | #[derive(LintDiagnostic)] | |
1029 | #[diag(lint_non_camel_case_type)] | |
1030 | pub struct NonCamelCaseType<'a> { | |
1031 | pub sort: &'a str, | |
1032 | pub name: &'a str, | |
1033 | #[subdiagnostic] | |
1034 | pub sub: NonCamelCaseTypeSub, | |
1035 | } | |
1036 | ||
1037 | #[derive(Subdiagnostic)] | |
1038 | pub enum NonCamelCaseTypeSub { | |
9ffffee4 | 1039 | #[label(lint_label)] |
9c376795 FG |
1040 | Label { |
1041 | #[primary_span] | |
1042 | span: Span, | |
1043 | }, | |
9ffffee4 | 1044 | #[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")] |
9c376795 FG |
1045 | Suggestion { |
1046 | #[primary_span] | |
1047 | span: Span, | |
1048 | replace: String, | |
1049 | }, | |
1050 | } | |
1051 | ||
1052 | #[derive(LintDiagnostic)] | |
1053 | #[diag(lint_non_snake_case)] | |
1054 | pub struct NonSnakeCaseDiag<'a> { | |
1055 | pub sort: &'a str, | |
1056 | pub name: &'a str, | |
1057 | pub sc: String, | |
1058 | #[subdiagnostic] | |
1059 | pub sub: NonSnakeCaseDiagSub, | |
1060 | } | |
1061 | ||
1062 | pub enum NonSnakeCaseDiagSub { | |
1063 | Label { span: Span }, | |
1064 | Help, | |
1065 | RenameOrConvertSuggestion { span: Span, suggestion: Ident }, | |
1066 | ConvertSuggestion { span: Span, suggestion: String }, | |
1067 | SuggestionAndNote { span: Span }, | |
1068 | } | |
1069 | ||
1070 | impl AddToDiagnostic for NonSnakeCaseDiagSub { | |
1071 | fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F) | |
1072 | where | |
1073 | F: Fn( | |
1074 | &mut rustc_errors::Diagnostic, | |
1075 | rustc_errors::SubdiagnosticMessage, | |
1076 | ) -> rustc_errors::SubdiagnosticMessage, | |
1077 | { | |
1078 | match self { | |
1079 | NonSnakeCaseDiagSub::Label { span } => { | |
9ffffee4 | 1080 | diag.span_label(span, fluent::lint_label); |
9c376795 FG |
1081 | } |
1082 | NonSnakeCaseDiagSub::Help => { | |
9ffffee4 | 1083 | diag.help(fluent::lint_help); |
9c376795 FG |
1084 | } |
1085 | NonSnakeCaseDiagSub::ConvertSuggestion { span, suggestion } => { | |
1086 | diag.span_suggestion( | |
1087 | span, | |
9ffffee4 | 1088 | fluent::lint_convert_suggestion, |
9c376795 FG |
1089 | suggestion, |
1090 | Applicability::MaybeIncorrect, | |
1091 | ); | |
1092 | } | |
1093 | NonSnakeCaseDiagSub::RenameOrConvertSuggestion { span, suggestion } => { | |
1094 | diag.span_suggestion( | |
1095 | span, | |
9ffffee4 | 1096 | fluent::lint_rename_or_convert_suggestion, |
9c376795 FG |
1097 | suggestion, |
1098 | Applicability::MaybeIncorrect, | |
1099 | ); | |
1100 | } | |
1101 | NonSnakeCaseDiagSub::SuggestionAndNote { span } => { | |
9ffffee4 | 1102 | diag.note(fluent::lint_cannot_convert_note); |
9c376795 FG |
1103 | diag.span_suggestion( |
1104 | span, | |
9ffffee4 | 1105 | fluent::lint_rename_suggestion, |
9c376795 FG |
1106 | "", |
1107 | Applicability::MaybeIncorrect, | |
1108 | ); | |
1109 | } | |
1110 | } | |
1111 | } | |
1112 | } | |
1113 | ||
1114 | #[derive(LintDiagnostic)] | |
1115 | #[diag(lint_non_upper_case_global)] | |
1116 | pub struct NonUpperCaseGlobal<'a> { | |
1117 | pub sort: &'a str, | |
1118 | pub name: &'a str, | |
1119 | #[subdiagnostic] | |
1120 | pub sub: NonUpperCaseGlobalSub, | |
1121 | } | |
1122 | ||
1123 | #[derive(Subdiagnostic)] | |
1124 | pub enum NonUpperCaseGlobalSub { | |
9ffffee4 | 1125 | #[label(lint_label)] |
9c376795 FG |
1126 | Label { |
1127 | #[primary_span] | |
1128 | span: Span, | |
1129 | }, | |
9ffffee4 | 1130 | #[suggestion(lint_suggestion, code = "{replace}", applicability = "maybe-incorrect")] |
9c376795 FG |
1131 | Suggestion { |
1132 | #[primary_span] | |
1133 | span: Span, | |
1134 | replace: String, | |
1135 | }, | |
1136 | } | |
1137 | ||
1138 | // noop_method_call.rs | |
1139 | #[derive(LintDiagnostic)] | |
1140 | #[diag(lint_noop_method_call)] | |
1141 | #[note] | |
1142 | pub struct NoopMethodCallDiag<'a> { | |
1143 | pub method: Symbol, | |
1144 | pub receiver_ty: Ty<'a>, | |
1145 | #[label] | |
1146 | pub label: Span, | |
1147 | } | |
1148 | ||
1149 | // pass_by_value.rs | |
1150 | #[derive(LintDiagnostic)] | |
1151 | #[diag(lint_pass_by_value)] | |
1152 | pub struct PassByValueDiag { | |
1153 | pub ty: String, | |
1154 | #[suggestion(code = "{ty}", applicability = "maybe-incorrect")] | |
1155 | pub suggestion: Span, | |
1156 | } | |
1157 | ||
1158 | // redundant_semicolon.rs | |
1159 | #[derive(LintDiagnostic)] | |
1160 | #[diag(lint_redundant_semicolons)] | |
1161 | pub struct RedundantSemicolonsDiag { | |
1162 | pub multiple: bool, | |
1163 | #[suggestion(code = "", applicability = "maybe-incorrect")] | |
1164 | pub suggestion: Span, | |
1165 | } | |
1166 | ||
1167 | // traits.rs | |
1168 | pub struct DropTraitConstraintsDiag<'a> { | |
1169 | pub predicate: Predicate<'a>, | |
1170 | pub tcx: TyCtxt<'a>, | |
1171 | pub def_id: DefId, | |
1172 | } | |
1173 | ||
1174 | // Needed for def_path_str | |
1175 | impl<'a> DecorateLint<'a, ()> for DropTraitConstraintsDiag<'_> { | |
1176 | fn decorate_lint<'b>( | |
1177 | self, | |
1178 | diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, | |
1179 | ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { | |
1180 | diag.set_arg("predicate", self.predicate); | |
1181 | diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id)) | |
1182 | } | |
1183 | ||
1184 | fn msg(&self) -> rustc_errors::DiagnosticMessage { | |
1185 | fluent::lint_drop_trait_constraints | |
1186 | } | |
1187 | } | |
1188 | ||
1189 | pub struct DropGlue<'a> { | |
1190 | pub tcx: TyCtxt<'a>, | |
1191 | pub def_id: DefId, | |
1192 | } | |
1193 | ||
1194 | // Needed for def_path_str | |
1195 | impl<'a> DecorateLint<'a, ()> for DropGlue<'_> { | |
1196 | fn decorate_lint<'b>( | |
1197 | self, | |
1198 | diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, | |
1199 | ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { | |
1200 | diag.set_arg("needs_drop", self.tcx.def_path_str(self.def_id)) | |
1201 | } | |
1202 | ||
1203 | fn msg(&self) -> rustc_errors::DiagnosticMessage { | |
1204 | fluent::lint_drop_glue | |
1205 | } | |
1206 | } | |
1207 | ||
1208 | // types.rs | |
1209 | #[derive(LintDiagnostic)] | |
1210 | #[diag(lint_range_endpoint_out_of_range)] | |
1211 | pub struct RangeEndpointOutOfRange<'a> { | |
1212 | pub ty: &'a str, | |
1213 | #[suggestion(code = "{start}..={literal}{suffix}", applicability = "machine-applicable")] | |
1214 | pub suggestion: Span, | |
1215 | pub start: String, | |
1216 | pub literal: u128, | |
1217 | pub suffix: &'a str, | |
1218 | } | |
1219 | ||
1220 | #[derive(LintDiagnostic)] | |
1221 | #[diag(lint_overflowing_bin_hex)] | |
1222 | pub struct OverflowingBinHex<'a> { | |
1223 | pub ty: &'a str, | |
1224 | pub lit: String, | |
1225 | pub dec: u128, | |
1226 | pub actually: String, | |
1227 | #[subdiagnostic] | |
1228 | pub sign: OverflowingBinHexSign, | |
1229 | #[subdiagnostic] | |
1230 | pub sub: Option<OverflowingBinHexSub<'a>>, | |
1231 | } | |
1232 | ||
1233 | pub enum OverflowingBinHexSign { | |
1234 | Positive, | |
1235 | Negative, | |
1236 | } | |
1237 | ||
1238 | impl AddToDiagnostic for OverflowingBinHexSign { | |
1239 | fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F) | |
1240 | where | |
1241 | F: Fn( | |
1242 | &mut rustc_errors::Diagnostic, | |
1243 | rustc_errors::SubdiagnosticMessage, | |
1244 | ) -> rustc_errors::SubdiagnosticMessage, | |
1245 | { | |
1246 | match self { | |
1247 | OverflowingBinHexSign::Positive => { | |
9ffffee4 | 1248 | diag.note(fluent::lint_positive_note); |
9c376795 FG |
1249 | } |
1250 | OverflowingBinHexSign::Negative => { | |
9ffffee4 FG |
1251 | diag.note(fluent::lint_negative_note); |
1252 | diag.note(fluent::lint_negative_becomes_note); | |
9c376795 FG |
1253 | } |
1254 | } | |
1255 | } | |
1256 | } | |
1257 | ||
1258 | #[derive(Subdiagnostic)] | |
1259 | pub enum OverflowingBinHexSub<'a> { | |
1260 | #[suggestion( | |
9ffffee4 | 1261 | lint_suggestion, |
9c376795 FG |
1262 | code = "{sans_suffix}{suggestion_ty}", |
1263 | applicability = "machine-applicable" | |
1264 | )] | |
1265 | Suggestion { | |
1266 | #[primary_span] | |
1267 | span: Span, | |
1268 | suggestion_ty: &'a str, | |
1269 | sans_suffix: &'a str, | |
1270 | }, | |
9ffffee4 | 1271 | #[help(lint_help)] |
9c376795 FG |
1272 | Help { suggestion_ty: &'a str }, |
1273 | } | |
1274 | ||
1275 | #[derive(LintDiagnostic)] | |
1276 | #[diag(lint_overflowing_int)] | |
1277 | #[note] | |
1278 | pub struct OverflowingInt<'a> { | |
1279 | pub ty: &'a str, | |
1280 | pub lit: String, | |
1281 | pub min: i128, | |
1282 | pub max: u128, | |
1283 | #[subdiagnostic] | |
1284 | pub help: Option<OverflowingIntHelp<'a>>, | |
1285 | } | |
1286 | ||
1287 | #[derive(Subdiagnostic)] | |
9ffffee4 | 1288 | #[help(lint_help)] |
9c376795 FG |
1289 | pub struct OverflowingIntHelp<'a> { |
1290 | pub suggestion_ty: &'a str, | |
1291 | } | |
1292 | ||
1293 | #[derive(LintDiagnostic)] | |
1294 | #[diag(lint_only_cast_u8_to_char)] | |
1295 | pub struct OnlyCastu8ToChar { | |
1296 | #[suggestion(code = "'\\u{{{literal:X}}}'", applicability = "machine-applicable")] | |
1297 | pub span: Span, | |
1298 | pub literal: u128, | |
1299 | } | |
1300 | ||
1301 | #[derive(LintDiagnostic)] | |
1302 | #[diag(lint_overflowing_uint)] | |
1303 | #[note] | |
1304 | pub struct OverflowingUInt<'a> { | |
1305 | pub ty: &'a str, | |
1306 | pub lit: String, | |
1307 | pub min: u128, | |
1308 | pub max: u128, | |
1309 | } | |
1310 | ||
1311 | #[derive(LintDiagnostic)] | |
1312 | #[diag(lint_overflowing_literal)] | |
1313 | #[note] | |
1314 | pub struct OverflowingLiteral<'a> { | |
1315 | pub ty: &'a str, | |
1316 | pub lit: String, | |
1317 | } | |
1318 | ||
1319 | #[derive(LintDiagnostic)] | |
1320 | #[diag(lint_unused_comparisons)] | |
1321 | pub struct UnusedComparisons; | |
1322 | ||
1323 | pub struct ImproperCTypes<'a> { | |
1324 | pub ty: Ty<'a>, | |
1325 | pub desc: &'a str, | |
1326 | pub label: Span, | |
1327 | pub help: Option<DiagnosticMessage>, | |
1328 | pub note: DiagnosticMessage, | |
1329 | pub span_note: Option<Span>, | |
1330 | } | |
1331 | ||
1332 | // Used because of the complexity of Option<DiagnosticMessage>, DiagnosticMessage, and Option<Span> | |
1333 | impl<'a> DecorateLint<'a, ()> for ImproperCTypes<'_> { | |
1334 | fn decorate_lint<'b>( | |
1335 | self, | |
1336 | diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, | |
1337 | ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { | |
1338 | diag.set_arg("ty", self.ty); | |
1339 | diag.set_arg("desc", self.desc); | |
9ffffee4 | 1340 | diag.span_label(self.label, fluent::lint_label); |
9c376795 FG |
1341 | if let Some(help) = self.help { |
1342 | diag.help(help); | |
1343 | } | |
1344 | diag.note(self.note); | |
1345 | if let Some(note) = self.span_note { | |
9ffffee4 | 1346 | diag.span_note(note, fluent::lint_note); |
9c376795 FG |
1347 | } |
1348 | diag | |
1349 | } | |
1350 | ||
1351 | fn msg(&self) -> rustc_errors::DiagnosticMessage { | |
1352 | fluent::lint_improper_ctypes | |
1353 | } | |
1354 | } | |
1355 | ||
1356 | #[derive(LintDiagnostic)] | |
1357 | #[diag(lint_variant_size_differences)] | |
1358 | pub struct VariantSizeDifferencesDiag { | |
1359 | pub largest: u64, | |
1360 | } | |
1361 | ||
1362 | #[derive(LintDiagnostic)] | |
1363 | #[diag(lint_atomic_ordering_load)] | |
1364 | #[help] | |
1365 | pub struct AtomicOrderingLoad; | |
1366 | ||
1367 | #[derive(LintDiagnostic)] | |
1368 | #[diag(lint_atomic_ordering_store)] | |
1369 | #[help] | |
1370 | pub struct AtomicOrderingStore; | |
1371 | ||
1372 | #[derive(LintDiagnostic)] | |
1373 | #[diag(lint_atomic_ordering_fence)] | |
1374 | #[help] | |
1375 | pub struct AtomicOrderingFence; | |
1376 | ||
1377 | #[derive(LintDiagnostic)] | |
1378 | #[diag(lint_atomic_ordering_invalid)] | |
1379 | #[help] | |
1380 | pub struct InvalidAtomicOrderingDiag { | |
1381 | pub method: Symbol, | |
1382 | #[label] | |
1383 | pub fail_order_arg_span: Span, | |
1384 | } | |
1385 | ||
1386 | // unused.rs | |
1387 | #[derive(LintDiagnostic)] | |
1388 | #[diag(lint_unused_op)] | |
1389 | pub struct UnusedOp<'a> { | |
1390 | pub op: &'a str, | |
1391 | #[label] | |
1392 | pub label: Span, | |
1393 | #[suggestion(style = "verbose", code = "let _ = ", applicability = "machine-applicable")] | |
1394 | pub suggestion: Span, | |
1395 | } | |
1396 | ||
1397 | #[derive(LintDiagnostic)] | |
1398 | #[diag(lint_unused_result)] | |
1399 | pub struct UnusedResult<'a> { | |
1400 | pub ty: Ty<'a>, | |
1401 | } | |
1402 | ||
1403 | // FIXME(davidtwco): this isn't properly translatable becauses of the | |
1404 | // pre/post strings | |
1405 | #[derive(LintDiagnostic)] | |
1406 | #[diag(lint_unused_closure)] | |
1407 | #[note] | |
1408 | pub struct UnusedClosure<'a> { | |
1409 | pub count: usize, | |
1410 | pub pre: &'a str, | |
1411 | pub post: &'a str, | |
1412 | } | |
1413 | ||
1414 | // FIXME(davidtwco): this isn't properly translatable becauses of the | |
1415 | // pre/post strings | |
1416 | #[derive(LintDiagnostic)] | |
1417 | #[diag(lint_unused_generator)] | |
1418 | #[note] | |
1419 | pub struct UnusedGenerator<'a> { | |
1420 | pub count: usize, | |
1421 | pub pre: &'a str, | |
1422 | pub post: &'a str, | |
1423 | } | |
1424 | ||
1425 | // FIXME(davidtwco): this isn't properly translatable becauses of the pre/post | |
1426 | // strings | |
1427 | pub struct UnusedDef<'a, 'b> { | |
1428 | pub pre: &'a str, | |
1429 | pub post: &'a str, | |
1430 | pub cx: &'a LateContext<'b>, | |
1431 | pub def_id: DefId, | |
1432 | pub note: Option<Symbol>, | |
9ffffee4 FG |
1433 | pub suggestion: Option<UnusedDefSuggestion>, |
1434 | } | |
1435 | ||
1436 | #[derive(Subdiagnostic)] | |
1437 | pub enum UnusedDefSuggestion { | |
1438 | #[suggestion( | |
1439 | lint_suggestion, | |
1440 | style = "verbose", | |
1441 | code = "let _ = ", | |
1442 | applicability = "machine-applicable" | |
1443 | )] | |
1444 | Default { | |
1445 | #[primary_span] | |
1446 | span: Span, | |
1447 | }, | |
9c376795 FG |
1448 | } |
1449 | ||
1450 | // Needed because of def_path_str | |
1451 | impl<'a> DecorateLint<'a, ()> for UnusedDef<'_, '_> { | |
1452 | fn decorate_lint<'b>( | |
1453 | self, | |
1454 | diag: &'b mut rustc_errors::DiagnosticBuilder<'a, ()>, | |
1455 | ) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> { | |
1456 | diag.set_arg("pre", self.pre); | |
1457 | diag.set_arg("post", self.post); | |
1458 | diag.set_arg("def", self.cx.tcx.def_path_str(self.def_id)); | |
1459 | // check for #[must_use = "..."] | |
1460 | if let Some(note) = self.note { | |
1461 | diag.note(note.as_str()); | |
1462 | } | |
9ffffee4 FG |
1463 | if let Some(sugg) = self.suggestion { |
1464 | diag.subdiagnostic(sugg); | |
1465 | } | |
9c376795 FG |
1466 | diag |
1467 | } | |
1468 | ||
1469 | fn msg(&self) -> rustc_errors::DiagnosticMessage { | |
1470 | fluent::lint_unused_def | |
1471 | } | |
1472 | } | |
1473 | ||
1474 | #[derive(LintDiagnostic)] | |
1475 | #[diag(lint_path_statement_drop)] | |
1476 | pub struct PathStatementDrop { | |
1477 | #[subdiagnostic] | |
1478 | pub sub: PathStatementDropSub, | |
1479 | } | |
1480 | ||
1481 | #[derive(Subdiagnostic)] | |
1482 | pub enum PathStatementDropSub { | |
9ffffee4 | 1483 | #[suggestion(lint_suggestion, code = "drop({snippet});", applicability = "machine-applicable")] |
9c376795 FG |
1484 | Suggestion { |
1485 | #[primary_span] | |
1486 | span: Span, | |
1487 | snippet: String, | |
1488 | }, | |
9ffffee4 | 1489 | #[help(lint_help)] |
9c376795 FG |
1490 | Help { |
1491 | #[primary_span] | |
1492 | span: Span, | |
1493 | }, | |
1494 | } | |
1495 | ||
1496 | #[derive(LintDiagnostic)] | |
1497 | #[diag(lint_path_statement_no_effect)] | |
1498 | pub struct PathStatementNoEffect; | |
1499 | ||
1500 | #[derive(LintDiagnostic)] | |
1501 | #[diag(lint_unused_delim)] | |
1502 | pub struct UnusedDelim<'a> { | |
1503 | pub delim: &'static str, | |
1504 | pub item: &'a str, | |
1505 | #[subdiagnostic] | |
1506 | pub suggestion: Option<UnusedDelimSuggestion>, | |
1507 | } | |
1508 | ||
1509 | #[derive(Subdiagnostic)] | |
9ffffee4 | 1510 | #[multipart_suggestion(lint_suggestion, applicability = "machine-applicable")] |
9c376795 FG |
1511 | pub struct UnusedDelimSuggestion { |
1512 | #[suggestion_part(code = "{start_replace}")] | |
1513 | pub start_span: Span, | |
1514 | pub start_replace: &'static str, | |
1515 | #[suggestion_part(code = "{end_replace}")] | |
1516 | pub end_span: Span, | |
1517 | pub end_replace: &'static str, | |
1518 | } | |
1519 | ||
1520 | #[derive(LintDiagnostic)] | |
1521 | #[diag(lint_unused_import_braces)] | |
1522 | pub struct UnusedImportBracesDiag { | |
1523 | pub node: Symbol, | |
1524 | } | |
1525 | ||
1526 | #[derive(LintDiagnostic)] | |
1527 | #[diag(lint_unused_allocation)] | |
1528 | pub struct UnusedAllocationDiag; | |
1529 | ||
1530 | #[derive(LintDiagnostic)] | |
1531 | #[diag(lint_unused_allocation_mut)] | |
1532 | pub struct UnusedAllocationMutDiag; |