Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPermit impl methods whose bounds cannot be satisfied to have no body #20021
Comments
This comment has been minimized.
This comment has been minimized.
|
It would be helpful to mark (or even erase) these uncallable methods in the "Trait Implementations" section of the rustdocs for the type implementing the trait. |
This comment has been minimized.
This comment has been minimized.
|
@tomjakubowski I think I am the one who will be working #20020 and most likely this issue unless @nikomatsakis beats me to it. I will try to keep that in mind :). |
kmcallister
added
the
A-traits
label
Jan 16, 2015
P1start
referenced this issue
Feb 7, 2015
Closed
A method marked `where Self: Sized` on a trait should not be considered during object safety checks #22031
This comment has been minimized.
This comment has been minimized.
|
Triaging this issue. #20020 has already been closed, but yet we can't use unimplemented methods without where. This is the code I used to see if it was still an issue: trait MyTrait<T> {
fn method(&self, t: &T) where T : Eq;
}
struct Foo;
struct Bar; // note that `Bar` does not derive `Eq`
impl MyTrait<Bar> for Foo {
fn method(&self, t: &Bar);
}
fn main() {}Rust version
|
apasel422
referenced this issue
Jan 10, 2016
Closed
Do not require to implement a trait method if a constraint is not satisfied #26880
This comment has been minimized.
This comment has been minimized.
|
In a similar situation, despite being object-safe, the following trait cannot be implemented for trait Foo {
fn foo(self);
}
impl<T> Foo for [T] {
fn foo(self) { unimplemented!() }
//~^ ERROR the trait `core::marker::Sized` is not implemented for the type `[T]`
}The As an unsatisfactory workaround, one can default trait Foo {
fn foo(self) where Self: Sized { unimplemented!() }
}
impl<T> Foo for [T] {}This allows the impl to compile, but is nonsensical because it is exactly the |
This comment has been minimized.
This comment has been minimized.
|
On Sun, Jan 10, 2016 at 09:10:54AM -0800, Andrew Paseltiner wrote:
FWIW, this is intentional, as we still aim to allow DST moves at some |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis Ah, I hadn't considered that. Are you still planning to amend the where clause RFC for this issue? |
This was referenced Aug 10, 2016
This comment has been minimized.
This comment has been minimized.
|
This is also arising in the context of rust-lang/rfcs#1216. Recent PR rust-lang/rfcs#1699 is also relevant. The specific issue is that the |
brson
added
I-nominated
T-compiler
labels
Aug 25, 2016
This comment has been minimized.
This comment has been minimized.
|
Nominating for triage. Add some tags please. Last work item in #17657 |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis These two are qualitatively different things though. In the case that this issue is about, no call to the method could ever type-check. In the case that rust-lang/rfcs#1699 is about, a call would type-check just fine, it's just that the method body would never actually be entered at runtime. |
nrc
added
T-lang
and removed
T-compiler
labels
Aug 25, 2016
This comment has been minimized.
This comment has been minimized.
|
Discussed in @rust-lang/lang meeting. A couple of notes:
triage: P-medium |
rust-highfive
added
P-medium
and removed
I-nominated
labels
Aug 25, 2016
nikomatsakis
added
E-medium
E-mentor
and removed
P-medium
E-mentor
labels
Aug 25, 2016
This comment has been minimized.
This comment has been minimized.
|
Ah, reviewing this though -- I'm not sure we ever settled on a syntax. It may be that we need an RFC here? Should review the existing RFC :) EDIT: Just did, it offers no guidance here. |
Mark-Simulacrum
added
the
C-feature-request
label
Jul 22, 2017
varkor
referenced this issue
Jan 21, 2018
Open
Tracking issue for promoting `!` to a type (RFC 1216) #35121
This comment has been minimized.
This comment has been minimized.
|
Triage: not aware of any specific updates here. |
nikomatsakis commentedDec 19, 2014
There is a curious case with where clauses where sometimes we can show that a method in an impl could not possibly be called. This is because the impl has more precise information than the trait. Here is an example:
We should permit the method body to be omitted in such a case. As a workaround, once #20020 is fixed, I imagine it would be possible to write an impl like this:
However, it is unfortunate to require that of the user. For one thing, perhaps it happens later that an impl of
Eqis added forBar-- now we have this method hanging around that will panic. It'd be nice to detect that statically.The plan then would be to permit:
This serves as a declaration that you believe this method could never be called. At trans time, we will generate a body that simply does the equivalent of
panic!("unsatisfiable methodmethodinvoked").I plan to open an amendment to the where clause RFC describing this particular case.