]> git.proxmox.com Git - rustc.git/blobdiff - vendor/anyhow/build.rs
New upstream version 1.65.0+dfsg1
[rustc.git] / vendor / anyhow / build.rs
index c470ba11b0a3b20250dd4280795a3883f1abdbe9..38006832e27ba8737bef57b1d9858d7f6afc1c95 100644 (file)
@@ -15,15 +15,17 @@ compile_error! {
 // type. If the current toolchain is able to compile it, we go ahead and use
 // backtrace in anyhow.
 const PROBE: &str = r#"
-    #![feature(backtrace)]
-    #![allow(dead_code)]
+    #![feature(error_generic_member_access, provide_any)]
 
+    use std::any::{Demand, Provider};
     use std::backtrace::{Backtrace, BacktraceStatus};
     use std::error::Error;
     use std::fmt::{self, Display};
 
     #[derive(Debug)]
-    struct E;
+    struct E {
+        backtrace: Backtrace,
+    }
 
     impl Display for E {
         fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
@@ -32,14 +34,26 @@ const PROBE: &str = r#"
     }
 
     impl Error for E {
-        fn backtrace(&self) -> Option<&Backtrace> {
-            let backtrace = Backtrace::capture();
-            match backtrace.status() {
-                BacktraceStatus::Captured | BacktraceStatus::Disabled | _ => {}
-            }
-            unimplemented!()
+        fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
+            demand.provide_ref(&self.backtrace);
         }
     }
+
+    struct P;
+
+    impl Provider for P {
+        fn provide<'a>(&'a self, _demand: &mut Demand<'a>) {}
+    }
+
+    const _: fn() = || {
+        let backtrace: Backtrace = Backtrace::capture();
+        let status: BacktraceStatus = backtrace.status();
+        match status {
+            BacktraceStatus::Captured | BacktraceStatus::Disabled | _ => {}
+        }
+    };
+
+    const _: fn(&dyn Error) -> Option<&Backtrace> = |err| err.request_ref::<Backtrace>();
 "#;
 
 fn main() {