diff --git a/README.md b/README.md index 8e5af71..77a90cf 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ Dual licensed under MIT / Apache 2.0. While this crate is `no_std` compatible, it still requires the `alloc` crate. Version notes: +- Version `0.17.0` fixed a potential soundness issue, but removed support for + template parameters in the process. Lifetime parameters are still supported. + As of 2023-06-13, the compiler is practically sound with 0.16 but this may + stop being the case at any time and without warning. - Version `0.13.0` and later contain checks for additional situations which cause undefined behavior if not caught. - Version `0.11.0` and later place restrictions on derive macros, earlier diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 8243ddf..9f5739e 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ouroboros_examples" -version = "0.16.0" +version = "0.17.0" authors = ["Joshua Maros "] edition = "2018" license = "MIT OR Apache-2.0" @@ -21,7 +21,7 @@ std = [] __tokio = ["tokio", "std"] [dependencies] -ouroboros = { version = "0.16.0", path = "../ouroboros" } +ouroboros = { version = "0.17.0", path = "../ouroboros" } tokio = { version = "1.27.0", features = [ "macros", "rt" ], optional = true } [dev-dependencies] diff --git a/examples/src/fail_tests/auto_covariant.stderr b/examples/src/fail_tests/auto_covariant.stderr index 66b8ecf..54f2ae2 100644 --- a/examples/src/fail_tests/auto_covariant.stderr +++ b/examples/src/fail_tests/auto_covariant.stderr @@ -1,6 +1,11 @@ error: Ouroboros cannot automatically determine if this type is covariant. - If it is covariant, it should be legal to convert any instance of that type to an instance of that type where all usages of 'this are replaced with a smaller lifetime. For example, Box<&'this i32> is covariant because it is legal to use it as a Box<&'a i32> where 'this: 'a. In contrast, Fn(&'this i32) cannot be used as Fn(&'a i32). + As an example, a Box<&'this ()> is covariant because it can be used as a + Box<&'smaller ()> for any lifetime smaller than 'this. In contrast, + a Fn(&'this ()) is not covariant because it cannot be used as a + Fn(&'smaller ()). In general, values that are safe to use with smaller + lifetimes than they were defined with are covariant, breaking this + guarantee means the value is not covariant. To resolve this error, add #[covariant] or #[not_covariant] to the field. --> src/fail_tests/auto_covariant.rs:11:12 diff --git a/examples/src/ok_tests.rs b/examples/src/ok_tests.rs index 7a08614..78a04cb 100644 --- a/examples/src/ok_tests.rs +++ b/examples/src/ok_tests.rs @@ -1,4 +1,4 @@ -use alloc::boxed::Box; +use alloc::{boxed::Box, borrow::ToOwned}; use core::fmt::Debug; use ouroboros::self_referencing; @@ -31,7 +31,7 @@ struct ChainedAndUndocumented { data: i32, #[borrows(data)] ref1: &'this i32, - #[borrows(data)] + #[borrows(ref1)] ref2: &'this &'this i32, } @@ -245,6 +245,12 @@ fn single_lifetime() { #[borrows(external)] internal: &'this &'a str, } + + let external = "Hello world!".to_owned(); + let instance = Struct::new(&external, |field_ref| field_ref); + drop(instance.borrow_external()); + drop(instance.borrow_internal()); + drop(instance); } #[test] diff --git a/ouroboros/Cargo.toml b/ouroboros/Cargo.toml index 3c256b4..83845c5 100644 --- a/ouroboros/Cargo.toml +++ b/ouroboros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ouroboros" -version = "0.16.0" +version = "0.17.0" authors = ["Joshua Maros "] edition = "2018" license = "MIT OR Apache-2.0" @@ -11,7 +11,7 @@ repository = "https://github.com/joshua-maros/ouroboros" [dependencies] aliasable = "0.1.3" -ouroboros_macro = { version = "0.16.0", path = "../ouroboros_macro" } +ouroboros_macro = { version = "0.17.0", path = "../ouroboros_macro" } static_assertions = "1.1.0" [features] diff --git a/ouroboros/src/lib.rs b/ouroboros/src/lib.rs index 13870da..db6d5c5 100644 --- a/ouroboros/src/lib.rs +++ b/ouroboros/src/lib.rs @@ -123,7 +123,7 @@ /// immutable: i32, /// mutable: i32, /// #[borrows(immutable, mut mutable)] -/// #[covariant] +/// #[not_covariant] /// complex_data: ComplexData<'this, 'this>, /// } /// diff --git a/ouroboros_macro/Cargo.toml b/ouroboros_macro/Cargo.toml index 5b2a56b..3d501b6 100644 --- a/ouroboros_macro/Cargo.toml +++ b/ouroboros_macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ouroboros_macro" -version = "0.16.0" +version = "0.17.0" authors = ["Joshua Maros "] edition = "2018" license = "MIT OR Apache-2.0" diff --git a/ouroboros_macro/src/generate/drop.rs b/ouroboros_macro/src/generate/drop.rs index a78d5e1..1cfb7f2 100644 --- a/ouroboros_macro/src/generate/drop.rs +++ b/ouroboros_macro/src/generate/drop.rs @@ -1,7 +1,4 @@ -use crate::{ - info_structures::StructInfo, - utils::{self, replace_this_with_lifetime}, -}; +use crate::info_structures::StructInfo; use proc_macro2::TokenStream; use quote::quote; use syn::Error; diff --git a/ouroboros_macro/src/info_structures.rs b/ouroboros_macro/src/info_structures.rs index f3e4a54..7e7fd5c 100644 --- a/ouroboros_macro/src/info_structures.rs +++ b/ouroboros_macro/src/info_structures.rs @@ -13,13 +13,13 @@ pub struct Options { } impl Options { - pub fn documentation_to_tokens(&self, documentation: &str) -> TokenStream { - if self.do_no_doc { - quote! { #[doc(hidden)] } - } else { - quote! { #[doc=#documentation] } - } - } + // pub fn documentation_to_tokens(&self, documentation: &str) -> TokenStream { + // if self.do_no_doc { + // quote! { #[doc(hidden)] } + // } else { + // quote! { #[doc=#documentation] } + // } + // } } #[derive(Clone, Copy, PartialEq)]