Skip to content

Commit 55a800d

Browse files
committed
Move remaining early buffered lints for rustc_ast_passes to dyn lint diagnostics
1 parent 8034cc3 commit 55a800d

File tree

8 files changed

+68
-149
lines changed

8 files changed

+68
-149
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ ast_passes_coroutine_and_c_variadic = functions cannot be both `{$coroutine_kind
107107
.const = `{$coroutine_kind}` because of this
108108
.variadic = C-variadic because of this
109109
110+
ast_passes_deprecated_where_clause_location = where clause not allowed here
111+
.note = see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
112+
110113
ast_passes_equality_in_where = equality constraints are not yet supported in `where` clauses
111114
.label = not supported
112115
.suggestion = if `{$ident}` is an associated type you're trying to set, use the associated type binding syntax
@@ -237,6 +240,8 @@ ast_passes_missing_unsafe_on_extern_lint = extern blocks should be unsafe
237240
ast_passes_module_nonascii = trying to load file for module `{$name}` with non-ascii identifier name
238241
.help = consider using the `#[path]` attribute to specify filesystem path
239242
243+
ast_passes_move_leading_ty_alias_where_clause = move it to the end of the type declaration
244+
240245
ast_passes_negative_bound_not_supported =
241246
negative bounds are not supported
242247
@@ -259,6 +264,7 @@ ast_passes_out_of_order_params = {$param_ord} parameters must be declared prior
259264
260265
ast_passes_pattern_in_bodiless = patterns aren't allowed in functions without bodies
261266
.label = pattern not allowed in function without body
267+
.remove_mut_sugg = remove `mut` from the parameter
262268
263269
ast_passes_pattern_in_fn_pointer = patterns aren't allowed in function pointer types
264270
@@ -270,6 +276,8 @@ ast_passes_precise_capturing_duplicated = duplicate `use<...>` precise capturing
270276
271277
ast_passes_precise_capturing_not_allowed_here = `use<...>` precise capturing syntax not allowed in {$loc}
272278
279+
ast_passes_remove_leading_ty_alias_where_clause = remove this `where`
280+
273281
ast_passes_static_without_body =
274282
free static item without body
275283
.suggestion = provide a definition for the static
@@ -322,6 +330,10 @@ ast_passes_unsafe_negative_impl = negative impls cannot be unsafe
322330
ast_passes_unsafe_static =
323331
static items cannot be declared with `unsafe` safety qualifier outside of `extern` block
324332
333+
ast_passes_unused_visibilities = visibility qualifiers have no effect on `const _` declarations
334+
.note = `const _` does not declare a name, so there is nothing for the qualifier to apply to
335+
.suggestion = remove the qualifier
336+
325337
ast_passes_visibility_not_permitted =
326338
visibility qualifiers are not permitted here
327339
.enum_variant = enum variants and their fields always share the visibility of the enum they are in
@@ -336,5 +348,3 @@ ast_passes_where_clause_after_type_alias = where clauses are not allowed after t
336348
337349
ast_passes_where_clause_before_type_alias = where clauses are not allowed before the type for type aliases
338350
.note = see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
339-
.remove_suggestion = remove this `where`
340-
.move_suggestion = move it to the end of the type declaration

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rustc_data_structures::fx::FxIndexMap;
3030
use rustc_errors::{DiagCtxtHandle, LintBuffer};
3131
use rustc_feature::Features;
3232
use rustc_session::Session;
33-
use rustc_session::lint::BuiltinLintDiag;
3433
use rustc_session::lint::builtin::{
3534
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, MISSING_UNSAFE_ON_EXTERN,
3635
PATTERNS_IN_FNS_WITHOUT_BODY, UNUSED_VISIBILITIES,
@@ -166,13 +165,13 @@ impl<'a> AstValidator<'a> {
166165
state.print_where_predicate(p);
167166
}
168167

169-
errors::WhereClauseBeforeTypeAliasSugg::Move {
168+
errors::ModifyLeadingTyAliasWhereClause::Move {
170169
left: span,
171170
snippet: state.s.eof(),
172171
right: ty_alias.after_where_clause.span.shrink_to_hi(),
173172
}
174173
} else {
175-
errors::WhereClauseBeforeTypeAliasSugg::Remove { span }
174+
errors::ModifyLeadingTyAliasWhereClause::Remove { span }
176175
};
177176

178177
Err(errors::WhereClauseBeforeTypeAlias { span, sugg })
@@ -230,14 +229,12 @@ impl<'a> AstValidator<'a> {
230229
});
231230
}
232231

