Skip to content

Incorrect trait bounds suggestion with derive macros #104071

Open
@Kixiron

Description

@Kixiron

Given the following code:

Commit

The current output is:

 λ  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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions