-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Trait bound is ignored #65149
Comments
Seems like it is related entirely to the "arbitrary" self types thing. MCVE: use std::pin::Pin;
pub trait Foo {
fn pin_recv(self: Pin<&mut Self>);
}
impl Foo for u64 {
fn pin_recv(self: Pin<&mut u64>) {}
}
pub struct Wrapped<T> {
num: T,
}
impl<T: Foo> Foo for Wrapped<T> {
fn pin_recv(self: Pin<&mut Self>) {
self.num.pin_recv()
// correct: `Pin::new(&mut self.num).pin_recv()`
}
} |
Another example trait Bounded {
const COUNT : usize;
}
fn make_array<B : Bounded>() -> [bool; B::COUNT] {
[false; B::COUNT]
} (Also note the formatting error in the text - rustc inserts the new bound after the current type, assuming that's where the colon is. Thus in this specific example the suggestion has invalid syntax due to the space before the colon in the code.) |
Is there a way to work around this? |
@fenhl see nagisa's comment above. |
Current output, we no longer provide the incorrect suggestions:
This is another case of #69069. |
Should we close the duplicates? And also this issue, given that we no longer suggest wrong? |
Maybe, but let's make sure we link them up.
No, we need to improve the output when dealing with arbitrary self types. The current output is at least no longer wrong but it is misleading and actively confusing for anyone not intimately knowledgeable about the language. |
Add more context to E0599 errors Point at the intermediary unfulfilled trait bounds. Fix rust-lang#52523, fix rust-lang#61661, cc rust-lang#36513, fix rust-lang#68131, fix rust-lang#64417, fix rust-lang#61768, cc rust-lang#57457, cc rust-lang#9082, fix rust-lang#57994, cc rust-lang#64934, cc rust-lang#65149.
Add more context to E0599 errors Point at the intermediary unfulfilled trait bounds. Fix rust-lang#52523, fix rust-lang#61661, cc rust-lang#36513, fix rust-lang#68131, fix rust-lang#64417, fix rust-lang#61768, cc rust-lang#57457, cc rust-lang#9082, fix rust-lang#57994, cc rust-lang#64934, cc rust-lang#65149.
@Rantanen your example gives me a different error.
This example instead: trait Bounded {
const COUNT : usize;
}
fn make_array<B : Bounded>() -> [bool; <B as Bounded>::COUNT] {
[false; B::COUNT]
} gives the following error:
Also notice that this example isn't related to arbitrary self types but gives the same wrong suggestion. |
We now suggest an appropriate fix for the original report (although a few extra changes are needed to get to working code, the suggestions lead you all the way there):
We no longer suggest adding a bound when it was used in a const expression:
|
I have a simple program below that is trying to call
poll_next
on aT: Stream
. The compiler seems to ignore the trait bound, and suggests adding the exact trait bound that is already in use.This is using the current beta rust version:
rustc 1.39.0-beta.5 (fa5c2f3e5 2019-10-02)
A complete git repo reproducing the issue is here: https://github.com/fuchsnj/poll_next_bug
(remember to run
rustup override set beta
)The text was updated successfully, but these errors were encountered: