- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
... and trying to use foo afterwards, which triggers
error[E0382]: use of moved value:
foo
Example:
struct Bar;
impl AsRef<Bar> for Bar {
    fn as_ref(&self) -> &Bar {
        self
    }
}
fn foo<T: AsRef<Bar>>(_: T) {}
pub fn main() {
    let bar = Bar;
    foo(bar);
    let baa = bar;
}currently yields
rustc 1.17.0 (56124baa9 2017-04-24)
error[E0382]: use of moved value: `bar`
  --> <anon>:15:9
   |
14 |     foo(bar);
   |         --- value moved here
15 |     let baa = bar;
   |         ^^^ value used here after move
   |
   = note: move occurs because `bar` has type `Bar`, which does not implement the `Copy` trait
error: aborting due to previous error
I suggest that it should also contain
help: if you meant to borrow `bar` use `foo(&bar)`?
kennytm, estebank and tgross35
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.