Skip to content

Commit

Permalink
Fix doc test when async fn in trait is natively supported
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 15, 2023
1 parent ef144ae commit 5e67709
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::process::Command;
use std::str;

fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=DOCS_RS");

let compiler = match rustc_minor_version() {
Some(compiler) => compiler,
Expand All @@ -17,6 +17,10 @@ fn main() {
if compiler < 47 {
println!("cargo:rustc-cfg=self_span_hack");
}

if compiler >= 75 && env::var_os("DOCS_RS").is_none() {
println!("cargo:rustc-cfg=native_async_fn_in_trait");
}
}

fn rustc_minor_version() -> Option<u32> {
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
//! Rust 1.39 did not include support for async fn in traits. Trying to include
//! an async fn in a trait produces the following error:
//!
//! ```compile_fail
#![cfg_attr(not(native_async_fn_in_trait), doc = "```compile_fail")]
#![cfg_attr(native_async_fn_in_trait, doc = "```")]
//! trait MyTrait {
//! async fn f() {}
//! }
//! ```
#![doc = "```"]
//!
//! ```text
//! error[E0706]: trait fns cannot be declared `async`
Expand Down

0 comments on commit 5e67709

Please sign in to comment.