-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.") | ||
.note("Consider using the `async-trait` crate in the meantime until further \ | ||
notice.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I need to dig into the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.emit(); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)