Skip to content

Change the encoding of supertrait clauses to support associated types #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fn gen_header(

if !trait_def.supertraits.is_empty() {
let supertraits = &trait_def.supertraits;
out.extend(quote! { #self_ty: #supertraits, });
out.extend(quote! { #proxy_ty_param: #supertraits, });
}
if let Some(predicates) = where_clause.map(|c| &c.predicates) {
out.extend(predicates.into_token_stream());
Expand Down
49 changes: 27 additions & 22 deletions tests/compile-fail/super_trait_not_implemented.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
error[E0277]: the trait bound `Box<Dog>: Supi` is not satisfied
--> tests/compile-fail/super_trait_not_implemented.rs:18:18
|
18 | requires_foo(Box::new(Dog)); // shouldn't, because `Box<Dog>: Supi` is not satisfied
| ------------ ^^^^^^^^^^^^^ the trait `Supi` is not implemented for `Box<Dog>`
| |
| required by a bound introduced by this call
|
= help: the trait `Supi` is implemented for `Dog`
note: required for `Box<Dog>` to implement `Foo`
--> tests/compile-fail/super_trait_not_implemented.rs:5:1
|
5 | #[auto_impl(Box, &)]
| ^^^^^^^^^^^^^^^^^^^^
6 | trait Foo: Supi {}
| ^^^ ---- unsatisfied trait bound introduced here
note: required by a bound in `requires_foo`
--> tests/compile-fail/super_trait_not_implemented.rs:14:20
|
14 | fn requires_foo<T: Foo>(_: T) {}
| ^^^ required by this bound in `requires_foo`
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `Box<T>: Supi` is not satisfied
--> tests/compile-fail/super_trait_not_implemented.rs:5:1
|
5 | #[auto_impl(Box, &)]
| ^^^^^^^^^^^^^^^^^^^^ the trait `Supi` is not implemented for `Box<T>`
|
= help: the trait `Supi` is implemented for `Dog`
note: required by a bound in `Foo`
--> tests/compile-fail/super_trait_not_implemented.rs:6:12
|
6 | trait Foo: Supi {}
| ^^^^ required by this bound in `Foo`
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `&'a T: Supi` is not satisfied
--> tests/compile-fail/super_trait_not_implemented.rs:5:1
|
5 | #[auto_impl(Box, &)]
| ^^^^^^^^^^^^^^^^^^^^ the trait `Supi` is not implemented for `&'a T`
|
= help: the trait `Supi` is implemented for `Dog`
note: required by a bound in `Foo`
--> tests/compile-fail/super_trait_not_implemented.rs:6:12
|
6 | trait Foo: Supi {}
| ^^^^ required by this bound in `Foo`
= note: this error originates in the attribute macro `auto_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
14 changes: 14 additions & 0 deletions tests/compile-pass/super_trait_associated_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use auto_impl::auto_impl;

#[auto_impl(Box, &)]
trait Supi {
type Assoc;
}

#[auto_impl(Box, &)]
trait Foo: Supi {
fn foo(&self, x: Self::Assoc) -> String;
}


fn main() {}
1 change: 1 addition & 0 deletions tests/compile-pass/super_trait_complex_for_refs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use auto_impl::auto_impl;

#[auto_impl(Box, &)]
trait Supi<'a, T> {
fn supi(&self);
}
Expand Down
1 change: 1 addition & 0 deletions tests/compile-pass/super_trait_simple_for_refs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use auto_impl::auto_impl;

#[auto_impl(Box, &)]
trait Supi {}

#[auto_impl(Box, &)]
Expand Down