Skip to content

Commit 31c0d96

Browse files
committed
Move more early buffered lints to dyn lint diagnostics (2/N)
1 parent 2e81673 commit 31c0d96

File tree

14 files changed

+50
-71
lines changed

14 files changed

+50
-71
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ ast_passes_match_arm_with_no_body =
216216
.suggestion = add a body after the pattern
217217
218218
ast_passes_missing_unsafe_on_extern = extern blocks must be unsafe
219+
.suggestion = needs `unsafe` before the extern keyword
220+
221+
ast_passes_missing_unsafe_on_extern_lint = extern blocks should be unsafe
222+
.suggestion = needs `unsafe` before the extern keyword
219223
220224
ast_passes_module_nonascii = trying to load file for module `{$name}` with non-ascii identifier name
221225
.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
@@ -1131,7 +1131,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11311131
MISSING_UNSAFE_ON_EXTERN,
11321132
item.id,
11331133
item.span,
1134-
BuiltinLintDiag::MissingUnsafeOnExtern {
1134+
errors::MissingUnsafeOnExternLint {
11351135
suggestion: item.span.shrink_to_lo(),
11361136
},
11371137
);

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,13 @@ pub(crate) struct MissingUnsafeOnExtern {
523523
pub span: Span,
524524
}
525525

526+
#[derive(LintDiagnostic)]
527+
#[diag(ast_passes_missing_unsafe_on_extern_lint)]
528+
pub(crate) struct MissingUnsafeOnExternLint {
529+
#[suggestion(code = "unsafe ", applicability = "machine-applicable")]
530+
pub suggestion: Span,
531+
}
532+
526533
#[derive(Diagnostic)]
527534
#[diag(ast_passes_fieldless_union)]
528535
pub(crate) struct FieldlessUnion {

compiler/rustc_expand/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ expand_macro_body_stability =
8080
.label = invalid body stability attribute
8181
.label2 = body stability attribute affects this macro
8282
83+
expand_macro_call_unused_doc_comment = unused doc comment
84+
.label = rustdoc does not generate documentation for macro invocations
85+
.help = to document an item produced by a macro, the macro must produce the documentation as part of its expansion
86+
8387
expand_macro_const_stability =
8488
macros cannot have const stability attributes
8589
.label = invalid const stability attribute

compiler/rustc_expand/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,11 @@ pub(crate) struct MacroArgsBadDelimSugg {
537537
#[suggestion_part(code = ")")]
538538
pub close: Span,
539539
}
540+
541+
#[derive(LintDiagnostic)]
542+
#[diag(expand_macro_call_unused_doc_comment)]
543+
#[help]
544+
pub(crate) struct MacroCallUnusedDocComment {
545+
#[label]
546+
pub span: Span,
547+
}

compiler/rustc_expand/src/expand.rs

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

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 14 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}
@@ -962,14 +956,6 @@ lint_unused_def = unused {$pre}`{$def}`{$post} that must be used
962956
lint_unused_delim = unnecessary {$delim} around {$item}
963957
.suggestion = remove these {$delim}
964958
965-
lint_unused_doc_comment = unused doc comment
966-
.label = rustdoc does not generate documentation for macro invocations
967-
.help = to document an item produced by a macro, the macro must produce the documentation as part of its expansion
968-
969-
lint_unused_extern_crate = unused extern crate
970-
.label = unused
971-
.suggestion = remove the unused `extern crate`
972-
973959
lint_unused_import_braces = braces around {$node} is unnecessary
974960
975961
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)