Skip to content
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

Using inline trait bounds instead of a where clause triggers build failure #518

Open
gshep opened this issue Sep 6, 2024 · 0 comments
Open

Comments

@gshep
Copy link
Member

gshep commented Sep 6, 2024

Problem

Inline trait bound for a service - impl<T: TestTrait> TestTraitBoundsService<T> - fails to compile. Log attached.

Steps

  1. cargo-sails new-program test-trait-bounds
struct TestTraitBoundsService<T>(PhantomData<T>);

trait TestTrait {}

impl TestTrait for u8 {}

#[sails_rs::service]
impl<T: TestTrait> TestTraitBoundsService<T> /* ... */
// Exposed service
    pub fn test_trait_bounds(&self) -> TestTraitBoundsService<u8> {
        TestTraitBoundsService::new()
    }
  1. cargo test

Possible Solution

No response

Notes

No response

Relevant Log Output

cargo test output

$ cargo test
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
   Compiling test-trait-bounds-app v0.1.0 (/home/user/devel/gear-tech/sails/test-trait-bounds/app)
error[E0599]: the method `do_something` exists for struct `Box<TestTraitBoundsService<T>>`, but its trait bounds were not satisfied
  --> app/src/lib.rs:20:12
   |
20 |     pub fn do_something(&mut self) -> String {
   |            ^^^^^^^^^^^^ method cannot be called on `Box<TestTraitBoundsService<T>>` due to unsatisfied trait bounds
   |
note: trait bound `T: TestTrait` was not satisfied
  --> app/src/lib.rs:13:9
   |
13 | impl<T: TestTrait> TestTraitBoundsService<T>
   |         ^^^^^^^^^  -------------------------
   |         |
   |         unsatisfied trait bound introduced here

For more information about this error, try `rustc --explain E0599`.
error: could not compile `test-trait-bounds-app` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `test-trait-bounds-app` (lib) due to 1 previous error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant