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 removal of .as_str() when called on a &str #62642

Closed
estebank opened this issue Jul 13, 2019 · 0 comments · Fixed by #64739
Closed

Suggest removal of .as_str() when called on a &str #62642

estebank opened this issue Jul 13, 2019 · 0 comments · Fixed by #64739
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Given

fn make_lipographic(banned: char, line: &str) -> String {
    line.as_str().chars().filter(|&c| c != banned).collect()
}

fn main() {
    let passage = String::from("If Youth, throughout all history, had had a champion to stand up for it");
    assert_eq!(make_lipographic('e', &passage), passage);
}

we currently emit

error[E0599]: no method named `as_str` found for type `&str` in the current scope
 --> src/main.rs:2:10
  |
2 |     line.as_str().chars().filter(|&c| c != banned).collect()
  |          ^^^^^^ help: there is a method with a similar name: `as_ptr`

This is a possible simple WIP mistake when changing some binding from String to &str that we could preempt and avoid a pretty bad suggestion.

@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 P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Jul 13, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 7, 2019
Remove as_str if the type is already &str

Fix rust-lang#62642

r? @estebank

do you think the suggestion tip is good enough?
bors added a commit that referenced this issue Oct 7, 2019
Remove as_str if the type is already &str

Fix #62642

r? @estebank

do you think the suggestion tip is good enough?
@bors bors closed this as completed in a5d9310 Oct 7, 2019
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant