-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.