-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
comparing bounds on impl method type parameters with bounds declared on trait is completely bogus #2687
Comments
Similarly, in ac1f84c, we require that the bounds on the method parameters be precisely equivalent, which is stronger than necessary. It is sufficient (I believe) that the bounds on the trait be stronger than the bounds on the implementation. |
…trait method, not exact match.
Is this still an issue? It seems to be fixed now. |
Still an issue with respect to type parameter bounds. |
I don't believe this is backwards incompatible, renominating. |
accepted for feature-complete milestone |
The following appears to work, but I assume that this is what @thestinger was talking about: trait Foo {
unsafe fn x();
}
impl Foo for int {
unsafe fn x() {}
}
impl Foo for uint {
fn x() {}
}
fn main() {} |
triage bump. nothing to add. |
Accepted for P-backcompat-lang |
Added UPDATE to main bug description above. |
I had a look at this issue and tried to create a test case. @nikomatsakis does this test case covers the issue you mentioned? |
@fhahn what error does it fail with? In the trait ParamTrait {}
struct Param;
impl ParamTrait for Param {}
struct Bar;
trait Foo {
fn test_fn<T:Eq>(&self, x: T, y: T);
}
impl Foo for Bar {
// The type param of the implementation is not
// the same as specified in the trait `Foo` nor implied
// by it.
fn test_fn<T: ParamTrait>(&self, x: T, y: T) {}
}
fn main() {
let x: Bar = Bar;
x.test_fn(Param, Param);
} |
@flaper87 thanks for the hint, I guess your updated example should indeed test this issue. I'll start working on a patch. |
…felix with the corresponding trait parameter bounds. This is a version of the patch in PR #12611 by Florian Hahn, modified to address Niko's feedback. It does not address the issue of duplicate type parameter bounds, nor does it address the issue of implementation-defined methods that contain *fewer* bounds than the trait, because Niko's review indicates that this should not be necessary (and indeed I believe it is not). A test has been added to ensure that this works. This will break code like: trait Foo { fn bar<T:Baz>(); } impl Foo for Boo { fn bar<T:Baz + Quux>() { ... } // ^~~~ ERROR } This will be rejected because the implementation requires *more* bounds than the trait. It can be fixed by either adding the missing bound to the trait: trait Foo { fn bar<T:Baz + Quux>(); // ^~~~ } impl Foo for Boo { fn bar<T:Baz + Quux>() { ... } // OK } Or by removing the bound from the impl: trait Foo { fn bar<T:Baz>(); } impl Foo for Boo { fn bar<T:Baz>() { ... } // OK // ^ remove Quux } This patch imports the relevant tests from #2687, as well as the test case in #5886, which is fixed as well by this patch. Closes #2687. Closes #5886. [breaking-change] r? @pnkfelix
ensure current getrandom works with strict provenance
ensure current getrandom works with strict provenance
Right now, a fn implementing an iface method must match the purity of the iface method exactly. This is too strict. We should allow a pure fn to implement an impure fn, and both pure/impure to implement an unsafe fn.
UPDATE: Updated title to reflect the real problem here. There is a FIXME in the code in the relevant area. If one declares a trait like:
then in the impl, the
m
method should take one type parameter with anEq
bound. We don't really check this correctly though. As far as I can tell, we just check thatm
has one type parameter with one bound, but not precisely what kind of bound it is.The text was updated successfully, but these errors were encountered: