Content-Length: 24542 | pFad | https://doc.rust-lang.org/std/iter/../clone/../../../std/../error_codes/./E0521.html

E0521 - Error codes index

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error code E0521

Borrowed data escapes outside of closure.

Erroneous code example:

#![allow(unused)]
fn main() {
let mut list: Vec<&str> = Vec::new();

let _add = |el: &str| {
    list.push(el); // error: `el` escapes the closure body here
};
}

A type annotation of a closure parameter implies a new lifetime declaration. Consider to drop it, the compiler is reliably able to infer them.

#![allow(unused)]
fn main() {
let mut list: Vec<&str> = Vec::new();

let _add = |el| {
    list.push(el);
};
}

See the Closure type inference and annotation and Lifetime elision sections of the Book for more details.









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/std/iter/../clone/../../../std/../error_codes/./E0521.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy