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

Duplicate trait suggestion #92347

Closed
DKenefake opened this issue Dec 28, 2021 · 1 comment
Closed

Duplicate trait suggestion #92347

DKenefake opened this issue Dec 28, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

@DKenefake
Copy link

Given the following code: here

fn rot<T : std::ops::Shl<Output = T>>(x:&T, k:u32) -> T {
    let bit_count = std::mem::size_of::<T>() << 3;
    (x << k as T) | (x >> (bit_count - k as T))
}

The current output is:

error[E0369]: no implementation for `&T << T`
  --> src\lib.rs:10:8
   |
10 |     (x << k as T) | (x >> (bit_count - k as T))
   |      - ^^ ------ T
   |      |
   |      &T
   |
help: consider further restricting this bound
   |
8  | fn rot<T : std::ops::Shl<Output = T> + std::ops::Shl<Output = T>>(x:&T, k:u32) -> T {
   |                                      +++++++++++++++++++++++++++

The code is incorrect and shouldn't compile, but the suggestion is to duplicate a trait restriction that is already present in the function and can be repeated n-times, e.g. with T: std::ops::Shl<Output = T> + std::ops::Shl<Output = T> it will suggest T: std::ops::Shl<Output = T> + std::ops::Shl<Output = T>+ std::ops::Shl<Output = T>. This appears to indicate that the traits are not being checked correctly for suggestions, suggesting trait restrictions that are already present. The same output occurs in the nightly build.

@DKenefake DKenefake 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 Dec 28, 2021
@DKenefake DKenefake changed the title Documentation Error for std:: Duplicate trait suggestion Dec 28, 2021
@BGR360
Copy link
Contributor

BGR360 commented Dec 29, 2021

@rustbot label +D-invalid-suggestion

@rustbot rustbot added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Dec 29, 2021
willcrichton added a commit to willcrichton/rust that referenced this issue Apr 26, 2022
to fix incorrect suggestion for trait bounds involving binary operators.
Fixes rust-lang#93927, rust-lang#92347, rust-lang#93744.
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 26, 2022
…-binops, r=estebank

Fix incorrect suggestion for trait bounds involving binary operators

This PR fixes rust-lang#93927, rust-lang#92347, rust-lang#93744 by replacing the bespoke trait-suggestion logic in `op.rs` with a more common code path.

The downside is that this fix causes some suggestions to not include an `Output=` type, reducing their usefulness.

Note that this causes one case in the `missing-bounds.rs` test to fail rustfix. So I would need to move that code into a separate non-fix test if this PR is otherwise acceptable.
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 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

4 participants