Blame 0002-Docs-avoid-doc-test-error-when-unsafe-vars-are-not-e.patch

f5ae38a
From b48b4a3899f4a5d0ba59973b5874dbf6322a323d Mon Sep 17 00:00:00 2001
f5ae38a
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
f5ae38a
Date: Wed, 17 Nov 2021 10:45:49 +0100
f5ae38a
Subject: [PATCH 2/3] Docs: avoid doc test error when unsafe-vars are not
f5ae38a
 enabled
f5ae38a
f5ae38a
'cargo test --doc' would fail:
f5ae38a
---- src/slab.rs - slab::ParseSlab (line 164) stdout ----
f5ae38a
error[E0599]: no method named `add_unsafe_var` found for struct `ParseSlab` in the current scope
f5ae38a
  --> src/slab.rs:173:26
f5ae38a
   |
f5ae38a
11 |     unsafe { slab_mut.ps.add_unsafe_var("bad".to_string(), &bad;; }  // `add_unsafe_var()` only exists if the `un...
f5ae38a
   |                          ^^^^^^^^^^^^^^ method not found in `ParseSlab`
f5ae38a
...
f5ae38a
f5ae38a
I checked that with the doc comment added, 'cargo test --doc' and
f5ae38a
'cargo test --doc --features unsafe-vars' passes, the doc output looks unchanged,
f5ae38a
and then when an error is introduced in the docs (e.g. a typo), they fail as
f5ae38a
expected with '--features unsafe-vars'.
f5ae38a
---
f5ae38a
 src/lib.rs  | 3 +++
f5ae38a
 src/slab.rs | 3 +++
f5ae38a
 2 files changed, 6 insertions(+)
f5ae38a
f5ae38a
diff --git a/src/lib.rs b/src/lib.rs
f5ae38a
index 5c752533e8..ac012293f1 100644
f5ae38a
--- a/src/lib.rs
f5ae38a
+++ b/src/lib.rs
f5ae38a
@@ -298,6 +298,8 @@
f5ae38a
 //! feature is not enabled by default because it slightly slows down other
f5ae38a
 //! non-variable operations.
f5ae38a
 //! ```
f5ae38a
+//! # #[cfg(feature="unsafe-vars")]
f5ae38a
+//! # {
f5ae38a
 //! use fasteval::Evaler;    // use this trait so we can call eval().
f5ae38a
 //! use fasteval::Compiler;  // use this trait so we can call compile().
f5ae38a
 //! fn main() -> Result<(), fasteval::Error> {
f5ae38a
@@ -327,6 +329,7 @@
f5ae38a
 //!
f5ae38a
 //!     Ok(())
f5ae38a
 //! }
f5ae38a
+//! # }
f5ae38a
 //! ```
f5ae38a
 //!
f5ae38a
 //! ## Let's Develop an Intuition of `fasteval` Internals
f5ae38a
diff --git a/src/slab.rs b/src/slab.rs
f5ae38a
index 40fdb65037..628a5d805a 100644
f5ae38a
--- a/src/slab.rs
f5ae38a
+++ b/src/slab.rs
f5ae38a
@@ -162,6 +162,8 @@ pub struct Slab {
f5ae38a
 /// Here is an example of correct and incorrect use of unsafe variable pointers:
f5ae38a
 ///
f5ae38a
 /// ```
f5ae38a
+/// # #[cfg(feature="unsafe-vars")]
f5ae38a
+/// # {
f5ae38a
 /// use fasteval::Evaler;    // use this trait so we can call eval().
f5ae38a
 /// use fasteval::Compiler;  // use this trait so we can call compile().
f5ae38a
 ///
f5ae38a
@@ -208,6 +210,7 @@ pub struct Slab {
f5ae38a
 ///
f5ae38a
 ///     Ok(())
f5ae38a
 /// }
f5ae38a
+/// # }
f5ae38a
 /// 
f5ae38a
 /// ```
f5ae38a
 pub struct ParseSlab {