-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Lifetime error when indexing with borrowed index in beta but not in stable #74933
Comments
Let’s find the culprit for this. @rustbot ping cleanup |
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good cc @AminArria @camelid @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke |
Assigning |
|
The explicit lifetimes are pub fn insert<'a, 'b>(this: &'a mut FieldMap, field: &'b Field<'a>, value: ()) -> () {
this[field] = value;
} edit: the lt of |
assigning to @nikomatsakis but they will probably need to delegate as there time is limited in near future. |
Will look into this today. @rustbot claim |
This code compiles in Rust 1.17 but not in Rust 1.18+: use std::ops::{Index, IndexMut};
pub struct T;
impl T {
fn test(&mut self) {
}
}
pub struct FieldMap;
pub fn insert<'a, 'b>(this: &'a mut FieldMap, field: &'b Field<'a>) -> () {
this[field].test();
}
pub struct Field<'a> {
x: &'a T,
}
impl<'a> Index<&'a Field<'a>> for FieldMap {
type Output = T;
fn index(&self, _: &'a Field<'a>) -> &T {
unimplemented!()
}
}
impl<'a> IndexMut<&'a Field<'a>> for FieldMap {
fn index_mut(&mut self, _: &'a Field<'a>) -> &mut T {
unimplemented!()
}
} #72280 unifies DerefMut/IndexMut to use the "fix-up" path originally used when performing method calls, so it broadens the bug to assignments as well. |
Okay, this is an issue near convert_place_op_to_mutable. Just re-infer the index type and re-do the coercion is sufficient to fix the regionck failure (nbdd0121@375a6d0). However I am not sure why the existing code does not work. This piece of code is last touched in #72068. cc @estebank @oli-obk do you have any clue why the existing approach does not work well with regionck? |
Hmm.. I would not have expected that code to have to change, since the failure seems to try to make the anonymous lifetime on |
I added a couple of examples of workarounds that allowed the function to compile, with the same signature. |
I tried to compile this code:
I expected the code to compile
Instead, it failed to compile with this lifetime error:
Workarounds
If I change the function in these ways it compiles.
https://play.rust-lang.org/?version=beta&mode=debug&edition=2018&gist=ca6b8a2243d7116cb8180bb4300f6edc
https://play.rust-lang.org/?version=beta&mode=debug&edition=2018&gist=21326b3dcd6c017d0e644ef7eab89769
Meta
This compiles successfully on Stable Rust 1.45.0 back to 1.26.0 (when
'_
lifetimes were stabilized)This fails to compile on these versions(haven't tried previous ones in the same channels):
This issue has been assigned to @nbdd0121 via this comment.
The text was updated successfully, but these errors were encountered: