-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Don't ICE when uncallable functions occur due to unsatisfiable where clauses #21203
Comments
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. |
@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. |
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. |
Should this be closed as wontfix/intended, then? |
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. |
@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). |
Triage: this now works. Full reproduction:
|
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? |
What? I didn't implement this? |
I think this is the relevant commit: dbf994b |
Yeah I was wondering if this was somehow fallout from that change. That's a bit unexpected though. |
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. |
triage: P-medium |
triage: P-medium |
1 similar comment
triage: P-medium |
P-low? |
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. |
#75961 is a duplicate of @nikomatsakis 's example. That issue contains more recent diagnostics: the example no longer compiles. |
The original issue now compiles with the trivial bounds feature, see #48214. |
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
The text was updated successfully, but these errors were encountered: