Created
October 9, 2015 21:39
-
-
Save msullivan/f70c3a1c4ee406991257 to your computer and use it in GitHub Desktop.
What seems to be a borrowchecker regression
This file contains hidden or 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
| // This compiles without error on stable and beta but gives a borrow | |
| // error on nightly. It worked as of nightly 6e5a32547. | |
| // Replacing the .by_ref() with explicitly taking a &mut ref fixes it. | |
| // Other more dubious things fix it also. | |
| pub type Session = i32; | |
| pub struct StreamParser<'a, T: Iterator<Item=i32>> { | |
| _tokens: T, | |
| _session: &'a mut Session, | |
| } | |
| impl<'a, T: Iterator<Item=i32>> StreamParser<'a, T> { | |
| pub fn thing(&mut self) -> bool { true } | |
| } | |
| pub fn parse_stream<T: Iterator<Item=i32>, U, F>( | |
| session: &mut Session, | |
| tokens: T, | |
| f: F) -> U | |
| where F: Fn(&mut StreamParser<T>) -> U { | |
| let mut tokp = StreamParser { _tokens: tokens, _session: session }; | |
| f(&mut tokp) | |
| } | |
| pub fn thing(session: &mut Session) { | |
| let toks = vec!(1, 2, 3); | |
| let mut stream = toks.into_iter(); | |
| let _b = parse_stream(session, | |
| stream.by_ref(), | |
| // If the by_ref is replaced with &mut stream | |
| // it works on nightly | |
| //&mut stream, | |
| |p| p.thing()); | |
| } | |
| fn main() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment