Trait bound not satisfied
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
pub trait Backend {}
pub struct Shape<const D: usize>([usize; D]);
pub struct Tensor<B: Backend, const D: usize, T> {
backend: B,
shape: Shape<D>,
data: Vec<T>,
}
impl<B: Backend, const D: usize, T> Tensor<B, D, T> {
pub fn empty(backend: B, shape: impl Into<Shape<D>>) -> Tensor<B, D, T> {
let shape: Shape<D> = shape.into();
let size = shape.0.iter().product();
Tensor {
backend,
shape,
data: Vec::with_capacity(size),
}
}
pub fn as_slice(&self) -> &[T] {
&self.data.as_slice()
}
}
impl<const D: usize> From<[usize; D]> for Shape<D> {
fn from(value: [usize; D]) -> Self {
Shape(value)
}
}
impl<const D: usize> From<u64> for Shape<D> {
fn from(value: u64) -> Self {
Shape([value as usize; D])
}
}
pub trait Op {}
pub trait ConvImpl<B: Backend, const D: usize, const D2: usize, T> {
fn conv(
&self,
tensor: &Tensor<B, D, T>,
weights: &Tensor<B, D2, T>,
stride: Shape<D2>,
) -> Tensor<B, D, T>;
}
pub trait Conv<B: Backend, const D: usize, const D2: usize, T> {
fn conv(&self, weights: &Tensor<B, D2, T>, stride: impl Into<Shape<D>>) -> Tensor<B, D, T>;
}
impl<B: Backend + ConvImpl<B, D, D2, T>, const D: usize, const D2: usize, T> Conv<B, D, D2, T>
for Tensor<B, D, T>
{
fn conv(&self, weights: &Tensor<B, D2, T>, stride: impl Into<Shape<D2>>) -> Tensor<B, D, T> {
self.backend.conv(&self, &weights, stride.into())
}
}
Current output
error[E0277]: the trait bound `Shape<D2>: From<impl Into<Shape<D2>>>` is not satisfied
--> crates/afterburner-core/src/lib.rs:58:61
|
58 | fn conv(&self, weights: &Tensor<B, D2, T>, stride: impl Into<Shape<D2>>) -> Tensor<B, D, T> {
| ^^^^^^^^^^^^^^^ the trait `From<impl Into<Shape<D2>>>` is not implemented for `Shape<D2>`, which is required by `impl Into<Shape<D2>>: Into<Shape<D2>>`
|
= note: required for `impl Into<Shape<D2>>` to implement `Into<Shape<D2>>`
note: the requirement `impl Into<Shape<D2>>: Into<Shape<D2>>` appears on the `impl`'s method `conv` but not on the corresponding trait's method
--> crates/afterburner-core/src/lib.rs:52:8
|
51 | pub trait Conv<B: Backend, const D: usize, const D2: usize, T> {
| ---- in this trait
52 | fn conv(&self, weights: &Tensor<B, D2, T>, stride: impl Into<Shape<D>>) -> Tensor<B, D, T>;
| ^^^^ this trait's method doesn't have the requirement `impl Into<Shape<D2>>: Into<Shape<D2>>`
Desired output
note: the requirement `impl Into<Shape<D2>>: Into<Shape<D2>>` appears on the `impl`'s method `conv` but not on the corresponding trait's method
--> crates/afterburner-core/src/lib.rs:52:8
|
51 | pub trait Conv<B: Backend, const D: usize, const D2: usize, T> {
| ---- in this trait
52 | fn conv(&self, weights: &Tensor<B, D2, T>, stride: impl Into<Shape<D>>) -> Tensor<B, D, T>;
| ^^^^ this trait's method doesn't have the requirement `impl Into<Shape<D2>>: Into<Shape<D2>>`
Rationale and extra context
I can't find a good reason why rust would tell me that the trait bound ain't satisfied. When in reality the impls and traits method signature differ. Changing them to make them similar resolves the error. The info section already gives the correct clue I would have expected this to be the actual error though instead of just a note.
Other cases
Rust Version
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: aarch64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the reproducer in crates/afterburner-core/src/lib.rs, especially the Conv method at lines 52 and 58, with rustc 1.81.0. Compare the emitted diagnostic with the desired output and determine whether the mismatch should be reported as the primary error; done means the reproducer produces the expected diagnostic without regressing related cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100