summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2022-04-17 19:27:13 -0300
committerSoniEx2 <endermoneymod@gmail.com>2022-04-17 19:27:13 -0300
commit01c6e6c4b6c81cfe55a543598daa9b7b8fb331e0 (patch)
tree432a226493331763df269e4f08ebe0addccb191d
parent2772887c9ea3676149bc37b5b296bd85ae0c9e1c (diff)
Fix LtPhPtr variance
-rw-r--r--src/extra_tests.rs14
-rw-r--r--src/lib.rs60
2 files changed, 45 insertions, 29 deletions
diff --git a/src/extra_tests.rs b/src/extra_tests.rs
new file mode 100644
index 0000000..8aed5a9
--- /dev/null
+++ b/src/extra_tests.rs
@@ -0,0 +1,14 @@
+//! Extra tests!
+//!
+//! ```compile_fail
+//! use std::mem;
+//! use hexchat_unsafe_plugin::PluginHandle;
+//!
+//! fn prepoop_your_pants_pluginhandle<'ph>(ph: &mut PluginHandle<'ph>) {
+//!     let temporary: String = "Hello, world!".to_string();
+//!     let hook = ph.hook_timer(0, |_| {
+//!         println!("{}", temporary);
+//!         true
+//!     });
+//! }
+//! ```
diff --git a/src/lib.rs b/src/lib.rs
index 3211786..fb207aa 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -187,11 +187,12 @@
 pub extern crate libc;
 
 mod eat;
+mod extra_tests;
 mod infoid;
 mod internals;
 mod pluginfo;
-mod word;
 mod strip;
+mod word;
 
 pub use eat::*;
 pub use infoid::InfoId;
@@ -295,7 +296,8 @@ pub unsafe trait Plugin<'ph> {
 #[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
 pub struct LtPhPtr<'ph> {
     ph: *mut RawPh,
-    _lt: PhantomData<&'ph RawPh>,
+    // 'ph has to be invariant because RawPh is self-referential.
+    _lt: PhantomData<fn(&'ph ()) -> &'ph ()>,
 }
 
 /// A hexchat plugin handle, used to register hooks and interact with hexchat.
@@ -588,33 +590,33 @@ impl<'ph> PluginHandle<'ph> {
         }
     }
 
-    /// Operates on a virtual plugin.
-    ///
-    /// # Examples
-    ///
-    /// ```no_run
-    /// use hexchat_unsafe_plugin::{PluginHandle};
-    ///
-    /// fn contexts_can_be_passed_in(ph: &mut PluginHandle<'_>) {
-    ///     let ctx = ph.get_context();
-    ///     let mut vplug = ph.plugingui_add("foo", "bar", "baz", "qux");
-    ///     ph.for_entry_mut(&mut vplug, |ph| {
-    ///         ph.set_context(&ctx);
-    ///     });
-    /// }
-    /// ```
-    pub fn for_entry_mut<'eh, F, R>(&mut self, entry: &mut PluginEntryHandle<'ph>, f: F) -> R where F: FnOnce(&mut PluginHandle<'eh>) -> R, 'ph: 'eh {
-        // we're doing something kinda (very) weird here, but this is the only
-        // way to get and set pluginprefs for virtual plugins.
-        // this should be sound.
-        let data = self.data;
-        let info = self.info;
-        let contexts = Rc::clone(&self.contexts);
-        let mut handle = unsafe { Self::new(data, info, contexts) };
-        handle.plugin = entry.entry as *mut RawPh;
-        handle.set_context(&self.get_context());
-        f(&mut handle)
-    }
+    ///// Operates on a virtual plugin.
+    /////
+    ///// # Examples
+    /////
+    ///// ```no_run
+    ///// use hexchat_unsafe_plugin::{PluginHandle};
+    /////
+    ///// fn contexts_can_be_passed_in(ph: &mut PluginHandle<'_>) {
+    /////     let ctx = ph.get_context();
+    /////     let mut vplug = ph.plugingui_add("foo", "bar", "baz", "qux");
+    /////     ph.for_entry_mut(&mut vplug, |ph| {
+    /////         ph.set_context(&ctx);
+    /////     });
+    ///// }
+    ///// ```
+    //pub fn for_entry_mut<'eh, F, R>(&mut self, entry: &mut PluginEntryHandle<'ph>, f: F) -> R where F: FnOnce(&mut PluginHandle<'eh>) -> R, 'ph: 'eh {
+    //    // we're doing something kinda (very) weird here, but this is the only
+    //    // way to get and set pluginprefs for virtual plugins.
+    //    // this should be sound.
+    //    let data = self.data;
+    //    let info = self.info;
+    //    let contexts = Rc::clone(&self.contexts);
+    //    let mut handle = unsafe { Self::new(data, info, contexts) };
+    //    handle.plugin = entry.entry as *mut RawPh;
+    //    handle.set_context(&self.get_context());
+    //    f(&mut handle)
+    //}
 
     /// Registers a virtual plugin.
     pub fn plugingui_add(&self, filename: &str, name: &str, description: &str, version: &str) -> PluginEntryHandle<'ph> {