From e3d4c4039a3b041c7610735c641e5688c25af8b2 Mon Sep 17 00:00:00 2001 From: finalchild Date: Thu, 18 Aug 2022 16:49:52 +0900 Subject: [PATCH] Migrate trait_fn_async --- compiler/rustc_ast_passes/src/ast_validation.rs | 11 +---------- compiler/rustc_ast_passes/src/errors.rs | 11 +++++++++++ .../rustc_error_messages/locales/en-US/ast_passes.ftl | 6 ++++++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index fee876489f7..234243f372c 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -287,16 +287,7 @@ impl<'a> AstValidator<'a> { fn check_trait_fn_not_async(&self, fn_span: Span, asyncness: Async) { if let Async::Yes { span, .. } = asyncness { - struct_span_err!( - self.session, - fn_span, - E0706, - "functions in traits cannot be declared `async`" - ) - .span_label(span, "`async` because of this") - .note("`async` trait functions are not currently supported") - .note("consider using the `async-trait` crate: https://crates.io/crates/async-trait") - .emit(); + self.session.emit_err(TraitFnAsync { fn_span, span }); } } diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index 8bea95ea092..ed44beafff2 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -71,3 +71,14 @@ pub enum InvalidVisibilityNote { #[note(ast_passes::individual_foreign_items)] IndividualForeignItems, } + +#[derive(SessionDiagnostic)] +#[error(ast_passes::trait_fn_async, code = "E0706")] +#[note] +#[note(ast_passes::note2)] +pub struct TraitFnAsync { + #[primary_span] + pub fn_span: Span, + #[label] + pub span: Span, +} diff --git a/compiler/rustc_error_messages/locales/en-US/ast_passes.ftl b/compiler/rustc_error_messages/locales/en-US/ast_passes.ftl index 153a91cc7e2..ab2313fd86c 100644 --- a/compiler/rustc_error_messages/locales/en-US/ast_passes.ftl +++ b/compiler/rustc_error_messages/locales/en-US/ast_passes.ftl @@ -21,3 +21,9 @@ ast_passes_invalid_visibility = .implied = `pub` not permitted here because it's implied .individual_impl_items = place qualifiers on individual impl items instead .individual_foreign_items = place qualifiers on individual foreign items instead + +ast_passes_trait_fn_async = + functions in traits cannot be declared `async` + .label = `async` because of this + .note = `async` trait functions are not currently supported + .note2 = consider using the `async-trait` crate: https://crates.io/crates/async-trait