Skip to content

Commit

Permalink
add support for type Type<'a>
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Jan 27, 2024
1 parent a0f053c commit 5b97e14
Show file tree
Hide file tree
Showing 20 changed files with 130 additions and 64 deletions.
3 changes: 2 additions & 1 deletion src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,10 @@ fn gen_type_item(
// We simply use the associated type from our type parameter.
let assoc_name = &item.ident;
let attrs = filter_attrs(&item.attrs);
let generics = &item.generics;

Ok(quote! {
#(#attrs)* type #assoc_name = #proxy_ty_param::#assoc_name;
#(#attrs)* type #assoc_name #generics = #proxy_ty_param::#assoc_name #generics;
})
}

Expand Down
6 changes: 2 additions & 4 deletions tests/compile-fail/attr_on_enum.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
error: couldn't parse trait item

= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!

--> tests/compile-fail/attr_on_enum.rs:4:1
|
4 | #[auto_impl(&, &mut)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 2 additions & 4 deletions tests/compile-fail/attr_on_fn.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
error: couldn't parse trait item

= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!

--> tests/compile-fail/attr_on_fn.rs:4:1
|
4 | #[auto_impl(&, &mut)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 2 additions & 4 deletions tests/compile-fail/attr_on_impl_block.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
error: couldn't parse trait item

= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!

--> tests/compile-fail/attr_on_impl_block.rs:6:1
|
6 | #[auto_impl(&, &mut)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 2 additions & 4 deletions tests/compile-fail/attr_on_struct.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
error: couldn't parse trait item

= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!

--> tests/compile-fail/attr_on_struct.rs:4:1
|
4 | #[auto_impl(&, &mut)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 2 additions & 4 deletions tests/compile-fail/attr_on_type.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
error: couldn't parse trait item

= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!

--> tests/compile-fail/attr_on_type.rs:4:1
|
4 | #[auto_impl(&, &mut)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
6 changes: 2 additions & 4 deletions tests/compile-fail/attr_on_unit_struct.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
error: couldn't parse trait item

= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!

