Repository navigation
borrowck: Fix Reborrow ICE on types with several lifetimes - #166171
rust-bors[bot] merged 1 commit into
Conversation
|
This PR changes a file inside |
|
r? @mejrs rustbot has assigned @mejrs. Use Why was this reviewer chosen?The reviewer was selected based on:
|
cd2ccaa to
a40d99f
Compare
|
r? aapoalas |
|
|
There was a problem hiding this comment.
LGTM - yeah, when there is no field that would explain what to reborrow using a deeper Reborrow then this is definitely the right choice: we shouldn't start looking into a PhantomData's generic because that way lays misery and pain (at least for now).
One thing you could do is remove the bug! from a zero-lifetime case: from the borrowck point of view that doesn't really matter, and in the future we might even explicitly allow that for Copy types. Having no lifetimes just makes a Reborrow equal Copy after all.
|
@bors delegate+ Please squash, consider removing the |
|
✌️ @Dnreikronos, you can now approve this pull request! If @aapoalas told you to " |
When no field of a `Reborrow` type is reborrowed, borrowck borrows the whole source value instead. That fallback assumed the target type has exactly one lifetime and hit a `bug!` otherwise, even though `Reborrow` impls on types with several lifetimes are accepted. Borrow the source under each of the target's lifetimes instead. The one lifetime case is unchanged, and the source stays borrowed for as long as any of the target's lifetimes is live.
a40d99f to
9f1b6ca
Compare
|
@bors r+ |
hey o/ I think the zero-lifetime case deserves its own fix. That keeps this PR focused on the crash with multiple lifetimes. |
…e_no_reborrowed_field, r=Dnreikronos borrowck: Fix Reborrow ICE on types with several lifetimes Fixes rust-lang#165653 The ICE comes from borrowck. When a Reborrow type has no field that actually gets reborrowed (no `&mut` and no other Reborrow type inside), borrowck borrows the whole value instead, and that code just assumed the type has one lifetime. Reborrow types can have more than one lifetime now, so something like the struct with `&'a &'b str` from the issue blew up right there. The fix is in that fallback. When nothing gets reborrowed, borrowck now borrows the whole value once for each lifetime of the target type instead of panicking. With one lifetime it does exactly what it did before. With more it keeps the value borrowed while any of them is still alive, so two live reborrows of a two lifetime marker still get the usual "borrowed as mutable more than once" error, and using them one after the other is fine, same as with one lifetime. The program from the issue now gets the same error its one lifetime version already gets, since it's reborrowing through a shared ref. I ran a bunch of programs against a recent nightly. Nothing that compiles there stops compiling, the crashes are gone (generic fields, associated type fields, fields that are only Copy in some functions, CoerceShared targets with more lifetimes than the source all hit the same spot), and the ones that error now get the same error as their one lifetime version. Two things I didn't touch are the `&'static mut` field ICE (rust-lang#164933) and a CoerceShared panic when the source and target PhantomData fields don't match, that one also happens with one lifetime so it's a different bug. Honestly I think borrowing under every lifetime is the safe choice but maybe not the smartest one, a smarter version could work out which lifetime really matters for each field. If someone who knows the Reborrow design better has an opinion on that I'm happy to change it.
…e_no_reborrowed_field, r=Dnreikronos borrowck: Fix Reborrow ICE on types with several lifetimes Fixes rust-lang#165653 The ICE comes from borrowck. When a Reborrow type has no field that actually gets reborrowed (no `&mut` and no other Reborrow type inside), borrowck borrows the whole value instead, and that code just assumed the type has one lifetime. Reborrow types can have more than one lifetime now, so something like the struct with `&'a &'b str` from the issue blew up right there. The fix is in that fallback. When nothing gets reborrowed, borrowck now borrows the whole value once for each lifetime of the target type instead of panicking. With one lifetime it does exactly what it did before. With more it keeps the value borrowed while any of them is still alive, so two live reborrows of a two lifetime marker still get the usual "borrowed as mutable more than once" error, and using them one after the other is fine, same as with one lifetime. The program from the issue now gets the same error its one lifetime version already gets, since it's reborrowing through a shared ref. I ran a bunch of programs against a recent nightly. Nothing that compiles there stops compiling, the crashes are gone (generic fields, associated type fields, fields that are only Copy in some functions, CoerceShared targets with more lifetimes than the source all hit the same spot), and the ones that error now get the same error as their one lifetime version. Two things I didn't touch are the `&'static mut` field ICE (rust-lang#164933) and a CoerceShared panic when the source and target PhantomData fields don't match, that one also happens with one lifetime so it's a different bug. Honestly I think borrowing under every lifetime is the safe choice but maybe not the smartest one, a smarter version could work out which lifetime really matters for each field. If someone who knows the Reborrow design better has an opinion on that I'm happy to change it.
This comment has been minimized.
This comment has been minimized.
…owed_field, r=Dnreikronos borrowck: Fix Reborrow ICE on types with several lifetimes Fixes #165653 The ICE comes from borrowck. When a Reborrow type has no field that actually gets reborrowed (no `&mut` and no other Reborrow type inside), borrowck borrows the whole value instead, and that code just assumed the type has one lifetime. Reborrow types can have more than one lifetime now, so something like the struct with `&'a &'b str` from the issue blew up right there. The fix is in that fallback. When nothing gets reborrowed, borrowck now borrows the whole value once for each lifetime of the target type instead of panicking. With one lifetime it does exactly what it did before. With more it keeps the value borrowed while any of them is still alive, so two live reborrows of a two lifetime marker still get the usual "borrowed as mutable more than once" error, and using them one after the other is fine, same as with one lifetime. The program from the issue now gets the same error its one lifetime version already gets, since it's reborrowing through a shared ref. I ran a bunch of programs against a recent nightly. Nothing that compiles there stops compiling, the crashes are gone (generic fields, associated type fields, fields that are only Copy in some functions, CoerceShared targets with more lifetimes than the source all hit the same spot), and the ones that error now get the same error as their one lifetime version. Two things I didn't touch are the `&'static mut` field ICE (#164933) and a CoerceShared panic when the source and target PhantomData fields don't match, that one also happens with one lifetime so it's a different bug. Honestly I think borrowing under every lifetime is the safe choice but maybe not the smartest one, a smarter version could work out which lifetime really matters for each field. If someone who knows the Reborrow design better has an opinion on that I'm happy to change it.
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
💔 Test for 52d604d failed: CI. Failed job:
|
|
@bors retry |
…e_no_reborrowed_field, r=Dnreikronos borrowck: Fix Reborrow ICE on types with several lifetimes Fixes rust-lang#165653 The ICE comes from borrowck. When a Reborrow type has no field that actually gets reborrowed (no `&mut` and no other Reborrow type inside), borrowck borrows the whole value instead, and that code just assumed the type has one lifetime. Reborrow types can have more than one lifetime now, so something like the struct with `&'a &'b str` from the issue blew up right there. The fix is in that fallback. When nothing gets reborrowed, borrowck now borrows the whole value once for each lifetime of the target type instead of panicking. With one lifetime it does exactly what it did before. With more it keeps the value borrowed while any of them is still alive, so two live reborrows of a two lifetime marker still get the usual "borrowed as mutable more than once" error, and using them one after the other is fine, same as with one lifetime. The program from the issue now gets the same error its one lifetime version already gets, since it's reborrowing through a shared ref. I ran a bunch of programs against a recent nightly. Nothing that compiles there stops compiling, the crashes are gone (generic fields, associated type fields, fields that are only Copy in some functions, CoerceShared targets with more lifetimes than the source all hit the same spot), and the ones that error now get the same error as their one lifetime version. Two things I didn't touch are the `&'static mut` field ICE (rust-lang#164933) and a CoerceShared panic when the source and target PhantomData fields don't match, that one also happens with one lifetime so it's a different bug. Honestly I think borrowing under every lifetime is the safe choice but maybe not the smartest one, a smarter version could work out which lifetime really matters for each field. If someone who knows the Reborrow design better has an opinion on that I'm happy to change it.
…uwer Rollup of 7 pull requests Successful merges: - #164252 (Share retain implementation between Vec and VecDeque) - #166171 (borrowck: Fix Reborrow ICE on types with several lifetimes) - #166506 (traits: Fix dead match arm for String type suggestions.) - #164542 (Add regression test for #151312) - #165651 (compiletest: Further clean up directive parsing) - #166196 (autodiff: don't ICE on invalid macro arguments) - #166556 (remove `Box::into_boxed_slice`)
…uwer Rollup of 10 pull requests Successful merges: - #164252 (Share retain implementation between Vec and VecDeque) - #166008 (fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature) - #166156 (tests: cover proc-macro metadata path remapping) - #166171 (borrowck: Fix Reborrow ICE on types with several lifetimes) - #166506 (traits: Fix dead match arm for String type suggestions.) - #164542 (Add regression test for #151312) - #165651 (compiletest: Further clean up directive parsing) - #166196 (autodiff: don't ICE on invalid macro arguments) - #166556 (remove `Box::into_boxed_slice`) - #166562 (docs: add backticks around `!` in primitive docs )
…uwer Rollup of 10 pull requests Successful merges: - #164252 (Share retain implementation between Vec and VecDeque) - #166008 (fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature) - #166156 (tests: cover proc-macro metadata path remapping) - #166171 (borrowck: Fix Reborrow ICE on types with several lifetimes) - #166506 (traits: Fix dead match arm for String type suggestions.) - #164542 (Add regression test for #151312) - #165651 (compiletest: Further clean up directive parsing) - #166196 (autodiff: don't ICE on invalid macro arguments) - #166556 (remove `Box::into_boxed_slice`) - #166562 (docs: add backticks around `!` in primitive docs )
Rollup merge of #166171 - Dnreikronos:reborrow/multi_lifetime_no_reborrowed_field, r=Dnreikronos borrowck: Fix Reborrow ICE on types with several lifetimes Fixes #165653 The ICE comes from borrowck. When a Reborrow type has no field that actually gets reborrowed (no `&mut` and no other Reborrow type inside), borrowck borrows the whole value instead, and that code just assumed the type has one lifetime. Reborrow types can have more than one lifetime now, so something like the struct with `&'a &'b str` from the issue blew up right there. The fix is in that fallback. When nothing gets reborrowed, borrowck now borrows the whole value once for each lifetime of the target type instead of panicking. With one lifetime it does exactly what it did before. With more it keeps the value borrowed while any of them is still alive, so two live reborrows of a two lifetime marker still get the usual "borrowed as mutable more than once" error, and using them one after the other is fine, same as with one lifetime. The program from the issue now gets the same error its one lifetime version already gets, since it's reborrowing through a shared ref. I ran a bunch of programs against a recent nightly. Nothing that compiles there stops compiling, the crashes are gone (generic fields, associated type fields, fields that are only Copy in some functions, CoerceShared targets with more lifetimes than the source all hit the same spot), and the ones that error now get the same error as their one lifetime version. Two things I didn't touch are the `&'static mut` field ICE (#164933) and a CoerceShared panic when the source and target PhantomData fields don't match, that one also happens with one lifetime so it's a different bug. Honestly I think borrowing under every lifetime is the safe choice but maybe not the smartest one, a smarter version could work out which lifetime really matters for each field. If someone who knows the Reborrow design better has an opinion on that I'm happy to change it.
…uwer Rollup of 10 pull requests Successful merges: - rust-lang/rust#164252 (Share retain implementation between Vec and VecDeque) - rust-lang/rust#166008 (fix inconsistent precedence of -Ctarget-feature wrt -Zllvm-target-feature) - rust-lang/rust#166156 (tests: cover proc-macro metadata path remapping) - rust-lang/rust#166171 (borrowck: Fix Reborrow ICE on types with several lifetimes) - rust-lang/rust#166506 (traits: Fix dead match arm for String type suggestions.) - rust-lang/rust#164542 (Add regression test for rust-lang/rust#151312) - rust-lang/rust#165651 (compiletest: Further clean up directive parsing) - rust-lang/rust#166196 (autodiff: don't ICE on invalid macro arguments) - rust-lang/rust#166556 (remove `Box::into_boxed_slice`) - rust-lang/rust#166562 (docs: add backticks around `!` in primitive docs )
Fixes #165653
The ICE comes from borrowck. When a Reborrow type has no field that actually gets reborrowed (no
&mutand no other Reborrow type inside), borrowck borrows the whole value instead, and that code just assumed the type has one lifetime. Reborrow types can have more than one lifetime now, so something like the struct with&'a &'b strfrom the issue blew up right there.The fix is in that fallback. When nothing gets reborrowed, borrowck now borrows the whole value once for each lifetime of the target type instead of panicking. With one lifetime it does exactly what it did before. With more it keeps the value borrowed while any of them is still alive, so two live reborrows of a two lifetime marker still get the usual "borrowed as mutable more than once" error, and using them one after the other is fine, same as with one lifetime. The program from the issue now gets the same error its one lifetime version already gets, since it's reborrowing through a shared ref.
I ran a bunch of programs against a recent nightly. Nothing that compiles there stops compiling, the crashes are gone (generic fields, associated type fields, fields that are only Copy in some functions, CoerceShared targets with more lifetimes than the source all hit the same spot), and the ones that error now get the same error as their one lifetime version. Two things I didn't touch are the
&'static mutfield ICE (#164933) and a CoerceShared panic when the source and target PhantomData fields don't match, that one also happens with one lifetime so it's a different bug.Honestly I think borrowing under every lifetime is the safe choice but maybe not the smartest one, a smarter version could work out which lifetime really matters for each field. If someone who knows the Reborrow design better has an opinion on that I'm happy to change it.