From 9d671f9f508bf390c4f61717c5092c7e84ee629d Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Wed, 13 Nov 2024 17:19:33 +0100 Subject: [PATCH 1/7] use core instead of std --- rstest/src/magic_conversion.rs | 20 ++++++++--------- rstest/src/timeout.rs | 5 +++-- .../resources/fixture/default_conversion.rs | 2 +- .../resources/fixture/defined_return_type.rs | 4 ++-- rstest/tests/resources/fixture/dyn.rs | 4 ++-- rstest/tests/resources/fixture/errors_once.rs | 8 +++---- rstest/tests/resources/fixture/impl.rs | 6 ++--- rstest/tests/resources/rstest/cases/inject.rs | 4 ++-- .../rstest/convert_string_literal.rs | 2 +- .../convert_string_literal_other_name.rs | 2 +- rstest/tests/resources/rstest/lifetimes.rs | 2 +- .../tests/resources/rstest/local_lifetime.rs | 2 +- .../tests/resources/rstest/matrix/inject.rs | 2 +- rstest/tests/resources/rstest/timeout.rs | 2 +- .../tests/resources/rstest/timeout_async.rs | 2 +- .../resources/rstest/timeout_other_name.rs | 2 +- rstest_fixtures/src/lib.rs | 6 ++--- rstest_macros/src/error.rs | 14 ++++++------ rstest_macros/src/parse/fixture.rs | 4 ++-- rstest_macros/src/parse/just_once.rs | 6 ++--- rstest_macros/src/parse/mod.rs | 22 +++++++++---------- rstest_macros/src/parse/rstest/files.rs | 6 ++--- rstest_macros/src/render/apply_arguments.rs | 22 +++++++++---------- rstest_macros/src/render/fixture.rs | 6 ++--- rstest_macros/src/render/inject.rs | 2 +- rstest_macros/src/render/mod.rs | 6 ++--- rstest_macros/src/render/test.rs | 12 +++++----- rstest_macros/src/test.rs | 2 +- rstest_reuse/src/lib.rs | 2 +- 29 files changed, 90 insertions(+), 89 deletions(-) diff --git a/rstest/src/magic_conversion.rs b/rstest/src/magic_conversion.rs index 4df2301e..a04fbc05 100644 --- a/rstest/src/magic_conversion.rs +++ b/rstest/src/magic_conversion.rs @@ -1,4 +1,4 @@ -pub struct Magic(pub std::marker::PhantomData); +pub struct Magic(pub core::marker::PhantomData); pub trait ViaParseDebug<'a, T> { fn magic_conversion(&self, input: &'a str) -> T; @@ -6,8 +6,8 @@ pub trait ViaParseDebug<'a, T> { impl<'a, T> ViaParseDebug<'a, T> for &&Magic where - T: std::str::FromStr, - T::Err: std::fmt::Debug, + T: core::str::FromStr, + T::Err: core::fmt::Debug, { fn magic_conversion(&self, input: &'a str) -> T { T::from_str(input).unwrap() @@ -20,7 +20,7 @@ pub trait ViaParse<'a, T> { impl<'a, T> ViaParse<'a, T> for &Magic where - T: std::str::FromStr, + T: core::str::FromStr, { fn magic_conversion(&self, input: &'a str) -> T { match T::from_str(input) { @@ -29,7 +29,7 @@ where panic!( "Cannot parse '{}' to get {}", input, - std::any::type_name::() + core::any::type_name::() ); } } @@ -49,13 +49,13 @@ impl<'a> ViaIdent<'a, &'a str> for &&Magic<&'a str> { #[cfg(test)] mod test { use super::*; - use std::str::FromStr; + use core::str::FromStr; #[test] fn should_return_the_same_slice_string() { assert_eq!( "something", - (&&&Magic::<&str>(std::marker::PhantomData)).magic_conversion("something") + (&&&Magic::<&str>(core::marker::PhantomData)).magic_conversion("something") ); } @@ -63,7 +63,7 @@ mod test { fn should_parse_via_parse_debug() { assert_eq!( 42u32, - (&&&Magic::(std::marker::PhantomData)).magic_conversion("42") + (&&&Magic::(core::marker::PhantomData)).magic_conversion("42") ); } @@ -81,7 +81,7 @@ mod test { assert_eq!( "some", - (&&&Magic::(std::marker::PhantomData)) + (&&&Magic::(core::marker::PhantomData)) .magic_conversion("some") .0 ); @@ -99,6 +99,6 @@ mod test { Err(E) } } - (&&&Magic::(std::marker::PhantomData)).magic_conversion(""); + (&&&Magic::(core::marker::PhantomData)).magic_conversion(""); } } diff --git a/rstest/src/timeout.rs b/rstest/src/timeout.rs index 011e3a41..fcca5319 100644 --- a/rstest/src/timeout.rs +++ b/rstest/src/timeout.rs @@ -1,4 +1,5 @@ -use std::{sync::mpsc, thread, time::Duration}; +use core::time::Duration; +use std::{sync::mpsc, thread}; #[cfg(feature = "async-timeout")] use futures::{select, Future, FutureExt}; @@ -51,7 +52,7 @@ mod tests { mod async_version { use super::*; - use std::time::Duration; + use core::time::Duration; async fn delayed_sum(a: u32, b: u32, delay: Duration) -> u32 { async_std::task::sleep(delay).await; diff --git a/rstest/tests/resources/fixture/default_conversion.rs b/rstest/tests/resources/fixture/default_conversion.rs index aee1ecf6..e894e7ca 100644 --- a/rstest/tests/resources/fixture/default_conversion.rs +++ b/rstest/tests/resources/fixture/default_conversion.rs @@ -1,5 +1,5 @@ use rstest::{fixture, rstest}; -use std::net::{Ipv4Addr, SocketAddr}; +use core::net::{Ipv4Addr, SocketAddr}; struct MyType(String); struct E; diff --git a/rstest/tests/resources/fixture/defined_return_type.rs b/rstest/tests/resources/fixture/defined_return_type.rs index db0315d7..7419889f 100644 --- a/rstest/tests/resources/fixture/defined_return_type.rs +++ b/rstest/tests/resources/fixture/defined_return_type.rs @@ -12,7 +12,7 @@ pub fn j() -> i32 { #[fixture(::default>::partial_1>)] pub fn fx(i: I, j: J) -> impl Iterator { - std::iter::once((i, j)) + core::iter::once((i, j)) } #[test] @@ -29,7 +29,7 @@ fn resolve_partial() { #[default(impl Iterator)] #[partial_1(impl Iterator)] pub fn fx_attrs(i: I, j: J) -> impl Iterator { - std::iter::once((i, j)) + core::iter::once((i, j)) } #[test] diff --git a/rstest/tests/resources/fixture/dyn.rs b/rstest/tests/resources/fixture/dyn.rs index 27ea0265..ab9203f9 100644 --- a/rstest/tests/resources/fixture/dyn.rs +++ b/rstest/tests/resources/fixture/dyn.rs @@ -1,8 +1,8 @@ use rstest::*; #[fixture] -fn dyn_box() -> Box> { - Box::new(std::iter::once(42)) +fn dyn_box() -> Box> { + Box::new(core::iter::once(42)) } #[fixture] diff --git a/rstest/tests/resources/fixture/errors_once.rs b/rstest/tests/resources/fixture/errors_once.rs index 034af631..6a210f8e 100644 --- a/rstest/tests/resources/fixture/errors_once.rs +++ b/rstest/tests/resources/fixture/errors_once.rs @@ -7,18 +7,18 @@ async fn error_async_once_fixture() { #[fixture] #[once] -fn error_generics_once_fixture() -> T { +fn error_generics_once_fixture() -> T { 42 } #[fixture] #[once] fn error_generics_once_fixture() -> impl Iterator { - std::iter::once(42) + core::iter::once(42) } #[fixture] #[once] -fn error_once_fixture_not_sync() -> std::cell::Cell { - std::cell::Cell::new(42) +fn error_once_fixture_not_sync() -> core::cell::Cell { + core::cell::Cell::new(42) } diff --git a/rstest/tests/resources/fixture/impl.rs b/rstest/tests/resources/fixture/impl.rs index 0e848271..c11245eb 100644 --- a/rstest/tests/resources/fixture/impl.rs +++ b/rstest/tests/resources/fixture/impl.rs @@ -1,7 +1,7 @@ use rstest::*; #[fixture] -fn fx_base_impl_return() -> impl Iterator { std::iter::once(42) } +fn fx_base_impl_return() -> impl Iterator { core::iter::once(42) } #[fixture] fn fx_base_impl_input(mut fx_base_impl_return: impl Iterator) -> u32 { @@ -19,7 +19,7 @@ fn base_impl_input(mut fx_base_impl_input: u32) { } #[fixture] -fn fx_nested_impl_return() -> impl Iterator { std::iter::once(42) } +fn fx_nested_impl_return() -> impl Iterator { core::iter::once(42) } #[fixture] fn fx_nested_impl_input(mut fx_nested_impl_return: impl Iterator) -> String { @@ -38,7 +38,7 @@ fn nested_impl_input(mut fx_nested_impl_input: String) { #[fixture] fn fx_nested_multiple_impl_return() -> (impl Iterator, impl ToString) { - (std::iter::once(42), 42i32) + (core::iter::once(42), 42i32) } #[fixture] diff --git a/rstest/tests/resources/rstest/cases/inject.rs b/rstest/tests/resources/rstest/cases/inject.rs index eb2dc758..0096451d 100644 --- a/rstest/tests/resources/rstest/cases/inject.rs +++ b/rstest/tests/resources/rstest/cases/inject.rs @@ -1,6 +1,6 @@ -use rstest::*; use actix_rt; -use std::future::Future; +use core::future::Future; +use rstest::*; #[rstest(expected, value, case::pass(42, 42), diff --git a/rstest/tests/resources/rstest/convert_string_literal.rs b/rstest/tests/resources/rstest/convert_string_literal.rs index 3e7989fe..a29c6447 100644 --- a/rstest/tests/resources/rstest/convert_string_literal.rs +++ b/rstest/tests/resources/rstest/convert_string_literal.rs @@ -1,5 +1,5 @@ +use core::net::SocketAddr; use rstest::*; -use std::net::SocketAddr; #[rstest] #[case(true, "1.2.3.4:42")] diff --git a/rstest/tests/resources/rstest/convert_string_literal_other_name.rs b/rstest/tests/resources/rstest/convert_string_literal_other_name.rs index b5a0f887..f9aba4da 100644 --- a/rstest/tests/resources/rstest/convert_string_literal_other_name.rs +++ b/rstest/tests/resources/rstest/convert_string_literal_other_name.rs @@ -1,5 +1,5 @@ +use core::net::SocketAddr; use other_name::*; -use std::net::SocketAddr; #[rstest] #[case(true, "1.2.3.4:42")] diff --git a/rstest/tests/resources/rstest/lifetimes.rs b/rstest/tests/resources/rstest/lifetimes.rs index 440751b1..c6bd13b8 100644 --- a/rstest/tests/resources/rstest/lifetimes.rs +++ b/rstest/tests/resources/rstest/lifetimes.rs @@ -2,7 +2,7 @@ use rstest::*; enum E<'a> { A(bool), - B(&'a std::cell::Cell>), + B(&'a core::cell::Cell>), } #[rstest] diff --git a/rstest/tests/resources/rstest/local_lifetime.rs b/rstest/tests/resources/rstest/local_lifetime.rs index 61d93682..f13cfdb9 100644 --- a/rstest/tests/resources/rstest/local_lifetime.rs +++ b/rstest/tests/resources/rstest/local_lifetime.rs @@ -1,4 +1,4 @@ -use std::cell::Cell; +use core::cell::Cell; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum E<'a> { diff --git a/rstest/tests/resources/rstest/matrix/inject.rs b/rstest/tests/resources/rstest/matrix/inject.rs index 6547f09b..df9173c8 100644 --- a/rstest/tests/resources/rstest/matrix/inject.rs +++ b/rstest/tests/resources/rstest/matrix/inject.rs @@ -1,6 +1,6 @@ use rstest::*; use actix_rt; -use std::future::Future; +use core::future::Future; #[rstest( first => [1, 2], diff --git a/rstest/tests/resources/rstest/timeout.rs b/rstest/tests/resources/rstest/timeout.rs index 88df7520..c12c7365 100644 --- a/rstest/tests/resources/rstest/timeout.rs +++ b/rstest/tests/resources/rstest/timeout.rs @@ -1,5 +1,5 @@ use rstest::*; -use std::time::Duration; +use core::time::Duration; fn ms(ms: u32) -> Duration { Duration::from_millis(ms.into()) diff --git a/rstest/tests/resources/rstest/timeout_async.rs b/rstest/tests/resources/rstest/timeout_async.rs index 1d12cf52..c7441dda 100644 --- a/rstest/tests/resources/rstest/timeout_async.rs +++ b/rstest/tests/resources/rstest/timeout_async.rs @@ -1,5 +1,5 @@ +use core::time::Duration; use rstest::*; -use std::time::Duration; fn ms(ms: u32) -> Duration { Duration::from_millis(ms.into()) diff --git a/rstest/tests/resources/rstest/timeout_other_name.rs b/rstest/tests/resources/rstest/timeout_other_name.rs index b360b313..d6fd8645 100644 --- a/rstest/tests/resources/rstest/timeout_other_name.rs +++ b/rstest/tests/resources/rstest/timeout_other_name.rs @@ -1,5 +1,5 @@ +use core::time::Duration; use other_name::*; -use std::time::Duration; fn ms(ms: u32) -> Duration { Duration::from_millis(ms.into()) diff --git a/rstest_fixtures/src/lib.rs b/rstest_fixtures/src/lib.rs index bb62acd6..60248c97 100644 --- a/rstest_fixtures/src/lib.rs +++ b/rstest_fixtures/src/lib.rs @@ -1,4 +1,4 @@ -use std::fmt::Debug; +use core::fmt::Debug; pub trait TearDown { fn tear_down(self); @@ -42,7 +42,7 @@ impl Fixture { } impl Debug for Fixture { - fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { + fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> { write!(f, "Fixture<{:?}>", self.inner) } } @@ -76,7 +76,7 @@ impl()> From for TearDownClosure { #[cfg(test)] mod test { use super::*; - use std::cell::RefCell; + use core::cell::RefCell; use std::rc::Rc; #[test] diff --git a/rstest_macros/src/error.rs b/rstest_macros/src/error.rs index 74fac8b6..63c6a14d 100644 --- a/rstest_macros/src/error.rs +++ b/rstest_macros/src/error.rs @@ -42,11 +42,11 @@ pub(crate) fn fixture(test: &ItemFn, info: &FixtureInfo) -> TokenStream { fn async_once<'a>(test: &'a ItemFn, info: &FixtureInfo) -> Errors<'a> { match (test.sig.asyncness, info.arguments.get_once()) { - (Some(_asyncness), Some(once)) => Box::new(std::iter::once(syn::Error::new_spanned( + (Some(_asyncness), Some(once)) => Box::new(core::iter::once(syn::Error::new_spanned( once, "Cannot apply #[once] to async fixture.", ))), - _ => Box::new(std::iter::empty()), + _ => Box::new(core::iter::empty()), } } @@ -79,11 +79,11 @@ fn has_some_generics(test: &ItemFn) -> bool { fn generics_once<'a>(test: &'a ItemFn, info: &FixtureInfo) -> Errors<'a> { match (has_some_generics(test), info.arguments.get_once()) { - (true, Some(once)) => Box::new(std::iter::once(syn::Error::new_spanned( + (true, Some(once)) => Box::new(core::iter::once(syn::Error::new_spanned( once, "Cannot apply #[once] on generic fixture.", ))), - _ => Box::new(std::iter::empty()), + _ => Box::new(core::iter::empty()), } } @@ -156,14 +156,14 @@ macro_rules! composed_tuple { }; } -impl std::ops::Deref for ErrorsVec { +impl core::ops::Deref for ErrorsVec { type Target = Vec; fn deref(&self) -> &Self::Target { &self.0 } } -impl std::ops::DerefMut for ErrorsVec { +impl core::ops::DerefMut for ErrorsVec { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } @@ -270,7 +270,7 @@ fn case_args_without_cases(params: &RsTestData) -> Errors { .map(|a| syn::Error::new(a.span(), "No cases for this argument.")), ); } - Box::new(std::iter::empty()) + Box::new(core::iter::empty()) } trait RenderType { diff --git a/rstest_macros/src/parse/fixture.rs b/rstest_macros/src/parse/fixture.rs index 70fe2018..47a7a392 100644 --- a/rstest_macros/src/parse/fixture.rs +++ b/rstest_macros/src/parse/fixture.rs @@ -56,7 +56,7 @@ impl ExtendWithFunctionAttrs for FixtureInfo { fn extend_with_function_attrs( &mut self, item_fn: &mut ItemFn, - ) -> std::result::Result<(), ErrorsVec> { + ) -> core::result::Result<(), ErrorsVec> { let composed_tuple!( fixtures, defaults, @@ -132,7 +132,7 @@ impl VisitMut for FixturesFunctionExtractor { Some(pt) => pt, None => return, }; - let (extracted, remain): (Vec<_>, Vec<_>) = std::mem::take(&mut arg.attrs) + let (extracted, remain): (Vec<_>, Vec<_>) = core::mem::take(&mut arg.attrs) .into_iter() .partition(|attr| attr_in(attr, &["with", "from"])); arg.attrs = remain; diff --git a/rstest_macros/src/parse/just_once.rs b/rstest_macros/src/parse/just_once.rs index 303d556e..bf055c31 100644 --- a/rstest_macros/src/parse/just_once.rs +++ b/rstest_macros/src/parse/just_once.rs @@ -1,4 +1,4 @@ -use std::marker::PhantomData; +use core::marker::PhantomData; use quote::ToTokens; use syn::{visit_mut::VisitMut, Attribute, FnArg, ItemFn, Pat}; @@ -87,7 +87,7 @@ where }; if let FnArg::Typed(ref mut arg) = node { // Extract interesting attributes - let attrs = std::mem::take(&mut arg.attrs); + let attrs = core::mem::take(&mut arg.attrs); let (extracted, remain): (Vec<_>, Vec<_>) = attrs.into_iter().partition(|a| attr_is(a, self.name)); @@ -167,7 +167,7 @@ where { fn visit_item_fn_mut(&mut self, item_fn: &mut ItemFn) { // Extract interesting attributes - let attrs = std::mem::take(&mut item_fn.attrs); + let attrs = core::mem::take(&mut item_fn.attrs); let (extracted, remain): (Vec<_>, Vec<_>) = attrs.into_iter().partition(|a| attr_is(a, self.name)); diff --git a/rstest_macros/src/parse/mod.rs b/rstest_macros/src/parse/mod.rs index baef9e66..6e0b6ca8 100644 --- a/rstest_macros/src/parse/mod.rs +++ b/rstest_macros/src/parse/mod.rs @@ -41,7 +41,7 @@ pub(crate) trait ExtendWithFunctionAttrs { fn extend_with_function_attrs( &mut self, item_fn: &mut ItemFn, - ) -> std::result::Result<(), ErrorsVec>; + ) -> core::result::Result<(), ErrorsVec>; } #[derive(Default, Debug, PartialEq, Clone)] @@ -260,19 +260,19 @@ pub(crate) fn extract_once(item_fn: &mut ItemFn) -> Result( +pub(crate) fn extract_argument_attrs<'a, B: 'a + core::fmt::Debug>( node: &mut FnArg, is_valid_attr: fn(&syn::Attribute) -> bool, build: impl Fn(syn::Attribute) -> syn::Result + 'a, ) -> Box> + 'a> { let name = node.maybe_ident().cloned(); if name.is_none() { - return Box::new(std::iter::empty()); + return Box::new(core::iter::empty()); } if let FnArg::Typed(ref mut arg) = node { // Extract interesting attributes - let attrs = std::mem::take(&mut arg.attrs); + let attrs = core::mem::take(&mut arg.attrs); let (extracted, remain): (Vec<_>, Vec<_>) = attrs.into_iter().partition(is_valid_attr); arg.attrs = remain; @@ -280,7 +280,7 @@ pub(crate) fn extract_argument_attrs<'a, B: 'a + std::fmt::Debug>( // Parse attrs Box::new(extracted.into_iter().map(build)) } else { - Box::new(std::iter::empty()) + Box::new(core::iter::empty()) } } @@ -302,7 +302,7 @@ impl Default for PartialsTypeFunctionExtractor { impl VisitMut for PartialsTypeFunctionExtractor { fn visit_item_fn_mut(&mut self, node: &mut ItemFn) { - let attrs = std::mem::take(&mut node.attrs); + let attrs = core::mem::take(&mut node.attrs); let (partials, remain): (Vec<_>, Vec<_>) = attrs .into_iter() @@ -355,7 +355,7 @@ struct CasesFunctionExtractor(Vec, Vec); impl VisitMut for CasesFunctionExtractor { fn visit_item_fn_mut(&mut self, node: &mut ItemFn) { - let attrs = std::mem::take(&mut node.attrs); + let attrs = core::mem::take(&mut node.attrs); let mut attrs_buffer = Default::default(); let case: syn::PathSegment = parse_quote! { case }; for attr in attrs.into_iter() { @@ -366,7 +366,7 @@ impl VisitMut for CasesFunctionExtractor { attr.path().segments.iter().nth(1).map(|p| p.ident.clone()); self.0.push(TestCase { args: expressions.into(), - attrs: std::mem::take(&mut attrs_buffer), + attrs: core::mem::take(&mut attrs_buffer), description, }); } @@ -376,7 +376,7 @@ impl VisitMut for CasesFunctionExtractor { attrs_buffer.push(attr) } } - node.attrs = std::mem::take(&mut attrs_buffer); + node.attrs = core::mem::take(&mut attrs_buffer); } } @@ -585,14 +585,14 @@ mod should { fn integrated() { let attributes = parse_attributes( r#" - simple :: tagged(first, second) :: type_tag<(u32, T, (std::string::String, i32))> :: more_tagged(a,b)"#, + simple :: tagged(first, second) :: type_tag<(u32, T, (core::string::String, i32))> :: more_tagged(a,b)"#, ); let expected = Attributes { attributes: vec![ Attribute::attr("simple"), Attribute::tagged("tagged", vec!["first", "second"]), - Attribute::typed("type_tag", "(u32, T, (std::string::String, i32))"), + Attribute::typed("type_tag", "(u32, T, (core::string::String, i32))"), Attribute::tagged("more_tagged", vec!["a", "b"]), ], }; diff --git a/rstest_macros/src/parse/rstest/files.rs b/rstest_macros/src/parse/rstest/files.rs index fd334884..7c50e9d0 100644 --- a/rstest_macros/src/parse/rstest/files.rs +++ b/rstest_macros/src/parse/rstest/files.rs @@ -277,7 +277,7 @@ impl ValueFilesExtractor { } } - fn extract_argument_attrs<'a, B: 'a + std::fmt::Debug>( + fn extract_argument_attrs<'a, B: 'a + core::fmt::Debug>( &mut self, node: &mut FnArg, is_valid_attr: fn(&syn::Attribute) -> bool, @@ -525,7 +525,7 @@ impl<'a> ValueListFromFiles<'a> { let path_str = abs_path.to_string_lossy(); values.push(( parse_quote! { - <::std::path::PathBuf as std::str::FromStr>::from_str(#path_str).unwrap() + <::std::path::PathBuf as core::str::FromStr>::from_str(#path_str).unwrap() }, render_file_description(&relative_path), )); @@ -908,7 +908,7 @@ mod should { .map(|r| r.to_logical_path(bdir)) .map(|p| { format!( - r#"<::std::path::PathBuf as std::str::FromStr>::from_str("{}").unwrap()"#, + r#"<::std::path::PathBuf as core::str::FromStr>::from_str("{}").unwrap()"#, p.as_os_str().to_str().unwrap() ) }) diff --git a/rstest_macros/src/render/apply_arguments.rs b/rstest_macros/src/render/apply_arguments.rs index 715e3a66..f632086c 100644 --- a/rstest_macros/src/render/apply_arguments.rs +++ b/rstest_macros/src/render/apply_arguments.rs @@ -118,7 +118,7 @@ impl ImplFutureArg for FnArg { Some(ty) => { let lifetime = update_type_with_lifetime(ty, lifetime_id); *ty = parse_quote! { - impl std::future::Future + impl core::future::Future }; self.remove_mutability(); lifetime @@ -166,30 +166,30 @@ mod should { #[case::simple( "fn f(a: u32) {}", &["a"], - "fn f(a: impl std::future::Future) {}" + "fn f(a: impl core::future::Future) {}" )] #[case::more_than_one( "fn f(a: u32, b: String, c: std::collection::HashMap) {}", &["a", "b", "c"], - r#"fn f(a: impl std::future::Future, - b: impl std::future::Future, - c: impl std::future::Future>) {}"#, + r#"fn f(a: impl core::future::Future, + b: impl core::future::Future, + c: impl core::future::Future>) {}"#, )] #[case::just_one( "fn f(a: u32, b: String) {}", &["b"], r#"fn f(a: u32, - b: impl std::future::Future) {}"# + b: impl core::future::Future) {}"# )] #[case::generics( "fn f>(a: S) {}", &["a"], - "fn f>(a: impl std::future::Future) {}" + "fn f>(a: impl core::future::Future) {}" )] #[case::remove_mut( "fn f(mut a: u32) {}", &["a"], - r#"fn f(a: impl std::future::Future) {}"# + r#"fn f(a: impl core::future::Future) {}"# )] fn replace_future_basic_type( #[case] item_fn: &str, @@ -213,17 +213,17 @@ mod should { #[case::base( "fn f(ident_name: &u32) {}", &["ident_name"], - "fn f<'_ident_name>(ident_name: impl std::future::Future) {}" + "fn f<'_ident_name>(ident_name: impl core::future::Future) {}" )] #[case::lifetime_already_exists( "fn f<'b>(a: &'b u32) {}", &["a"], - "fn f<'b>(a: impl std::future::Future) {}" + "fn f<'b>(a: impl core::future::Future) {}" )] #[case::some_other_generics( "fn f<'b, IT: Iterator>(a: &u32, it: IT) {}", &["a"], - "fn f<'_a, 'b, IT: Iterator>(a: impl std::future::Future, it: IT) {}" + "fn f<'_a, 'b, IT: Iterator>(a: impl core::future::Future, it: IT) {}" )] fn replace_reference_type( #[case] item_fn: &str, diff --git a/rstest_macros/src/render/fixture.rs b/rstest_macros/src/render/fixture.rs index 74451a8e..0a3a8508 100644 --- a/rstest_macros/src/render/fixture.rs +++ b/rstest_macros/src/render/fixture.rs @@ -54,7 +54,7 @@ pub(crate) fn render(mut fixture: ItemFn, info: FixtureInfo) -> TokenStream { .extract_default_type() .unwrap_or_else(|| fixture.sig.output.clone()); let default_generics = - generics_clean_up(&fixture.sig.generics, std::iter::empty(), &default_output); + generics_clean_up(&fixture.sig.generics, core::iter::empty(), &default_output); let default_where_clause = &default_generics.where_clause; let where_clause = &fixture.sig.generics.where_clause; let mut output = fixture.sig.output.clone(); @@ -536,8 +536,8 @@ mod should { let expected = parse_str::( r#" async fn get<'_async_ref_u32>( - async_ref_u32: impl std::future::Future, - async_u32: impl std::future::Future, + async_ref_u32: impl core::future::Future, + async_u32: impl core::future::Future, simple: u32 ) { } diff --git a/rstest_macros/src/render/inject.rs b/rstest_macros/src/render/inject.rs index d3946f0d..2a2c7b18 100644 --- a/rstest_macros/src/render/inject.rs +++ b/rstest_macros/src/render/inject.rs @@ -110,7 +110,7 @@ fn handling_magic_conversion_code(fixture: Cow, arg_type: &Type) -> Expr { parse_quote! { { use #rstest_path::magic_conversion::*; - (&&&Magic::<#arg_type>(std::marker::PhantomData)).magic_conversion(#fixture) + (&&&Magic::<#arg_type>(core::marker::PhantomData)).magic_conversion(#fixture) } } } diff --git a/rstest_macros/src/render/mod.rs b/rstest_macros/src/render/mod.rs index 275abefc..28f9e710 100644 --- a/rstest_macros/src/render/mod.rs +++ b/rstest_macros/src/render/mod.rs @@ -41,7 +41,7 @@ pub(crate) fn single(mut test: ItemFn, mut info: RsTestInfo) -> TokenStream { let resolver = resolver::fixtures::get(&info.arguments, info.data.fixtures()); let args = test.sig.inputs.iter().cloned().collect::>(); - let attrs = std::mem::take(&mut test.attrs); + let attrs = core::mem::take(&mut test.attrs); let asyncness = test.sig.asyncness; single_test_case( @@ -208,7 +208,7 @@ fn render_test_call( let timeout = timeout.map(|x| quote! {#x}).or_else(|| { std::env::var("RSTEST_TIMEOUT") .ok() - .map(|to| quote! { std::time::Duration::from_secs( (#to).parse().unwrap()) }) + .map(|to| quote! { core::time::Duration::from_secs( (#to).parse().unwrap()) }) }); let rstest_path = crate_name(); match (timeout, is_async) { @@ -411,7 +411,7 @@ trait DisplayLen { fn display_len(&self) -> usize; } -impl DisplayLen for D { +impl DisplayLen for D { fn display_len(&self) -> usize { format!("{self}").len() } diff --git a/rstest_macros/src/render/test.rs b/rstest_macros/src/render/test.rs index f4086757..a6d03f81 100644 --- a/rstest_macros/src/render/test.rs +++ b/rstest_macros/src/render/test.rs @@ -326,8 +326,8 @@ mod single_test_should { let expected = parse_str::( r#"async fn test<'_async_ref_u32>( - async_ref_u32: impl std::future::Future, - async_u32: impl std::future::Future, + async_ref_u32: impl core::future::Future, + async_u32: impl core::future::Future, simple: u32 ) { } @@ -908,8 +908,8 @@ mod cases_should { let expected = parse_str::( r#"async fn test<'_async_ref_u32>( - async_ref_u32: impl std::future::Future, - async_u32: impl std::future::Future, + async_ref_u32: impl core::future::Future, + async_u32: impl core::future::Future, simple: u32 ) { } @@ -1354,8 +1354,8 @@ mod matrix_cases_should { let expected = parse_str::( r#"async fn test<'_async_ref_u32>( - async_ref_u32: impl std::future::Future, - async_u32: impl std::future::Future, + async_ref_u32: impl core::future::Future, + async_u32: impl core::future::Future, simple: u32 ) { } diff --git a/rstest_macros/src/test.rs b/rstest_macros/src/test.rs index 672c5c5c..a47f3b43 100644 --- a/rstest_macros/src/test.rs +++ b/rstest_macros/src/test.rs @@ -286,7 +286,7 @@ impl> FromIterator for TestCase { impl<'a> From<&'a str> for TestCase { fn from(argument: &'a str) -> Self { - std::iter::once(argument).collect() + core::iter::once(argument).collect() } } diff --git a/rstest_reuse/src/lib.rs b/rstest_reuse/src/lib.rs index f7489f6e..510bc337 100644 --- a/rstest_reuse/src/lib.rs +++ b/rstest_reuse/src/lib.rs @@ -310,7 +310,7 @@ pub fn template(_args: proc_macro::TokenStream, input: proc_macro::TokenStream) template.attrs = match rstest_index { Some(idx) => attributes.split_off(idx), - None => std::mem::take(&mut attributes), + None => core::mem::take(&mut attributes), }; let (macro_attribute, visibility) = match get_export(&attributes) { From 0a2009ad6196be83d42f33f08e81259dede0cbcc Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 14 Nov 2024 12:49:00 +0100 Subject: [PATCH 2/7] Revert "use core instead of std" This reverts commit 9d671f9f508bf390c4f61717c5092c7e84ee629d. --- rstest/src/magic_conversion.rs | 20 ++++++++--------- rstest/src/timeout.rs | 5 ++--- .../resources/fixture/default_conversion.rs | 2 +- .../resources/fixture/defined_return_type.rs | 4 ++-- rstest/tests/resources/fixture/dyn.rs | 4 ++-- rstest/tests/resources/fixture/errors_once.rs | 8 +++---- rstest/tests/resources/fixture/impl.rs | 6 ++--- rstest/tests/resources/rstest/cases/inject.rs | 4 ++-- .../rstest/convert_string_literal.rs | 2 +- .../convert_string_literal_other_name.rs | 2 +- rstest/tests/resources/rstest/lifetimes.rs | 2 +- .../tests/resources/rstest/local_lifetime.rs | 2 +- .../tests/resources/rstest/matrix/inject.rs | 2 +- rstest/tests/resources/rstest/timeout.rs | 2 +- .../tests/resources/rstest/timeout_async.rs | 2 +- .../resources/rstest/timeout_other_name.rs | 2 +- rstest_fixtures/src/lib.rs | 6 ++--- rstest_macros/src/error.rs | 14 ++++++------ rstest_macros/src/parse/fixture.rs | 4 ++-- rstest_macros/src/parse/just_once.rs | 6 ++--- rstest_macros/src/parse/mod.rs | 22 +++++++++---------- rstest_macros/src/parse/rstest/files.rs | 6 ++--- rstest_macros/src/render/apply_arguments.rs | 22 +++++++++---------- rstest_macros/src/render/fixture.rs | 6 ++--- rstest_macros/src/render/inject.rs | 2 +- rstest_macros/src/render/mod.rs | 6 ++--- rstest_macros/src/render/test.rs | 12 +++++----- rstest_macros/src/test.rs | 2 +- rstest_reuse/src/lib.rs | 2 +- 29 files changed, 89 insertions(+), 90 deletions(-) diff --git a/rstest/src/magic_conversion.rs b/rstest/src/magic_conversion.rs index a04fbc05..4df2301e 100644 --- a/rstest/src/magic_conversion.rs +++ b/rstest/src/magic_conversion.rs @@ -1,4 +1,4 @@ -pub struct Magic(pub core::marker::PhantomData); +pub struct Magic(pub std::marker::PhantomData); pub trait ViaParseDebug<'a, T> { fn magic_conversion(&self, input: &'a str) -> T; @@ -6,8 +6,8 @@ pub trait ViaParseDebug<'a, T> { impl<'a, T> ViaParseDebug<'a, T> for &&Magic where - T: core::str::FromStr, - T::Err: core::fmt::Debug, + T: std::str::FromStr, + T::Err: std::fmt::Debug, { fn magic_conversion(&self, input: &'a str) -> T { T::from_str(input).unwrap() @@ -20,7 +20,7 @@ pub trait ViaParse<'a, T> { impl<'a, T> ViaParse<'a, T> for &Magic where - T: core::str::FromStr, + T: std::str::FromStr, { fn magic_conversion(&self, input: &'a str) -> T { match T::from_str(input) { @@ -29,7 +29,7 @@ where panic!( "Cannot parse '{}' to get {}", input, - core::any::type_name::() + std::any::type_name::() ); } } @@ -49,13 +49,13 @@ impl<'a> ViaIdent<'a, &'a str> for &&Magic<&'a str> { #[cfg(test)] mod test { use super::*; - use core::str::FromStr; + use std::str::FromStr; #[test] fn should_return_the_same_slice_string() { assert_eq!( "something", - (&&&Magic::<&str>(core::marker::PhantomData)).magic_conversion("something") + (&&&Magic::<&str>(std::marker::PhantomData)).magic_conversion("something") ); } @@ -63,7 +63,7 @@ mod test { fn should_parse_via_parse_debug() { assert_eq!( 42u32, - (&&&Magic::(core::marker::PhantomData)).magic_conversion("42") + (&&&Magic::(std::marker::PhantomData)).magic_conversion("42") ); } @@ -81,7 +81,7 @@ mod test { assert_eq!( "some", - (&&&Magic::(core::marker::PhantomData)) + (&&&Magic::(std::marker::PhantomData)) .magic_conversion("some") .0 ); @@ -99,6 +99,6 @@ mod test { Err(E) } } - (&&&Magic::(core::marker::PhantomData)).magic_conversion(""); + (&&&Magic::(std::marker::PhantomData)).magic_conversion(""); } } diff --git a/rstest/src/timeout.rs b/rstest/src/timeout.rs index fcca5319..011e3a41 100644 --- a/rstest/src/timeout.rs +++ b/rstest/src/timeout.rs @@ -1,5 +1,4 @@ -use core::time::Duration; -use std::{sync::mpsc, thread}; +use std::{sync::mpsc, thread, time::Duration}; #[cfg(feature = "async-timeout")] use futures::{select, Future, FutureExt}; @@ -52,7 +51,7 @@ mod tests { mod async_version { use super::*; - use core::time::Duration; + use std::time::Duration; async fn delayed_sum(a: u32, b: u32, delay: Duration) -> u32 { async_std::task::sleep(delay).await; diff --git a/rstest/tests/resources/fixture/default_conversion.rs b/rstest/tests/resources/fixture/default_conversion.rs index e894e7ca..aee1ecf6 100644 --- a/rstest/tests/resources/fixture/default_conversion.rs +++ b/rstest/tests/resources/fixture/default_conversion.rs @@ -1,5 +1,5 @@ use rstest::{fixture, rstest}; -use core::net::{Ipv4Addr, SocketAddr}; +use std::net::{Ipv4Addr, SocketAddr}; struct MyType(String); struct E; diff --git a/rstest/tests/resources/fixture/defined_return_type.rs b/rstest/tests/resources/fixture/defined_return_type.rs index 7419889f..db0315d7 100644 --- a/rstest/tests/resources/fixture/defined_return_type.rs +++ b/rstest/tests/resources/fixture/defined_return_type.rs @@ -12,7 +12,7 @@ pub fn j() -> i32 { #[fixture(::default>::partial_1>)] pub fn fx(i: I, j: J) -> impl Iterator { - core::iter::once((i, j)) + std::iter::once((i, j)) } #[test] @@ -29,7 +29,7 @@ fn resolve_partial() { #[default(impl Iterator)] #[partial_1(impl Iterator)] pub fn fx_attrs(i: I, j: J) -> impl Iterator { - core::iter::once((i, j)) + std::iter::once((i, j)) } #[test] diff --git a/rstest/tests/resources/fixture/dyn.rs b/rstest/tests/resources/fixture/dyn.rs index ab9203f9..27ea0265 100644 --- a/rstest/tests/resources/fixture/dyn.rs +++ b/rstest/tests/resources/fixture/dyn.rs @@ -1,8 +1,8 @@ use rstest::*; #[fixture] -fn dyn_box() -> Box> { - Box::new(core::iter::once(42)) +fn dyn_box() -> Box> { + Box::new(std::iter::once(42)) } #[fixture] diff --git a/rstest/tests/resources/fixture/errors_once.rs b/rstest/tests/resources/fixture/errors_once.rs index 6a210f8e..034af631 100644 --- a/rstest/tests/resources/fixture/errors_once.rs +++ b/rstest/tests/resources/fixture/errors_once.rs @@ -7,18 +7,18 @@ async fn error_async_once_fixture() { #[fixture] #[once] -fn error_generics_once_fixture() -> T { +fn error_generics_once_fixture() -> T { 42 } #[fixture] #[once] fn error_generics_once_fixture() -> impl Iterator { - core::iter::once(42) + std::iter::once(42) } #[fixture] #[once] -fn error_once_fixture_not_sync() -> core::cell::Cell { - core::cell::Cell::new(42) +fn error_once_fixture_not_sync() -> std::cell::Cell { + std::cell::Cell::new(42) } diff --git a/rstest/tests/resources/fixture/impl.rs b/rstest/tests/resources/fixture/impl.rs index c11245eb..0e848271 100644 --- a/rstest/tests/resources/fixture/impl.rs +++ b/rstest/tests/resources/fixture/impl.rs @@ -1,7 +1,7 @@ use rstest::*; #[fixture] -fn fx_base_impl_return() -> impl Iterator { core::iter::once(42) } +fn fx_base_impl_return() -> impl Iterator { std::iter::once(42) } #[fixture] fn fx_base_impl_input(mut fx_base_impl_return: impl Iterator) -> u32 { @@ -19,7 +19,7 @@ fn base_impl_input(mut fx_base_impl_input: u32) { } #[fixture] -fn fx_nested_impl_return() -> impl Iterator { core::iter::once(42) } +fn fx_nested_impl_return() -> impl Iterator { std::iter::once(42) } #[fixture] fn fx_nested_impl_input(mut fx_nested_impl_return: impl Iterator) -> String { @@ -38,7 +38,7 @@ fn nested_impl_input(mut fx_nested_impl_input: String) { #[fixture] fn fx_nested_multiple_impl_return() -> (impl Iterator, impl ToString) { - (core::iter::once(42), 42i32) + (std::iter::once(42), 42i32) } #[fixture] diff --git a/rstest/tests/resources/rstest/cases/inject.rs b/rstest/tests/resources/rstest/cases/inject.rs index 0096451d..eb2dc758 100644 --- a/rstest/tests/resources/rstest/cases/inject.rs +++ b/rstest/tests/resources/rstest/cases/inject.rs @@ -1,6 +1,6 @@ -use actix_rt; -use core::future::Future; use rstest::*; +use actix_rt; +use std::future::Future; #[rstest(expected, value, case::pass(42, 42), diff --git a/rstest/tests/resources/rstest/convert_string_literal.rs b/rstest/tests/resources/rstest/convert_string_literal.rs index a29c6447..3e7989fe 100644 --- a/rstest/tests/resources/rstest/convert_string_literal.rs +++ b/rstest/tests/resources/rstest/convert_string_literal.rs @@ -1,5 +1,5 @@ -use core::net::SocketAddr; use rstest::*; +use std::net::SocketAddr; #[rstest] #[case(true, "1.2.3.4:42")] diff --git a/rstest/tests/resources/rstest/convert_string_literal_other_name.rs b/rstest/tests/resources/rstest/convert_string_literal_other_name.rs index f9aba4da..b5a0f887 100644 --- a/rstest/tests/resources/rstest/convert_string_literal_other_name.rs +++ b/rstest/tests/resources/rstest/convert_string_literal_other_name.rs @@ -1,5 +1,5 @@ -use core::net::SocketAddr; use other_name::*; +use std::net::SocketAddr; #[rstest] #[case(true, "1.2.3.4:42")] diff --git a/rstest/tests/resources/rstest/lifetimes.rs b/rstest/tests/resources/rstest/lifetimes.rs index c6bd13b8..440751b1 100644 --- a/rstest/tests/resources/rstest/lifetimes.rs +++ b/rstest/tests/resources/rstest/lifetimes.rs @@ -2,7 +2,7 @@ use rstest::*; enum E<'a> { A(bool), - B(&'a core::cell::Cell>), + B(&'a std::cell::Cell>), } #[rstest] diff --git a/rstest/tests/resources/rstest/local_lifetime.rs b/rstest/tests/resources/rstest/local_lifetime.rs index f13cfdb9..61d93682 100644 --- a/rstest/tests/resources/rstest/local_lifetime.rs +++ b/rstest/tests/resources/rstest/local_lifetime.rs @@ -1,4 +1,4 @@ -use core::cell::Cell; +use std::cell::Cell; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum E<'a> { diff --git a/rstest/tests/resources/rstest/matrix/inject.rs b/rstest/tests/resources/rstest/matrix/inject.rs index df9173c8..6547f09b 100644 --- a/rstest/tests/resources/rstest/matrix/inject.rs +++ b/rstest/tests/resources/rstest/matrix/inject.rs @@ -1,6 +1,6 @@ use rstest::*; use actix_rt; -use core::future::Future; +use std::future::Future; #[rstest( first => [1, 2], diff --git a/rstest/tests/resources/rstest/timeout.rs b/rstest/tests/resources/rstest/timeout.rs index c12c7365..88df7520 100644 --- a/rstest/tests/resources/rstest/timeout.rs +++ b/rstest/tests/resources/rstest/timeout.rs @@ -1,5 +1,5 @@ use rstest::*; -use core::time::Duration; +use std::time::Duration; fn ms(ms: u32) -> Duration { Duration::from_millis(ms.into()) diff --git a/rstest/tests/resources/rstest/timeout_async.rs b/rstest/tests/resources/rstest/timeout_async.rs index c7441dda..1d12cf52 100644 --- a/rstest/tests/resources/rstest/timeout_async.rs +++ b/rstest/tests/resources/rstest/timeout_async.rs @@ -1,5 +1,5 @@ -use core::time::Duration; use rstest::*; +use std::time::Duration; fn ms(ms: u32) -> Duration { Duration::from_millis(ms.into()) diff --git a/rstest/tests/resources/rstest/timeout_other_name.rs b/rstest/tests/resources/rstest/timeout_other_name.rs index d6fd8645..b360b313 100644 --- a/rstest/tests/resources/rstest/timeout_other_name.rs +++ b/rstest/tests/resources/rstest/timeout_other_name.rs @@ -1,5 +1,5 @@ -use core::time::Duration; use other_name::*; +use std::time::Duration; fn ms(ms: u32) -> Duration { Duration::from_millis(ms.into()) diff --git a/rstest_fixtures/src/lib.rs b/rstest_fixtures/src/lib.rs index 60248c97..bb62acd6 100644 --- a/rstest_fixtures/src/lib.rs +++ b/rstest_fixtures/src/lib.rs @@ -1,4 +1,4 @@ -use core::fmt::Debug; +use std::fmt::Debug; pub trait TearDown { fn tear_down(self); @@ -42,7 +42,7 @@ impl Fixture { } impl Debug for Fixture { - fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { write!(f, "Fixture<{:?}>", self.inner) } } @@ -76,7 +76,7 @@ impl()> From for TearDownClosure { #[cfg(test)] mod test { use super::*; - use core::cell::RefCell; + use std::cell::RefCell; use std::rc::Rc; #[test] diff --git a/rstest_macros/src/error.rs b/rstest_macros/src/error.rs index 63c6a14d..74fac8b6 100644 --- a/rstest_macros/src/error.rs +++ b/rstest_macros/src/error.rs @@ -42,11 +42,11 @@ pub(crate) fn fixture(test: &ItemFn, info: &FixtureInfo) -> TokenStream { fn async_once<'a>(test: &'a ItemFn, info: &FixtureInfo) -> Errors<'a> { match (test.sig.asyncness, info.arguments.get_once()) { - (Some(_asyncness), Some(once)) => Box::new(core::iter::once(syn::Error::new_spanned( + (Some(_asyncness), Some(once)) => Box::new(std::iter::once(syn::Error::new_spanned( once, "Cannot apply #[once] to async fixture.", ))), - _ => Box::new(core::iter::empty()), + _ => Box::new(std::iter::empty()), } } @@ -79,11 +79,11 @@ fn has_some_generics(test: &ItemFn) -> bool { fn generics_once<'a>(test: &'a ItemFn, info: &FixtureInfo) -> Errors<'a> { match (has_some_generics(test), info.arguments.get_once()) { - (true, Some(once)) => Box::new(core::iter::once(syn::Error::new_spanned( + (true, Some(once)) => Box::new(std::iter::once(syn::Error::new_spanned( once, "Cannot apply #[once] on generic fixture.", ))), - _ => Box::new(core::iter::empty()), + _ => Box::new(std::iter::empty()), } } @@ -156,14 +156,14 @@ macro_rules! composed_tuple { }; } -impl core::ops::Deref for ErrorsVec { +impl std::ops::Deref for ErrorsVec { type Target = Vec; fn deref(&self) -> &Self::Target { &self.0 } } -impl core::ops::DerefMut for ErrorsVec { +impl std::ops::DerefMut for ErrorsVec { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } @@ -270,7 +270,7 @@ fn case_args_without_cases(params: &RsTestData) -> Errors { .map(|a| syn::Error::new(a.span(), "No cases for this argument.")), ); } - Box::new(core::iter::empty()) + Box::new(std::iter::empty()) } trait RenderType { diff --git a/rstest_macros/src/parse/fixture.rs b/rstest_macros/src/parse/fixture.rs index 47a7a392..70fe2018 100644 --- a/rstest_macros/src/parse/fixture.rs +++ b/rstest_macros/src/parse/fixture.rs @@ -56,7 +56,7 @@ impl ExtendWithFunctionAttrs for FixtureInfo { fn extend_with_function_attrs( &mut self, item_fn: &mut ItemFn, - ) -> core::result::Result<(), ErrorsVec> { + ) -> std::result::Result<(), ErrorsVec> { let composed_tuple!( fixtures, defaults, @@ -132,7 +132,7 @@ impl VisitMut for FixturesFunctionExtractor { Some(pt) => pt, None => return, }; - let (extracted, remain): (Vec<_>, Vec<_>) = core::mem::take(&mut arg.attrs) + let (extracted, remain): (Vec<_>, Vec<_>) = std::mem::take(&mut arg.attrs) .into_iter() .partition(|attr| attr_in(attr, &["with", "from"])); arg.attrs = remain; diff --git a/rstest_macros/src/parse/just_once.rs b/rstest_macros/src/parse/just_once.rs index bf055c31..303d556e 100644 --- a/rstest_macros/src/parse/just_once.rs +++ b/rstest_macros/src/parse/just_once.rs @@ -1,4 +1,4 @@ -use core::marker::PhantomData; +use std::marker::PhantomData; use quote::ToTokens; use syn::{visit_mut::VisitMut, Attribute, FnArg, ItemFn, Pat}; @@ -87,7 +87,7 @@ where }; if let FnArg::Typed(ref mut arg) = node { // Extract interesting attributes - let attrs = core::mem::take(&mut arg.attrs); + let attrs = std::mem::take(&mut arg.attrs); let (extracted, remain): (Vec<_>, Vec<_>) = attrs.into_iter().partition(|a| attr_is(a, self.name)); @@ -167,7 +167,7 @@ where { fn visit_item_fn_mut(&mut self, item_fn: &mut ItemFn) { // Extract interesting attributes - let attrs = core::mem::take(&mut item_fn.attrs); + let attrs = std::mem::take(&mut item_fn.attrs); let (extracted, remain): (Vec<_>, Vec<_>) = attrs.into_iter().partition(|a| attr_is(a, self.name)); diff --git a/rstest_macros/src/parse/mod.rs b/rstest_macros/src/parse/mod.rs index 6e0b6ca8..baef9e66 100644 --- a/rstest_macros/src/parse/mod.rs +++ b/rstest_macros/src/parse/mod.rs @@ -41,7 +41,7 @@ pub(crate) trait ExtendWithFunctionAttrs { fn extend_with_function_attrs( &mut self, item_fn: &mut ItemFn, - ) -> core::result::Result<(), ErrorsVec>; + ) -> std::result::Result<(), ErrorsVec>; } #[derive(Default, Debug, PartialEq, Clone)] @@ -260,19 +260,19 @@ pub(crate) fn extract_once(item_fn: &mut ItemFn) -> Result( +pub(crate) fn extract_argument_attrs<'a, B: 'a + std::fmt::Debug>( node: &mut FnArg, is_valid_attr: fn(&syn::Attribute) -> bool, build: impl Fn(syn::Attribute) -> syn::Result + 'a, ) -> Box> + 'a> { let name = node.maybe_ident().cloned(); if name.is_none() { - return Box::new(core::iter::empty()); + return Box::new(std::iter::empty()); } if let FnArg::Typed(ref mut arg) = node { // Extract interesting attributes - let attrs = core::mem::take(&mut arg.attrs); + let attrs = std::mem::take(&mut arg.attrs); let (extracted, remain): (Vec<_>, Vec<_>) = attrs.into_iter().partition(is_valid_attr); arg.attrs = remain; @@ -280,7 +280,7 @@ pub(crate) fn extract_argument_attrs<'a, B: 'a + core::fmt::Debug>( // Parse attrs Box::new(extracted.into_iter().map(build)) } else { - Box::new(core::iter::empty()) + Box::new(std::iter::empty()) } } @@ -302,7 +302,7 @@ impl Default for PartialsTypeFunctionExtractor { impl VisitMut for PartialsTypeFunctionExtractor { fn visit_item_fn_mut(&mut self, node: &mut ItemFn) { - let attrs = core::mem::take(&mut node.attrs); + let attrs = std::mem::take(&mut node.attrs); let (partials, remain): (Vec<_>, Vec<_>) = attrs .into_iter() @@ -355,7 +355,7 @@ struct CasesFunctionExtractor(Vec, Vec); impl VisitMut for CasesFunctionExtractor { fn visit_item_fn_mut(&mut self, node: &mut ItemFn) { - let attrs = core::mem::take(&mut node.attrs); + let attrs = std::mem::take(&mut node.attrs); let mut attrs_buffer = Default::default(); let case: syn::PathSegment = parse_quote! { case }; for attr in attrs.into_iter() { @@ -366,7 +366,7 @@ impl VisitMut for CasesFunctionExtractor { attr.path().segments.iter().nth(1).map(|p| p.ident.clone()); self.0.push(TestCase { args: expressions.into(), - attrs: core::mem::take(&mut attrs_buffer), + attrs: std::mem::take(&mut attrs_buffer), description, }); } @@ -376,7 +376,7 @@ impl VisitMut for CasesFunctionExtractor { attrs_buffer.push(attr) } } - node.attrs = core::mem::take(&mut attrs_buffer); + node.attrs = std::mem::take(&mut attrs_buffer); } } @@ -585,14 +585,14 @@ mod should { fn integrated() { let attributes = parse_attributes( r#" - simple :: tagged(first, second) :: type_tag<(u32, T, (core::string::String, i32))> :: more_tagged(a,b)"#, + simple :: tagged(first, second) :: type_tag<(u32, T, (std::string::String, i32))> :: more_tagged(a,b)"#, ); let expected = Attributes { attributes: vec![ Attribute::attr("simple"), Attribute::tagged("tagged", vec!["first", "second"]), - Attribute::typed("type_tag", "(u32, T, (core::string::String, i32))"), + Attribute::typed("type_tag", "(u32, T, (std::string::String, i32))"), Attribute::tagged("more_tagged", vec!["a", "b"]), ], }; diff --git a/rstest_macros/src/parse/rstest/files.rs b/rstest_macros/src/parse/rstest/files.rs index 7c50e9d0..fd334884 100644 --- a/rstest_macros/src/parse/rstest/files.rs +++ b/rstest_macros/src/parse/rstest/files.rs @@ -277,7 +277,7 @@ impl ValueFilesExtractor { } } - fn extract_argument_attrs<'a, B: 'a + core::fmt::Debug>( + fn extract_argument_attrs<'a, B: 'a + std::fmt::Debug>( &mut self, node: &mut FnArg, is_valid_attr: fn(&syn::Attribute) -> bool, @@ -525,7 +525,7 @@ impl<'a> ValueListFromFiles<'a> { let path_str = abs_path.to_string_lossy(); values.push(( parse_quote! { - <::std::path::PathBuf as core::str::FromStr>::from_str(#path_str).unwrap() + <::std::path::PathBuf as std::str::FromStr>::from_str(#path_str).unwrap() }, render_file_description(&relative_path), )); @@ -908,7 +908,7 @@ mod should { .map(|r| r.to_logical_path(bdir)) .map(|p| { format!( - r#"<::std::path::PathBuf as core::str::FromStr>::from_str("{}").unwrap()"#, + r#"<::std::path::PathBuf as std::str::FromStr>::from_str("{}").unwrap()"#, p.as_os_str().to_str().unwrap() ) }) diff --git a/rstest_macros/src/render/apply_arguments.rs b/rstest_macros/src/render/apply_arguments.rs index f632086c..715e3a66 100644 --- a/rstest_macros/src/render/apply_arguments.rs +++ b/rstest_macros/src/render/apply_arguments.rs @@ -118,7 +118,7 @@ impl ImplFutureArg for FnArg { Some(ty) => { let lifetime = update_type_with_lifetime(ty, lifetime_id); *ty = parse_quote! { - impl core::future::Future + impl std::future::Future }; self.remove_mutability(); lifetime @@ -166,30 +166,30 @@ mod should { #[case::simple( "fn f(a: u32) {}", &["a"], - "fn f(a: impl core::future::Future) {}" + "fn f(a: impl std::future::Future) {}" )] #[case::more_than_one( "fn f(a: u32, b: String, c: std::collection::HashMap) {}", &["a", "b", "c"], - r#"fn f(a: impl core::future::Future, - b: impl core::future::Future, - c: impl core::future::Future>) {}"#, + r#"fn f(a: impl std::future::Future, + b: impl std::future::Future, + c: impl std::future::Future>) {}"#, )] #[case::just_one( "fn f(a: u32, b: String) {}", &["b"], r#"fn f(a: u32, - b: impl core::future::Future) {}"# + b: impl std::future::Future) {}"# )] #[case::generics( "fn f>(a: S) {}", &["a"], - "fn f>(a: impl core::future::Future) {}" + "fn f>(a: impl std::future::Future) {}" )] #[case::remove_mut( "fn f(mut a: u32) {}", &["a"], - r#"fn f(a: impl core::future::Future) {}"# + r#"fn f(a: impl std::future::Future) {}"# )] fn replace_future_basic_type( #[case] item_fn: &str, @@ -213,17 +213,17 @@ mod should { #[case::base( "fn f(ident_name: &u32) {}", &["ident_name"], - "fn f<'_ident_name>(ident_name: impl core::future::Future) {}" + "fn f<'_ident_name>(ident_name: impl std::future::Future) {}" )] #[case::lifetime_already_exists( "fn f<'b>(a: &'b u32) {}", &["a"], - "fn f<'b>(a: impl core::future::Future) {}" + "fn f<'b>(a: impl std::future::Future) {}" )] #[case::some_other_generics( "fn f<'b, IT: Iterator>(a: &u32, it: IT) {}", &["a"], - "fn f<'_a, 'b, IT: Iterator>(a: impl core::future::Future, it: IT) {}" + "fn f<'_a, 'b, IT: Iterator>(a: impl std::future::Future, it: IT) {}" )] fn replace_reference_type( #[case] item_fn: &str, diff --git a/rstest_macros/src/render/fixture.rs b/rstest_macros/src/render/fixture.rs index 0a3a8508..74451a8e 100644 --- a/rstest_macros/src/render/fixture.rs +++ b/rstest_macros/src/render/fixture.rs @@ -54,7 +54,7 @@ pub(crate) fn render(mut fixture: ItemFn, info: FixtureInfo) -> TokenStream { .extract_default_type() .unwrap_or_else(|| fixture.sig.output.clone()); let default_generics = - generics_clean_up(&fixture.sig.generics, core::iter::empty(), &default_output); + generics_clean_up(&fixture.sig.generics, std::iter::empty(), &default_output); let default_where_clause = &default_generics.where_clause; let where_clause = &fixture.sig.generics.where_clause; let mut output = fixture.sig.output.clone(); @@ -536,8 +536,8 @@ mod should { let expected = parse_str::( r#" async fn get<'_async_ref_u32>( - async_ref_u32: impl core::future::Future, - async_u32: impl core::future::Future, + async_ref_u32: impl std::future::Future, + async_u32: impl std::future::Future, simple: u32 ) { } diff --git a/rstest_macros/src/render/inject.rs b/rstest_macros/src/render/inject.rs index 2a2c7b18..d3946f0d 100644 --- a/rstest_macros/src/render/inject.rs +++ b/rstest_macros/src/render/inject.rs @@ -110,7 +110,7 @@ fn handling_magic_conversion_code(fixture: Cow, arg_type: &Type) -> Expr { parse_quote! { { use #rstest_path::magic_conversion::*; - (&&&Magic::<#arg_type>(core::marker::PhantomData)).magic_conversion(#fixture) + (&&&Magic::<#arg_type>(std::marker::PhantomData)).magic_conversion(#fixture) } } } diff --git a/rstest_macros/src/render/mod.rs b/rstest_macros/src/render/mod.rs index 28f9e710..275abefc 100644 --- a/rstest_macros/src/render/mod.rs +++ b/rstest_macros/src/render/mod.rs @@ -41,7 +41,7 @@ pub(crate) fn single(mut test: ItemFn, mut info: RsTestInfo) -> TokenStream { let resolver = resolver::fixtures::get(&info.arguments, info.data.fixtures()); let args = test.sig.inputs.iter().cloned().collect::>(); - let attrs = core::mem::take(&mut test.attrs); + let attrs = std::mem::take(&mut test.attrs); let asyncness = test.sig.asyncness; single_test_case( @@ -208,7 +208,7 @@ fn render_test_call( let timeout = timeout.map(|x| quote! {#x}).or_else(|| { std::env::var("RSTEST_TIMEOUT") .ok() - .map(|to| quote! { core::time::Duration::from_secs( (#to).parse().unwrap()) }) + .map(|to| quote! { std::time::Duration::from_secs( (#to).parse().unwrap()) }) }); let rstest_path = crate_name(); match (timeout, is_async) { @@ -411,7 +411,7 @@ trait DisplayLen { fn display_len(&self) -> usize; } -impl DisplayLen for D { +impl DisplayLen for D { fn display_len(&self) -> usize { format!("{self}").len() } diff --git a/rstest_macros/src/render/test.rs b/rstest_macros/src/render/test.rs index a6d03f81..f4086757 100644 --- a/rstest_macros/src/render/test.rs +++ b/rstest_macros/src/render/test.rs @@ -326,8 +326,8 @@ mod single_test_should { let expected = parse_str::( r#"async fn test<'_async_ref_u32>( - async_ref_u32: impl core::future::Future, - async_u32: impl core::future::Future, + async_ref_u32: impl std::future::Future, + async_u32: impl std::future::Future, simple: u32 ) { } @@ -908,8 +908,8 @@ mod cases_should { let expected = parse_str::( r#"async fn test<'_async_ref_u32>( - async_ref_u32: impl core::future::Future, - async_u32: impl core::future::Future, + async_ref_u32: impl std::future::Future, + async_u32: impl std::future::Future, simple: u32 ) { } @@ -1354,8 +1354,8 @@ mod matrix_cases_should { let expected = parse_str::( r#"async fn test<'_async_ref_u32>( - async_ref_u32: impl core::future::Future, - async_u32: impl core::future::Future, + async_ref_u32: impl std::future::Future, + async_u32: impl std::future::Future, simple: u32 ) { } diff --git a/rstest_macros/src/test.rs b/rstest_macros/src/test.rs index a47f3b43..672c5c5c 100644 --- a/rstest_macros/src/test.rs +++ b/rstest_macros/src/test.rs @@ -286,7 +286,7 @@ impl> FromIterator for TestCase { impl<'a> From<&'a str> for TestCase { fn from(argument: &'a str) -> Self { - core::iter::once(argument).collect() + std::iter::once(argument).collect() } } diff --git a/rstest_reuse/src/lib.rs b/rstest_reuse/src/lib.rs index 510bc337..f7489f6e 100644 --- a/rstest_reuse/src/lib.rs +++ b/rstest_reuse/src/lib.rs @@ -310,7 +310,7 @@ pub fn template(_args: proc_macro::TokenStream, input: proc_macro::TokenStream) template.attrs = match rstest_index { Some(idx) => attributes.split_off(idx), - None => core::mem::take(&mut attributes), + None => std::mem::take(&mut attributes), }; let (macro_attribute, visibility) = match get_export(&attributes) { From c2938c0b3880c7060468552a49d14083357c164d Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 14 Nov 2024 12:50:31 +0100 Subject: [PATCH 3/7] use core while rendering --- rstest_macros/src/render/apply_arguments.rs | 2 +- rstest_macros/src/render/inject.rs | 2 +- rstest_macros/src/render/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rstest_macros/src/render/apply_arguments.rs b/rstest_macros/src/render/apply_arguments.rs index 715e3a66..8f921247 100644 --- a/rstest_macros/src/render/apply_arguments.rs +++ b/rstest_macros/src/render/apply_arguments.rs @@ -118,7 +118,7 @@ impl ImplFutureArg for FnArg { Some(ty) => { let lifetime = update_type_with_lifetime(ty, lifetime_id); *ty = parse_quote! { - impl std::future::Future + impl core::future::Future }; self.remove_mutability(); lifetime diff --git a/rstest_macros/src/render/inject.rs b/rstest_macros/src/render/inject.rs index d3946f0d..2a2c7b18 100644 --- a/rstest_macros/src/render/inject.rs +++ b/rstest_macros/src/render/inject.rs @@ -110,7 +110,7 @@ fn handling_magic_conversion_code(fixture: Cow, arg_type: &Type) -> Expr { parse_quote! { { use #rstest_path::magic_conversion::*; - (&&&Magic::<#arg_type>(std::marker::PhantomData)).magic_conversion(#fixture) + (&&&Magic::<#arg_type>(core::marker::PhantomData)).magic_conversion(#fixture) } } } diff --git a/rstest_macros/src/render/mod.rs b/rstest_macros/src/render/mod.rs index 275abefc..f5cc9c08 100644 --- a/rstest_macros/src/render/mod.rs +++ b/rstest_macros/src/render/mod.rs @@ -208,7 +208,7 @@ fn render_test_call( let timeout = timeout.map(|x| quote! {#x}).or_else(|| { std::env::var("RSTEST_TIMEOUT") .ok() - .map(|to| quote! { std::time::Duration::from_secs( (#to).parse().unwrap()) }) + .map(|to| quote! { core::time::Duration::from_secs( (#to).parse().unwrap()) }) }); let rstest_path = crate_name(); match (timeout, is_async) { From 82cb3c3e279194ef51fadfcf12dd85f162334ffe Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 14 Nov 2024 12:52:16 +0100 Subject: [PATCH 4/7] make magic_conversion no_std --- rstest/src/magic_conversion.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rstest/src/magic_conversion.rs b/rstest/src/magic_conversion.rs index 4df2301e..db0c13a0 100644 --- a/rstest/src/magic_conversion.rs +++ b/rstest/src/magic_conversion.rs @@ -1,4 +1,4 @@ -pub struct Magic(pub std::marker::PhantomData); +pub struct Magic(pub core::marker::PhantomData); pub trait ViaParseDebug<'a, T> { fn magic_conversion(&self, input: &'a str) -> T; @@ -6,8 +6,8 @@ pub trait ViaParseDebug<'a, T> { impl<'a, T> ViaParseDebug<'a, T> for &&Magic where - T: std::str::FromStr, - T::Err: std::fmt::Debug, + T: core::str::FromStr, + T::Err: core::fmt::Debug, { fn magic_conversion(&self, input: &'a str) -> T { T::from_str(input).unwrap() @@ -20,7 +20,7 @@ pub trait ViaParse<'a, T> { impl<'a, T> ViaParse<'a, T> for &Magic where - T: std::str::FromStr, + T: core::str::FromStr, { fn magic_conversion(&self, input: &'a str) -> T { match T::from_str(input) { @@ -29,7 +29,7 @@ where panic!( "Cannot parse '{}' to get {}", input, - std::any::type_name::() + core::any::type_name::() ); } } From 74d265d8a4bfa206ea52dd06dd3f42481e0f11e1 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 14 Nov 2024 13:13:53 +0100 Subject: [PATCH 5/7] fix tests --- rstest_macros/src/render/apply_arguments.rs | 20 ++++++++++---------- rstest_macros/src/render/fixture.rs | 4 ++-- rstest_macros/src/render/test.rs | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/rstest_macros/src/render/apply_arguments.rs b/rstest_macros/src/render/apply_arguments.rs index 8f921247..effb3da9 100644 --- a/rstest_macros/src/render/apply_arguments.rs +++ b/rstest_macros/src/render/apply_arguments.rs @@ -166,30 +166,30 @@ mod should { #[case::simple( "fn f(a: u32) {}", &["a"], - "fn f(a: impl std::future::Future) {}" + "fn f(a: impl core::future::Future) {}" )] #[case::more_than_one( "fn f(a: u32, b: String, c: std::collection::HashMap) {}", &["a", "b", "c"], - r#"fn f(a: impl std::future::Future, - b: impl std::future::Future, - c: impl std::future::Future>) {}"#, + r#"fn f(a: impl core::future::Future, + b: impl core::future::Future, + c: impl core::future::Future>) {}"#, )] #[case::just_one( "fn f(a: u32, b: String) {}", &["b"], r#"fn f(a: u32, - b: impl std::future::Future) {}"# + b: impl core::future::Future) {}"# )] #[case::generics( "fn f>(a: S) {}", &["a"], - "fn f>(a: impl std::future::Future) {}" + "fn f>(a: impl core::future::Future) {}" )] #[case::remove_mut( "fn f(mut a: u32) {}", &["a"], - r#"fn f(a: impl std::future::Future) {}"# + r#"fn f(a: impl core::future::Future) {}"# )] fn replace_future_basic_type( #[case] item_fn: &str, @@ -213,17 +213,17 @@ mod should { #[case::base( "fn f(ident_name: &u32) {}", &["ident_name"], - "fn f<'_ident_name>(ident_name: impl std::future::Future) {}" + "fn f<'_ident_name>(ident_name: impl core::future::Future) {}" )] #[case::lifetime_already_exists( "fn f<'b>(a: &'b u32) {}", &["a"], - "fn f<'b>(a: impl std::future::Future) {}" + "fn f<'b>(a: impl core::future::Future) {}" )] #[case::some_other_generics( "fn f<'b, IT: Iterator>(a: &u32, it: IT) {}", &["a"], - "fn f<'_a, 'b, IT: Iterator>(a: impl std::future::Future, it: IT) {}" + "fn f<'_a, 'b, IT: Iterator>(a: impl core::future::Future, it: IT) {}" )] fn replace_reference_type( #[case] item_fn: &str, diff --git a/rstest_macros/src/render/fixture.rs b/rstest_macros/src/render/fixture.rs index 74451a8e..1c82fb03 100644 --- a/rstest_macros/src/render/fixture.rs +++ b/rstest_macros/src/render/fixture.rs @@ -536,8 +536,8 @@ mod should { let expected = parse_str::( r#" async fn get<'_async_ref_u32>( - async_ref_u32: impl std::future::Future, - async_u32: impl std::future::Future, + async_ref_u32: impl core::future::Future, + async_u32: impl core::future::Future, simple: u32 ) { } diff --git a/rstest_macros/src/render/test.rs b/rstest_macros/src/render/test.rs index f4086757..43779ed8 100644 --- a/rstest_macros/src/render/test.rs +++ b/rstest_macros/src/render/test.rs @@ -326,8 +326,8 @@ mod single_test_should { let expected = parse_str::( r#"async fn test<'_async_ref_u32>( - async_ref_u32: impl std::future::Future, - async_u32: impl std::future::Future, + async_ref_u32: impl core::future::Future, + async_u32: impl core::future::Future, simple: u32 ) { } @@ -908,8 +908,8 @@ mod cases_should { let expected = parse_str::( r#"async fn test<'_async_ref_u32>( - async_ref_u32: impl std::future::Future, - async_u32: impl std::future::Future, + async_ref_u32: impl core::future::Future, + async_u32: impl core::future::Future, simple: u32 ) { } @@ -1354,8 +1354,8 @@ mod matrix_cases_should { let expected = parse_str::( r#"async fn test<'_async_ref_u32>( - async_ref_u32: impl std::future::Future, - async_u32: impl std::future::Future, + async_ref_u32: impl core::future::Future, + async_u32: impl core::future::Future, simple: u32 ) { } From f130467a5ba7109756a19e79770ee8f3f55544c0 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 14 Nov 2024 13:48:26 +0100 Subject: [PATCH 6/7] test for default magic_conversion logic --- rstest_macros/src/render/inject.rs | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/rstest_macros/src/render/inject.rs b/rstest_macros/src/render/inject.rs index 2a2c7b18..77db5a8a 100644 --- a/rstest_macros/src/render/inject.rs +++ b/rstest_macros/src/render/inject.rs @@ -208,4 +208,89 @@ mod should { assert_eq!(injected, expected.ast()); } + + #[rstest] + #[case::simple_type( + "fn test(arg: MyType) {}", + 0, + "let arg = { + use rstest::magic_conversion::*; + (&&&Magic::(core::marker::PhantomData)).magic_conversion(\"value to convert\") + };" + )] + #[case::discard_impl( + "fn test(arg: impl AsRef) {}", + 0, + r#"let arg = "value to convert";"# + )] + #[case::discard_generic_type( + "fn test>(arg: S) {}", + 0, + r#"let arg = "value to convert";"# + )] + #[case::reference_type( + "fn test(arg: &MyType) {}", + 0, + "let arg = { + use rstest::magic_conversion::*; + (&&&Magic::<&MyType>(core::marker::PhantomData)).magic_conversion(\"value to convert\") + };" + )] + #[case::mutable_reference_type( + "fn test(arg: &mut MyType) {}", + 0, + "let arg = { + use rstest::magic_conversion::*; + (&&&Magic::<&mut MyType>(core::marker::PhantomData)).magic_conversion(\"value to convert\") + };" + )] + #[case::generic_type_with_lifetime( + "fn test<'a, T>(arg: &'a T) where T: Default {}", + 0, + "let arg = { + use rstest::magic_conversion::*; + (&&&Magic::<&'a T>(core::marker::PhantomData)).magic_conversion(\"value to convert\") + };" + )] + #[case::type_with_generic_parameters( + "fn test(arg: Option) {}", + 0, + "let arg = { + use rstest::magic_conversion::*; + (&&&Magic::>(core::marker::PhantomData)).magic_conversion(\"value to convert\") + };" + )] + #[case::complex_type( + "fn test(arg: Result, MyError>) {}", + 0, + "let arg = { + use rstest::magic_conversion::*; + (&&&Magic::, MyError>>(core::marker::PhantomData)).magic_conversion(\"value to convert\") + };" + )] + fn generated_code_uses_phantom_data( + #[case] fn_str: &str, + #[case] n_arg: usize, + #[case] expected: &str, + ) { + let function = fn_str.ast(); + let arg = fn_args(&function).nth(n_arg).unwrap(); + let generics = function + .sig + .generics + .type_params() + .map(|tp| &tp.ident) + .cloned() + .collect::>(); + + let mut resolver = std::collections::HashMap::new(); + let expr = expr(r#""value to convert""#); + resolver.insert(arg.maybe_pat().unwrap().clone(), &expr); + + let ag = ArgumentResolver::new(&resolver, &generics); + + let injected = ag.resolve(&arg).unwrap(); + + assert_eq!(injected, expected.ast()); + } } From cd605d54d7fefe18c7d2b03e0624f4408bf04bb2 Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Thu, 14 Nov 2024 14:30:58 +0100 Subject: [PATCH 7/7] revert core usage in rstest --- rstest/src/magic_conversion.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rstest/src/magic_conversion.rs b/rstest/src/magic_conversion.rs index db0c13a0..4df2301e 100644 --- a/rstest/src/magic_conversion.rs +++ b/rstest/src/magic_conversion.rs @@ -1,4 +1,4 @@ -pub struct Magic(pub core::marker::PhantomData); +pub struct Magic(pub std::marker::PhantomData); pub trait ViaParseDebug<'a, T> { fn magic_conversion(&self, input: &'a str) -> T; @@ -6,8 +6,8 @@ pub trait ViaParseDebug<'a, T> { impl<'a, T> ViaParseDebug<'a, T> for &&Magic where - T: core::str::FromStr, - T::Err: core::fmt::Debug, + T: std::str::FromStr, + T::Err: std::fmt::Debug, { fn magic_conversion(&self, input: &'a str) -> T { T::from_str(input).unwrap() @@ -20,7 +20,7 @@ pub trait ViaParse<'a, T> { impl<'a, T> ViaParse<'a, T> for &Magic where - T: core::str::FromStr, + T: std::str::FromStr, { fn magic_conversion(&self, input: &'a str) -> T { match T::from_str(input) { @@ -29,7 +29,7 @@ where panic!( "Cannot parse '{}' to get {}", input, - core::any::type_name::() + std::any::type_name::() ); } }