Skip to content

Duplicate trait suggestion #92347

Closed
Closed
@DKenefake

Description

@DKenefake

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-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