Allow explicit lifetime arguments (behind new #![feature(late_bound_turbofishing)]) and prevent explicit lifetime arguments where they do not appear in a function signature - #160471
Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @oli-obk (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
||
| fn bar<'a>(_: &'a u32) { | ||
| let f = foo_late::<'a>; | ||
| require_static(f); |
There was a problem hiding this comment.
this needs to fail, but currently it's not... don't know how to fix
There was a problem hiding this comment.
isn't this just the usual FnDef outlives issue that already exists without your PR?
There was a problem hiding this comment.
Oops- I think so? But I;m not sure. the following (which is early-bound afaik) compiles when it shouldn't(?) in the rust playground
fn require_static<T: 'static>(_: T) {}
fn foo<'a: 'a>(b: &'a u32) -> &'a u32 { b }
fn bar<'a>(_: &'a u32) {
let f = foo::<'a>;
require_static(f);
}
fn main() {
let x = 4;
{
bar(&x);
}
}
This comment has been minimized.
This comment has been minimized.
|
that CI run didn't give a good backtrace so to save future me from agony, the problem is here |
This comment has been minimized.
This comment has been minimized.
|
this is gonna be rough: |
|
Ok, here's my take:
|
| pub parent: Option<DefId>, | ||
| pub parent_count: usize, | ||
| pub own_params: Vec<GenericParamDef>, | ||
| pub own_all_params: Vec<GenericParamDef>, |
There was a problem hiding this comment.
document this. Also it's just all lifetime params
| if !spans.is_empty() { | ||
| spans | ||
| } else { | ||
| visitor.visit_fn_decl(decl).break_value().map_or_default(|val| vec![val]) |
There was a problem hiding this comment.
wouldn't we generally want to append these to spans?
There was a problem hiding this comment.
I thought so, but it turns out that doing it unconditionally causes cycles in a bunch of places...
error[E0391]: cycle detected when computing generics of `IntFactory::stream`
--> /home/addie/rust/tests/ui/parallel-rustc/fn-sig-cycle-ice-154560.rs:9:5
|
LL | fn stream(&self) -> impl IntFactory<stream(..): Send>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: ...which requires looking up a named region inside `IntFactory::stream`...
= note: ...which requires resolving lifetimes for `IntFactory::stream`...
= note: ...which again requires computing generics of `IntFactory::stream`, completing the cycle
note: cycle used when computing generics of `IntFactory::stream::{opaque#0}`
There was a problem hiding this comment.
Ok... apparently it also just... Breaks the late-bound var checking too. why does this tiny, almost one-liner change make Literally Everything Explode??
| // | ||
| // While most hidden lifetimes are late-bound (e.g. `fn(_: &u32)` ), | ||
| // there are some cases (complicated and involve associated types) | ||
| // where an early-bound lifetime parameter can be hidden from the function signature. |
There was a problem hiding this comment.
name a test in this comment that shows this
r? oli-obk
note: commit
dd17e77is part of another PR (#159403) and needs to be merged before this does (I'll rebase the commit out when it gets merged, which should be soon)This PR is a little bit big (and probably super messy). here's what it changes/adds:
late_bound_turbofishingfor the new behavioraddie's checklist:
so what:
...and if the feature gate is missing, a diagnostic will be reported.
...although its diagnostic probably could stand to be improved.
ty :3