-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustc doesn't reject incompatible trait and impl methods w.r.t argument bounds #13629
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
Comments
Oh dear, that's bad. Nominating. |
These were mistakenly not updated as part of the removal of the Send bound by default on procedures. cc rust-lang#13629
These were mistakenly not updated as part of the removal of the Send bound by default on procedures. cc #13629
1.0 backcompat lang. |
Consider the example given above and the one below: pub trait T1 {}
pub struct S;
impl T1 for S {}
pub trait Runtime {
fn spawn_sibling(&self) -> Box<T1:Send>;
}
pub struct Foo;
impl Runtime for Foo {
fn spawn_sibling(&self) -> Box<T1> {
box S as Box<T1>
}
}
fn main() {} Intuitively, they are both wrong. But currently rustc accepts the former and rejects the latter. The reasoning here seems to be: in the first example, So by the usual variance rule, the current behavior is actually correct! Very counter-intuitive. I'm not sure why built-in bounds here makes an exception to the variance rule. |
cc me |
I am not sure yet that this is broken. I think it is expected behavior. |
Specifically, impls can require less than traits require. The idea is: if I didn't know the impls type, and I only know the trait type (as in a generic fn), I will pass in a |
That said, I'm not sure there is much purpose to permitting this kind of subtyping, and it might make sense to tighten up the rules just so people don't get surprised. The original goal was to permit impls to act as a kind of refinement, so that in cases where we did know the static type, we could use the tighter types from the impl, rather than the more generic types from the trait, but I don't think this is how our method resolution will work anyway. And you could always declare an inherent method for places where this matters. |
cc @flaper87 |
Also, the "Taming the Wildcards" paper does mention that a type parameter lower bound is contra-variant in itself. The way we use built-in bounds here, i.e. at least Either way, this is rather subtle and could be a surprise. |
Nominating for closure as a dupe of #2687. |
Closing as expected behavior. |
… r=jonas-schievink feat: Make "Remove dbg!()" assist work on selections Fixes rust-lang/rust-analyzer#12114
…ip1995 Return iterator must not capture lifetimes in Rust 2024 In Rust 2024, by default lifetimes will be captured which does not reflect the reality since we return an iterator of `DefId` which do not capture the input parameters. changelog: none
The following is extracted from libnative / libgreen implementation of
std::rt::Runtime
:The implementation misses the
Send
bound of one of its argument so it should not compile, but currently it does.The text was updated successfully, but these errors were encountered: