Incorrect trait bounds suggestion with derive macros · Issue #104071 · rust-lang/rust (original) (raw)

 λ  cargo check
    Checking dbsp v0.1.0 (G:\Users\Chase\Code\Rust\database-stream-processor)
error[E0277]: the trait bound `R: Neg` is not satisfied
   --> src\trace\ord\indexed_zset_batch.rs:314:13
    |
314 |     result: <Layers<K, V, R, O> as Trie>::MergeBuilder,
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Neg` is not implemented for `R`
    |
note: required for `R` to implement `IntoErasedDiff`
   --> src\trace\layers\erased\vtable.rs:227:9
    |
227 | impl<T> IntoErasedDiff for T
    |         ^^^^^^^^^^^^^^     ^
note: required for `TypedLayer<V, R>` to implement `Trie`
   --> src\trace\layers\erased\mod.rs:306:12
    |
306 | impl<K, R> Trie for TypedLayer<K, R>
    |            ^^^^     ^^^^^^^^^^^^^^^^
help: consider further restricting this bound
    |
310 |     R: DBWeight + std::ops::Neg,
    |                 +++++++++++++++

error[E0277]: the trait bound `for<'a> &'a R: Neg` is not satisfied
   --> src\trace\ord\indexed_zset_batch.rs:314:13
    |
314 |     result: <Layers<K, V, R, O> as Trie>::MergeBuilder,
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Neg` is not implemented for `&'a R`
    |
note: required for `R` to implement `NegByRef`
   --> src\algebra\mod.rs:168:9
    |
168 | impl<T> NegByRef for T
    |         ^^^^^^^^     ^
note: required for `R` to implement `IntoErasedDiff`
   --> src\trace\layers\erased\vtable.rs:227:9
    |
227 | impl<T> IntoErasedDiff for T
    |         ^^^^^^^^^^^^^^     ^
note: required for `TypedLayer<V, R>` to implement `Trie`
   --> src\trace\layers\erased\mod.rs:306:12
    |
306 | impl<K, R> Trie for TypedLayer<K, R>
    |            ^^^^     ^^^^^^^^^^^^^^^^
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
    |
311 |     O: OrdOffset, &'a R: for<'a> Neg
    |                 ~~~~~~~~~~~~~~~~~~~~

error[E0277]: the trait bound `R: Neg` is not satisfied
   --> src\trace\ord\indexed_zset_batch.rs:305:10
    |
305 | #[derive(SizeOf)]
    |          ^^^^^^ the trait `Neg` is not implemented for `R`
    |
note: required for `R` to implement `IntoErasedDiff`
   --> src\trace\layers\erased\vtable.rs:227:9
    |
227 | impl<T> IntoErasedDiff for T
    |         ^^^^^^^^^^^^^^     ^
note: required for `TypedLayer<V, R>` to implement `Trie`
   --> src\trace\layers\erased\mod.rs:306:12
    |
306 | impl<K, R> Trie for TypedLayer<K, R>
    |            ^^^^     ^^^^^^^^^^^^^^^^
    = note: this error originates in the derive macro `SizeOf` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
    |
310 |     R: DBWeight + std::ops::Neg,
    |                 +++++++++++++++

error[E0277]: the trait bound `for<'a> &'a R: Neg` is not satisfied
   --> src\trace\ord\indexed_zset_batch.rs:305:10
    |
305 | #[derive(SizeOf)]
    |          ^^^^^^ the trait `for<'a> Neg` is not implemented for `&'a R`
    |
note: required for `R` to implement `NegByRef`
   --> src\algebra\mod.rs:168:9
    |
168 | impl<T> NegByRef for T
    |         ^^^^^^^^     ^
note: required for `R` to implement `IntoErasedDiff`
   --> src\trace\layers\erased\vtable.rs:227:9
    |
227 | impl<T> IntoErasedDiff for T
    |         ^^^^^^^^^^^^^^     ^
note: required for `TypedLayer<V, R>` to implement `Trie`
   --> src\trace\layers\erased\mod.rs:306:12
    |
306 | impl<K, R> Trie for TypedLayer<K, R>
    |            ^^^^     ^^^^^^^^^^^^^^^^
    = note: this error originates in the derive macro `SizeOf` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider extending the `where` clause, but there might be an alternative better way to express this requirement
    |
305 | #[derive(SizeOf, &'a R: for<'a> Neg)]
    |                ++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `dbsp` due to 4 previous errors

Which has some weird suggestions, mainly #[derive(SizeOf, &'a R: for<'a> Neg)]. Additionally, the "alternative better way" of "but there might be an alternative better way to express this requirement" is worded a little strangely, it's kind of a double positive

 λ  rustc -Vv
rustc 1.66.0-nightly (7fcf850d7 2022-10-23)
binary: rustc
commit-hash: 7fcf850d7942804990a1d2e3fe036622a0fe4c74
commit-date: 2022-10-23
host: x86_64-pc-windows-msvc
release: 1.66.0-nightly
LLVM version: 15.0.2
 λ  cargo -Vv
cargo 1.66.0-nightly (071eeaf21 2022-10-22)
release: 1.66.0-nightly
commit-hash: 071eeaf210708219a5a1b2c4728ca2f97df7f2ae
commit-date: 2022-10-22
host: x86_64-pc-windows-msvc
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:Schannel)
os: Windows 10.0.19044 (Windows 10 Home) [64-bit]