Repository navigation
Borrow checker's strange error. #57404
Copy link
Copy link
Closed
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-codegenArea: Code generationArea: Code generationA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-unboxed_closures`#![feature(unboxed_closures)]``#![feature(unboxed_closures)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.ICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Description
#![feature(unboxed_closures)]
#![feature(const_vec_new)]
#![feature(fn_traits)]
pub struct PackBytes;
static mut HANDLERS: Vec<Box<dyn FnMut<&mut PackBytes, Output=()>>> = Vec::new();
fn main() {
let mut pack = PackBytes;
unsafe { HANDLERS[0].as_mut().call_mut(&mut pack); }
}
error[E0597]: `pack` does not live long enough
--> src/main.rs:15:35
|
15 | HANDLERS[0].as_mut().call_mut(&mut pack); }
| ------------------------------^^^^^^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `pack` is borrowed for `'static`
16 | }
| - `pack` dropped here while still borrowed
#![feature(unboxed_closures)]
#![feature(const_vec_new)]
#![feature(fn_traits)]
pub struct PackBytes;
static mut HANDLERS: Vec<Box<dyn for<'a> FnMut<&'a mut PackBytes, Output=()>>> = Vec::new();
fn main() {
let mut pack = PackBytes;
unsafe { HANDLERS[0].as_mut().call_mut(&mut pack); }
}
error: internal compiler error: src/librustc_codegen_llvm/abi.rs:433: argument to function with "rust-call" ABI is not a tuple
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:590:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.33.0-nightly (b92552d55 2019-01-06) running on x86_64-unknown-linux-gnu
note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin
note: some of the compiler flags provided by cargo are hidden
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-codegenArea: Code generationArea: Code generationA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-unboxed_closures`#![feature(unboxed_closures)]``#![feature(unboxed_closures)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.ICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Activity
[-]Borrow checker strange error.[/-][+]Borrow checker's strange error.[/+]hellow554 commentedon Jan 7, 2019
Reduced example
cheblin commentedon Jan 7, 2019
this, stripped works
cheblin commentedon Jan 7, 2019
scalexm commentedon Jan 7, 2019
The first compilation error -- the example with
static mut HANDLERS: Vec<Box<dyn FnMut<&mut PackBytes, Output=()>>> = Vec::new();looks fine to me. Types used for static variables must outlive the'staticlifetime. The compiler can prove thatdyn FnMut<&'b mut PackBytes> + 'aoutlives'staticonly if'a == 'b == 'static. Hence'staticlifetimes are inferred in lieu of the anonymous lifetimes. Since yourpackvariable does not live for the whole'staticlifetime, it cannot be used as you are trying to.Maybe the actual bug is that
dyn FnMut<&T, Output=()>should desugar todyn for<'a> FnMut<&'a T, Output=()>, as it would be fordyn FnMut(&T)? It may be weird to special-case only theFn/FnMut/FnOncetraits though -- i.e. if you define your own traittrait Foo<T> { }, thenFoo<&i32>just meansFoo<&'b i32>for some lifetime'bto be inferred by the compiler, it does not meanfor<'a> Foo<&'a i32>.Your reduced example is actually different since it actually does not involve static data. It seems to be the same bug as in #22565, and hence is a bug with the
unboxed_closurefeature.Going from
FnMut<&'a mut (), Output=()>toFnMut<(&'a mut (),), Output=()>(note the tuple of size1) makes the ICE go away.Alexendoo commentedon Nov 9, 2022
Fixed by #99943
Add regression test for rust-lang#57404
Rollup merge of rust-lang#105945 - JohnTitor:issue-57404, r=compiler-…
Auto merge of rust-lang#105951 - matthiaskrgr:rollup-aqxz888, r=matth…