Skip to content
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

Doc: http://static.rust-lang.org/doc/tutorial-ffi.html sample does not compile #5876

Closed
mikedilger opened this issue Apr 14, 2013 · 1 comment

Comments

@mikedilger
Copy link
Contributor

New to rust, I can't debug it, but I tried the following changes to main without figuring it out:

fn main() {
    let args: ~[~str] = core::os::args();
    assert!(args.len()>1);

    /* This works */
    io::println( args[1] );

    /* This works too */
    io::println( sha1( ~"xyz" ) );

    /* This gives a compile error:
    "moving out of immutable vec content" */
    io::println( sha1( args[1] ) );
}

My rust compiled from git commit 5f13e9c

@thestinger
Copy link
Contributor

This is because it passes by-value, which will move values with destructors. It has to be passed as a slice or copied because os::args is immutable. I rewrote the FFI tutorial but it hasn't been regenerated by the documentation bot yet. Until then you can use https://github.com/mozilla/rust/blob/incoming/doc/tutorial-ffi.md

flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 28, 2020
Don't lint if it has always inline attribute

Don't trigger the lint `trivially_copy_pass_by_ref` if it has `#[inline(always)]` attribute.

Note: I am not particularly familiar with `inline` impacts, so I implemented this the way that if only `#[inline]` attribute is here (without `always`), the lint will still trigger. Also, it will still trigger if it has `#[inline(never)]`.
Just tell me if it sounds too much conservative.

Fixes: rust-lang#5876

changelog: none
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