Skip to content

Commit 18cd17d

Browse files
committed
Migrate FnPtrTyWithPat, MultipleExplicitLifetimeBound, ImplTraitTyInPathParam, ImplTraitTyNested, ImplTraitTyWithoutTraitBound, deprecated_extern_missing_abi
1 parent c8de335 commit 18cd17d

File tree

3 files changed

+67
-33
lines changed

3 files changed

+67
-33
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -624,13 +624,7 @@ impl<'a> AstValidator<'a> {
624624
TyKind::BareFn(bfty) => {
625625
self.check_fn_decl(&bfty.decl, SelfSemantic::No);
626626
Self::check_decl_no_pat(&bfty.decl, |span, _, _| {
627-
struct_span_err!(
628-
self.session,
629-
span,
630-
E0561,
631-
"patterns aren't allowed in function pointer types"
632-
)
633-
.emit();
627+
self.session.emit_err(FnPtrTyWithPat { span });
634628
});
635629
self.check_late_bound_lifetime_defs(&bfty.generic_params);
636630
if let Extern::Implicit(_) = bfty.ext {
@@ -643,13 +637,9 @@ impl<'a> AstValidator<'a> {
643637
for bound in bounds {
644638
if let GenericBound::Outlives(lifetime) = bound {
645639
if any_lifetime_bounds {
646-
struct_span_err!(
647-
self.session,
648-
lifetime.ident.span,
649-
E0226,
650-
"only a single explicit lifetime bound is permitted"
651-
)
652-
.emit();
640+
self.session.emit_err(MultipleExplicitLifetimeBound {
641+
span: lifetime.ident.span,
642+
});
653643
break;
654644
}
655645
any_lifetime_bounds = true;
@@ -658,29 +648,15 @@ impl<'a> AstValidator<'a> {
658648
}
659649
TyKind::ImplTrait(_, bounds) => {
660650
if self.is_impl_trait_banned {
661-
struct_span_err!(
662-
self.session,
663-
ty.span,
664-
E0667,
665-
"`impl Trait` is not allowed in path parameters"
666-
)
667-
.emit();
651+
self.session.emit_err(ImplTraitTyInPathParam { span: ty.span });
668652
}
669653

670-
if let Some(outer_impl_trait_sp) = self.outer_impl_trait {
671-
struct_span_err!(
672-
self.session,
673-
ty.span,
674-
E0666,
675-
"nested `impl Trait` is not allowed"
676-
)
677-
.span_label(outer_impl_trait_sp, "outer `impl Trait`")
678-
.span_label(ty.span, "nested `impl Trait` here")
679-
.emit();
654+
if let Some(outer_span) = self.outer_impl_trait {
655+
self.session.emit_err(ImplTraitTyNested { nested_span: ty.span, outer_span });
680656
}
681657

682658
if !bounds.iter().any(|b| matches!(b, GenericBound::Trait(..))) {
683-
self.err_handler().span_err(ty.span, "at least one trait must be specified");
659+
self.session.emit_err(ImplTraitTyWithoutTraitBound { span: ty.span });
684660
}
685661
}
686662
_ => {}
@@ -701,7 +677,7 @@ impl<'a> AstValidator<'a> {
701677
MISSING_ABI,
702678
id,
703679
span,
704-
"extern declarations without an explicit ABI are deprecated",
680+
fluent::ast_passes::deprecated_extern_missing_abi,
705681
BuiltinLintDiagnostics::MissingAbi(span, abi::Abi::FALLBACK),
706682
)
707683
}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,41 @@ pub struct GenericArgAfterConstraint {
408408
pub constraints_len: usize,
409409
pub correct_order: String,
410410
}
411+
412+
#[derive(SessionDiagnostic)]
413+
#[diag(ast_passes::fn_ptr_ty_with_pat, code = "E0561")]
414+
pub struct FnPtrTyWithPat {
415+
#[primary_span]
416+
pub span: Span,
417+
}
418+
419+
#[derive(SessionDiagnostic)]
420+
#[diag(ast_passes::multiple_explicit_lifetime_bound, code = "E0226")]
421+
pub struct MultipleExplicitLifetimeBound {
422+
#[primary_span]
423+
pub span: Span,
424+
}
425+
426+
#[derive(SessionDiagnostic)]
427+
#[diag(ast_passes::impl_trait_ty_in_path_param, code = "E0667")]
428+
pub struct ImplTraitTyInPathParam {
429+
#[primary_span]
430+
pub span: Span,
431+
}
432+
433+
#[derive(SessionDiagnostic)]
434+
#[diag(ast_passes::impl_trait_ty_nested, code = "E0666")]
435+
pub struct ImplTraitTyNested {
436+
#[primary_span]
437+
#[label(ast_passes::nested_label)]
438+
pub nested_span: Span,
439+
#[label(ast_passes::outer_label)]
440+
pub outer_span: Span,
441+
}
442+
443+
#[derive(SessionDiagnostic)]
444+
#[diag(ast_passes::impl_trait_ty_without_trait_bound)]
445+
pub struct ImplTraitTyWithoutTraitBound {
446+
#[primary_span]
447+
pub span: Span,
448+
}

compiler/rustc_error_messages/locales/en-US/ast_passes.ftl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,23 @@ ast_passes_generic_arg_after_constraint =
195195
[one] generic argument
196196
*[other] generic arguments
197197
}
198+
199+
ast_passes_fn_ptr_ty_with_pat =
200+
patterns aren't allowed in function pointer types
201+
202+
ast_passes_multiple_explicit_lifetime_bound =
203+
only a single explicit lifetime bound is permitted
204+
205+
ast_passes_impl_trait_ty_in_path_param =
206+
`impl Trait` is not allowed in path parameters
207+
208+
ast_passes_impl_trait_ty_nested =
209+
nested `impl Trait` is not allowed
210+
.outer_label = outer `impl Trait`
211+
.nested_label = nested `impl Trait` here
212+
213+
ast_passes_impl_trait_ty_without_trait_bound =
214+
at least one trait must be specified
215+
216+
ast_passes_deprecated_extern_missing_abi =
217+
extern declarations without an explicit ABI are deprecated

0 commit comments

Comments
 (0)