-
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
Compile regression "cannot infer an appropriate lifetime for lifetime parameter" #70917
Comments
Reproducer: fn main() {}
pub trait Strategy {
type Value;
}
fn prop_map<O, F: Fn(S::Value) -> O, S: Strategy>(_: S, _: F) -> Map<S, F> {
loop {}
}
fn boxed<S: 'static + Strategy>(_: S) -> *const dyn Strategy<Value = S::Value> {
loop {}
}
pub struct Map<S, F> {
x: std::marker::PhantomData<(S, F)>,
}
impl<S: Strategy, O, F: Fn(S::Value) -> O> Strategy for Map<S, F> {
type Value = O;
}
fn cloned<'a, T: 'a, I: Iterator<Item = &'a T>>(x: I) -> I {
x
}
fn lift1_with<'a, T, A, S>(base: S) -> *const dyn Strategy<Value = A>
where
T: 'static,
A: 'static + Iterator<Item = &'a T>,
S: Strategy<Value = A> + 'static,
{
boxed(prop_map(base, cloned))
} |
Reduced (playground/stable -> playground/nightly): fn assert_static<T: 'static>(_: T) {}
fn capture_type<T>() {}
fn capture_lifetime<'a: 'a>() {}
// Errors on stable & nightly.
fn test_type<'a>() {
assert_static(capture_type::<&'a ()>);
}
// Errors *only* on nightly.
fn test_lifetime<'a>() {
assert_static(capture_lifetime::<'a>);
} @nikomatsakis Are we supposed to ignore only lifetime parameters in cc @rust-lang/lang @matthewjasper |
I should say, I didn't expect to fix a lifetime vs type inconsistency, the goal was to fix type vs const inconsistencies. Somehow we have a behavior with no tests, I'm not sure how intentional it was. |
(I'm perfectly happy to issue a point release, 0.9.6, to proptest btw if we decide the new compiler behavior is correct and proptest is in the wrong.) |
Assigning |
Let me leave a brief comment explaining what is going on, because it took me a bit to figure out what @eddyb was talking about. The type in question is one of the "anonymous types" that we construct for functions. You can think of these types as being roughly We are processing a constraint like I'm not sure why the old code seemingly ignored this requirement. It seems like a bug to me though, a kind of artifact of the structure of the code that @eddyb fixed "in passing" by making the code operate more uniformly. |
Notes from the language team meeting yesterday:
|
@craterbot run start=master#bf1f2eedda4fa02b7c9347dd849ed73ddd43dedc end=master#209b2be09fcaff937480d1fbbe8b31646e361c7a mode=check-only |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
Touched on briefly at the ad hoc triage meeting today. But since we are awaiting crater results, there is nothing for us to discuss at the moment. Leaving nominated for discussion at next week's triage meeting (or hopefully sooner, async), since by then the crater results should be available. |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
I've gone ahead and released proptest 0.9.6 which has a fix for the problem here. |
🎉 Experiment
|
All these depend on
|
But oof, that's a lot of regressions. Looking at |
We should probably allow this, since it's sound (AFAIK). If nothing else, we should be more intentional about a breaking change. |
I'm thinking similarly. To recap what I said in the meeting, we could allow this -- it might even be something we want to consider generalizing to other types. It would I think be sound but would require caution if/when we introduce impl<'a> Iterator for typeof(foo::<'a>) {
type Item = &'a u32
} would be bad, because we would think that However, I would like to modify RFC 1214 anyway so that we have it so that lifetime variables which appear in some positions of types are considered "unconstrained" and then cannot appear in associated types. I particularly wanted to do this for things like |
Removed nomination as per pre-triage discussions. This was already discussed on last compiler meeting and we'll probably again tomorrow because it's an unassigned regression. |
Found where I introduced the breaking change: these were using
And Doesn't even look like the behavior was intentional, but at least now I know where to restore it (however it is annoying that this code is duplicated...). EDIT: opened #71218 with the fix. |
@eddyb yeah, I expected to see some code like that -- I agree the behavior was not intentional. |
On linux, the following works:
(rustc version is rustc 1.44.0-nightly (b543afc 2020-04-05))
The following does not work:
Build fails with:
(rustc version is: rustc 1.44.0-nightly (42abbd8 2020-04-07))
The text was updated successfully, but these errors were encountered: