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 upDon't ICE when uncallable functions occur due to unsatisfiable where clauses #21203
Comments
This comment has been minimized.
This comment has been minimized.
|
So I think this is a good reason to just permit where clauses like this. Ideally we'll report errors at the callee, though it's easiest to report errors at the caller. |
kmcallister
added
the
A-typesystem
label
Jan 16, 2015
This comment has been minimized.
This comment has been minimized.
|
@erickt you seem to have disappeared from IRC, but the point about privacy is a good one -- I feel like the privacy rules are being too strict here. |
erickt
referenced this issue
Jan 16, 2015
Merged
Add associated types support for #[derive(...)] #21237
This comment has been minimized.
This comment has been minimized.
|
I'm not so sure about the privacy thing any more. After some conversation with @aturon we felt like the current rules might be best. |
This comment has been minimized.
This comment has been minimized.
|
Should this be closed as wontfix/intended, then? |
This comment has been minimized.
This comment has been minimized.
|
I lost track of this, did anyone remove the check that ensures bound types include a type parameter? I remember we had talked about shuffling around some error reporting as well, but its been too many days since I've thought about this. |
This comment has been minimized.
This comment has been minimized.
|
@Gankro I think the privacy rules are somewhat orthogonal to allowing non-generic where clauses (although the motivating use case is definitely undermined by the current privacy rules). |
This comment has been minimized.
This comment has been minimized.
|
Triage: this now works. Full reproduction:
|
steveklabnik
closed this
Mar 4, 2016
This comment has been minimized.
This comment has been minimized.
|
Huh. When did that happen? I know there have been some pending PRs about this, but there were some thorny issues, and I didn't realize that we'd made any actual changes here. @arielb1, do you know? |
This comment has been minimized.
This comment has been minimized.
|
What? I didn't implement this? |
arielb1
reopened this
Mar 8, 2016
arielb1
added
the
I-nominated
label
Mar 8, 2016
This comment has been minimized.
This comment has been minimized.
|
I think this is the relevant commit: dbf994b |
This comment has been minimized.
This comment has been minimized.
|
Yeah I was wondering if this was somehow fallout from that change. That's a bit unexpected though. |
alexcrichton
added
the
T-compiler
label
Mar 9, 2016
This comment has been minimized.
This comment has been minimized.
|
So we do need a solution that addresses this example raised by @arielb1 #[no_mangle]
pub fn bogus<'a>(x: &'a mut ()) where &'a mut (): Clone {
<&'a mut ()>::clone(&x);
}The key point in this example is that this where clause could never hold -- but because it's only parametric over a lifetime, we will try to trans it, and find that there is no existing impl. This could either fail in typeck -- but we'd have to search for impls using an erased parameter -- or else fail in trans -- where the absence of an impl could cause us to emit a trap or something like that, on the premise that the fn should not in fact be callable. Basically in trans we can just check if we know statically that the fn could never be called and generate a trap or what have you. Or just don't translate it. Or something. This seems similar to the logic that we use to screen things out of vtables. |
nikomatsakis
changed the title
Allow where clause predicates that contain no type parameters
Don't ICE when uncallable functions occur due to unsatisfiable where clauses
Mar 10, 2016
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium |
nikomatsakis
referenced this issue
Mar 10, 2016
Closed
Allow where clauses involving types which don't include a type parameter. #27972
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium |
1 similar comment
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium |
rust-highfive
added
P-medium
and removed
I-nominated
labels
Mar 17, 2016
brson
added
the
C-enhancement
label
Oct 20, 2016
This comment has been minimized.
This comment has been minimized.
|
P-low? |
This comment has been minimized.
This comment has been minimized.
|
Triage: @nikomatsakis 's sample compiles, but if you try to use it, can never work. Aka, this is still an issue, as far as I can tell. |
erickt commentedJan 15, 2015
UPDATED DESCRIPTION:
We now allow the original problem, but some corner cases are still unhandled. See comments below.
ORIGINAL DESCRIPTION:
Where clauses right now require predicates to contain type parameters, as in:
But we cannot add constraints on non-generic types:
Will error out with:
In hand written code this usually won't come up, but this would be really helpful for a code generator like
macro_rules!or#[derive], especially when dealing with associated types. Currently the only way to know if a type is generic or not is to manually walk it and see if any of the type paths start with the same name as a type parameter. If so, add that type to the predicate list. Instead, it would be much simpler if we could just add all the types listed in a field or enum to the predicate list and let the type checker report an error if one of those types doesn't implement the trait.cc @nikomatsakis, @jroesch