Created
February 13, 2018 19:24
-
-
Save golddranks/b58522e51d88f0291477d7b7770ec604 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A problem with type inference. A closure object is bound to cb | |
let cb = Box::new(move |state| { | |
let callgraph = cell.replace(None).unwrap(); | |
visit::after_analysis(state, callgraph) | |
}); | |
// And right after, cb is set to callback. | |
control.after_analysis.callback = cb; | |
////////////////////////////////////////////////////////////////// | |
// This works: | |
control.after_analysis.callback = Box::new(move |state| { | |
let callgraph = cell.replace(None).unwrap(); | |
visit::after_analysis(state, callgraph) | |
}); | |
////////////////////////////////////////////////////////////////// | |
// This works too. | |
let cb: Box<Fn(&mut CompileState) + 'a> = Box::new(move |state| { | |
let callgraph = cell.replace(None).unwrap(); | |
visit::after_analysis(state, callgraph) | |
}); | |
control.after_analysis.callback = cb; | |
////////////////////////////////////////////////////////////////// | |
// The error message: | |
error[E0631]: type mismatch in closure arguments | |
--> src/main.rs:108:43 | |
| | |
104 | let cb = Box::new(move |state| { | |
| ------------ found signature of `fn(&mut rustc_driver::driver::CompileState<'_, '_>) -> _` | |
... | |
108 | control.after_analysis.callback = cb; | |
| ^^ expected signature of `for<'r, 's, 't0> fn(&'r mut rustc_driver::driver::CompileState<'s, 't0>) -> _` | |
| | |
= note: required for the cast to the object type `for<'r, 's, 't0> std::ops::Fn(&'r mut rustc_driver::driver::CompileState<'s, 't0>)` | |
error[E0271]: type mismatch resolving `for<'r, 's, 't0> <[closure@src/main.rs:104:27: 107:10 cell:_] as std::ops::FnOnce<(&'r mut rustc_driver::driver::CompileState<'s, 't0>,)>>::Output == ()` | |
--> src/main.rs:108:43 | |
| | |
108 | control.after_analysis.callback = cb; | |
| ^^ expected bound lifetime parameter, found concrete lifetime | |
| | |
= note: required for the cast to the object type `for<'r, 's, 't0> std::ops::Fn(&'r mut rustc_driver::driver::CompileState<'s, 't0>)` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment