-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Redundant error for "implementation ... not general enough" in "NLL" mode / since 1.63 (when it was made permanent). #100742
Comments
cc @compiler-errors as you were just looking at something similar, @rust-lang/wg-diagnostics We should also special case the situation of hrlts for single element closures, to suggest I don't agree that the E308 error is necessarily worse, some experienced devs can recognize what's going on thanks to the expected/found output, but we should likely be emitting a new more targeted error for these, with a more verbose explanation about hrlts. Maybe something along the lines of
|
Unsurprisingly, (though what is surprising is that I'm on the 2021 edition, should I have used
Sorry, that sounds like I didn't make my point clearly. The problem is that only borrowck can tell you about lifetimes, in a useful way. The I can totally read it the "mismatched types", but it's the old error and I just did some digging and the improvement appears to date back to 1.52.0: https://godbolt.org/z/z5qeecKb1. What you're suggesting sounds very close to the (good IMO) "error: implementation of AFAICT the "mismatched types" error is an anomaly that we should figure out how to get rid of, and if there any improvements to be made they should be made to the modern "not general enough" error. |
Fair, makes sense to do that. We also need to check for all the places where E0308 is currently being emitted as the only output for these (I believe that anecdotally there are a few). We should also give the "not general enough" error not only a wording makeover, but also its very own Error Code where we can talk about hrlts, that fun topic that keeps on giving. |
Did a 1.51.0 to 1.52.0 bisection and found a likely candidate in 152f660...0148b97: So I believe that @matthewjasper intentionally improved the error here to not look like the extra error we're getting again in 1.63.0, but to what's been consistent between 1.52.0 and 1.62.0 (inclusive). That PR mentions this issue: And we can see in e.g. #57374 (comment) that forcing NLL caused this issue even before 1.63.0 - but I don't really understand how this interacts with editions: did only |
...
is not general enough" started getting a redundant diagnostic in 1.63.
This is a classic demonstration of the limitations of ("early-bound") generics wrt HRTB:
(I don't know what issue we have open about it - #30904 is too specific, there must be one about generic functions - and also if we ever fix this it will likely require
for<'x> typeof(type_generic::<LtGen<'x>>)
function types, which I've brought up to @nikomatsakis before but I haven't seen any other discussion of)Either way, for now, the above should error (if you're curious, the simplest fix is to use a closure, that itself can be
for<'x>
, and which calls the function, like|x| type_generic(x)
).And for a long time (since MIR borrowck?) we've had this error:
It's not perfect, but it shows the difference between some inferred lifetime (
'2
) and the HRTB ('1
).However, since 1.63.0 (see comparison on godbolt: https://godbolt.org/z/EzjPzE7xs), we also get:
This is a weirder error, that I naively assumed would be the old regionck (but that got removed, right? so it can't be that), though I suppose it could be some generic obligation solving from inside MIR borrowck.
'_
is used for lifetime inference variablesfor<'r>
auto-naming in the printout (not here because I wrotefor<'x>
)delay_span_bug
if they're not emitted from exactly the same place)EDIT: more information found since opening the issue (in #100742 (comment)):
EDIT2: better timeline in #100742 (comment) - the error was improved back in #81972 but the "bonus error" comes from "NLL mode" - e.g. #57374 (comment).
cc @estebank @rust-lang/wg-nll @lcnr (this may be subtle in nature, hopefully someone knows what happened)
cc @Manishearth (who has a similar error though unlikely related to this 1.62.0->1.63.0 change, since it's on 1.61.0 instead, and does not even have the good error showing up at all - that one still needs to be reduced)
The text was updated successfully, but these errors were encountered: