Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more context to async fn trait error. Suggest async-trait. #65937

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/librustc_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,12 @@ impl<'a> AstValidator<'a> {
fn check_trait_fn_not_async(&self, span: Span, asyncness: IsAsync) {
if asyncness.is_async() {
struct_span_err!(self.session, span, E0706,
"trait fns cannot be declared `async`").emit()
"trait fns cannot be declared `async`")
.note("Due to technical restrictions rust does not currently support `async` \
trait fns.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                .note("due to technical restrictions Rust does not currently support `async` \
                       trait functions")

@nikomatsakis @rust-lang/docs how would we feel about adding a link to https://smallcultfollowing.com/babysteps/blog/2019/10/26/async-fn-in-traits-are-hard/ here? Alternatively, @nikomatsakis, would you feel up to adding that blogpost (or a summarized version of it) to the book or some other stable documentation location?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should publish it on the inside Rust blog, perhaps, though I'm not sure if it's quite a "perfect fit." I don't think we should link to random-ish (obviously in this case it's Niko, but the point stands, I think) blogs from inside the compiler. We might also be able to uplift the content into a extended diagnostic perhaps?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extending the error code description sounds like the best course of action.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than link to blog posts, we could link to the async await book - https://rust-lang.github.io/async-book/07_workarounds/06_async_in_traits.html
(I'd be more than happy for the async book to be referencing useful blog posts)

.note("Consider using the `async-trait` crate in the meantime until further \
notice.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                .help("consider using the `async-trait` crate")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I need to dig into the struct_span_err macro a bit more to figure out what else can be used with it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.emit();
}
}

Expand Down