--> tests/compile-fail/attr_on_unit_struct.rs:4:1
|
4 | #[auto_impl(&, &mut)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `trait`
= note: the #[auto_impl] attribute can only be applied to traits!
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
34 changes: 28 additions & 6 deletions tests/compile-fail/fn_associated_const.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
error: this trait cannot be auto-implemented for Fn-traits (only traits with exactly one method and no other items are allowed)
--> tests/compile-fail/fn_associated_const.rs:5:1
|
5 | trait Foo {
| ^^^^^
5 | / trait Foo {
6 | | const LEN: usize;
7 | |
8 | | fn a(&self);
9 | | }
| |_^

error: the trait `Foo` cannot be auto-implemented for Fn-traits, because it has associated consts

= note: only traits with a single method can be implemented for Fn-traits

--> tests/compile-fail/fn_associated_const.rs:6:5
|
6 | const LEN: usize;
| ^^^^^
| ^^^^^^^^^^^^^^^^^
|
= note: only traits with a single method can be implemented for Fn-traits

error[E0046]: not all trait items implemented, missing: `LEN`
--> tests/compile-fail/fn_associated_const.rs:4:1
|
4 | #[auto_impl(Fn)]
| ^^^^^^^^^^^^^^^^ missing `LEN` in implementation
5 | trait Foo {
6 | const LEN: usize;
| ---------------- `LEN` from trait
|
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0618]: expected function, found `&T`
--> tests/compile-fail/fn_associated_const.rs:4:1
|
4 | #[auto_impl(Fn)]
| ^^^^^^^^^^^^^^^^ call expression requires function
|
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
34 changes: 28 additions & 6 deletions tests/compile-fail/fn_associated_type.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
error: this trait cannot be auto-implemented for Fn-traits (only traits with exactly one method and no other items are allowed)
--> tests/compile-fail/fn_associated_type.rs:5:1
|
5 | trait Foo {
| ^^^^^
5 | / trait Foo {
6 | | type Out;
7 | |
8 | | fn a(&self);
9 | | }
| |_^

error: the trait `Foo` cannot be auto-implemented for Fn-traits, because it has associated types

= note: only traits with a single method can be implemented for Fn-traits

--> tests/compile-fail/fn_associated_type.rs:6:5
|
6 | type Out;
| ^^^^
| ^^^^^^^^^
|
= note: only traits with a single method can be implemented for Fn-traits

error[E0046]: not all trait items implemented, missing: `Out`
--> tests/compile-fail/fn_associated_type.rs:4:1
|
4 | #[auto_impl(Fn)]
| ^^^^^^^^^^^^^^^^ missing `Out` in implementation
5 | trait Foo {
6 | type Out;
| -------- `Out` from trait
|
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0618]: expected function, found `&T`
--> tests/compile-fail/fn_associated_type.rs:4:1
|
4 | #[auto_impl(Fn)]
| ^^^^^^^^^^^^^^^^ call expression requires function
|
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
2 changes: 1 addition & 1 deletion tests/compile-fail/fn_const_generics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ error: the trait 'Greeter' cannot be implemented for Fn-traits: constant argumen
--> tests/compile-fail/fn_const_generics.rs:6:14
|
6 | fn greet<const N: usize>(&self, id: usize);
| ^^^^^
| ^^^^^^^^^^^^^^
11 changes: 10 additions & 1 deletion tests/compile-fail/fn_generics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ error: the trait 'Greeter' cannot be implemented for Fn-traits: generic argument
--> tests/compile-fail/fn_generics.rs:7:14
|
7 | fn greet<T: Display>(&self, name: T);
| ^
| ^^^^^^^^^^

error[E0412]: cannot find type `T` in this scope
--> tests/compile-fail/fn_generics.rs:7:39
|
5 | #[auto_impl(Fn)]
| ---------------- similarly named type parameter `U` defined here
6 | trait Greeter {
7 | fn greet<T: Display>(&self, name: T);
| ^ help: a type parameter with a similar name exists: `U`
15 changes: 13 additions & 2 deletions tests/compile-fail/fn_multiple_methods.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
error: this trait cannot be auto-implemented for Fn-traits (only traits with exactly one method and no other items are allowed)
--> tests/compile-fail/fn_multiple_methods.rs:5:1
|
5 | trait Foo {
| ^^^^^
5 | / trait Foo {
6 | | fn a(&self);
7 | | fn b(&self);
8 | | }
| |_^

error[E0618]: expected function, found `&T`
--> tests/compile-fail/fn_multiple_methods.rs:4:1
|
4 | #[auto_impl(Fn)]
| ^^^^^^^^^^^^^^^^ call expression requires function
|
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
5 changes: 3 additions & 2 deletions tests/compile-fail/keep_default_for_on_assoc_type.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
error: `#[auto_impl]` attributes are only allowed on methods
--> tests/compile-fail/keep_default_for_on_assoc_type.rs:6:5
|
6 | #[auto_impl(keep_default_for(&))]
| ^
6 | / #[auto_impl(keep_default_for(&))]
7 | | type Foo;
| |_____________^
13 changes: 12 additions & 1 deletion tests/compile-fail/keep_default_for_on_required_method.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@ error: the method `required` has the attribute `keep_default_for` but is not a d
--> tests/compile-fail/keep_default_for_on_required_method.rs:7:5
|
7 | fn required(&self);
| ^^
| ^^^^^^^^^^^^^^^^^^

error[E0046]: not all trait items implemented, missing: `required`
--> tests/compile-fail/keep_default_for_on_required_method.rs:4:1
|
4 | #[auto_impl(&)]
| ^^^^^^^^^^^^^^^ missing `required` in implementation
...
7 | fn required(&self);
| ------------------- `required` from trait
|
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
7 changes: 3 additions & 4 deletions tests/compile-fail/mut_self_for_arc.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
error: the trait `Foo` cannot be auto-implemented for Arc, because this method has a `&mut self` receiver

= note: only `&self` and no receiver are allowed

--> tests/compile-fail/mut_self_for_arc.rs:6:5
|
6 | fn foo(&mut self);
| ^^
| ^^^^^^^^^^^^^^^^^
|
= note: only `&self` and no receiver are allowed
7 changes: 3 additions & 4 deletions tests/compile-fail/mut_self_for_immutable_ref.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
error: the trait `Foo` cannot be auto-implemented for immutable references, because this method has a `&mut self` receiver

= note: only `&self` and no receiver are allowed

--> tests/compile-fail/mut_self_for_immutable_ref.rs:6:5
|
6 | fn foo(&mut self);
| ^^
| ^^^^^^^^^^^^^^^^^
|
= note: only `&self` and no receiver are allowed
7 changes: 3 additions & 4 deletions tests/compile-fail/mut_self_for_rc.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
error: the trait `Foo` cannot be auto-implemented for Rc, because this method has a `&mut self` receiver

= note: only `&self` and no receiver are allowed

--> tests/compile-fail/mut_self_for_rc.rs:6:5
|
6 | fn foo(&mut self);
| ^^
| ^^^^^^^^^^^^^^^^^
|
= note: only `&self` and no receiver are allowed
7 changes: 3 additions & 4 deletions tests/compile-fail/value_self_for_immutable_ref.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
error: the trait `Foo` cannot be auto-implemented for immutable references, because this method has a `self` receiver

= note: only `&self` and no receiver are allowed

--> tests/compile-fail/value_self_for_immutable_ref.rs:6:5
|
6 | fn foo(self);
| ^^
| ^^^^^^^^^^^^
|
= note: only `&self` and no receiver are allowed
7 changes: 3 additions & 4 deletions tests/compile-fail/value_self_for_mutable_ref.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
error: the trait `Foo` cannot be auto-implemented for mutable references, because this method has a `self` receiver

= note: only `&self`, `&mut self` and no receiver are allowed

--> tests/compile-fail/value_self_for_mutable_ref.rs:6:5
|
6 | fn foo(self);
| ^^
| ^^^^^^^^^^^^
|
= note: only `&self`, `&mut self` and no receiver are allowed
6 changes: 6 additions & 0 deletions tests/recent/compile-pass/associated_lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[auto_impl::auto_impl(&, Arc, Box)]
pub trait Trait {
type Type<'a, T>: Iterator<Item = T> + 'a;
}

fn main() {}

0 comments on commit 5b97e14

Please sign in to comment.