Skip to content

Commit c851c3f

Browse files
committed
Move more early buffered lints to dyn lint diagnostics (2/N)
1 parent 951f9e9 commit c851c3f

File tree

14 files changed

+48
-67
lines changed

14 files changed

+48
-67
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ ast_passes_match_arm_with_no_body =
201201
.suggestion = add a body after the pattern
202202
203203
ast_passes_missing_unsafe_on_extern = extern blocks must be unsafe
204+
.suggestion = needs `unsafe` before the extern keyword
204205
205206
ast_passes_module_nonascii = trying to load file for module `{$name}` with non-ascii identifier name
206207
.help = consider using the `#[path]` attribute to specify filesystem path

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11041104
MISSING_UNSAFE_ON_EXTERN,
11051105
item.id,
11061106
item.span,
1107-
BuiltinLintDiag::MissingUnsafeOnExtern {
1107+
errors::MissingUnsafeOnExternLint {
11081108
suggestion: item.span.shrink_to_lo(),
11091109
},
11101110
);

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ pub(crate) struct MissingUnsafeOnExtern {
489489
pub span: Span,
490490
}
491491

492+
#[derive(LintDiagnostic)]
493+
#[diag(ast_passes_missing_unsafe_on_extern)]
494+
pub(crate) struct MissingUnsafeOnExternLint {
495+
#[suggestion(code = "unsafe ", applicability = "machine-applicable")]
496+
pub suggestion: Span,
497+
}
498+
492499
#[derive(Diagnostic)]
493500
#[diag(ast_passes_fieldless_union)]
494501
pub(crate) struct FieldlessUnion {

compiler/rustc_expand/messages.ftl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ expand_unknown_macro_variable = unknown macro variable `{$name}`
190190
expand_unsupported_key_value =
191191
key-value macro attributes are not supported
192192
193+
expand_unused_doc_comment = unused doc comment
194+
.label = rustdoc does not generate documentation for {$kind}
195+
.plain_help = use `//` for a plain comment
196+
.block_help = use `/* */` for a plain comment
197+
193198
expand_var_still_repeating =
194199
variable `{$ident}` is still repeating at this depth
195200

compiler/rustc_expand/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,11 @@ pub(crate) struct MacroArgsBadDelimSugg {
539539
#[suggestion_part(code = ")")]
540540
pub close: Span,
541541
}
542+
543+
#[derive(LintDiagnostic)]
544+
#[diag(expand_unused_doc_comment)]
545+
#[help]
546+
pub(crate) struct UnusedDocComment {
547+
#[label]
548+
pub span: Span,
549+
}

compiler/rustc_expand/src/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
21822182
UNUSED_DOC_COMMENTS,
21832183
current_span,
21842184
self.cx.current_expansion.lint_node_id,
2185-
BuiltinLintDiag::UnusedDocComment(attr.span),
2185+
crate::errors::UnusedDocComment { span: attr.span },
21862186
);
21872187
} else if rustc_attr_parsing::is_builtin_attr(attr)
21882188
&& !AttributeParser::<Early>::is_parsed_attribute(&attr.path())

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,6 @@ lint_int_to_ptr_transmutes = transmuting an integer to a pointer creates a point
453453
.suggestion_with_exposed_provenance = use `std::ptr::with_exposed_provenance{$suffix}` instead to use a previously exposed provenance
454454
.suggestion_without_provenance_mut = if you truly mean to create a pointer without provenance, use `std::ptr::without_provenance_mut`
455455
456-
lint_legacy_derive_helpers = derive helper attribute is used before it is introduced
457-
.label = the attribute is introduced here
458-
459456
lint_lintpass_by_hand = implementing `LintPass` by hand
460457
.help = try using `declare_lint_pass!` or `impl_lint_pass!` instead
461458
@@ -524,9 +521,6 @@ lint_mismatched_lifetime_syntaxes_suggestion_mixed =
524521
lint_mismatched_lifetime_syntaxes_suggestion_mixed_only_paths =
525522
use `'_` for type paths
526523
527-
lint_missing_unsafe_on_extern = extern blocks should be unsafe
528-
.suggestion = needs `unsafe` before the extern keyword
529-
530524
lint_mixed_script_confusables =
531525
the usage of Script Group `{$set}` in this crate consists solely of mixed script confusables
532526
.includes_note = the usage includes {$includes}
@@ -966,10 +960,6 @@ lint_unused_doc_comment = unused doc comment
966960
.label = rustdoc does not generate documentation for macro invocations
967961
.help = to document an item produced by a macro, the macro must produce the documentation as part of its expansion
968962
969-
lint_unused_extern_crate = unused extern crate
970-
.label = unused
971-
.suggestion = remove the unused `extern crate`
972-
973963
lint_unused_import_braces = braces around {$node} is unnecessary
974964
975965
lint_unused_imports = {$num_snippets ->

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ pub fn decorate_builtin_lint(
135135
stability::Deprecated { sub, kind: "macro".to_owned(), path, note, since_kind }
136136
.decorate_lint(diag);
137137
}
138-
BuiltinLintDiag::UnusedDocComment(attr_span) => {
139-
lints::UnusedDocComment { span: attr_span }.decorate_lint(diag);
140-
}
141138
BuiltinLintDiag::PatternsInFnsWithoutBody { span: remove_span, ident, is_foreign } => {
142139
let sub = lints::PatternsInFnsWithoutBodySub { ident, span: remove_span };
143140
if is_foreign {
@@ -147,9 +144,6 @@ pub fn decorate_builtin_lint(
147144
}
148145
.decorate_lint(diag);
149146
}
150-
BuiltinLintDiag::LegacyDeriveHelpers(label_span) => {
151-
lints::LegacyDeriveHelpers { span: label_span }.decorate_lint(diag);
152-
}
153147
BuiltinLintDiag::OrPatternsBackCompat(suggestion_span, suggestion) => {
154148
lints::OrPatternsBackCompat { span: suggestion_span, suggestion }.decorate_lint(diag);
155149
}
@@ -210,9 +204,6 @@ pub fn decorate_builtin_lint(
210204
};
211205
lints::DeprecatedWhereClauseLocation { suggestion }.decorate_lint(diag);
212206
}
213-
BuiltinLintDiag::MissingUnsafeOnExtern { suggestion } => {
214-
lints::MissingUnsafeOnExtern { suggestion }.decorate_lint(diag);
215-
}
216207
BuiltinLintDiag::SingleUseLifetime {
217208
param_span,
218209
use_span: Some((use_span, elide)),
@@ -242,7 +233,6 @@ pub fn decorate_builtin_lint(
242233
.decorate_lint(diag);
243234
}
244235
BuiltinLintDiag::SingleUseLifetime { use_span: None, deletion_span, ident, .. } => {
245-
debug!(?deletion_span);
246236
lints::UnusedLifetime { deletion_span, ident }.decorate_lint(diag);
247237
}
248238
BuiltinLintDiag::NamedArgumentUsedPositionally {
@@ -283,9 +273,6 @@ pub fn decorate_builtin_lint(
283273
BuiltinLintDiag::ByteSliceInPackedStructWithDerive { ty } => {
284274
lints::ByteSliceInPackedStructWithDerive { ty }.decorate_lint(diag);
285275
}
286-
BuiltinLintDiag::UnusedExternCrate { span, removal_span } => {
287-
lints::UnusedExternCrate { span, removal_span }.decorate_lint(diag);
288-
}
289276
BuiltinLintDiag::ExternCrateNotIdiomatic { vis_span, ident_span } => {
290277
let suggestion_span = vis_span.between(ident_span);
291278
let code = if vis_span.is_empty() { "use " } else { " use " };

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,14 +2749,6 @@ pub(crate) enum RedundantImportSub {
27492749
DefinedPrelude(#[primary_span] Span),
27502750
}
27512751

2752-
#[derive(LintDiagnostic)]
2753-
#[diag(lint_unused_doc_comment)]
2754-
#[help]
2755-
pub(crate) struct UnusedDocComment {
2756-
#[label]
2757-
pub span: Span,
2758-
}
2759-
27602752
#[derive(LintDiagnostic)]
27612753
pub(crate) enum PatternsInFnsWithoutBody {
27622754
#[diag(lint_pattern_in_foreign)]
@@ -2780,13 +2772,6 @@ pub(crate) struct PatternsInFnsWithoutBodySub {
27802772
pub ident: Ident,
27812773
}
27822774

2783-
#[derive(LintDiagnostic)]
2784-
#[diag(lint_legacy_derive_helpers)]
2785-
pub(crate) struct LegacyDeriveHelpers {
2786-
#[label]
2787-
pub span: Span,
2788-
}
2789-
27902775
#[derive(LintDiagnostic)]
27912776
#[diag(lint_or_patterns_back_compat)]
27922777
pub(crate) struct OrPatternsBackCompat {
@@ -2878,13 +2863,6 @@ pub(crate) enum DeprecatedWhereClauseLocationSugg {
28782863
},
28792864
}
28802865

2881-
#[derive(LintDiagnostic)]
2882-
#[diag(lint_missing_unsafe_on_extern)]
2883-
pub(crate) struct MissingUnsafeOnExtern {
2884-
#[suggestion(code = "unsafe ", applicability = "machine-applicable")]
2885-
pub suggestion: Span,
2886-
}
2887-
28882866
#[derive(LintDiagnostic)]
28892867
#[diag(lint_single_use_lifetime)]
28902868
pub(crate) struct SingleUseLifetime {
@@ -2940,15 +2918,6 @@ pub(crate) struct ByteSliceInPackedStructWithDerive {
29402918
pub ty: String,
29412919
}
29422920

2943-
#[derive(LintDiagnostic)]
2944-
#[diag(lint_unused_extern_crate)]
2945-
pub(crate) struct UnusedExternCrate {
2946-
#[label]
2947-
pub span: Span,
2948-
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
2949-
pub removal_span: Span,
2950-
}
2951-
29522921
#[derive(LintDiagnostic)]
29532922
#[diag(lint_extern_crate_not_idiomatic)]
29542923
pub(crate) struct ExternCrateNotIdiomatic {

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,6 @@ pub enum BuiltinLintDiag {
640640
path: String,
641641
since_kind: DeprecatedSinceKind,
642642
},
643-
UnusedDocComment(Span),
644643
UnusedBuiltinAttribute {
645644
attr_name: Symbol,
646645
macro_name: String,
@@ -652,7 +651,6 @@ pub enum BuiltinLintDiag {
652651
ident: Ident,
653652
is_foreign: bool,
654653
},
655-
LegacyDeriveHelpers(Span),
656654
OrPatternsBackCompat(Span, String),
657655
ReservedPrefix(Span, String),
658656
/// `'r#` in edition < 2021.
@@ -668,9 +666,6 @@ pub enum BuiltinLintDiag {
668666
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
669667
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),
670668
DeprecatedWhereclauseLocation(Span, Option<(Span, String)>),
671-
MissingUnsafeOnExtern {
672-
suggestion: Span,
673-
},
674669
SingleUseLifetime {
675670
/// Span of the parameter which declares this lifetime.
676671
param_span: Span,
@@ -699,10 +694,6 @@ pub enum BuiltinLintDiag {
699694
// FIXME: enum of byte/string
700695
ty: String,
701696
},
702-
UnusedExternCrate {
703-
span: Span,
704-
removal_span: Span,
705-
},
706697
ExternCrateNotIdiomatic {
707698
vis_span: Span,
708699
ident_span: Span,

0 commit comments

Comments
 (0)