233-
fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) {
232+
fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>)) {
234233
for Param { pat, .. } in &decl.inputs {
235234
match pat.kind {
236235
PatKind::Missing | PatKind::Ident(BindingMode::NONE, _, None) | PatKind::Wild => {}
237-
PatKind::Ident(BindingMode::MUT, ident, None) => {
238-
report_err(pat.span, Some(ident), true)
239-
}
240-
_ => report_err(pat.span, None, false),
236+
PatKind::Ident(BindingMode::MUT, ident, None) => report_err(pat.span, Some(ident)),
237+
_ => report_err(pat.span, None),
241238
}
242239
}
243240
}
@@ -929,7 +926,7 @@ impl<'a> AstValidator<'a> {
929926
TyKind::FnPtr(bfty) => {
930927
self.check_fn_ptr_safety(bfty.decl_span, bfty.safety);
931928
self.check_fn_decl(&bfty.decl, SelfSemantic::No);
932-
Self::check_decl_no_pat(&bfty.decl, |span, _, _| {
929+
Self::check_decl_no_pat(&bfty.decl, |span, _| {
933930
self.dcx().emit_err(errors::PatternFnPointer { span });
934931
});
935932
if let Extern::Implicit(extern_span) = bfty.ext {
@@ -1355,7 +1352,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13551352
UNUSED_VISIBILITIES,
13561353
item.id,
13571354
item.vis.span,
1358-
BuiltinLintDiag::UnusedVisibility(item.vis.span),
1355+
errors::UnusedVisibility { span: item.vis.span },
13591356
)
13601357
}
13611358

@@ -1641,25 +1638,20 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
16411638

16421639
// Functions without bodies cannot have patterns.
16431640
if let FnKind::Fn(ctxt, _, Fn { body: None, sig, .. }) = fk {
1644-
Self::check_decl_no_pat(&sig.decl, |span, ident, mut_ident| {
1645-
if mut_ident && matches!(ctxt, FnCtxt::Assoc(_)) {
1646-
if let Some(ident) = ident {
1647-
self.lint_buffer.buffer_lint(
1648-
PATTERNS_IN_FNS_WITHOUT_BODY,
1649-
id,
1650-
span,
1651-
BuiltinLintDiag::PatternsInFnsWithoutBody {
1652-
span,
1653-
ident,
1654-
is_foreign: matches!(ctxt, FnCtxt::Foreign),
1655-
},
1656-
)
1657-
}
1658-
} else {
1659-
match ctxt {
1660-
FnCtxt::Foreign => self.dcx().emit_err(errors::PatternInForeign { span }),
1661-
_ => self.dcx().emit_err(errors::PatternInBodiless { span }),
1662-
};
1641+
Self::check_decl_no_pat(&sig.decl, |span, mut_ident| match ctxt {
1642+
FnCtxt::Assoc(_) if let Some(mut_ident) = mut_ident => {
1643+
self.lint_buffer.buffer_lint(
1644+
PATTERNS_IN_FNS_WITHOUT_BODY,
1645+
id,
1646+
span,
1647+
errors::PatternInBodilessLint { removal: span.until(mut_ident.span) },
1648+
);
1649+
}
1650+
FnCtxt::Foreign => {
1651+
self.dcx().emit_err(errors::PatternInForeign { span });
1652+
}
1653+
_ => {
1654+
self.dcx().emit_err(errors::PatternInBodiless { span });
16631655
}
16641656
});
16651657
}
@@ -1723,17 +1715,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
17231715
if let AssocItemKind::Type(ty_alias) = &item.kind
17241716
&& let Err(err) = self.check_type_alias_where_clause_location(ty_alias)
17251717
{
1726-
let sugg = match err.sugg {
1727-
errors::WhereClauseBeforeTypeAliasSugg::Remove { .. } => None,
1728-
errors::WhereClauseBeforeTypeAliasSugg::Move { snippet, right, .. } => {
1729-
Some((right, snippet))
1730-
}
1731-
};
17321718
self.lint_buffer.buffer_lint(
17331719
DEPRECATED_WHERE_CLAUSE_LOCATION,
17341720
item.id,
17351721
err.span,
1736-
BuiltinLintDiag::DeprecatedWhereclauseLocation(err.span, sugg),
1722+
errors::DeprecatedWhereClauseLocation { sugg: err.sugg },
17371723
);
17381724
}
17391725

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,18 +575,30 @@ pub(crate) struct WhereClauseBeforeTypeAlias {
575575
#[primary_span]
576576
pub span: Span,
577577
#[subdiagnostic]
578-
pub sugg: WhereClauseBeforeTypeAliasSugg,
578+
pub sugg: ModifyLeadingTyAliasWhereClause,
579+
}
580+
581+
#[derive(LintDiagnostic)]
582+
#[diag(ast_passes_deprecated_where_clause_location)]
583+
#[note]
584+
pub(crate) struct DeprecatedWhereClauseLocation {
585+
#[subdiagnostic]
586+
pub sugg: ModifyLeadingTyAliasWhereClause,
579587
}
580588

581589
#[derive(Subdiagnostic)]
582-
pub(crate) enum WhereClauseBeforeTypeAliasSugg {
583-
#[suggestion(ast_passes_remove_suggestion, applicability = "machine-applicable", code = "")]
590+
pub(crate) enum ModifyLeadingTyAliasWhereClause {
591+
#[suggestion(
592+
ast_passes_remove_leading_ty_alias_where_clause,
593+
applicability = "machine-applicable",
594+
code = ""
595+
)]
584596
Remove {
585597
#[primary_span]
586598
span: Span,
587599
},
588600
#[multipart_suggestion(
589-
ast_passes_move_suggestion,
601+
ast_passes_move_leading_ty_alias_where_clause,
590602
applicability = "machine-applicable",
591603
style = "verbose"
592604
)]
@@ -743,7 +755,6 @@ pub(crate) struct CVariadicNotSupported<'a> {
743755

744756
#[derive(Diagnostic)]
745757
#[diag(ast_passes_pattern_in_foreign, code = E0130)]
746-
// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
747758
pub(crate) struct PatternInForeign {
748759
#[primary_span]
749760
#[label]
@@ -752,13 +763,19 @@ pub(crate) struct PatternInForeign {
752763

753764
#[derive(Diagnostic)]
754765
#[diag(ast_passes_pattern_in_bodiless, code = E0642)]
755-
// FIXME: deduplicate with rustc_lint (`BuiltinLintDiag::PatternsInFnsWithoutBody`)
756766
pub(crate) struct PatternInBodiless {
757767
#[primary_span]
758768
#[label]
759769
pub span: Span,
760770
}
761771

772+
#[derive(LintDiagnostic)]
773+
#[diag(ast_passes_pattern_in_bodiless)]
774+
pub(crate) struct PatternInBodilessLint {
775+
#[suggestion(ast_passes_remove_mut_sugg, code = "", applicability = "machine-applicable")]
776+
pub removal: Span,
777+
}
778+
762779
#[derive(Diagnostic)]
763780
#[diag(ast_passes_equality_in_where)]
764781
#[note]
@@ -990,3 +1007,11 @@ pub(crate) struct AbiX86Interrupt {
9901007
pub spans: Vec<Span>,
9911008
pub param_count: usize,
9921009
}
1010+
1011+
#[derive(LintDiagnostic)]
1012+
#[diag(ast_passes_unused_visibilities)]
1013+
#[note]
1014+
pub(crate) struct UnusedVisibility {
1015+
#[suggestion(style = "short", code = "", applicability = "machine-applicable")]
1016+
pub span: Span,
1017+
}

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,6 @@ lint_deprecated_lint_name =
222222
.suggestion = change it to
223223
.help = change it to {$replace}
224224
225-
lint_deprecated_where_clause_location = where clause not allowed here
226-
.note = see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
227-
.suggestion_move_to_end = move it to the end of the type declaration
228-
.suggestion_remove_where = remove this `where`
229-
230225
lint_diag_out_of_impl =
231226
diagnostics should only be created in `Diagnostic`/`Subdiagnostic`/`LintDiagnostic` impls
232227
@@ -746,12 +741,6 @@ lint_path_statement_drop = path statement drops value
746741
747742
lint_path_statement_no_effect = path statement with no effect
748743
749-
lint_pattern_in_bodiless = patterns aren't allowed in functions without bodies
750-
.label = pattern not allowed in function without body
751-
752-
lint_pattern_in_foreign = patterns aren't allowed in foreign function declarations
753-
.label = pattern not allowed in foreign function
754-
755744
lint_query_instability = using `{$query}` can result in unstable query results
756745
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
757746
@@ -783,8 +772,6 @@ lint_redundant_semicolons_suggestion = remove {$multiple_semicolons ->
783772
*[false] this semicolon
784773
}
785774
786-
lint_remove_mut_from_pattern = remove `mut` from the parameter
787-
788775
lint_removed_lint = lint `{$name}` has been removed: {$reason}
789776
790777
lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
@@ -1004,10 +991,6 @@ lint_unused_op = unused {$op} that must be used
1004991
1005992
lint_unused_result = unused result of type `{$ty}`
1006993
1007-
lint_unused_visibilities = visibility qualifiers have no effect on `const _` declarations
1008-
.note = `const _` does not declare a name, so there is nothing for the qualifier to apply to
1009-
.suggestion = remove the qualifier
1010-
1011994
lint_use_let_underscore_ignore_suggestion = use `let _ = ...` to ignore the expression or result
1012995
1013996
lint_useless_ptr_null_checks_fn_ptr = function pointers are not nullable, so checking them for null will always return false

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,6 @@ pub fn decorate_builtin_lint(
104104
stability::Deprecated { sub, kind: "macro".to_owned(), path, note, since_kind }
105105
.decorate_lint(diag);
106106
}
107-
BuiltinLintDiag::PatternsInFnsWithoutBody { span: remove_span, ident, is_foreign } => {
108-
let sub = lints::PatternsInFnsWithoutBodySub { ident, span: remove_span };
109-
if is_foreign {
110-
lints::PatternsInFnsWithoutBody::Foreign { sub }
111-
} else {
112-
lints::PatternsInFnsWithoutBody::Bodiless { sub }
113-
}
114-
.decorate_lint(diag);
115-
}
116-
BuiltinLintDiag::DeprecatedWhereclauseLocation(left_sp, sugg) => {
117-
let suggestion = match sugg {
118-
Some((right_sp, sugg)) => lints::DeprecatedWhereClauseLocationSugg::MoveToEnd {
119-
left: left_sp,
120-
right: right_sp,
121-
sugg,
122-
},
123-
None => lints::DeprecatedWhereClauseLocationSugg::RemoveWhere { span: left_sp },
124-
};
125-
lints::DeprecatedWhereClauseLocation { suggestion }.decorate_lint(diag);
126-
}
127107
BuiltinLintDiag::SingleUseLifetime {
128108
param_span,
129109
use_span: Some((use_span, elide)),
@@ -240,9 +220,6 @@ pub fn decorate_builtin_lint(
240220
BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => {
241221
lints::UnusedCrateDependency { extern_crate, local_crate }.decorate_lint(diag)
242222
}
243-
BuiltinLintDiag::UnusedVisibility(span) => {
244-
lints::UnusedVisibility { span }.decorate_lint(diag)
245-
}
246223
BuiltinLintDiag::AttributeLint(kind) => decorate_attribute_lint(sess, tcx, &kind, diag),
247224
}
248225
}

0 commit comments

Comments
 (0)