Skip to content

Last use analysis doesn't doesn't move out results of anonymous functions #1818

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

Closed
brson opened this issue Feb 12, 2012 · 0 comments
Closed

Comments

@brson
Copy link
Contributor

brson commented Feb 12, 2012

Both of these r's generate errors about copying noncopyable values, but they should be moves.

fn apply<T>(s: str, f: fn(str) -> T) -> T {                                                                                                                                   
    g(s) {|v|                                                                                                                                                                 
        let r = f(v);                                                                                                                                                         
        r                                                                                                                                                                     
    }                                                                                                                                                                         
}                                                                                                                                                                             

fn apply2<T>(s: str, f: fn(str) -> T) -> T {                                                                                                                                  
    g(s, fn&(v: str) -> T {                                                                                                                                                   
        let r = f(v);                                                                                                                                                         
        r                                                                                                                                                                     
    })                                                                                                                                                                        
}                                                                                                                                                                             

fn g<T>(s: str, f: fn(str) -> T) -> T {                                                                                                                                       
    f(s)                                                                                                                                                                      
}                                                                                                                                                                             

fn main() {                                                                                                                                                                   
}  
@ghost ghost assigned marijnh Feb 12, 2012
Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants