Skip to content

Commit 5e67709

Browse files
committed
Fix doc test when async fn in trait is natively supported
1 parent ef144ae commit 5e67709

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::process::Command;
33
use std::str;
44

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

88
let compiler = match rustc_minor_version() {
99
Some(compiler) => compiler,
@@ -17,6 +17,10 @@ fn main() {
1717
if compiler < 47 {
1818
println!("cargo:rustc-cfg=self_span_hack");
1919
}
20+
21+
if compiler >= 75 && env::var_os("DOCS_RS").is_none() {
22+
println!("cargo:rustc-cfg=native_async_fn_in_trait");
23+
}
2024
}
2125

2226
fn rustc_minor_version() -> Option<u32> {

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
//! Rust 1.39 did not include support for async fn in traits. Trying to include
1313
//! an async fn in a trait produces the following error:
1414
//!
15-
//! ```compile_fail
15+
#![cfg_attr(not(native_async_fn_in_trait), doc = "```compile_fail")]
16+
#![cfg_attr(native_async_fn_in_trait, doc = "```")]
1617
//! trait MyTrait {
1718
//! async fn f() {}
1819
//! }
19-
//! ```
20+
#![doc = "```"]
2021
//!
2122
//! ```text
2223
//! error[E0706]: trait fns cannot be declared `async`

0 commit comments

Comments
 (0)