From 287ecd75a69872111f8c059568c002ee7c60cf9a Mon Sep 17 00:00:00 2001 From: Daniel Henry-Mantilla Date: Fri, 8 Jul 2022 17:34:46 +0200 Subject: [PATCH] Reduce MSRV down to 1.53.0 --- .github/workflows/CI.yml | 13 +- .github/workflows/future-proof.yml | 12 +- Cargo.lock | 8 +- Cargo.toml | 10 +- rust-toolchain.toml | 2 +- src/lib.rs | 7 +- src/proc_macros/gat-attr/_mod.rs | 2 +- src/proc_macros/mod.rs | 2 +- tests/main.rs | 282 ++++++++++++++--------------- 9 files changed, 165 insertions(+), 173 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e1a1af4..eea07ab 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -9,12 +9,12 @@ on: jobs: # == CHECK == # check: - name: "Check beta stable and MSRV=1.60.0" + name: "Check beta stable and MSRV=1.53.0" runs-on: ubuntu-latest strategy: matrix: rust-toolchains: - - 1.60.0 + - 1.53.0 - stable - beta cargo-locked: ["--locked", ""] @@ -52,7 +52,7 @@ jobs: - macos-latest - windows-latest rust-toolchains: - - 1.60.0 + - 1.53.0 - stable steps: - name: Install Rust toolchain @@ -65,17 +65,18 @@ jobs: - name: Clone repo uses: actions/checkout@v2 - - name: Cargo test + - name: Cargo test (MSRV) + if: matrix.rust-toolchains == '1.53.0' uses: actions-rs/cargo@v1 with: command: test - - name: Cargo test (embedded doc tests) + - name: Cargo test (full) if: matrix.rust-toolchains == 'stable' uses: actions-rs/cargo@v1 with: command: test - args: --features docs --doc + args: --features docs,test-lending-iterator-filter # == UI TESTS == ui-test: diff --git a/.github/workflows/future-proof.yml b/.github/workflows/future-proof.yml index 22a177c..b86a2c5 100644 --- a/.github/workflows/future-proof.yml +++ b/.github/workflows/future-proof.yml @@ -21,7 +21,7 @@ jobs: - macos-latest - windows-latest rust-toolchains: - - 1.60.0 + - 1.53.0 - stable - beta - nightly @@ -41,14 +41,16 @@ jobs: if: matrix.cargo-locked != '--locked' run: cargo update -v - - name: Cargo test + - name: Cargo test (MSRV) + if: matrix.rust-toolchains == '1.53.0' uses: actions-rs/cargo@v1 with: command: test args: ${{ matrix.cargo-locked }} - - name: Cargo test (embed `README.md` + UI) - if: matrix.rust-toolchains != '1.60.0' + - name: Cargo test (full) + if: matrix.rust-toolchains != '1.53.0' uses: actions-rs/cargo@v1 with: - command: test-ui + command: test + args: ${{ matrix.cargo-locked }} --features docs,test-lending-iterator-filter diff --git a/Cargo.lock b/Cargo.lock index eb9cb34..3f09c11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "macro_rules_attribute" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2db753a9eacb63f7aa2c64bfdd2cd3f35cc8b0946799f0b60f7110f4f3104e3b" +checksum = "258c86475e1616d6f2d8f5227cfaabd3dae1f6d5388b9597df8a199d4497aba7" dependencies = [ "macro_rules_attribute-proc_macro", "paste", @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "macro_rules_attribute-proc_macro" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61568f4b6f1d9c6b31185090275fb372dab0f5cea6a772e906ec56d1dc6d74aa" +checksum = "f26a8d2502d5aa4d411ef494ba7470eb299f05725179ce3b5de77aa01a9ffdea" [[package]] name = "nougat" diff --git a/Cargo.toml b/Cargo.toml index e00c288..8b54ac1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,15 +23,21 @@ debug-macros = [ "nougat-proc_macros/debug-macros" ] +test-lending-iterator-filter = [ + "polonius-the-crab", +] + [dependencies] -macro_rules_attribute.version = "0.1.0" +macro_rules_attribute.version = "0.1.2" + +polonius-the-crab.version = "0.2.1" +polonius-the-crab.optional = true [dependencies.nougat-proc_macros] path = "src/proc_macros" version = "0.2.0-rc1" # Keep in sync [dev-dependencies] -polonius-the-crab.version = "0.2.1" [workspace] members = [ diff --git a/rust-toolchain.toml b/rust-toolchain.toml index aaf5e5d..16ff3fe 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = '1.57.0' +channel = '1.53.0' # Templated by `cargo-generate` using https://github.com/danielhenrymantilla/proc-macro-template diff --git a/src/lib.rs b/src/lib.rs index da9d264..d99ead9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ //! [`Gat!`]: Gat //! [#\[gat\]]: gat -#![doc = include_str!("../README.md")] +#![cfg_attr(docs, + cfg_attr(all(), doc = include_str!("../README.md")), +)] #![doc(html_logo_url = "https://user-images.githubusercontent.com/9920355/170709986-aaa13f92-0faf-4b5d-89c9-6463b6b3d49b.png")] #![deny(rustdoc::private_intra_doc_links)] @@ -13,6 +15,7 @@ /// ## Example(s) /// /** - ```rust + # use ::core::convert::TryInto; # fn main() {} #[macro_use] extern crate nougat; @@ -218,6 +221,6 @@ pub use ::nougat_proc_macros::Gat; pub use ::macro_rules_attribute::apply; #[cfg_attr(feature = "ui-tests", - doc = include_str!("compile_fail_tests.md"), + cfg_attr(all(), doc = include_str!("compile_fail_tests.md")), )] mod _compile_fail_tests {} diff --git a/src/proc_macros/gat-attr/_mod.rs b/src/proc_macros/gat-attr/_mod.rs index 6533c2a..b07cef0 100644 --- a/src/proc_macros/gat-attr/_mod.rs +++ b/src/proc_macros/gat-attr/_mod.rs @@ -143,7 +143,7 @@ impl visit_mut::VisitMut if type_path.path.segments.first().unwrap().ident == "Self" && matches!( type_path.path.segments.last().unwrap().arguments, - | PathArguments::AngleBracketed { .. } + PathArguments::AngleBracketed { .. } ) { let Self_; diff --git a/src/proc_macros/mod.rs b/src/proc_macros/mod.rs index f9e6ab6..10a0bf7 100644 --- a/src/proc_macros/mod.rs +++ b/src/proc_macros/mod.rs @@ -68,7 +68,7 @@ fn combine_trait_name_and_assoc_type ( ) -> Ident { Ident::new( - &format!("{}__{}", trait_name, assoc_type), + &format!("{}ඞ{}", trait_name, assoc_type), assoc_type.span(), // .located_at(trait_name.span()), ) } diff --git a/tests/main.rs b/tests/main.rs index d0787e8..e31d7d9 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -1,6 +1,7 @@ #![allow(unused)] use { ::core::{ + convert::TryInto, ops::Not, }, ::nougat::{ @@ -21,154 +22,133 @@ trait LendingIterator { ; } -// type Item<'lt, I> = Gat!(::Item<'lt>); - -// struct Infinite; - -// #[gat] -// impl LendingIterator for Infinite { -// type Item<'next> -// where -// Self : 'next, -// = -// &'next mut Self -// ; - -// fn next ( -// self: &'_ mut Self, -// ) -> Option<&'_ mut Self> -// { -// Some(self) -// } -// } - -// struct WindowsMut { -// slice: Slice, -// /// This is unfortunately needed for a non-`unsafe` implementation. -// start: usize, -// } - -// #[gat] -// impl<'lt, T, const WIDTH: usize> -// LendingIterator -// for -// WindowsMut<&'lt mut [T], WIDTH> -// { -// type Item<'next> -// where -// Self : 'next, -// = -// &'next mut [T; WIDTH] -// ; - -// fn next (self: &'_ mut WindowsMut<&'lt mut [T], WIDTH>) -// -> Option<&'_ mut [T; WIDTH]> -// { -// let to_yield = -// self.slice -// .get_mut(self.start ..)? -// .get_mut(.. WIDTH)? -// ; -// self.start += 1; -// Some(to_yield.try_into().unwrap()) -// } -// } - -// fn _check (mut iter: I) -// { -// let _ = _check::; -// let _ = _check::>; -// while let Some(_item) = iter.next() { -// // … -// } -// } - -// /// `T : MyFnMut <=> T : FnMut(A) -> _` -// trait MyFnMut : FnMut(A) -> Self::Ret { -// type Ret; -// } -// impl R, A, R> MyFnMut for F { -// type Ret = R; -// } - -// struct Map(I, F); - -// #[gat] -// impl LendingIterator for Map -// where -// I : LendingIterator, -// for<'any> -// F : MyFnMut> -// , -// { -// type Item<'next> -// where -// Self : 'next, -// = -// >>::Ret -// ; - -// fn next (self: &'_ mut Map) -// -> Option< -// >>::Ret -// > -// { -// self.0.next().map(&mut self.1) -// } -// } - -// struct Filter { -// iterator: I, -// should_yield: F, -// } - -// #[gat] -// impl LendingIterator for Filter -// where -// I : LendingIterator, -// F : FnMut(&'_ Item<'_, I>) -> bool, -// { -// type Item<'next> -// where -// Self : 'next, -// = -// ::Item<'next> -// ; - -// fn next (self: &'_ mut Filter) -// -> Option> -// { -// use ::polonius_the_crab::prelude::*; -// let mut iter = &mut self.iterator; -// polonius_loop!(|iter| -> Option> { -// let ret = iter.next(); -// if matches!(&ret, Some(it) if (self.should_yield)(it).not()) { -// polonius_continue!(); -// } -// polonius_return!(ret); -// }) -// } -// } - -// trait LendingIterator2__Item<'next, SelfLt = Self, Bounds = &'next SelfLt> { -// type T : ?Sized + Sized; -// } - -// trait LendingIterator2 { -// type Item : -// ?Sized + for<'next> LendingIterator2__Item<'next, SelfLt> -// ; - -// fn next (self: &'_ mut Self) -// -> < -// >::Item -// as -// LendingIterator2__Item<'_, SelfLt> -// >::T -// ; -// } - -// type Foo<'outlives> = dyn 'outlives + LendingIterator2< -// &'outlives (), -// Item = dyn for<'next> LendingIterator2__Item<'next, &'outlives (), T = &'next u8>, -// >; +type Item<'lt, I> = Gat!(::Item<'lt>); + +struct Infinite; + +#[gat] +impl LendingIterator for Infinite { + type Item<'next> + where + Self : 'next, + = + &'next mut Self + ; + + fn next ( + self: &'_ mut Self, + ) -> Option<&'_ mut Self> + { + Some(self) + } +} + +struct WindowsMut { + slice: Slice, + /// This is unfortunately needed for a non-`unsafe` implementation. + start: usize, +} + +#[gat] +impl<'lt, T, const WIDTH: usize> + LendingIterator +for + WindowsMut<&'lt mut [T], WIDTH> +{ + type Item<'next> + where + Self : 'next, + = + &'next mut [T; WIDTH] + ; + + fn next (self: &'_ mut WindowsMut<&'lt mut [T], WIDTH>) + -> Option<&'_ mut [T; WIDTH]> + { + let to_yield = + self.slice + .get_mut(self.start ..)? + .get_mut(.. WIDTH)? + ; + self.start += 1; + Some(to_yield.try_into().unwrap()) + } +} + +fn _check (mut iter: I) +{ + let _ = _check::; + let _ = _check::>; + while let Some(_item) = iter.next() { + // … + } +} + +/// `T : MyFnMut <=> T : FnMut(A) -> _` +trait MyFnMut : FnMut(A) -> Self::Ret { + type Ret; +} +impl R, A, R> MyFnMut for F { + type Ret = R; +} + +struct Map(I, F); + +#[gat] +impl LendingIterator for Map +where + I : LendingIterator, + for<'any> + F : MyFnMut> + , +{ + type Item<'next> + where + Self : 'next, + = + >>::Ret + ; + + fn next (self: &'_ mut Map) + -> Option< + >>::Ret + > + { + self.0.next().map(&mut self.1) + } +} + +#[cfg(feature = "test-lending-iterator-filter")] +struct Filter { + iterator: I, + should_yield: F, +} + +#[cfg(feature = "test-lending-iterator-filter")] +#[gat] +impl LendingIterator for Filter +where + I : LendingIterator, + F : FnMut(&'_ Item<'_, I>) -> bool, +{ + type Item<'next> + where + Self : 'next, + = + ::Item<'next> + ; + + fn next (self: &'_ mut Filter) + -> Option> + { + use ::polonius_the_crab::prelude::*; + let mut iter = &mut self.iterator; + polonius_loop!(|iter| -> Option> { + let ret = iter.next(); + if matches!(&ret, Some(it) if (self.should_yield)(it).not()) { + polonius_continue!(); + } + polonius_return!(ret); + }) + } +}