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

Incorrect trait bounds suggestion with derive macros #104071

Open
Kixiron opened this issue Nov 6, 2022 · 1 comment
Open

Incorrect trait bounds suggestion with derive macros #104071

Kixiron opened this issue Nov 6, 2022 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Kixiron
Copy link
Member

Kixiron commented Nov 6, 2022

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]
@Kixiron Kixiron added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 6, 2022
@estebank
Copy link
Contributor

estebank commented Nov 8, 2022

The wording should likely have been "but there might be an alternative, better, way to express this requirement".

The suggestion machinery can check whether the span we're operating on is coming from a macro, but it might be difficult to differentiate between proc-macros that have properly annotated their spans so the suggestion works, and those that haven't (other than maybe try and compare span byte pos, depending on what we have available?).

@estebank estebank added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. A-proc-macros Area: Procedural macros labels Nov 8, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 16, 2023
Do not provide suggestions when the spans come from expanded code that doesn't point at user code

Hide invalid proc-macro suggestions and track spans
coming from proc-macros pointing at attribute.

Effectively, unless the proc-macro keeps user spans,
suggestions will not be produced for the code they
produce.

r? `@ghost`

Fix rust-lang#107113, fix rust-lang#107976, fix rust-lang#107977, fix rust-lang#108748, fix rust-lang#106720, fix rust-lang#90557.

Could potentially address rust-lang#50141, rust-lang#67373, rust-lang#55146, rust-lang#78862, rust-lang#74043, rust-lang#88514, rust-lang#83320, rust-lang#91520, rust-lang#104071. CC rust-lang#50122, rust-lang#76360.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 17, 2023
Do not provide suggestions when the spans come from expanded code that doesn't point at user code

Hide invalid proc-macro suggestions and track spans
coming from proc-macros pointing at attribute.

Effectively, unless the proc-macro keeps user spans,
suggestions will not be produced for the code they
produce.

r? ``@ghost``

Fix rust-lang#107113, fix rust-lang#107976, fix rust-lang#107977, fix rust-lang#108748, fix rust-lang#106720, fix rust-lang#90557.

Could potentially address rust-lang#50141, rust-lang#67373, rust-lang#55146, rust-lang#78862, rust-lang#74043, rust-lang#88514, rust-lang#83320, rust-lang#91520, rust-lang#104071. CC rust-lang#50122, rust-lang#76360.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants