From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../rust/extend/tests/compile_fail/double_vis.rs | 14 ++++++ .../extend/tests/compile_fail/double_vis.stderr | 5 ++ .../supertraits_are_actually_included.rs | 14 ++++++ .../supertraits_are_actually_included.stderr | 10 ++++ .../tests/compile_pass/associated_constants.rs | 10 ++++ .../rust/extend/tests/compile_pass/async_trait.rs | 25 ++++++++++ .../compile_pass/changing_extension_trait_name.rs | 10 ++++ .../tests/compile_pass/complex_trait_name.rs | 16 ++++++ .../tests/compile_pass/double_ext_on_same_type.rs | 17 +++++++ .../compile_pass/extension_on_complex_types.rs | 58 ++++++++++++++++++++++ .../rust/extend/tests/compile_pass/generics.rs | 15 ++++++ .../rust/extend/tests/compile_pass/hello_world.rs | 20 ++++++++ .../rust/extend/tests/compile_pass/issue_2.rs | 33 ++++++++++++ .../tests/compile_pass/more_than_one_extension.rs | 13 +++++ .../extend/tests/compile_pass/multiple_config.rs | 13 +++++ .../tests/compile_pass/multiple_generic_params.rs | 11 ++++ .../rust/extend/tests/compile_pass/pub_impl.rs | 15 ++++++ .../extend/tests/compile_pass/ref_and_ref_mut.rs | 13 +++++ .../rust/extend/tests/compile_pass/sized.rs | 36 ++++++++++++++ .../rust/extend/tests/compile_pass/super_trait.rs | 16 ++++++ .../extend/tests/compile_pass/visibility_config.rs | 15 ++++++ 21 files changed, 379 insertions(+) create mode 100644 third_party/rust/extend/tests/compile_fail/double_vis.rs create mode 100644 third_party/rust/extend/tests/compile_fail/double_vis.stderr create mode 100644 third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.rs create mode 100644 third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.stderr create mode 100644 third_party/rust/extend/tests/compile_pass/associated_constants.rs create mode 100644 third_party/rust/extend/tests/compile_pass/async_trait.rs create mode 100644 third_party/rust/extend/tests/compile_pass/changing_extension_trait_name.rs create mode 100644 third_party/rust/extend/tests/compile_pass/complex_trait_name.rs create mode 100644 third_party/rust/extend/tests/compile_pass/double_ext_on_same_type.rs create mode 100644 third_party/rust/extend/tests/compile_pass/extension_on_complex_types.rs create mode 100644 third_party/rust/extend/tests/compile_pass/generics.rs create mode 100644 third_party/rust/extend/tests/compile_pass/hello_world.rs create mode 100644 third_party/rust/extend/tests/compile_pass/issue_2.rs create mode 100644 third_party/rust/extend/tests/compile_pass/more_than_one_extension.rs create mode 100644 third_party/rust/extend/tests/compile_pass/multiple_config.rs create mode 100644 third_party/rust/extend/tests/compile_pass/multiple_generic_params.rs create mode 100644 third_party/rust/extend/tests/compile_pass/pub_impl.rs create mode 100644 third_party/rust/extend/tests/compile_pass/ref_and_ref_mut.rs create mode 100644 third_party/rust/extend/tests/compile_pass/sized.rs create mode 100644 third_party/rust/extend/tests/compile_pass/super_trait.rs create mode 100644 third_party/rust/extend/tests/compile_pass/visibility_config.rs (limited to 'third_party/rust/extend/tests') diff --git a/third_party/rust/extend/tests/compile_fail/double_vis.rs b/third_party/rust/extend/tests/compile_fail/double_vis.rs new file mode 100644 index 0000000000..4e0e135ad3 --- /dev/null +++ b/third_party/rust/extend/tests/compile_fail/double_vis.rs @@ -0,0 +1,14 @@ +mod a { + use extend::ext; + + #[ext(pub(super))] + pub impl i32 { + fn foo() -> Foo { + Foo + } + } + + pub struct Foo; +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_fail/double_vis.stderr b/third_party/rust/extend/tests/compile_fail/double_vis.stderr new file mode 100644 index 0000000000..c98b614935 --- /dev/null +++ b/third_party/rust/extend/tests/compile_fail/double_vis.stderr @@ -0,0 +1,5 @@ +error: Cannot set visibility on `#[ext]` and `impl` block + --> $DIR/double_vis.rs:4:11 + | +4 | #[ext(pub(super))] + | ^^^ diff --git a/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.rs b/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.rs new file mode 100644 index 0000000000..5fba303138 --- /dev/null +++ b/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.rs @@ -0,0 +1,14 @@ +use extend::ext; + +trait MyTrait {} + +#[ext(supertraits = MyTrait)] +impl String { + fn my_len(&self) -> usize { + self.len() + } +} + +fn main() { + assert_eq!(String::new().my_len(), 0); +} diff --git a/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.stderr b/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.stderr new file mode 100644 index 0000000000..60059f73fb --- /dev/null +++ b/third_party/rust/extend/tests/compile_fail/supertraits_are_actually_included.stderr @@ -0,0 +1,10 @@ +error[E0277]: the trait bound `String: MyTrait` is not satisfied + --> $DIR/supertraits_are_actually_included.rs:6:6 + | +5 | #[ext(supertraits = MyTrait)] + | ------- required by this bound in `StringExt` +6 | impl String { + | ^^^^^^ + | | + | the trait `MyTrait` is not implemented for `String` + | required by a bound in this diff --git a/third_party/rust/extend/tests/compile_pass/associated_constants.rs b/third_party/rust/extend/tests/compile_pass/associated_constants.rs new file mode 100644 index 0000000000..5cb982c6a4 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/associated_constants.rs @@ -0,0 +1,10 @@ +use extend::ext; + +#[ext] +impl Option { + const FOO: usize = 1; +} + +fn main() { + assert_eq!(Option::::FOO, 1); +} diff --git a/third_party/rust/extend/tests/compile_pass/async_trait.rs b/third_party/rust/extend/tests/compile_pass/async_trait.rs new file mode 100644 index 0000000000..067bdc9bb7 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/async_trait.rs @@ -0,0 +1,25 @@ +use extend::ext; +use async_trait::async_trait; + +#[ext] +#[async_trait] +impl String { + async fn foo() -> usize { + 1 + } +} + +#[ext] +#[async_trait] +pub impl i32 { + async fn bar() -> usize { + 1 + } +} + +async fn foo() { + let _: usize = String::foo().await; + let _: usize = i32::bar().await; +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/changing_extension_trait_name.rs b/third_party/rust/extend/tests/compile_pass/changing_extension_trait_name.rs new file mode 100644 index 0000000000..fc83b19339 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/changing_extension_trait_name.rs @@ -0,0 +1,10 @@ +use extend::ext; + +#[ext(name = Foo)] +impl i32 { + fn foo() {} +} + +fn main() { + ::foo(); +} diff --git a/third_party/rust/extend/tests/compile_pass/complex_trait_name.rs b/third_party/rust/extend/tests/compile_pass/complex_trait_name.rs new file mode 100644 index 0000000000..3457495132 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/complex_trait_name.rs @@ -0,0 +1,16 @@ +mod foo { + use extend::ext; + + #[ext(pub)] + impl (T1, T2, T3) { + fn size(&self) -> usize { + 3 + } + } +} + +fn main() { + use foo::TupleOfT1T2T3Ext; + + assert_eq!(3, (0, 0, 0).size()); +} diff --git a/third_party/rust/extend/tests/compile_pass/double_ext_on_same_type.rs b/third_party/rust/extend/tests/compile_pass/double_ext_on_same_type.rs new file mode 100644 index 0000000000..972d530fa8 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/double_ext_on_same_type.rs @@ -0,0 +1,17 @@ +use extend::ext; + +#[ext] +impl Option { + fn foo() -> usize { + 1 + } +} + +#[ext] +impl Option { + fn bar() -> i32 { + 1 + } +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/extension_on_complex_types.rs b/third_party/rust/extend/tests/compile_pass/extension_on_complex_types.rs new file mode 100644 index 0000000000..20dfb7ca90 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/extension_on_complex_types.rs @@ -0,0 +1,58 @@ +use extend::ext; + +#[ext] +impl<'a> &'a str { + fn foo(self) {} +} + +#[ext] +impl [T; 3] { + fn foo(self) {} +} + +#[ext] +impl *const i32 { + fn foo(self) {} +} + +#[ext] +impl [T] { + fn foo(&self) {} +} + +#[ext] +impl<'a, T> &'a [T] { + fn foo(self) {} +} + +#[ext] +impl (i32, i64) { + fn foo(self) {} +} + +#[ext] +impl fn(i32) -> bool { + fn foo(self) {} +} + +fn bare_fn(_: i32) -> bool { + false +} + +#[ext] +impl dyn Send + Sync + 'static {} + +fn main() { + "".foo(); + + [1, 2, 3].foo(); + + let ptr: *const i32 = &123; + ptr.foo(); + + &[1, 2, 3].foo(); + + (1i32, 1i64).foo(); + + (bare_fn as fn(i32) -> bool).foo(); +} diff --git a/third_party/rust/extend/tests/compile_pass/generics.rs b/third_party/rust/extend/tests/compile_pass/generics.rs new file mode 100644 index 0000000000..4c56b14677 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/generics.rs @@ -0,0 +1,15 @@ +use extend::ext; + +#[ext] +impl<'a, T: Clone> Vec<&'a T> +where + T: 'a + Copy, +{ + fn size(&self) -> usize { + self.len() + } +} + +fn main() { + assert_eq!(3, vec![&1, &2, &3].size()); +} diff --git a/third_party/rust/extend/tests/compile_pass/hello_world.rs b/third_party/rust/extend/tests/compile_pass/hello_world.rs new file mode 100644 index 0000000000..75c61183b4 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/hello_world.rs @@ -0,0 +1,20 @@ +use extend::ext; + +#[ext] +impl i32 { + fn add_one(&self) -> Self { + self + 1 + } + + fn foo() -> MyType { + MyType + } +} + +#[derive(Debug, Eq, PartialEq)] +struct MyType; + +fn main() { + assert_eq!(i32::foo(), MyType); + assert_eq!(1.add_one(), 2); +} diff --git a/third_party/rust/extend/tests/compile_pass/issue_2.rs b/third_party/rust/extend/tests/compile_pass/issue_2.rs new file mode 100644 index 0000000000..76516486ab --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/issue_2.rs @@ -0,0 +1,33 @@ +#![allow(unused_variables)] + +use extend::ext; +use std::iter::FromIterator; + +#[ext] +impl C +where + C: IntoIterator, + K: Eq, + F: Fn(&T) -> K, +{ + fn group_by(self, f: F) -> Out + where + Out: FromIterator<(K, Vec)>, + { + todo!() + } + + fn group_by_and_map_values(self, f: F, g: G) -> Out + where + G: Fn(T) -> T2 + Copy, + Out: FromIterator<(K, Vec)>, + { + todo!() + } + + fn group_by_and_return_groups(self, f: F) -> Vec> { + todo!() + } +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/more_than_one_extension.rs b/third_party/rust/extend/tests/compile_pass/more_than_one_extension.rs new file mode 100644 index 0000000000..e5ce539f15 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/more_than_one_extension.rs @@ -0,0 +1,13 @@ +use extend::ext; + +#[ext] +impl i32 { + fn foo() {} +} + +#[ext] +impl i64 { + fn bar() {} +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/multiple_config.rs b/third_party/rust/extend/tests/compile_pass/multiple_config.rs new file mode 100644 index 0000000000..9ffdad1316 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/multiple_config.rs @@ -0,0 +1,13 @@ +use extend::ext; + +#[ext(pub(crate), name = Foo)] +impl i32 { + fn foo() {} +} + +#[ext(pub, name = Bar)] +impl i64 { + fn foo() {} +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/multiple_generic_params.rs b/third_party/rust/extend/tests/compile_pass/multiple_generic_params.rs new file mode 100644 index 0000000000..29e4b9ca21 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/multiple_generic_params.rs @@ -0,0 +1,11 @@ +use extend::ext; +use std::marker::PhantomData; + +struct Foo(PhantomData); + +#[ext] +impl T { + fn some_method(&self, _: Foo) {} +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/pub_impl.rs b/third_party/rust/extend/tests/compile_pass/pub_impl.rs new file mode 100644 index 0000000000..f7bff519c0 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/pub_impl.rs @@ -0,0 +1,15 @@ +mod a { + use extend::ext; + + #[ext] + pub impl i32 { + fn foo() -> Foo { Foo } + } + + pub struct Foo; +} + +fn main() { + use a::i32Ext; + i32::foo(); +} diff --git a/third_party/rust/extend/tests/compile_pass/ref_and_ref_mut.rs b/third_party/rust/extend/tests/compile_pass/ref_and_ref_mut.rs new file mode 100644 index 0000000000..156f62027d --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/ref_and_ref_mut.rs @@ -0,0 +1,13 @@ +use extend::ext; + +#[ext] +impl &i32 { + fn foo() {} +} + +#[ext] +impl &mut i32 { + fn bar() {} +} + +fn main() {} diff --git a/third_party/rust/extend/tests/compile_pass/sized.rs b/third_party/rust/extend/tests/compile_pass/sized.rs new file mode 100644 index 0000000000..dae05f3f52 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/sized.rs @@ -0,0 +1,36 @@ +use extend::ext_sized; + +#[ext_sized(name = One)] +impl i32 { + fn requires_sized(self) -> Option { + Some(self) + } +} + +#[ext_sized(name = Two, supertraits = Default)] +impl i32 { + fn with_another_supertrait(self) -> Option { + Some(self) + } +} + +#[ext_sized(name = Three, supertraits = Default + Clone + Copy)] +impl i32 { + fn multiple_supertraits(self) -> Option { + Some(self) + } +} + +#[ext_sized(name = Four, supertraits = Sized)] +impl i32 { + fn already_sized(self) -> Option { + Some(self) + } +} + +fn main() { + 1.requires_sized(); + 1.with_another_supertrait(); + 1.multiple_supertraits(); + 1.already_sized(); +} diff --git a/third_party/rust/extend/tests/compile_pass/super_trait.rs b/third_party/rust/extend/tests/compile_pass/super_trait.rs new file mode 100644 index 0000000000..30b147d24a --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/super_trait.rs @@ -0,0 +1,16 @@ +use extend::ext; + +trait MyTrait {} + +impl MyTrait for String {} + +#[ext(supertraits = Default + Clone + MyTrait)] +impl String { + fn my_len(&self) -> usize { + self.len() + } +} + +fn main() { + assert_eq!(String::new().my_len(), 0); +} diff --git a/third_party/rust/extend/tests/compile_pass/visibility_config.rs b/third_party/rust/extend/tests/compile_pass/visibility_config.rs new file mode 100644 index 0000000000..bcb8b19576 --- /dev/null +++ b/third_party/rust/extend/tests/compile_pass/visibility_config.rs @@ -0,0 +1,15 @@ +mod a { + use extend::ext; + + #[ext(pub)] + impl i32 { + fn foo() -> Foo { Foo } + } + + pub struct Foo; +} + +fn main() { + use a::i32Ext; + i32::foo(); +} -- cgit v1.2.3