-
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
Trait constraints should allow anonymous lifetimes for references. #13840
Comments
/cc @rust-lang/lang , is this a bug? I would expect a lifetime specifier to be needed here. Updated code. Works:
doesn't
|
I had expected leaving out the lifetime to be the same as supplying an anonymous one, possibly in error. |
The only time you can leave out lifetimes is following the elision rules: https://doc.rust-lang.org/book/lifetimes.html#lifetime-elision and this signature isn't compatible with any of them. |
@steveklabnik In a way, this is a feature request. |
Well, adding more rules for elision would take an RFC these days. We don't keep feature requests in this repository. I've moved it over: rust-lang/rfcs#1352 |
Makes sense. Thanks! |
No problem, thanks for bringing it up! Sorry I was confused about the bug/feature split. |
I think the confusion was mine, thanks for sorting it out! |
(I personally would like this to work eventually, but we currently do not support it, so I think this is "not a bug".) |
…undvars, r=lowr fix: handle lifetime variables in `CallableSig` query Fixes rust-lang#13838 The problem is similar to rust-lang#13223: we've been skipping non-empty binders, letting lifetime bound variables escape. I ended up refactoring `hir_ty::callable_sig_from_fnonce()`. Like rust-lang#13223, I chose to make use of `InferenceTable` which is capable of handling variables (I feel we should always use it when we solve trait-related stuff instead of manually building obligations/queries). I couldn't make up a test that crashes without this patch (since the function I'm fixing is only used *outside* `hir-ty`, simple `hir-ty` test wouldn't cause crash), but at least I tested with my local build and made sure it doesn't crash with the code in the original issue. I'd appreciate any help to find a regression test.
This compiles:
This should be the same, but doesn't compile:
The compiler complains of a "missing lifetime specifier" at the &int.
The text was updated successfully, but these errors were encountered: