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

Suggest as_ref() in E0507 if applicable #61109

Closed
estebank opened this issue May 24, 2019 · 0 comments · Fixed by #61147
Closed

Suggest as_ref() in E0507 if applicable #61109

estebank opened this issue May 24, 2019 · 0 comments · Fixed by #61147
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. P-low Low priority

Comments

@estebank
Copy link
Contributor

Given:

pub struct LipogramCorpora {
    selections: Vec<(char, Option<String>)>,
}

impl LipogramCorpora {
    pub fn validate_all(&mut self) -> Result<(), char> {
        for selection in &self.selections {
            if selection.1.is_some() {
                if selection.1.unwrap().contains(selection.0) {
                    return Err(selection.0);
                }
            }
        }
        Ok(())
    }
}

rustc should suggest using selection.1..as_ref():

error[E0507]: cannot move out of borrowed content
 --> src/lib.rs:9:20
  |
9 |                 if selection.1.unwrap().contains(selection.0) {
  |                    ^^^^^^^^^^^
  |                    |
  |                    cannot move out of borrowed content
  |                    help: consider borrowing instead of moving: `selection.1.as_ref()`

cc #51100, #57158

From https://thenewwazoo.github.io/clone.html

@estebank estebank added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels May 24, 2019
Lonami referenced this issue in thenewwazoo/thenewwazoo.github.io May 24, 2019
@estebank estebank added E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. P-low Low priority labels May 25, 2019
@estebank estebank removed the E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. label May 25, 2019
bors added a commit that referenced this issue May 27, 2019
When encountering move error on an `Option`, suggest using `as_ref`

Fix #61109, cc #15457.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. P-low Low priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant