From 5e677097d2e67f7a5c5e3023e2f3b99b36a9e132 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 14 Oct 2023 19:48:59 -0700 Subject: [PATCH] Fix doc test when async fn in trait is natively supported --- build.rs | 6 +++++- src/lib.rs | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build.rs b/build.rs index d7f6b15..f25fb0a 100644 --- a/build.rs +++ b/build.rs @@ -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, @@ -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 { diff --git a/src/lib.rs b/src/lib.rs index e35dd03..896f724 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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`