-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
NLL: if let
not detecting proper lifetime
#51826
Labels
A-NLL
Area: Non-lexical lifetimes (NLL)
NLL-polonius
Issues related for using Polonius in the borrow checker
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
Another similar example (playground): #![feature(nll)]
struct Packet<'a> {
b: &'a [u8],
}
impl<'a> Packet<'a> {
fn new(b: &'a [u8]) -> Option<Self> {
Some(Packet { b: b })
}
}
struct PacketReader {
bytes: Vec<u8>,
}
impl PacketReader {
fn poll<'a>(&'a mut self) -> Packet<'a> {
loop {
if let Some(p) = Packet::new(&self.bytes[..]) {
return p;
}
// we need to read some more
self.bytes.truncate(0);
}
}
} This produces:
|
Actually, maybe the above example is really #51526? |
matthewjasper
added
NLL-polonius
Issues related for using Polonius in the borrow checker
and removed
NLL-deferred
labels
Dec 1, 2018
I think I have a similar issue, but inside the if branch, not in the else or after. #[derive(Debug)]
struct NotCopy(u8);
struct Foo(Vec<NotCopy>);
impl Foo {
fn iter(&self) -> impl Iterator<Item = (NotCopy, &NotCopy)> {
self.0.iter().map(|x| (NotCopy(x.0), x))
}
fn iter2(&self) -> impl Iterator<Item = NotCopy> + '_ {
self.iter().map(|(x, _)| x)
}
fn work(&mut self) {
// let x = self.iter2().find(|_| true); if let Some(x) = x {
if let Some(x) = self.iter2().find(|_| true) {
self.0.push(x);
}
}
}
fn main() {
let mut v = Foo(vec![NotCopy(0)]);
v.work();
println!("{:?}", v.0);
}
The workaround is to uncomment the commented line and comment the one after. |
crlf0710
added
the
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
label
Jun 11, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-NLL
Area: Non-lexical lifetimes (NLL)
NLL-polonius
Issues related for using Polonius in the borrow checker
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Hello,
I have recently been pointed to this example:
To me, the code looks sane, and looks like it should compile with NLL enabled (as the borrow to
vec
ends at the end of theif
block, and shouldn't propagate to theelse
block), yet it looks like it doesn't.Hope that helps, and as always thank you for your work on
rustc
!The text was updated successfully, but these errors were encountered: